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

Stop and Delete a cloud machine or volume from the cost row, each confirmed only by typing its name #18187

opened this

Merged 14h 3m ago, live in production

A machine or volume on a write-allowed DigitalOcean or Hetzner account now has Stop and Delete on its cost row, and nothing runs until the person types its name, for Stop as for Delete.

Notes

opened this

A machine or volume on a write-allowed DigitalOcean or Hetzner account now has Stop and Delete on its cost row, and nothing runs until the person types its name, for Stop as for Delete. The nine tests in test/spend-end.test.ts, the gate (0 failing), tsc, bun scripts/design-lint.ts and a spot-check of the rules named in the issue (including mcp-size and unused-exports) pass. I did not run the whole suite.

What changed

  • Branch: the #18067 branch was not on the forge, so I wrote this fresh from main. The budget half was never carried over.
  • Plan: src/actions/spend_end.ts builds the plan. It says what is deleted, what it costs now with its source and read time, what is lost and what keeps billing. It lives in a new cloud_end_plan table for 30 minutes and runs once. It does not touch the cloud.
  • Name check: confirmEnd refuses unless typed === plan.confirmWord. A refused attempt reaches no vendor and leaves the plan open.
  • Refusals: a read-only account is refused at plan time with an audit row. Each end writes the gated fetch's audit row and a cloud.end event. Calls go through withCloud, driverOf and gone.
  • Page: forms for Stop and Delete sit on the /infra costliest table rows and on a resource's own pane, posting to /infra/end/plan and /infra/end/confirm. The confirm page shows the name field and the danger button for both actions. I added one allow-list entry in test/danger-buttons.test.ts for that button, because it is behind a plan and a typed name rather than confirmAction.
  • Terminal: X (stop) and D (delete) on a row in cloudtree.ts open the plan, then a prompt for the name. What is typed is passed on as typed; plan.confirmWord is never passed.
  • MCP: infra plan with want: {end, action} returns a plan id, and apply takes names: ["<name>"]. It adds no new tool and no schema property, and mcp-size is unchanged.
  • Docs: a section in docs/features/infra.md.

Choices to check

  • Stop vs Delete: Stop deletes the machine and its own disk; attached volumes stay and the plan says they keep billing. Delete also deletes the attached volumes after the machine. A volume that is attached to something is refused.
  • Pinned forges: a machine or volume that a pinned forge's row owns is not offered; that is End on its page.
  • Bad dependent volume: if a dependent volume will not detach within the wait, the answer lists it as left behind.
  • Terminal keys: S was already the sort key, so Stop is X.

Left out

  • Other clouds (AWS, Cloudflare, Azure, OVH) and Hetzner/DigitalOcean resource kinds other than machine and volume.
  • Waiting on the vendor to confirm a machine is gone.

Reused: withCloud, caller, gone, driverOf, recordAudit, confirmScreen and promptScreen. The gate noted endForms against fileTab and keys against cloud-tree.test.ts's press as near-duplicates; I left both.

Try it: with a write-allowed DigitalOcean or Hetzner account, open /infra, press Stop beside a machine, read the plan, then type a wrong name, then the right one. In the terminal, open Cloud resources, move to a machine, and press X.

[
  {"go": "/infra", "look": "A machine on a write-allowed DigitalOcean or Hetzner account, in the costliest table", "expect": "Stop and Delete buttons beside its name; a volume has only Delete; read-only and AWS rows have none"},
  {"go": "/infra", "look": "Press Stop on a machine", "expect": "A plan page lists what is deleted, the cost with its source and read time, what is lost, what keeps billing, and the expiry; no vendor call has happened"},
  {"go": "/infra", "look": "On the plan, submit the name field empty, then with a wrong name", "expect": "The plan page returns with a refusal; nothing is deleted. The field and the red button are there for Stop as for Delete", "ask": "Is the confirm wording clear enough for a Stop that deletes a disk?"},
  {"go": "/infra", "look": "Open a machine's own page", "expect": "Stop and Delete beside Ask about this"}
]

🤖 Generated with Claude Code

Closes #18182

Show 1 earlier items

7 earlier comments
commented

Admins can now stop or delete a cloud machine or volume from its cost row, and each action needs the resource's name typed first. This push fixes the failing check, which came from the new cloud.end event having no audience classification.

src/actions/spend_end.ts records a cloud.end event for each stop or delete, and src/core/event_audience.ts didn't classify that kind. The event names the owner's cloud account, so I classified it for admins only, alongside the other cloud spend and configuration events. I did not add a reader-visible variant.

test/event-audience-coverage.test.ts passes locally (5 tests), and bun x tsc --noEmit is clean. I did not rerun the full suite, so the forge's check on this push is the next confirmation.

bun scripts/gate.ts --fix changed nothing. It reported only advisory notes about long comments in other files and similar-looking helpers in the new tests, so I left those alone.

To try it, open the cloud cost tree as an admin and use Stop or Delete on a machine or volume row. A non-admin should not see the buttons, and the action refuses a mistyped name.

The pushed commit carries No door: an audience classification, no page, action, route or tool changes.

commented

Stop and Delete for a cloud machine or volume are done. Each is held to the resource's name typed first, and only admins can plan or confirm one. This push fixes one of the two failures in the last check; the other I could not reproduce.

  • Fixed (account-purge test): cloud_end_plan.user_id named a user without a cascade, so deleting an account would have left plan rows behind. It now has REFERENCES user(id) ON DELETE CASCADE. The migration isn't on main yet, so I edited it in place and regenerated its pin.
  • Not fixed (survival performance test in test/game-mods.test.ts): this failure is unrelated to the change, which touches nothing under game mods. It passes alone (36 of 36) and failed in the check after waiting 20 s for text on screen, which looks like a timeout under a loaded runner. If it fails again on the next check, it needs a look separately.
  • Checks run here: test/account-purge.test.ts and test/spend-end.test.ts pass (24 tests), and bun x tsc --noEmit is clean. I did not run the full suite, so the forge's check on this push is the next confirmation.
  • Left out: cloud.end stays admin-only in the event audience, with no reader-visible variant.
  • To try it: open the cloud cost tree as an admin and use Stop or Delete on a machine or volume row. A non-admin sees no buttons, and a mistyped name runs nothing.
commented

This pull now takes main's Stop and Delete (#18170) and adds one thing: a Stop also asks for the resource's name typed back. The merge conflicts are gone.

Main had already landed its own Stop and Delete in src/actions/cloud_end.ts, and the old version of this branch conflicted with it. The merge commit takes main's tree outright and drops this branch's spend_end.ts version. Main's version had Stop as a single confirm, with only Delete asking for the name, which is what this issue changes.

  • Server: performEnd now refuses a missing or wrong name for Stop as well as Delete. A refused Stop reaches no vendor call.
  • Web: the plan page shows the name field and the danger button for Stop too.
  • Terminal: src/tui/screens/cloud_end.ts always asks for the name, for Stop as well as Delete. It passes only what was typed.
  • Docs: docs/features/cloud-end.md says both ask for the name.
  • Tests: the Stop test in test/cloud-end.test.ts now covers Stop with no name, Stop with a wrong name, and Stop with the right one. A page test checks that Stop's form has the name field. I did not run the full suite.
  • Checks: test/cloud-end.test.ts (11 pass), tsc --noEmit, design-lint and gate.ts are clean.

Not done:

  • MCP tool: main has no MCP tool for ending a resource, so the issue's "MCP apply with no name" test has no tool to test.
  • Cloud audit: I did not look at whether main's cloud.end event handling covers what the issue lists, so the earlier cloud.end commits on this branch are not carried over.
  • Plan lifetime: plans don't expire after 30 minutes. Main's plans are stateless and carry a digest of what the cloud was last read as, so there's no process-wide plan store.

To try: as an admin, open a machine under /infra, press Stop…, and the confirm needs the machine's name. In the terminal's Cloud resources screen, x plans a stop and X a delete.

[{"go":"/infra","look":"open a machine on a write-allowed DigitalOcean or Hetzner account and press Stop…","expect":"the plan page has a 'Type <name> to stop it' field and a danger Stop button; submitting it empty or with a wrong name is refused and nothing stops"},{"go":"/infra","look":"press Delete… on a volume","expect":"the same name field, 'Type <name> to delete it'"}]

🤖 Generated with Claude Code

commented

The branch now merges with main and is pushed. The change is smaller than before: it adds the name-typed Stop and a cloud.end event on top of main's Stop and Delete (#18170).

Main had landed its own plan-and-confirm Stop and Delete while this branch built a parallel one. The remote branch also already carried a resolution that took main's version and made Stop ask for the name. I merged that in and kept the one thing it lacked.

  • What changed:
    • Name typed for Stop: a Stop needs the resource's name typed back, as a Delete does, because it deletes the machine's own disk. This holds on the server (src/actions/cloud_end.ts), on the web confirm page and in the terminal prompt. The web page shows the name field and a danger button for both.
    • cloud.end event: each Stop or Delete writes a cloud.end event, classified admin-only in src/core/event_audience.ts.
  • Tests: a Stop with no name or the wrong name is refused and nothing reaches the vendor; with the right name it runs and writes one cloud.end event. The cloud-end, audience-coverage and account-purge tests pass (82), tsc is clean and the gate is clean. I did not run the full suite, so the forge's check on this push is the next confirmation.
  • Dropped: my parallel implementation, the cloud_end_plan table and its migration, and test/spend-end.test.ts. Main's plan is stateless and carries a digest instead. The account-purge cascade fix from earlier went with that table.
  • Not done: the issue also asked for Stop and Delete on /infra's costliest table. Main offers them only on a resource's own page, and I did not add them to the table. The MCP tool's apply was also not changed or tested for the missing-name case.
  • To try it: as an admin, open a machine under /infra on a write-allowed account and press Stop…. The confirm asks for the machine's name, and a wrong name is refused. In the terminal, x and X on a resource ask the same.
commented

This pull adds Stop and Delete to /infra's costliest table, adds a 30-minute plan expiry, and writes a cloud.end event for refused attempts too. It does not touch the MCP apply, for the reason below. bun x tsc --noEmit, design-lint and the cloud-end and cloud-tree tests pass. I did not run the full suite. The /infra row links were not tried against the running preview.

What changed

  • Cost rows: each row on the costliest table now has a "Stop · Delete" pair beside its name. Each link opens the same name-typed plan as the resource page, and nothing runs from the table. Rows on read-only accounts, unsupported clouds or non-machine/volume kinds get no links. The write flag is read once per account per page, so the 2,000-resource query-count test still holds.
  • Expiry: the plan's digest is now <time shown>.<hash>, with the time inside the hash. A confirm after 30 minutes, or with a digest the forge didn't issue, is refused before the typed name is checked and before any vendor call. No new store.
  • Events for refusals: cloud.end is now written for every attempt. That covers a read-only or unsupported account, a stale or changed plan, and a missing or wrong name. A refused one carries ok: false and a refused reason, and each also writes its audit row. Tests check this and the expiry.
  • Docs: docs/features/cloud-end.md is updated.

Not done

  • MCP apply: there is no MCP tool that stops or deletes a cloud resource on this head. The infra tool's apply only builds a plan the forge showed, and performEnd, which holds the typed-name check, is reached only by the web route and the terminal. I did not invent a tool just to put a check on it. If an MCP end is wanted, it should be a separate change that calls performEnd. The check and its refusal-event path would then apply to it without change.
  • Terminal: unchanged. x and X on a selected cost row already plan and ask for the typed name.
  • Gate note: it says costliestTable resembles workSection in org.ts (0.63 similarity). It is a note, not a failure, and I left the two separate.

I could not name the dead-code and module-state tests from your list on the touched modules. This change adds no new export and no module-level Map, Set or array that a function writes to. The per-request map is local to a closure.

[
  {"go": "/infra", "look": "Beside each machine or volume name in the table, on a write-allowed DigitalOcean or Hetzner account: 'Stop · Delete' (volumes: Delete only)", "expect": "Links present; none on read-only accounts or on rows that are not machines or volumes"},
  {"go": "/infra, then press Stop on a machine row", "look": "The plan: Will, Cost now, Lost, Kept, a field 'Type <name> to stop it', a danger button", "expect": "Submitting with no name or a wrong name shows the refusal and nothing stops"},
  {"go": "The same plan page, left open for over 30 minutes, then submit the right name", "look": "The flash message", "expect": "'That plan is more than 30 minutes old…: review the plan again.' and nothing reaches the cloud"}
]

🤖 Generated with Claude Code

commented

On /infra's costliest table, a machine or volume on a write-allowed account gets Stop · Delete beside its name. Each link opens a plan, and nothing runs until the resource's name is typed back, for a Stop as well as a Delete. This round fixes the four review findings.

  • MCP tool (box 2): a new cloud_end tool in src/http/mcp/tools/cloud_end.ts. It is a thin caller of planEnd and performEnd:
    • plan with an act (stop or delete) and an id (as infra list gives it) returns the plan and its digest.
    • apply needs that digest and the name typed back.
    • apply needs an admin-scope token. It is marked tier: "delete", so the forge's own agent can never apply one, and it is added to test/delete-tier.test.ts.
    • A new test plans through MCP, then shows that apply with no name, with a wrong name, or with a read-only token is refused and nothing reaches the vendor.
  • Read-only refused at plan time (box 5): planEnd now writes the refused audit row and a refused cloud.end event as soon as a read-only account's plan is asked for. performEnd reads the plan through an internal step that writes nothing, so a confirm does not write the plan-time row a second time. A new test asks for a read-only plan and checks that exactly one audit row and one refused event are written, with no vendor call.
  • Plan expiry: the digest is now an HMAC keyed with the forge's per-boot secret (app.hookSecret). A client can no longer mint a fresh time stamp for an old plan, and a restart expires every plan shown before it. A new test recomputes the old unkeyed sha256 over a fresh stamp and is refused; it would pass the check without the key. docs/features/cloud-end.md says the typed name is still the real gate.
  • row-ends: styled in src/web/style/components.ts with tokens only: muted text, --accent on the links only. Where a mouse can hover, the pair stays transparent until its row is hovered or holds keyboard focus. On touch it always shows, and the links stay in the tab order and work without JavaScript. Because only opacity changes, the row never moves. The class is documented in the new docs/design/areas/infra.md.

The how-to docs/features/cloud-end.md now names the MCP door and the plan-time refusal.

Left out: planEnd audits only the read-only refusal at plan time. Other plan-time refusals (an attached volume, a pinned forge's own machine) are audited only when someone tries to confirm them, so opening a plan page doesn't fill the audit log.

Checks run: bun x tsc --noEmit passes, bun scripts/design-lint.ts passes, and bun scripts/gate.ts --explain has 0 failing rules (2 notes). test/delete-tier.test.ts failed until cloud_end was added to its roster, as above. bun scripts/fast.ts named 2,872 test files, too many to run here, so I ran the 21 suites closest to this change and all pass. They include test/cloud-end.test.ts (16), cloud-tree, delete-tier, the mcp- and llms-tools suites, design-, both-doors, unused-exports and module-state.

To try it: on the preview, open /infra as an admin and hover a costly machine's row. Stop opens the plan with the name field and the danger button. Over MCP:

  • cloud_end {action:"plan", act:"stop", id:"<id from infra list>"}
  • then cloud_end {action:"apply", act:"stop", id:…, digest:…} with no name. It is refused with "Type <name> to stop it".
[
  {"go": "/infra", "look": "a machine's row in the costliest table, hovered then tabbed to", "expect": "Stop · Delete appears muted beside the name with accent links; the row does not shift"},
  {"go": "/infra/end/stop/<cloud>/<account>/<project>/<machine id>", "look": "the plan", "expect": "Will, Cost now, Lost and Kept rows, a name field and a danger Stop button"},
  {"go": "/settings/cloud/audit", "look": "after opening a plan on a read-only account", "expect": "a refused row whose plan starts with the read-only refusal", "ask": "Is auditing at plan time noisy enough to matter?"}
]

🤖 Generated with Claude Code

commented

Stop and Delete for a cloud machine or volume (#18182), now merged with current main. A stop also asks for the resource's name typed back, because it deletes the machine's own disk. A plan can be confirmed for 30 minutes: its digest carries the time it was shown, keyed with the forge's per-boot secret. Every attempt is audited and records a cloud.end event, whether it was refused or done. The costliest table on /infra gets a Stop · Delete pair on each row. Over MCP, the cloud_end tool does the same: plan reads, apply acts.

What fixed the red check:

  • cloud_end asks first: it is now on the list of tools that ask first (crew/conversation_confirm.ts), asking on apply the way infra's apply does. It also has its sentence in crew/conversation_ask.ts, though its apply is in the delete tier and a chat is refused it before anything is asked. It is now in the MCP tool list in test/mcp-forge-protocol.test.ts.
  • Merge with main: the apps-feedback failure was a test that exists only on main. Merging brought in #18206, which added infra end, a second MCP way to stop or delete. It ran into this pull's rules in two places:
    • It cut the digest at 32 characters; it now takes 80.
    • It applied a stop without the name typed; it now asks for want.typed on a stop as on a delete, and its plan returns name. Its doc string and docs/features/cloud-end.md say so.

Test changed on purpose: test/mcp-cloud-cost.test.ts expected the old 16-hex digest and a stop without a typed name. It was right for main's rules, which this pull changes, so it now expects the stamped digest and a refused untyped stop.

Left as is:

  • cloud_end and infra end are two MCP ways to do the same thing. Folding one into the other is a separate decision.
  • From the forge's own agent, infra end's stop is still held for the person's yes, as on main. cloud_end's apply is never run from a chat at all.

Checks: the gate and bun x tsc --noEmit pass. The 9 test files covering this change pass (148 tests), and the 41 cloud, infra and MCP tool files pass apart from one: cloud-inventory's redirect test failed once when run alongside the others, then passed on its own here and on main. It is not changed here. The fast script named 2,930 files because of the merge, so I didn't run the whole list; the forge's check runs the full suite.

To try it: on the preview, open /infra and pick Stop… on a costliest row; the plan asks for the name typed back. Over MCP: infra {action:"end", id, want:{act:"stop"}}, then the same call with want.digest and want.typed.

🤖 Generated with Claude Code

commented

Left #18182 open: 1 unticked item remain (On /infra's costliest table and on a resource's own page, a machine or volume on a write-allowed DigitalOcean or Hetzner account has Stop and Delete. Pressing either one shows a plan (src/actions/spend_end.ts). The plan says what is deleted, what it costs now with its source and read time, what is lost, and what keeps billing. It expires after 30 minutes.).

Sign in to join this conversation.

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

Keyboard shortcuts

Docs