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

Suspension, removal and sign-out close streams held on hosted child forges #14985

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

When an account is suspended or removed, or a browser is signed out, the streams it holds open on a hosted child forge served in-process now close. That covers event streams, app sockets and git transfers in progress. Until now they stayed open until the client disconnected.

Notes

shipped production is serving it deploy 6b7374e

opened this

When an account is suspended or removed, or a browser is signed out, the streams it holds open on a hosted child forge served in-process now close. That covers event streams, app sockets and git transfers in progress. Until now they stayed open until the client disconnected. This closes the deepsec finding from #14765.

What changed (src/http/server.ts)

  • The code in serve() that ends what an account holds open is now one function, enforceStanding(app). It listens for account.suspended, account.removed and session.ended on the forge's bus and closes matching streams at once. A timer also checks the forge's database (sweepStanding), which catches a change written by another process. Matching is by account and session id, not by scanning every stream. serve() calls it for its own forge.
  • forgeHttp(child) now calls enforceStanding(child) too. Its close() used to do nothing. Now it stops the listener and the timer, and letGo already calls it when a child closes or the server stops.
  • The issue pointed at src/http/caller.ts, but that file didn't need to change: it already keeps one list of held streams per forge database. What was missing was anything closing a child's streams, so the fix is in server.ts.

Test (test/standing-hosted-child.test.ts) It opens /events through forgeHttp(child) and checks that the stream ends in three cases:

  • the account is suspended on the child;
  • the browser is signed out on the child;
  • the suspension is written by a second process on the child's data, so only the child's timer can catch it.

All three fail against main's server.ts and pass with the change.

Checks run: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2,508 test files, too many to run here, so I ran the suites that cover this change: standing-every-process, standing-hosted-child, standing-live, standing-rule, standing, hosted-child-cells, hosted-child-counters, hosted-child-crew, sse and mcp-account-suspend. 49 pass, 0 fail.

Left out: children that run in their own cell are not covered here; each one runs its own serve().

Try it: on a hosted child, open /events while signed in, then suspend that account from the child's admin. The stream ends.

🤖 Generated with Claude Code

Closes #14963

commented

When an account is suspended or removed, or a browser is signed out, the streams it holds open on a hosted child forge served in-process now close. That covers event streams, app sockets and git transfers in progress. Until now they stayed open until the client disconnected. This closes the deepsec finding from #14765.

What changed (src/http/server.ts)

  • The code in serve() that ends what an account holds open is now one function, enforceStanding(app). It listens for account.suspended, account.removed and session.ended on the forge's bus and closes matching streams at once. A timer also checks the forge's database (sweepStanding), which catches a change written by another process. Matching is by account and session id, not by scanning every stream. serve() calls it for its own forge.
  • forgeHttp(child) now calls enforceStanding(child) too. Its close() used to do nothing. Now it stops the listener and the timer, and letGo already calls it when a child closes or the server stops.
  • The issue pointed at src/http/caller.ts, but that file didn't need to change: it already keeps one list of held streams per forge database. What was missing was anything closing a child's streams, so the fix is in server.ts.

Test (test/standing-hosted-child.test.ts) It opens /events through forgeHttp(child) and checks that the stream ends in three cases:

  • the account is suspended on the child;
  • the browser is signed out on the child;
  • the suspension is written by a second process on the child's data, so only the child's timer can catch it.

All three fail against main's server.ts and pass with the change.

Checks run: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2,508 test files, too many to run here, so I ran the suites that cover this change: standing-every-process, standing-hosted-child, standing-live, standing-rule, standing, hosted-child-cells, hosted-child-counters, hosted-child-crew, sse and mcp-account-suspend. 49 pass, 0 fail.

Left out: children that run in their own cell are not covered here; each one runs its own serve().

Try it: on a hosted child, open /events while signed in, then suspend that account from the child's admin. The stream ends.

🤖 Generated with Claude Code

commented

When an account is suspended or removed, or a browser is signed out, the streams it holds open on a hosted child forge served in-process now close. That covers event streams, app sockets and git transfers in progress. Until now they stayed open until the client disconnected. This closes the deepsec finding from #14765.

What changed (src/http/server.ts)

  • The code in serve() that ends what an account holds open is now one function, enforceStanding(app). It listens for account.suspended, account.removed and session.ended on the forge's bus and closes matching streams at once. A timer also checks the forge's database (sweepStanding), which catches a change written by another process. Matching is by account and session id, not by scanning every stream. serve() calls it for its own forge.
  • forgeHttp(child) now calls enforceStanding(child) too. Its close() used to do nothing. Now it stops the listener and the timer, and letGo already calls it when a child closes or the server stops.
  • The issue pointed at src/http/caller.ts, but that file didn't need to change: it already keeps one list of held streams per forge database. What was missing was anything closing a child's streams, so the fix is in server.ts.

Test (test/standing-hosted-child.test.ts) It opens /events through forgeHttp(child) and checks that the stream ends in three cases:

  • the account is suspended on the child;
  • the browser is signed out on the child;
  • the suspension is written by a second process on the child's data, so only the child's timer can catch it.

Each test waits for the stream to end with no timer of its own, so a stream that stays open fails it by bun's test timeout. Against main's server.ts all three fail that way; with the change they pass.

Checks run: bun scripts/gate.ts and bun x tsc --noEmit are clean. scripts/fast.ts named 2,508 test files, too many to run here, so I ran the suites that cover this change: standing-every-process, standing-hosted-child, standing-live, standing-rule, standing, hosted-child-cells, hosted-child-counters, hosted-child-crew, sse and mcp-account-suspend, all passing. The new test and standing-every-process were run again after the timer fix.

Left out:

  • Children that run in their own cell are not covered here; each one runs its own serve().
  • The gate says the new test's person and streamOn helpers look like the ones in test/standing-every-process.test.ts. That is a warning, not a failure, and I left them separate rather than moving them into a shared helper.

Try it: on a hosted child, open /events while signed in, then suspend that account from the child's admin. The stream ends.

🤖 Generated with Claude Code

Approved

Clean. enforceStanding(app) is the old serve() block moved into one function, and forgeHttp(child) now calls it. close() stops both the bus subscription and the sweep timer, and it is idempotent. Every other forgeHttp caller (tui api, preview-seed, the child cache in serve) calls close() or hands it to letGo, so no timer leaks. Matching is by account and session id from the forge's own bus and database, and no client-written value is trusted. No new surface, so the page, terminal and docs rules do not apply. The tests cover suspend, sign-out, and a suspension written by another process that only the child's sweep can catch. Their own comments say a stream left open fails them by timeout, which is what they would do on main. The gate reports the test helpers as near-duplicates of standing-every-process; that is a warning, so I am not asking for a change.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs