Skip to content

fix(server): follow-ups from the review of the server/index.ts split - #1393

Merged
devswha merged 4 commits into
mainfrom
chore/core-followups
Oct 19, 2026
Merged

devswha merged 4 commits into
mainfrom
chore/core-followups

Conversation

@devswha

@devswha devswha commented Oct 19, 2026

Copy link
Copy Markdown
Owner

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

devswha and others added 4 commits October 19, 2026 21:19
#1384 moved createCore, and with it the PTY sidecar's Node probe, after
the first tailnet identity read. The probe is a spawnSync with a 3 s
timeout; while it holds the thread, the identity read's own 2.5 s limit
keeps running, and a read cut short leaves the owner unknown for five
minutes. Start the read after createCore, as it ran after the probe
before #1384.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
server/core imported paneContext from server/pane-routes.ts, an HTTP
route file. It now lives in server/pane-context.ts, which the routes and
the core both import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
createCore spread the terminal, input and pending frame objects into the
record the socket looks frames up in. Anything else on one of them would
have become a frame type a client can send, and a type defined twice
would have replaced a handler without a word. Each type is now named
with its handler, so neither can happen: an extra name, a missing one or
one written twice fails the build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ownership.test.ts matched imports and exports with regular expressions,
which missed require(), a template-literal import() and a last export
without a semicolon. It now parses each file with TypeScript's parser
(typescript-api), resolves the tsconfig path aliases, and covers both
checks with fixtures that must fail and fixtures that must pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b93818a8-2cf9-4852-977e-41498557d54a
📥 Commits

Reviewing files that changed from the base of the PR and between a661220 and 0eb22e5.

📒 Files selected for processing: 8
  • server/core/composer.ts
  • server/core/input.ts
  • server/core/ownership.test.ts
  • server/core/server-core.ts
  • server/index.ts
  • server/pane-context.ts
  • server/pane-routes.ts
  • server/workspace-routes.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Improvements
    • Commands and file actions now use consistent pane context, including the active working directory and available agent information.
    • Server setup now establishes identity context after core initialization.
    • Message handling more precisely routes supported message types, helping prevent unintended handling of unrelated data.

The change moves pane-context lookup into a dedicated module, updates server-core frame-handler wiring and initialization order, and replaces regex-based ownership checks with TypeScript AST parsing.

Changes: Server core changes

Layer / File(s) Summary
Extract and wire pane context
server/pane-context.ts, server/pane-routes.ts, server/core/composer.ts, server/core/input.ts, server/workspace-routes.ts, server/index.ts
A new paneContext helper resolves the pane working directory and agent. Routes and core consumers now import it from pane-context.ts.
Wire core frames and initialization
server/core/server-core.ts, server/index.ts
createCore passes createSocket an explicit map of frame handlers. Server startup initializes serveOnly before creating the core and calls identityOf(false, null) afterward.
Parse core ownership checks
server/core/ownership.test.ts
Ownership tests use TypeScript AST parsing to check module access into server/core and exports. Added cases cover import forms, aliases, accepted paths, and export variants.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0eb22

No merge-blocking issue remains from these changes; normal checks can proceed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the PR as server follow-up fixes related to the server/index.ts split. It is concise and accurately reflects the changeset.
Description check Passed The description explains the four changes, their rationale, resulting behavior, and verification results. It uses a "Verification" heading instead of the template's "Validation" heading, but it provid…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the four changes, their rationale, resulting behavior, and verification results. It uses a "Verification" heading instead of the template's "Validation" heading, but it provides the required validation information and is otherwise complete.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha
devswha merged commit d5a74c0 into main Oct 19, 2026
17 checks passed
@devswha
devswha deleted the chore/core-followups branch October 19, 2026 13:00
devswha added a commit that referenced this pull request Oct 19, 2026
This answers one open question from the `server/index.ts` split: what
keeps `createServer`'s start-up order from breaking. Nothing pinned it,
and #1384 broke it. That PR started the first tailnet identity read
before the PTY sidecar's Node probe, and #1393 moved the read back. This
PR pins the order that broke.

## The order and why it matters

- The Node probe (`sidecarAvailable` → `isRealNode`) is a
`Bun.spawnSync` with a 3 s timeout.
- The identity read times itself (2.5 s) from the moment it starts.
- If the read starts first, the probe's wait counts against the read's
limit.
- A read cut short leaves the owner unknown for five minutes. With no
token and nothing paired, another tailnet user then gets `open` access.

## What changes

- **`server/startup-order.test.ts` (new).** The test runs `createServer`
with a probe that records itself and a `TailnetIdentitySource` whose
status reader records itself. It waits for the read, then expects the
probe first. I moved `identityOf(false, null)` back before `createCore`,
as it was in #1384, and the test failed with `["identity read",
"probe"]`. With the code as it is, the test passes.
- **The `sidecar` option** also takes a function, a probe to run in
place of the real one, the way `terminalAttach` already takes a value or
a function. A boolean works exactly as before, so nothing else changes.
- **No changelog fragment.** The change is a test seam and a test, and
no user sees it.

The handoff's other order question was about the collector's first frame
carrying live OmO and Claude status. It is left to `createCore`'s
comment: nothing has broken there, and it would need a much heavier
test.

## Verification

- `bun run typecheck` is clean. The conventions tests pass.
- Pins were every contract test that passes `sidecar`
(`conversation-push`, `api`, `usage-login`) plus `device-access` (the
tailnet access paths). Each ran with `--rerun-each 3`, on `main` first
and then on this branch: 495 pass, 0 fail on `main`, 495 pass, 0 fail on
the branch.
- `bun run check fast`: 4,502 pass, 0 fail, 8 skip. `bun run check
integration`: 589 pass, 0 fail, 1 skip.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant