Public: anyone can read this; the crew can change it.

Spend 1: a monthly budget per cloud account, one notice at 80% and one at 100% #18121

opened this

Merged 16h 53m ago, live in production

An admin can now set a monthly dollar budget on each cloud account. They are told once at 80% and once at 100% of the month's projected spend, and nothing is stopped. I ran bun x tsc --noEmit, the gate and the touched suites, and they pass.

Notes

opened this

An admin can now set a monthly dollar budget on each cloud account. They are told once at 80% and once at 100% of the month's projected spend, and nothing is stopped. I ran bun x tsc --noEmit, the gate and the touched suites, and they pass. I didn't run the whole suite or try it on a preview.

What changed

  • Setting it: "Set budget" sits beside the ceiling on Cloud accounts (/settings/cloud). The same action backs a new set_budget verb on the cloud_account MCP tool and a new "Cloud budgets" terminal screen. It takes whole dollars from 1, an empty value clears it, and only an admin may set it.
  • Spend measure:
    • For DigitalOcean, Hetzner and OVHcloud it is the forge's list-price estimate of what it made.
    • For AWS and Azure it is the vendor's billed spend so far this month, projected by days (billed × days in month ÷ days elapsed).
    • Every figure says whether it is billed or an estimate, and as of when.
  • Unknown, never $0: a bill never read, a bill that failed to read, prices never read, a machine or database with no price, or a cloud whose cost the forge doesn't read all show "spend unknown: why". The first figure on /infra for a cloud the forge makes machines on reads "unknown" in those cases too.
  • Notices: the new hourly cloud-budget duty writes one row per account, month and percent (80 or 100) to a new cloud_budget_notice table, then raises an event. The notifier tells each admin who has set a notification URL from that row. A second reading in the month, or a restart, sends nothing. A reading that jumps past 100% sends only the 100% notice, and 80% is never sent after 100%. A new month starts again.
  • Where it shows: /infra shows the budget line under each account's figure. Any account with a budget is listed there, whatever its cloud. The terminal Infrastructure line carries the same words.
  • Marks and docs: /settings/cloud/budget is marked admin in src/http/marks/settings.json. The how-to is docs/features/cloud-budget.md.

Tests

test/cloud-budget.test.ts crosses 80% and 100% for both billed (AWS) and estimated (DigitalOcean) accounts, with exactly one notice at each. It also covers a second reading, a restart through the notifier, a month rollover, and unknown versus $0. test/tui-budgets.test.ts covers the terminal screen. I changed one existing expectation in test/infra-page.test.ts: the meter now carries makes and budget, so it uses toMatchObject.

What I chose not to do

  • Delivery: the notice is claimed when it is detected, not when it is delivered. If a restart lands between claiming and the push, or the push fails, that notice is lost rather than sent twice. The cause is the double-notice risk you named.
  • Billed numbers: there is no billed number for DigitalOcean, Hetzner or OVHcloud, because the forge reads none for them. Those accounts always show the forge's estimate.
  • Gate note: scripts/gate.ts prints similarity notes (setBudget against setCeiling, and the like). They are not refusals. I left the budget code parallel to the ceiling code on purpose.

To try

As an admin, open /settings/cloud, set a budget on an account, then open /infra to see the line under that account's figure. In the terminal, open the palette, pick "Cloud budgets" and press b.

Reused: accountReads, accountCents, priced and readTimes for the readings, the notifier's ask-line path, setCeiling's action shape, and promptScreen for the terminal prompt.

Closes #18101

4 earlier comments · 1 event
commented

An admin can now set a monthly dollar budget on each cloud account. They are told once at 80% and once at 100% of the month's projected spend, and nothing is stopped. I ran bun x tsc --noEmit, the gate and the touched suites, and they pass. I didn't run the whole suite or try it on a preview.

What changed

  • Setting it: "Set budget" sits beside the ceiling on Cloud accounts (/settings/cloud). The same action backs a new set_budget verb on the cloud_account MCP tool and a new "Cloud budgets" terminal screen. It takes whole dollars from 1, an empty value clears it, and only an admin may set it.
  • Spend measure:
    • For DigitalOcean, Hetzner and OVHcloud it is the forge's list-price estimate of what it made.
    • For AWS and Azure it is the vendor's billed spend so far this month, projected by days (billed × days in month ÷ days elapsed).
    • Every figure says whether it is billed or an estimate, and as of when.
  • Unknown, never $0: a bill never read, a bill that failed to read, prices never read, a machine or database with no price, or a cloud whose cost the forge doesn't read all show "spend unknown: why". The first figure on /infra for a cloud the forge makes machines on reads "unknown" in those cases too.
  • Notices: the new hourly cloud-budget duty writes one row per account, month and percent (80 or 100) to a new cloud_budget_notice table, then raises an event. The notifier tells each admin who has set a notification URL from that row. A second reading in the month, or a restart, sends nothing. A reading that jumps past 100% sends only the 100% notice, and 80% is never sent after 100%. A new month starts again.
  • Where it shows: /infra shows the budget line under each account's figure. Any account with a budget is listed there, whatever its cloud. The terminal Infrastructure line carries the same words.
  • Marks and docs: /settings/cloud/budget is marked admin in src/http/marks/settings.json. The how-to is docs/features/cloud-budget.md.

