Repository navigation
refactor(server): move connection authority and teardown into createConnections - #1344
Conversation
…core/connections Step 4 of splitting the stateful core of server/index.ts by state owner. closing, revoked, mode, roles, watches and unwatchDevice leave SocketData for state that only server/core/connections.ts writes, keyed by the data object the upgrade passed. createConnections owns mayType, authorizeSocket, admit, setRole, the observe processes and end(), which keeps the stalled, revoked and closed teardowns as they were. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stall ends once and leaves presence and the device watch to the socket's close. A revoke leaves pending.close to it. A relayed close only closes the relay. Every end detaches before it drops the claims, and a device revoked before its socket opened is not admitted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
|
CodeRabbit did not review this PR: its first run stopped at "Review limit reached". This step touches device revocation, observe mode and pending-input teardown, so per AGENTS.md it waits for a real CodeRabbit review before merge. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Change
Step 4 of splitting the stateful core of
server/index.tsby state owner. A connection's authority and its end now have one owner. No behavior changes.closing,revoked,mode,roles,watchesandunwatchDeviceleaveSocketData.server/core/connections.tskeeps them in aWeakMapkeyed by thedataobject the upgrade passed, and only that file writes them. Other code readsmode,rolesandclosingthroughconnectionOf(client), which returns the live state, not a copy.createConnectionstakesmayType,authorizeSocket, the device revocation watch (admit), the role switch (setRole), the observe processes (watchPane,unwatchPane,killWatches) andend(client, reason).endreplacesstopSlowClient, the revoke callback and the WebSocketclosebody. Its three branches are those three bodies, each in its old order.detachClaimedanddropClaimsinindex.tshold the claim loop and the three clears that each body repeated.connectionDatabuilds the data for both the local and the relayed upgrade.Scope:
clients,present, presence and ping stay inindex.ts. The panes a connection holds (attached,conversationInterests,output) stay onSocketDatauntil the terminal registry steps. The role frame still holds pending input beforesetRole, as before. This step was built from the series' handoff summary and the code; the full design note was not available to this session.Why this is safe
presentand the device watch to the socket's close. A revoke has no early return and leavespending.closeto the socket's close. A close runs after both, and for a relayed connection it only closes the relay. The newserver/core/connections.test.tspins each of these, the detach-before-drop order, and the immediate end of a device revoked before its socket opened.client.data.<field>replaced by the state. A script rewrote the 34 reads toconnectionOf(...), and its counts match an inventory taken onmain(11closing, 13mode, 10roles). The writes moved by hand.SocketDatano longer has these fields, and the state type is not exported.dataobject the upgrade passed. A probe on Bun 1.4.3 foundws.data === datainopen,messageandclose. If a Bun upgrade changes that,stateOfthrows instead of reading a missing state.createConnectionsis called wheremayTypewas declared. Everything it takes is declared above it or is a function declaration, and it runs nothing when it is built.pending.close, so it waits for a real CodeRabbit review perAGENTS.md.server/index.tsgoes from 2,381 to 2,319 lines.Validation
bun run check run bun test --timeout 15000over the contract files whose behavior this step can break (device-access,output,watch,submit,pending-input,take-over,ping,keys-lifecycle,input-membership,secret,conversation-push,api): 340 pass, 0 fail on an untouchedmainand on this branch. After the rebase onto the currentmain, the same files with the new unit test give 345 pass, 0 fail.connections.tsone at a time: aclosingguard on the close branch,pending.closeon revoke, dropping claims before detaching, admitting a revoked device, dropping presence on a stall, and counting a switch to the same mode.bun run check fast, before the rebase: typecheck and build are ok, and 4,439 unit tests pass with 0 failures. The convention tests pass, and the fixed-sleep baseline is unchanged (noBun.sleepmoves).bun run check integration, before the rebase: 585 pass, 0 fail, 1 skip in 43 files. The rebase brought in only fix(gjc): retain bindings across unrelated SDK heartbeats #1343's GJC files.🤖 Generated with Claude Code