Repository navigation
fix(runtime): reject stale inventory after PTY lifecycle changes - #21014
Conversation
📝 WalkthroughWalkthroughThe runtime now invalidates pending PTY controller inventory when a PTY spawns, exits, or registers. It records invalidation by provider or aggregate execution host and uses canonical provider keys. New fixtures and tests cover stale responses, lifecycle replacements, host routing, concurrent generations, retries, and deadlines. Audit artifacts record 16 failing baseline cases and 22 passing fixed cases. Priority: ➖ Normal 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 286d57ba-bce6-4e28-8bd8-c573f59105ef
📒 Files selected for processing (10)
docs/audits/stale-pty-inventory/README.mddocs/audits/stale-pty-inventory/fix.patchdocs/audits/stale-pty-inventory/reproduce.mjsdocs/audits/stale-pty-inventory/results.jsonsrc/main/runtime/orca-runtime-invalidate-all-handles-for-pty.tssrc/main/runtime/orca-runtime-on-pty-exit.tssrc/main/runtime/orca-runtime-register-pty.tssrc/main/runtime/pty-inventory-lifecycle-admission.test.tssrc/main/runtime/pty-inventory-lifecycle-fixture.tssrc/main/runtime/pty-inventory-lifecycle-scope.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
Important
The lifecycle fence is keyed differently from the reader it must trip, so it silently no-ops for SSH targets whose id needs percent-encoding (e.g. [email protected]:2222) — the stale census this PR is meant to reject is still accepted there.
Reviewed changes
- Lifecycle inventory fence —
invalidatePtyControllerInventoryForLifecyclebumps the provider inventory generation fromonPtySpawned,onPtyExit, andregisterPty, so the existingisCurrentInventorycheck rejects the entire pending census before handle adoption, record mutation, or absence processing. - Scoping —
foreign/runtimehosts bump the aggregate generation and return; SSH/local hosts bump a per-provider entry; targeted reads keep their single retry and original deadline; no wire fields or per-PTY registry. - Tests — 18 new cases (admission + scope/retry bounds) over a shared fixture, plus the before/after audit harness under
docs/audits/stale-pty-inventory/. I reran the two new suites and the adjacent inventory suites (51 passed).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Use the aggregate generation when PTY ownership is unknown. · fix.patch:35
docs/audits/stale-pty-inventory/fix.patch:35
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUse the aggregate generation when PTY ownership is unknown.
SSH relay restoration calls
onPtySpawnedwithout aconnectionIdorregisterPtyrecord. For a legacy unqualifiedappPtyId,getPtyExecutionHostreturnsnull, so invalidation updatesLOCAL_EXECUTION_HOST_ID. A targeted SSH inventory can then still satisfyisCurrentInventorybecause its SSH provider generation and the aggregate generation are unchanged. When bothhostIdandconnectionare absent, updateptyControllerAggregateInventoryGenerationinstead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: defc04e5-8853-4b15-8c76-aec8269e5386
📒 Files selected for processing (6)
docs/audits/stale-pty-inventory/README.mddocs/audits/stale-pty-inventory/fix.patchdocs/audits/stale-pty-inventory/reproduce.mjsdocs/audits/stale-pty-inventory/results.jsonsrc/main/runtime/orca-runtime-refresh-pty-worktree-records-with-controller-inventory.tssrc/main/runtime/pty-inventory-lifecycle-scope.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/runtime/pty-inventory-lifecycle-scope.test.ts
- docs/audits/stale-pty-inventory/README.md
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The delta since the prior pullfrog review (099f339) canonicalizes the provider inventory generation key on the reader side and adds encoding-sensitive regression coverage for the previously flagged mismatch.
- Canonicalized the reader's provider key —
refreshPtyWorktreeRecordsWithControllerInventorynow derivesproviderKeyviatoSshExecutionHostId(connectionId)/LOCAL_EXECUTION_HOST_IDinstead of the raw`ssh:${connectionId}`/'local', matching whatinvalidatePtyControllerInventoryForLifecyclewrites. - Added encoding-sensitive regression tests — the scope suite now runs the legacy-unqualified and
ssh:<id>@@childstale-inventory cases over[email protected]:2222andssh target, the ids the fence previously missed. - Updated the audit record —
README.md/results.jsonnow report 16 failing / 6 passing before and 22 passing after, andreproduce.mjsasserts process exit codes in addition to pass/fail counts.
I independently confirmed the new tests are not theatre: swapping the pre-fix reader back in makes both encoding-sensitive cases fail with the stale row adopted (pending non-null), and they pass on the head. Head CI is green (16 success, 12 skipped, 1 in progress, 0 failures).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
A terminal inventory can arrive after the terminal has already closed or been replaced. Orca could then use that old list to reconnect the wrong terminal. This change rejects an inventory that became outdated while it was being fetched.
What Changed
Invalidate an in-flight inventory when an accepted spawn, registration, or exit changes ownership. The existing stale-response check rejects the whole result before it updates owners or processes missing entries.
Why
An old “this terminal exists” or “this terminal is missing” answer is unsafe after ownership changes. Reusing the existing generation check avoids another registry or wire field.
Tradeoff
A lifecycle race can require fetching inventory again. Targeted reads keep one retry within the original deadline; other hosts remain independent.
Linked Issue
Related to #19018. This is primarily an ownership-correctness fix, not a measured incident-scale OOM fix.
Visual Proof
No before/after UI capture is attached; this is a lifecycle behavior change. Automated behavior evidence is linked under Testing.
Testing
The recorded proof covers stale positive and absent rows, reused IDs, replacement terminals, host isolation, fresh discovery, and bounded retries. 22 before/after proof cases plus 16 adjacent regression cases are recorded in
docs/audits/stale-pty-inventory/.Review
The stale-result guard is host-scoped: it covers local and WSL PTYs, direct SSH providers, folder workspaces, and paired sessions on the runtime that owns them. A paired client does not substitute its local inventory for a remote host's inventory. The targeted proof covers 22 before/after cases plus 16 adjacent regressions, and current typecheck, static analysis, and full CI pass. A lifecycle race can still require the documented bounded retry.