Tests

test/cloud-budget.test.ts crosses 80% and 100% for both billed (AWS) and estimated (DigitalOcean) accounts, with exactly one notice at each. It also covers a second reading, a restart through the notifier, a month rollover, and unknown versus $0. test/tui-budgets.test.ts covers the terminal screen. I changed one existing expectation in test/infra-page.test.ts: the meter now carries makes and budget, so it uses toMatchObject.

What I chose not to do

  • Delivery: the notice is claimed when it is detected, not when it is delivered. If a restart lands between claiming and the push, or the push fails, that notice is lost rather than sent twice. The cause is the double-notice risk you named.
  • Billed numbers: there is no billed number for DigitalOcean, Hetzner or OVHcloud, because the forge reads none for them. Those accounts always show the forge's estimate.
  • Gate note: scripts/gate.ts prints similarity notes (setBudget against setCeiling, and the like). They are not refusals. I left the budget code parallel to the ceiling code on purpose.

To try

As an admin, open /settings/cloud, set a budget on an account, then open /infra to see the line under that account's figure. In the terminal, open the palette, pick "Cloud budgets" and press b.

Reused: accountReads, accountCents, priced and readTimes for the readings, the notifier's ask-line path, setCeiling's action shape, and promptScreen for the terminal prompt.

commented

I fixed the failing audience-coverage test and pushed it. cloud.budget and cloud.budget_notice were new event kinds that nobody had classified, so the scan failed. Both are now listed in src/core/event_audience.ts next to cloud.ceiling.

This pull adds a monthly budget per cloud account, with one notice at 80% and one at 100% of it. Changing a budget and the notices are spend configuration, so both kinds are admin-only. Readers and guests never see them.

Locally, test/event-audience-coverage.test.ts passes (5 tests) and bun x tsc --noEmit is clean. I did not run the full suite; the forge's check runs it on this push.

The gate printed notes (long comment lines, near-duplicate functions such as setBudget and setCeiling) but no failure. I left them alone and did not run --fix.

To try it, open the cloud accounts page or the budgets screen in the terminal, set a budget on an account, and check that the event appears only in the admin feed.

commented

This push fixes the three failing checks. I ran the two test files that held them (test/palette-roster.test.ts and test/mcp-size.test.ts) and both pass. I did not run the full suite. Before the push, tsc --noEmit printed nothing and bun scripts/gate.ts --fix ran.

  • MCP size test: the dollars property on the cloud_account tool had a 70-byte description, over the 60-byte limit. I shortened it to "set_ceiling; set_budget (omit to clear it)." in src/http/mcp/tools/cloud_account.ts.
  • Palette roster tests: the new "Cloud budgets" screen now shows up in the site-admin roster. I added the entry to the expected lists in test/palette-roster.test.ts, one for the person roster and one for the agent roster. The tests were out of date, not the code.
  • Gate: --fix rewrapped long comments in src/tui/screens/budgets.ts and test/tui-budgets.test.ts. I committed that as a separate commit and pushed it. I re-ran test/tui-budgets.test.ts after that commit and it passes.

I left the gate's "one implementation?" similarity notes alone. They ask whether a few near-duplicate functions should be merged, and they don't block the push.

To try it, open the Cloud budgets screen as a site admin.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was src/generated/screens.ts. I took main's version and re-ran bun scripts/own-source.ts to regenerate it, so it now lists both main's screens and the cloud budgets screen.

I ran tsc --noEmit and four test files: test/own-source.test.ts, test/palette-roster.test.ts, test/mcp-size.test.ts and test/tui-budgets.test.ts. All 32 tests pass. I did not run the full suite, so the forge's check on this push is the first full run of the merged branch.

bun scripts/gate.ts --fix changed nothing. The gate's note about long comment lines is in files from main, not this pull. I left them alone, since the nightly rewrap handles them on main.

🤖 Generated with Claude Code

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

Both requested fixes are in and pushed.

  • One cap. MAX_BUDGET_DOLLARS in src/cloud/budget.ts is now 100,000. The max on the web input in src/web/pages/cloud.ts is also 100000. The MCP schema already said 100000, so the page, setBudget and the MCP tool now agree. The commit says Direction: one cap for a monthly budget so an agent and the page agree (#18101).
  • Stray edit. const PLACE = /^… in src/actions/cloud_ceiling.ts has its space back.

Not done: I left the optional standingWords change alone. Hiding "no budget set; spend unknown: …" on /settings/cloud and /infra would make those two pages differ from the terminal screens, which show the same line. That would break the "terminal shows what the page shows" rule. I'd rather change all three together in a separate pull.

Checks:

  • bun x tsc --noEmit is clean.
  • The budget tests pass (23), including test/subscription-budget.test.ts, which checks that $1,000,000 is refused.
  • bun scripts/gate.ts exits 0. It only prints similarity hints and a note about long comments in files this pull doesn't touch.
  • I did not run the full suite.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs