Title: fix(sse): bound workspace SSE connection lifetime by waleedlatif1 · Pull Request #7058 · simstudioai/sim · GitHub
Open Graph Title: fix(sse): bound workspace SSE connection lifetime by waleedlatif1 · Pull Request #7058 · simstudioai/sim
X Title: fix(sse): bound workspace SSE connection lifetime by waleedlatif1 · Pull Request #7058 · simstudioai/sim
Description: Summary createWorkspaceSSE tore down a connection only from the request.signal abort listener and the stream's cancel(). Both fire only when the runtime reports the client disconnect, and nothing else bounded the connection — so a missed report left the pub/sub handler in a process-lifetime Set, the heartbeat interval running, and the stream's undrained queue held until the process restarted. Retention scaled with uptime instead of with concurrent clients. Unread-consumer check — the heartbeat reads controller.desiredSize (the default strategy reports 1 - queued) and closes once nothing has been pulled for several minutes. This is what actually reclaims a vanished consumer, within minutes. A healthy client keeps its stream drained and is never unread, so this never touches a working connection. Lifetime ceiling (4h, jittered) — the backstop for whatever the abort, cancel, and unread paths all miss, so retention is bounded by the ceiling rather than by process uptime. Checked on the existing heartbeat tick, so it adds no second timer. Matches lib/realtime/event-stream-route.ts, which uses the same deadline pattern for the same purpose. Deliberately far longer than the unread window: a short ceiling would only force reconnects on the connections that are working, and every reconnect is a window in which a transient event can be missed. The abort listener is now removed on every path. { once: true } only self-removes if abort fires; the ceiling and unread paths close while the signal is still live, so the listener would have stayed installed retaining close → the controller, the teardown list, and the workspace id — most of the scope this change exists to release. It registers with an owned AbortController as its removal token. A failed heartbeat enqueue now runs full teardown instead of clearing only its own interval and leaving the subscriptions registered. cleanup takes a reason, so the close log says which path ran (aborted, cancelled, expired, unread, errored). Opens minus closes, grouped by reason, is what makes this class of leak visible rather than inferred. Reconnect resync (useMothershipChatEvents) — task_status events are transient and never replayed, and the hook previously reconciled nothing on reconnect. It now re-syncs the workspace chat lists on reconnect, on the first open of a re-subscription, and on a first open that only succeeded after an error, matching the pattern useMcpToolsEvents already uses. Only the lists: they carry the create/rename/delete state a gap can drop and are always safe to refetch. Chat detail reconciliation is deliberately out of scope and unchanged from staging. Refetching a mounted detail can replace an in-flight optimistic transcript with a server copy that lacks the streaming message, and cached state cannot reliably say whether a turn is still running — the optimistic markers outlive it. Doing that properly needs the streaming state that can answer it, and belongs in its own change rather than being half-solved here. createWorkspaceSSE is the only push-driven, indefinite-lifetime SSE surface in the app. The two other long-lived SSE routes are poll loops that already carry their own duration ceilings and never depended on abort. A shared bounded-SSE primitive would be the honest end state for all three, but that is a three-site refactor and doesn't belong in a leak fix. Type of Change Bug fix Testing sse-endpoint.test.ts covers the ceiling, the unread path, a drained connection surviving past the unread threshold, abort, consumer cancel, and teardown idempotency when two paths overlap. use-mothership-chat-events.test.ts covers the resync invalidating the lists and leaving details untouched. Verified the tests are load-bearing rather than assuming it: disabling each backstop reds exactly its own test and leaves the rest green. The abort-listener removal isn't unit-observable (AbortSignal exposes no listener count), so it's covered by review — I dropped an earlier test that looked like it covered it but only re-asserted an idempotency guard another test already owns. bun run lint, bun run check:audits (33 audits), and tsc clean. 163 test files / 1816 tests green across hooks, lib/events, and lib/copilot/chat. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary createWorkspaceSSE tore down a connection only from the request.signal abort listener and the stream's cancel(). Both fire only when the runtime reports the client disconnect, and noth...
X Description: Summary createWorkspaceSSE tore down a connection only from the request.signal abort listener and the stream's cancel(). Both fire only when the runtime reports the client disconnect, and ...
Opengraph URL: https://github.com/simstudioai/sim/pull/7058
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:83641e91-72de-d2e2-8960-8f20dc8f00fb |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DCA6:C876F:B4C308:F9650B:6AFB5459 |
| html-safe-nonce | 7fd90afbad08e1eed62acee54b10318ceb3cc16aa48394de9cfb056d5ab4f2e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0E2OkM4NzZGOkI0QzMwODpGOTY1MEI6NkFGQjU0NTkiLCJ2aXNpdG9yX2lkIjoiNTIwNTAwNzgzMzg1MTA1NDk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6d2ae252ace67d9df0a1bf627dfcc3d11663dd0f2a9850051edf681d3a373d16 |
| hovercard-subject-tag | pull_request:4354080325 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/7058/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary createWorkspaceSSE tore down a connection only from the request.signal abort listener and the stream's cancel(). Both fire only when the runtime reports the client disconnect, and noth... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width