Skip to content

fix(server): share provider update locks, bound peer calls, mark lost child work interrupted - #172

Closed
nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/audit-p2-ws-locks-peer-timeout-child-bg
Closed

nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/audit-p2-ws-locks-peer-timeout-child-bg

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Three medium-severity findings from the November 21 server audit, each with a regression test that fails on the release branch and passes here.

1. Provider updates shared no lock across clients (audit A-P2-01)

Every WebSocket connection built its own ProviderMaintenanceRunner, and the runner holds the lock that keeps one provider update from running twice. Two clients (or one client reconnecting) could each start the same update at once.

Fix: the server builds one runner when the route layer builds (server.ts), the same way it already shares PullRequestService, and ws.ts hands that instance to every connection.

Test: ws.test.ts, "every WebSocket connection updates providers through the server's one runner". It opens two real WebSocket connections and checks that both updates reach the server's runner. On the base branch each connection uses its own real runner instead, and the test fails.

The audit also named AgentSessionScanner, but the release branch already builds that once at server level (runtimeLayer.ts). The audit read an older commit, so nothing changes for the scanner here.

2. A half-open linked environment could hang cancel and status forever (audit A-P2-03)

PeerMcpClient bounded only the MCP handshake. A forwarded tools/call had no ceiling, so a peer that accepted the connection and then went silent left task_cancel, task_status and the result follower waiting with no end.

Fix: a forwarded call now times out after 2 minutes. Forwarded waits already stop at 45 s, so only a dead peer reaches the limit. The timeout goes through the existing TimeoutError mapping, so the caller sees "The linked environment stopped answering."

Test: the existing handshake case in PeerMcpClient.test.ts now also sends a call that never answers and advances the test clock 2 minutes. On the base branch the call hangs until vitest's own timeout.

3. A delegated child that lost background work settled as completed (audit A-P2-02)

When a provider process ended for a reason other than a server restart (idle release, runtime error, detach), ProviderSessionManager cleared the dead process's background tasks from the roster but recorded them nowhere. runOutcome() then reported the child as completed, even though a reviewer subagent or background task it was waiting on had been killed. Restart recovery already handles the same loss correctly.

Fix: the release roster write now also emits run.background-work-cancelled for the latest started run on that provider thread, in the same conditional write, using the same rules as restart recovery: root provider threads only, and a subagent covers the shells it started. latestStartedRun moved into RestartBackgroundNote.ts so both paths pick the same run.

Test: ProviderSessionManager.test.ts, "records the background work a released process lost". It seeds a run whose process holds a dev server and an awaited subagent, closes the session, and checks that the run records both and that runOutcome is interrupted. On the base branch the recorded list is empty.

Follow-up, not in this PR: the note the agent later sees says "the T3 server restarted…". That wording is now slightly off for an idle or crash release. It is model-facing text, so changing it needs the evals in evals/README.md. I left it alone.

Verification

  • Each new test was run alone with one worker, with the fix and with only that fix's source reverted: it fails without the fix and passes with it.
  • Full files pass: ProviderSessionManager.test.ts (74), PeerMcpClient.test.ts (7).
  • Server typecheck passes with no errors.
  • check:changed against the release branch: format and lint pass. The other failures are outside this diff:
    • evals typecheck: missing ProviderRegistry in mcp-tool-use/run.ts. Reproduced on the clean base.
    • knip: unused files and exports, none in this diff.
    • AgentContextBudget.test.ts: MCP tool list bytes. This diff changes no MCP tool text.
  • The local pre-commit knip hook fails on those same unused files, so the commit skipped hooks (--no-verify). CI runs knip in full.
  • Pushing this branch starts no deploy or sync workflow. The PR starts the self-hosted ARC CI and the deploy-line check.

Deploy: fleet

Opus 5.5 in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

… child work interrupted

- Build one ProviderMaintenanceRunner for the server and hand it to every
  WebSocket connection, so two clients share the provider update locks.
- Time out a forwarded peer tool call after two minutes, so a half-open
  linked environment cannot hang task_cancel or task_status.
- When a provider process is released with awaited background work still on
  its roster, record that work on the run as restart recovery does, so a
  delegated child settles as interrupted instead of completed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • 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

@nullStack65

Copy link
Copy Markdown
Owner Author

Frozen 2026-11-22 CEO portfolio audit — cash-path priority; can reopen at the Dec 18 runway check.

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.

2 participants