Skip to content

fix(runtime): retire predecessor exit evidence on replacement - #32341

Merged
nwparker merged 3 commits into
mainfrom
nwparker/bug-24513-incarnation-exit
Oct 24, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/bug-24513-incarnation-exit

Conversation

@nwparker

@nwparker nwparker commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

ELI5

A running replacement terminal could still report that its previous process had been stopped. Clear the previous process's exit details once Orca knows a different process owns the terminal.

What Changed

Retire lastExitCode and lastExitCause from the PTY and its indexed leaves at both existing proven-incarnation replacement transitions: registration and provider spawn. Spawn must be covered because it can change the incarnation before registration arrives.

Before: stop incarnation A, reuse its PTY for known incarnation B, then terminal show reports B connected with A's operator_close cause. After: B has no exit cause until B exits. A delayed exit for A remains fenced. Same or missing identities retain the shipped conservative behavior.

Why

Exit evidence belongs to the process incarnation that exited. The existing replacement branches already invalidate the predecessor's handle, but leave its exit evidence behind. The shared retirement operation adds 13 production lines and keeps the existing identity decisions.

This continues the original fix and regression cases by @Cubatica in #24513 (f10eb5fe985be9007ddc20ed84c0401e08cf7eef), adapted to the current runtime modules and extended to the spawn-first path. The original commit remains in the history, and the adaptation includes coauthor credit.

Linked Issue

Fixes #24950

Visual Proof

N/A — runtime exit provenance exposed by terminal summaries; no rendered UI changes.

Testing

  • Automated tests added/updated.
  • Manually tested in a live app/provider. Validation here uses the real shared runtime service with deterministic lifecycle calls.

Controlled red run on the current base with only the production fix removed: 2 failed, 17 passed. Both failures were the public summary inheriting operator_close, once through registration and once through spawn. Final restored tree: 55/55 passed across exit provenance, handle incarnation, queued graph exit, and inventory lifecycle admission (160.56 seconds); an earlier fresh verification also passed 55/55.

ORCA_BACKGROUND_LAUNCH=1 node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts src/main/runtime/exit-provenance-audit.test.ts src/main/runtime/orca-runtime-terminal-handle-incarnation.test.ts src/main/runtime/queued-terminal-graph-exit.test.ts src/main/runtime/pty-inventory-lifecycle-admission.test.ts --maxWorkers=1

The new cases also inspect PTY/leaf evidence, reject a late predecessor exit, record the replacement's own exit, and retain evidence for same/missing/unknown identity.

The optional ORCA_LAYOUT_OWNER=main provenance run passed 18 tests with one explicit skip (117.58 seconds): unknown-to-known registration already has a different policy in this unshipped mode. Both replacement paths pass. Fresh native node typecheck passed without diagnostics:

ORCA_BACKGROUND_LAUNCH=1 node config/scripts/run-typecheck-projects-in-parallel.mjs --project=config/tsconfig.node.json --compiler=native

Changed-code quality passed all six scans and the casting SAFETY check against 8d94ed06570a. Focused formatting/lint checks and git diff --check are clean. Full build and repository-wide test/lint suites were not run.

Review

Independent adversarial source review found no blockers. It checked spawn-before-registration ordering, the inherited method placement, stale-exit fencing, indexed leaf access, identity preservation, and red regression evidence.

Merge risk: LOW. The original registration-only patch is incomplete on current code because an earlier spawn can consume the identity transition. Residual risk is live-provider/platform integration, which this deterministic runtime coverage does not establish.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer content is copied.

Notes

Reliability invariant: a known replacement never inherits predecessor exit provenance; uncertain identity retains the existing policy. Oracle: showTerminal reports the replacement connected under its own incarnation with no old exit cause, and later reports its own exit.

No exact exit-provenance gate was found in config/reliability-gates.jsonc; adjacent terminal-session.explicit-close-retirement covers handle retirement and is not claimed as this invariant's gate. The regression file is the executable evidence. Red and green logs are retained with the local review artifacts; no new production diagnostics are needed.

Surface Evidence / gap
macOS shared runtime Both public lifecycle entry points, real service, deterministic tests
Local daemon, SSH, WSL, paired remote Shared transition code covered; physical providers not exercised
Linux, Windows, mobile No native/device execution; no platform-specific code changes
Mixed versions No wire/persistence changes; missing incarnation retains existing behavior
Folder workspaces / git worktrees No repository or worktree-specific branch added

Cost is O(leaves for the replaced PTY) using the existing index. No new timer, RPC, subprocess, provider inventory scan, polling, or persistence work. No shell/path/platform operation changes. The unshipped main-layout path already differs on unknown-to-known registration; one preservation test explicitly skips only that pre-existing policy difference.

Checklist

  • Small, focused bug fix with before/after and original author credit.
  • Self-reviewed and independently reviewed for correctness, security, and performance.
  • Cross-platform, remote, mobile, folder workspace, and compatibility impact considered.
  • Visuals marked N/A with reason.
  • Full pnpm lint, typecheck, test, and build matrix; targeted local gates above, CI covers the remainder.

Cubatica and others added 3 commits October 2, 2026 14:24
When a PTY id is re-registered with a different, known incarnation, the handle was already invalidated but lastExitCode/lastExitCause (pty and leaves) still carried the predecessor exit, so a live replacement reported the old stop. Clear them at that same proven-replacement point. Same or unknown incarnation keeps the evidence (fail closed).
Clear predecessor exit evidence on the PTY and its indexed leaves when
registration or provider spawn proves a different known incarnation owns it.
Cover both paths so an earlier spawn cannot hide the transition from later
registration. Keep same and uncertain incarnation evidence conservative.

Adapted from Cubatica's original fix and regression cases in #24513; extend
the coverage to spawn-first replacement on the current runtime modules.

Co-authored-by: Cubatica <4414418+Cubatica@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 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 3 minutes.

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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2faa90a0-2cd5-45f4-8770-4018c7403840
📥 Commits

Reviewing files that changed from the base of the PR and between d9dc87b and eca6033.

📒 Files selected for processing: 3
  • src/main/runtime/exit-provenance-audit.test.ts
  • src/main/runtime/terminal/identity/pty-worktree-record.ts
  • src/main/runtime/terminal/lifecycle/pty-handle-invalidation.ts
  • 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.

@nwparker
nwparker merged commit c1d980c into main Oct 24, 2026
43 of 44 checks passed
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.

[Bug]: Replacement terminal process inherits predecessor's stopped/exit state

2 participants