Skip to content

app/: per-organization credit override for staff, with its reminder email and heartbeat (sc-8900) - #144

Merged
ndbroadbent merged 1 commit into
mainfrom
app-credit-override
Dec 3, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
app-credit-override

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Staff can raise an organization's monthly credits until a date, for example for a big open source project that needs more than the standard 1,000,000 open source pool (sc-8900, from marketing). This is PR (c) of the staff tooling port. The admin MCP tool set_credit_override comes with or after the /mcp/admin PR, which calls domain::credit_overrides::set / clear.

Design

  • Schema (migration 2026_12_04_100000_credit_overrides):
    • credit_overrides holds at most one override per organization: credits, until (a UTC date, inclusive), label, reason, set_by.
    • credit_override_audit has a row for every change: user (or NULL for the console), actor (staff email or console), old_allowance, new_allowance, the override set (all NULL when cleared), reason and created_at.
  • What it overrides: the plan's monthly allowance (Plan::included_credits), and nothing else.
    • While the override applies, the allowance is max(plan, override), so it only ever raises it.
    • The open source pool still comes first and pack credits last.
    • This applies everywhere the allowance is read: credits_left, out_of_credits, take (spending), blocked, the out-of-credits build error and usage.
  • Expiry: the override is read whenever the allowance is, so the day after until the organization is back on its plan's allowance and no job has to run. Credits already used that month still count.
  • Setting it:
    • domain::credit_overrides::set(Change { org, credits, until, label, reason }, Actor::Staff(&user) | Actor::Console) and clear(org, reason, actor).
    • Both return laravel::Result<Result<serde_json::Value, String>>. The inner Err is a refusal to show as it is: an unknown organization, a reason under 5 characters, an end date not after today, credits that don't raise the plan's allowance, an unlimited plan, or a label over 60 characters.
    • The answer is {org, override, allowance, was: {allowance, override}}.
    • Setting the same values again just records another audit row.
  • Console: org:set-credits --org <slug> --credits <n> --until <YYYY-MM-DD> [--label "..."] --reason "...", and --clear --reason "...".
  • Usage answer (/api/ui, MCP get_organization): included_credits is the allowance in effect. credit_override: {credits, until, label} appears only while an override applies, so existing goldens don't change. Staff's reason is never shown to the customer.
  • Billing page: one muted line under the plan meter: "Open source sponsorship: 3,000,000 a month until 1 Jun 2027, then 25,000." The label defaults to "Raised by VisualCI".
  • Reminder:
    • A new email kind, credit_override_ending, goes to the organization's admins. It has no opt-out and is in the staff email preview's samples.
    • credits:override-reminders runs daily at 06:00 UTC. It queues the email for every override whose until is within 7 days.
    • The dedupe key is per organization and end date, so a repeated run sends nothing. An override extended to a new date gets a new reminder.
    • It pushes VISUALCI_CREDIT_OVERRIDES_HEARTBEAT_URL / _TOKEN (Heartbeat::CreditOverrides), and a run that errors fails the heartbeat.
    • The env-vars docs page and .env.example were regenerated.
  • Docs:
    • docs/design.md (Billing) and docs/deploy.md (schedule and commands).
    • The public credits reference says that large open source projects can ask for more.

What changes in this PR's VisualCI build

  • screenshots:seed gives Side project (Free) an override: 3,000,000 a month until 2027-06-01, labelled "Open source sponsorship".
  • app/billing/free should change: "of 3,000,000 credits on Free", a shorter meter fill, and the new line "Open source sponsorship: 3,000,000 a month until 1 Jun 2027, then 25,000."
  • The organization list's usage figure for Side project (… / 3,000,000) changes wherever that page is captured.
  • app/billing/team (Acme) shouldn't change.
  • A new email snapshot appears: credit_override_ending-acme-s-extra-visualci-credits-run-until.

Tests (on agents-build-1)

  • cargo fmt --all --check and cargo clippy --locked --workspace --all-targets -- -D warnings are clean.
  • cargo test --locked -p visualci-app: 261 passed. The rest of the workspace passes too.
  • The new tests are in app/tests/credit_overrides.rs:
    • setting an override writes the audit rows (staff, console and clear), and the usage answer and spending use the raised allowance;
    • an ended override falls back to the plan's allowance (usage, out_of_credits, blocked);
    • the domain refusals;
    • org:set-credits sets, clears, and refuses an unknown organization, a past date and a missing reason;
    • the reminder goes once, to admins only and only for overrides ending within the week, and again after an extension;
    • the email's text.
  • The screenshots_seed test checks the seeded override.
  • frontend: pnpm build and pnpm test pass (44 tests, including the new credit-override.test.ts), and node scripts/skills.mjs --check passes.

Deploy note

The heartbeat only alerts once its Gatus external endpoint exists and the VISUALCI_CREDIT_OVERRIDES_HEARTBEAT_* secrets are set. That needs an infra change, like the other heartbeats.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@visualci-com

visualci-com Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #215 · 2 added, 339 unchanged · approved by visualci features agent for Nathan Broadbent

This PR vs base: 8 changed since #187, across 2 builds

Snapshot Before After
emails/credit_override_ending-acme-s-extra-visualci-credits-run.html (added) text text, see the build
emails/credit_override_ending-acme-s-extra-visualci-credits-run.txt (added) text text, see the build

docspring/visualci · journeys · build #213 · 12 unchanged · no changes

This PR vs base: nothing since #188, across 2 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

…mail and heartbeat (sc-8900)

Staff raise an organization's monthly credits until a date (a big open source project beyond the 1M pool): the
override replaces the plan's monthly allowance while it applies (never lowering it), falls back on its own the day
after `until`, is set with `org:set-credits` (and the admin MCP tool, next), records every change in
credit_override_audit, shows on the billing page by its public label, and its organization's admins get an email a
week before it ends (`credits:override-reminders`, daily, VISUALCI_CREDIT_OVERRIDES_HEARTBEAT_*).
@ndbroadbent
ndbroadbent merged commit 01095a2 into main Dec 3, 2026
14 checks passed
@ndbroadbent
ndbroadbent deleted the app-credit-override branch December 3, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant