Repository navigation
fix(terminal): prevent automatic replacement of host-mirrored agents - #29289
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to
|
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:
5514efe8-9542-4923-bc9e-1e1586c65f0d
📒 Files selected for processing: 10
src/renderer/src/lib/host-mirror-handle-gap-resume.test.tssrc/renderer/src/lib/host-mirror-handle-gap-wait.tssrc/renderer/src/lib/host-mirrored-pane-liveness.tssrc/renderer/src/lib/host-mirrored-pane-resume-replay.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.tssrc/renderer/src/lib/retracted-host-pane-resume.test.tssrc/renderer/src/lib/worktree-reactivation-preserved-pane-replacement.test.tssrc/renderer/src/runtime/host-session-mirror-frame-ordering-harness.tssrc/renderer/src/runtime/host-session-mirror-hydration-frame-ordering.test.tsxsrc/renderer/src/runtime/host-session-mirror-settle-receipt-frames.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| if (isHostMirroredSleepingRecord(record)) { | ||
| continue |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Block native resumes that share a host-owned provider session.
If a newer native record shares a provider session with an older mirrored record, the sweep clears the mirrored record and launches the native one. The new duplicate-record test exercises that path. A retracted mirror row does not establish that the host stopped writing the session. Check for a mirrored record across the claim key before launching any record for that session. Keep the mirrored record until host ownership is resolved.
a4a4320 to
b0d6dea
Compare
ELI5
A paired desktop could restart an agent after another client closed its tab, creating another writer for the same conversation. The desktop now leaves that automatic restart decision to the machine running the agent.
What Changed
The resume sweep declines a replacement launch for a
web-terminal-*recovery record. The guard sits immediately before launch, after existing completed-session cleanup, duplicate cleanup and preserved-pane ownership checks. This keeps those behaviors unchanged while preventing an automatic second writer.The launch guard covers retracted rows, inventory settling before the old row disappears, a split pane whose sibling has the only handle, and an expired handle wait. Stable and legacy pane keys are recognized. Existing native and direct SSH recovery paths remain covered.
Why
A missing mirrored row or expired handle wait cannot distinguish an explicit close, reconnect re-key, pending handle, or actual process exit. Retirement proofs also do not distinguish user close from natural exit. The host's existing automatic-session API explicitly rejects these legacy sleeping records as insufficient authority. Treating the sweep as an explicit user resume would bypass that boundary.
Blocking only the replacement launch is narrower than bypassing all cleanup for mirrored records. Completed history is still cleaned up, and an older mirrored duplicate does not survive when a newer native record recovers the conversation.
Linked Issue
Refs #21235. Addresses the reproduced paired-client retraction path and related mirror ordering cases. The latest iOS host-side live-pane omission is not verified or claimed fixed; #24386 addresses related live-PTY census work. Keep #21235 open until those remaining triggers are verified.
Visual Proof
No live paired-client recording captured. Tests drive production resume/store logic and stream-frame reconciliation, including phone-triggered background wake, with mocked runtime boundaries. Live paired sleep/wake remains a validation gap.
Testing
macOS arm64;
ORCA_BACKGROUND_LAUNCH=1on every test command.pnpm tc:web,pnpm run check:code-quality:changed, formatting, andgit diff --checkpassed.src/renderer/src/lib/retracted-host-pane-resume.test.tsandsrc/renderer/src/lib/host-mirror-handle-gap-resume.test.ts. Both fail on main's production code (the sweep launches a replacement agent) and pass on this branch.Review
Merge risk: medium, with a smaller regression surface than the first revision. Completed-session and duplicate cleanup retain their prior behavior. A lone recoverable mirror record survives without launching a replacement.
Remaining behavior tradeoff: even a genuinely exited or deliberately slept mirrored remote agent can require host recovery or an explicit resume. In particular, automatic client recovery of remote
worktree-sleeprecords is suppressed. Restoring it safely requires a host-authorized recovery checkpoint and an atomic ownership claim; no such protocol change is included here. Headless hosts cannot rely on renderer-based wake.Independent read-only review found no safe existing host exit/close predicate that could authorize a narrower automatic launch. Full PR CI must pass for the updated commit before merge; the previous commit's aggregate failed on the two activation expectations updated here.
Agent skill upstream boundary
Notes
No wire, persisted-format, platform command, or provider-specific changes. Native host-owned mobile wake retains its existing path. No live Windows/Linux/SSH/paired iOS validation; full lint/test/build are left to CI.
Checklist