Repository navigation
refactor(server): move the pane attach into createSpawnAttachment - #1365
Conversation
Step 5 of splitting the stateful core of server/index.ts by state owner. spawnAttachment, terminalInfoFor, spawnFailure, the PaneAttachment record and the ATTACH_* constants move as they were into createSpawnAttachment. The closure keeps its locals. The only changed line reads the server's stopped flag through isStopped(), as a reassigned let cannot be passed. 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
|
…1393) Follow-ups from the merge pass's review of the `server/index.ts` split (#1365–#1384), as one PR. There is one commit per item. ## 1. Start the tailnet identity read after the Node probe again (fix) #1384 moved `createCore` after the HTTP services, and with it the PTY sidecar's Node probe. The first tailnet identity read (`identityOf(false, null)`) therefore started before the probe instead of after it. - The probe (`sidecarAvailable` → `isRealNode`) is a `Bun.spawnSync` with a 3 s timeout. - While it holds the thread, the identity read's own 2.5 s limit keeps running. - A read that is cut short leaves the owner unknown for five minutes. With no token and no paired device, that can let another tailnet user in through `open` access. Codex reproduced this with a stalled probe and a large status reply. The merge pass could not reproduce it on Linux with Bun 1.4.3, and macOS and Windows were not tried. The read now starts right after `createCore`, so it runs after the probe as it did before #1384. Nothing that `createCore` starts reads the tailnet identity. #1384 claimed the two groups were independent, and that was wrong about time: a thread blocked by one counts against the other's timeout. #1384 is unreleased, so no released behaviour changes and this PR has no changelog fragment. ## 2. Move `paneContext` out of the pane routes `server/core/input.ts` and `server/core/composer.ts` imported `paneContext` from `server/pane-routes.ts`, an HTTP route file. It now lives in `server/pane-context.ts`, and the routes, `workspace-routes.ts`, `index.ts` and the core all import it from there. The body is unchanged. ## 3. Name each frame type in the socket's handler record `createCore` used to spread `terminalFrames`, `inputFrames` and `pendingFrames` into the record that the socket looks frames up in. That had two weaknesses: - Any other key on one of those objects, such as a helper added later, would have become a frame type a client can send. - A type defined in two objects would have silently replaced one handler with the other. Each frame type is now named with its handler in an object literal passed straight to `createSocket`. I checked by editing the record and running `tsc`: - Naming a type twice fails with TS1117. - Naming a type that is not a handled frame, for example `ping`, fails with TS2353. - Leaving a type out fails with TS2741. The handlers are the same functions as before, so dispatch does not change. They are plain functions that do not use `this`. ## 4. Read the core's boundary with the TypeScript parser `ownership.test.ts` used regular expressions. They missed `require()`, a template-literal `import()` and a last export with no semicolon. Both checks now parse each file with TypeScript's parser (`typescript-api`, already in the repo for `scripts/build-xterm.ts`). - **Import check.** It reads: - import and export declarations, including type-only ones; - `import x = require()`; - `import()`, `require()`, `require.resolve()` and `mock.module()` with a string or template literal; - `import("…")` types. It resolves relative names and tsconfig's `@shared/*` alias. A template literal with substitutions counts when its fixed start already points inside `server/core/`. - **Export check.** It reads every statement of `server/core/index.ts`. `export *`, `export * as`, default exports and exported declarations all count as names. - **Fixtures.** 17 sources must be reported, including the three forms named in the review and `@shared/../server/core/…`. 9 sources must pass, among them the index in its four spellings, a mere string or comment and a template import outside the core. Every export form has its own fixture. The real scan covers `server`, `src`, `shared`, `scripts`, `site`, `telemetry` and `app`, and still asserts that it includes `server/index.ts`. ## Verification - `bun run typecheck`: clean. - `server/conventions.test.ts`, `scripts/conventions.test.ts` and `server/core/`: 29 pass, 0 fail. - Every `server/*.contract.test.ts` (39 files) with `--rerun-each 3`, run on `main` first and then on this branch: 1,602 pass, 3 skip, 0 fail on `main`, 1,602 pass, 3 skip, 0 fail on the branch. - `bun run check fast`: 4,501 pass, 0 fail, 8 skip. `bun run check integration`: 589 pass, 0 fail, 1 skip. - No `Bun.sleep` moved, and `scripts/fixed-sleeps.json` is unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Change
Step 5 of splitting the stateful core of
server/index.tsby state owner. Starting a pane's terminal moves toserver/core/terminal-process.ts. No behavior changes.createSpawnAttachmenttakesspawnAttachmentwhole: the pty attach, the mirrored screen, the retries while herdr refuses, the take-over a user asks for and the relookup after a live handoff.terminalInfoForandspawnFailure, which only it calls, move with it.PaneAttachmentrecord, theATTACH_*constants,PANE_GONE_CODESandMAX_REPLAY_BYTESmove too.index.tsimports back the record type,ATTACH_HELD_MESSAGEand the fourATTACH_*defaults its options use.takeover,takeoverWanted,retries,refusedSince,trying, the hold buffer,attachedTerminal) stay locals of the closure, as the series' design requires.Scope: this PR moves code and changes no type. The design's next shape for this code, an attachment that holds a
PtyProcessor aMirrorProcessso that a mirror has noresizeortakeOverto call, would rewrite everyattachment.ptyandattachment.mirrorsite inindex.ts. It is left for the terminal registry step, which moves the attachment maps that shape is drawn against.attachments,pendingAttachments,retiringAttachments,ensureAttachment,closeAttachment,resizePtyanddetachstay inindex.ts.Why this is safe
main's, cut by a script at each declaration's own first and last line, with its two-space indentation kept. A second check, by sequence match againstmain, found 429 of the 430 moved lines identical and in order.spawnAttachment.stoppedis aletthatstop()sets later, so its value cannot be passed in. It is read throughisStopped: () => stoppedinstead, andif (stopped)becameif (isStopped()).terminalInfoForwas, and the factory runs nothing when it is built.ensureAttachmentcallsspawnAttachmentonly from anattachframe, aftercreateServerreturns.--takeoveris passed and when an attach counts as taken, so this PR waits for a real CodeRabbit review perAGENTS.md.server/index.tsgoes from 2,330 to 1,898 lines.Validation
bun run check run bun test --timeout 15000 --rerun-each 3):take-over,attach-held,reattach,outputandapicontract tests,mirror.testandattach-output.test. 555 pass, 0 fail on an untouchedmain, and 555 pass, 0 fail on this branch.bun run check fast: typecheck and build are ok, and 4,493 unit tests pass with 0 failures. The convention tests pass, and the fixed-sleep baseline is unchanged (noBun.sleepmoves).bun run check integration: 589 pass, 0 fail, 1 skip in 44 files.🤖 Generated with Claude Code