Repository navigation
fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) - #24421
Conversation
…es by identity (#16741 T5-3) Splits runtime-environment subscriptions and the status probe out of their IPC modules and fixes the reconnect and teardown races the split exposed. Subscriptions (runtime-environment-subscriptions): - A subscription id is reserved while its socket opens, so a duplicate request for the same id is refused instead of racing the first. - Every callback checks it still owns its id by token, so a late event or close from a superseded socket cannot reach a subscription that reused the id. - A close that arrives during setup closes the new socket and fails the call instead of registering a subscription that is already dead. Status (runtime-environment-status-probe, status-owner): - A status request records the capability incarnation it started under; if the environment was re-paired or retired meanwhile, it answers runtime_environment_changed instead of publishing stale status, diagnostics or a runtime id. - runtimeEnvironmentChangedFailure moves to the revision guard and shouldUseSharedControlEnvelope to support routing, so both have one home. Status and transport routing still resolve environments with plain resolveEnvironment; the managed-tunnel hook is T6. Porting note (source: #16741 a68b6f3): - Left for T5-4 (reconciliation): the control/resource transport-generation scopes and preserveResourceStreams, retireRuntimeEnvironmentControlTransport, and their test cases. - Left for T6/T8: the managed-tunnel resolution, the orcadDeployment disconnect guard and connectivity forget hook, and the managed, migration and ssh-access handler channels and registrations.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 58 seconds. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
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. Comment |
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full PR at 96be0538db: the subscription/status code moves and the identity fences they add.
- Subscription identity fencing (
runtime-environment-subscriptions.ts, new): a subscription id is reserved inpendingSubscriptionswhile its socket opens (duplicate same-id subscribe refused), each socket carries aSymboltoken, andownsId()/transportIsCurrent()gate every callback so a late frame, late close, or lateonClosefrom a replaced connection cannot publish to or evict its replacement. A close during setup closes the new socket and rejects. - Status identity fencing (
runtime-environment-status-owner.ts+ newruntime-environment-status-probe.ts): the owner'srequestcaptures the capability incarnation at start and answersruntime_environment_changedif it moved before the response settled (soverified/publishnever run for a retired probe); the probe re-checks the incarnation afterrefreshbefore attaching diagnostics. - Code moves:
runtimeEnvironmentChangedFailureinto the revision guard (now takespairingChanged, default false, preserving both messages),shouldUseSharedControlEnvelopeinto support routing, andgetRuntimeEnvironmentStatusre-exported for existing importers.runtime-environments.tsdrops from ~295 to 71 lines. - Tests: id reservation / token ownership after reuse / close-during-setup, retired-probe settlement (success, failure, throw) publishing nothing while other environments and fresh probes stay unfenced, and teardown now asserts the close notice plus late-frame and late-close suppression.
I traced the fencing end to end and ran pnpm test on the three changed files (14 pass), on the runtime-environment / runtime-host-status / remote-runtime suites (49 files, 297 pass, 1 skipped), pnpm tc:node, and pnpm run check:code-quality:changed (0 findings) — all green. Re-pair also recreates the cached status owner (and invalidateRuntimeEnvironmentTransport advances both the capability incarnation and the transport generation), so both fences hold on the reconnect/teardown paths this targets.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
* Revert "feat(orcad): source-side dormant export of a relay-hosted SSH target (#16741 T6-8) (#24519)" This reverts commit 783101b. * Revert "feat(ssh): update, roll back, recover and stop a managed orcad server (#16741 T6-5 follow-up) (#24463)" This reverts commit 38c2d1d. * Revert "feat(ssh): deploy and pair an empty managed orcad server over SSH (#16741 T6-5) (#24453)" This reverts commit 8b76683. * Revert "fix(ssh): orcad GC honors the activation journal; readiness requires proven daemon coverage (#16741 T6 follow-up) (#24451)" This reverts commit d3f8c50. * Revert "feat(ssh): remote orcad stop by request file and journaled decommission (#16741 T6-4) (#24449)" This reverts commit 43d9b43. * Revert "feat(orcad): supervisable server: stop requests, managed stop receipts and a lifetime that keeps its lock on failed teardown (#16741 T6-3) (#24433)" This reverts commit b093d3a. * Revert "feat(ssh): crash-safe orcad activation, rollback and recovery (#16741 T6-2) (#24423)" This reverts commit 1a9ac0e. * Revert "feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) (#24420)" This reverts commit 99db2bf. * Revert "feat(relay): capability-gated owner reset with a durable preparation journal (#16741 T3 R1) (#24418)" This reverts commit 34a582b. * Revert "feat(ssh): track connection-manager drains, test probes and provider continuations (#16741 T2 P3+P8a) (#24407)" This reverts commit d53063d. * Revert "feat(daemon): idle retirement, session census and recovery-only provider (#16741 T2 P4b) (#24409)" This reverts commit ff212db. * Revert "feat(ssh): add pty.resumeClient and split SSH PTY process listing (#16741 T2 P5+P6) (#24414)" This reverts commit 92cb717. * Revert "feat(relay): await owned watcher and agent children on shutdown (#16741 T2 P1) (#24400)" This reverts commit 6b36e4f. * Revert "feat(session): retry failed renderer session writes and verify local folder PTYs (#16741 T2 P9) (#24406)" This reverts commit d23ecef. * Revert "feat(ssh): remote orcad primitives on the pinned Node runtime (#16741 T6-1) (#24419)" This reverts commit dd87ae5. * Revert "fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) (#24421)" This reverts commit ece9e4d. * Revert "feat(orcad): migration manifest and dormant-state contracts (#16741 T6-7) (#24422)" This reverts commit 3fbdaba. * Revert "feat(ssh): wire SshConnection through the work and transport close ledgers (#16741 T2 P2) (#24401)" This reverts commit 4e8edc8. * Revert "feat(profiles): carry markdown frontmatter visibility in project transfers (#16741 T2 P7) (#24405)" This reverts commit 60c9326. * Revert "fix(runtime): project the PTY incarnation onto mobile session tabs (#24413)" This reverts commit 99e0303. * Revert "feat(daemon): tag daemon stream data with the PTY incarnation id (#16741 T2 P4a) (#24402)" This reverts commit 817af76. * Revert "feat(ssh): port the SSH connection work ledger and transport close ledger (#16741 T2) (#24210)" This reverts commit c991893. * Revert "feat(relay): fence and drain file and git response streams on shutdown (#24185)" This reverts commit dc08ffe. * Revert "refactor(runtime-rpc): extract the Node WebSocket lifecycle; opt-in pinned port (#24186)" This reverts commit a789233. * Revert "feat(relay): route relay handlers through work admission; producer publication drain (#24181)" This reverts commit 0b812bd. * Revert "feat(relay): land the #16741 T1 seam (work drain, publication drain, release gate) (#24156)" This reverts commit 3aa2d3a. --------- Co-authored-by: m4air <[email protected]>

This is T5 slice 3 of the #16741 port (runtime-environment reconciliation). It moves runtime-environment subscriptions and the status probe out of their IPC modules, and fixes the reconnect and teardown races the split exposed. It changes behavior, so it ships on its own.
ELI5
When Orca is paired with another Orca server, it keeps live connections open for terminals, browser views and status. If a server is re-paired or removed while one of those connections is still opening or still sending, the connection could deliver stale data to the wrong place, or be left open with nobody owning it. This change makes each connection prove it still belongs to the request that opened it before it delivers anything.
What Changed
Before:
After:
runtime-environment-subscriptions.ts):runtime-environment-status-probe.ts,runtime-environment-status-owner.ts): a status request records the capability incarnation it started under. If the server was re-paired or retired meanwhile, it answersruntime_environment_changedand publishes nothing.runtimeEnvironmentChangedFailurenow lives in the revision guard.shouldUseSharedControlEnvelopenow lives in support routing.ipc/runtime-environments.tsdrops from 295 to 71 lines.Paired-client behavior is otherwise unchanged. Routing still resolves servers the same way as before; the managed SSH tunnel hook arrives with T6.
Why
These races only show up during reconnect and teardown, which is when a paired client is most fragile. Splitting the subscription and status code into their own modules gives each race one owner and one place to fence it. The alternative was patching the 240-line inline handler in place.
Left out:
preserveResourceStreamsand control-only retirement only matter once two registrations can be grouped.Linked Issue
Part of the Node runtime plan, Phase 3, T5 slice 3. Ported from #16741 (a68b6f3). Follows #24420.
Visual Proof
N/A. This is internal IPC with no UI change. The visible effect is fewer stale updates after a re-pair or disconnect.
Testing
New and updated tests:
runtime-environment-subscription-identity: id reservation during setup, token ownership after reuse, close during setup;runtime-environment-status-retirement: a retired probe settling with success, failure or throw publishes nothing, and other servers and fresh probes are not fenced;runtimeEnvironmentssubscription teardown: late frames and duplicate close after retirement.Regression: every runtime-environment, web-preload, remote-runtime transport, runtime-host-status, shared-control and ephemeral-VM test: 146 files, 1,037 passed.
The changed-code quality gate passes.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
status.getand subscribe calls.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)