Skip to content

fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) - #24421

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/node-rt-p3-t5-3
Oct 1, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/node-rt-p3-t5-3

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​225 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​223
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​360 $\color{#cf222e}{\Huge{\mathbf{−}}}$​296 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64

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:

  • A subscription id was only checked against connections that had finished opening. A second request with the same id, or a late event from a replaced connection, could slip through.
  • A close that arrived while a connection was still opening was ignored, so a dead subscription could be registered.
  • A status check that finished after its server was re-paired could still publish the old status, diagnostics and runtime id.

After:

  • Subscriptions (runtime-environment-subscriptions.ts):
    • A subscription id is reserved while its socket opens, and a duplicate request for it is refused.
    • Every callback checks, by token, that it still owns its id.
    • A close during setup closes the new socket and fails the call cleanly.
  • Status (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 answers runtime_environment_changed and publishes nothing.
  • Code moves:
    • runtimeEnvironmentChangedFailure now lives in the revision guard.
    • shouldUseSharedControlEnvelope now lives in support routing.
    • ipc/runtime-environments.ts drops 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:

  • Reconciliation pieces (T5-4): the control/resource transport-generation split, preserveResourceStreams and control-only retirement only matter once two registrations can be grouped.
  • Managed-tunnel resolution and SSH-access/managed-deployment handler channels: T6.
  • Live-migration channels: T8.

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;
    • runtimeEnvironments subscription 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Wire: nothing changes on the wire. The client still sends the same status.get and subscribe calls.
  • SSH and remote: a refused stale status says "changed", never that a process exited.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f1364230-72ab-49c0-9806-fdc1eb9ae076

📥 Commits

Reviewing files that changed from the base of the PR and between 817af76 and 96be053.

📒 Files selected for processing (11)
  • src/main/ipc/runtime-environment-capability-evidence.ts
  • src/main/ipc/runtime-environment-revision-guard.ts
  • src/main/ipc/runtime-environment-status-owner.ts
  • src/main/ipc/runtime-environment-status-probe.ts
  • src/main/ipc/runtime-environment-status-retirement.test.ts
  • src/main/ipc/runtime-environment-subscription-identity.test.ts
  • src/main/ipc/runtime-environment-subscriptions.ts
  • src/main/ipc/runtime-environment-support-routing.ts
  • src/main/ipc/runtime-environment-transport-routing.ts
  • src/main/ipc/runtime-environments-subscription-teardown.test.ts
  • src/main/ipc/runtime-environments.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Refactors runtime environment subscriptions and status probes with identity fencing.

The PR appears safe to merge; no actionable regression was established.

Summary

The PR separates runtime-environment subscription and status handling from their IPC routing modules and adds identity fences for opens, callbacks, and status probes.

  • Subscription IDs are reserved during setup, and callbacks retain token ownership checks.
  • Status probes reject results from a retired capability incarnation.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  IPC[Runtime-environment IPC] --> S[Subscription owner]
  IPC --> P[Status probe]
  S --> T[Token and transport-generation checks]
  P --> I[Capability-incarnation check]
  T --> R[Remote transport]
  I --> R
Loading

Reviews (1) · Last reviewed commit: "fix(runtime): fence runtime-environment ..."

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 in pendingSubscriptions while its socket opens (duplicate same-id subscribe refused), each socket carries a Symbol token, and ownsId()/transportIsCurrent() gate every callback so a late frame, late close, or late onClose from 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 + new runtime-environment-status-probe.ts): the owner's request captures the capability incarnation at start and answers runtime_environment_changed if it moved before the response settled (so verified/publish never run for a retired probe); the probe re-checks the incarnation after refresh before attaching diagnostics.
  • Code moves: runtimeEnvironmentChangedFailure into the revision guard (now takes pairingChanged, default false, preserving both messages), shouldUseSharedControlEnvelope into support routing, and getRuntimeEnvironmentStatus re-exported for existing importers. runtime-environments.ts drops 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit ece9e4d into main Oct 1, 2026
33 checks passed
OrcaWin added a commit that referenced this pull request Oct 2, 2026
* 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]>
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