Repository navigation
fix(remote-runtime): stop a slept paired client from erasing its own agent rows - #12664
Conversation
…agent rows A paired client working against a remote machine, slept and reopened later, came back with every terminal tab still open but fewer agents in the sidebar (reported: 6 tabs, 4 agents). The client mirror deletes a mirrored pane's agent status whenever the host snapshot carries none, unless the client's own byte-derived entry is still FRESH. For a remote pane the client is the only writer of OSC-derived status, and a laptop closed past AGENT_STATUS_STALE_AFTER_MS makes every such entry stale by definition — so the first snapshot after wake erased the sidebar row of every pane the client owned, while the tab and its live host PTY remained. Freshness was the wrong gate on that path. It exists to arbitrate two writers; in the delete branch the host published nothing, so there is nothing to arbitrate and "my status is old" became "delete the pane". Ownership is the right gate: a pane this renderer claimed and wrote keeps its entry and decays through the normal staleness boundary to idle, exactly like a local pane. Teardown releases the claim, which is how the host takes the pane back. Contract change: reverses the stale-boundary deletion pinned by #12641, whose premise (staleness hands the pane back to the host) does not hold when the host has no value to hand it back to; that test is updated in place. Refs STA-3107.
📝 WalkthroughWalkthroughThe change separates renderer ownership from agent-status freshness. Stale renderer-owned entries remain stored until teardown or ownership release. New regression tests cover six-pane paired-client reconnects, PTY resubscription, parked-tab activation, host snapshots, renderer-owned status writes, sidebar rows, and status retirement rules. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (1)
src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts (1)
1-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the new explanatory comments.
Keep only the non-obvious invariant at each site. Remove scenario history and step-by-step test narration.
src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts#L1-L20: Reduce the file banner to the stale client-owned row-retention invariant.src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts#L198-L203: State the mocked production contract in one line.src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts#L306-L308: State the two liveness signals in one line.src/renderer/src/runtime/web-session-tabs-sync.ts#L824-L827: State that owned entries remain when no host replacement exists.src/renderer/src/runtime/web-session-tabs-sync-remote-status-title-flap.test.ts#L462-L470: State that stale owned entries remain stored and render idle.src/renderer/src/components/terminal-pane/paired-reconnect-multi-pane-materialization.test.ts#L1-L12: State the six-pane reconnect invariant.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through how the code works.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ca150959-27c3-46fa-b990-46b5b94c3330
📒 Files selected for processing (4)
src/renderer/src/components/terminal-pane/paired-reconnect-multi-pane-materialization.test.tssrc/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.tssrc/renderer/src/runtime/web-session-tabs-sync-remote-status-title-flap.test.tssrc/renderer/src/runtime/web-session-tabs-sync.ts
…agent rows (stablyai#12664) After a laptop sleep against a remote machine, the sidebar agent count came back lower than the number of open terminal tabs — rows vanished for panes whose tab and host process were both still alive. The client mirror deletes a mirrored pane's agent status whenever the host snapshot carries none for it, unless the client's own byte-derived entry is still fresh. But for a remote pane the client is the ONLY writer of that status, and a laptop closed past the 30-minute staleness boundary makes every such entry stale by definition — so the first snapshot after wake erased the sidebar row of every pane the client owned. Freshness was the wrong gate. It exists to arbitrate between two competing writers, but on the delete branch the host published nothing, so there was nothing to arbitrate and "my status is old" quietly became "delete this pane". The branch now gates on ownership: a pane this renderer claimed and wrote keeps its entry and decays to idle through the normal staleness boundary, exactly like a local pane. Teardown releases the claim, which is how the host takes the pane back. That reverses a contract stablyai#12641 pinned, so its test was updated in place with the reasoning inline rather than deleted — the old premise was that going stale hands the pane back to the host, which does not hold when the host has no value to hand back. The assertion is now stricter: the entry must be retained AND read as stale so consumers render it idle. This is the sidebar-count half of STA-3107. The blank-terminal half was fixed by stablyai#11542 and is proven so: reverting that fix in a six-pane harness makes exactly one of six panes fail to resubscribe while its siblings recover, matching the report. A remaining gap is documented in the PR: a pane the client never wrote status for stays host-authoritative and can still lose its row. Separating "the host has no opinion" from "the host proved there is no agent" needs the origin marker tracked as STA-3455.
Fixes half of STA-3107 (#11791): "Reconnecting to the remote machine doesn't load all terminals properly."
The report has two symptoms. They turned out to have different causes, so I tested them as separate invariants.
(b) Sidebar agent count lower than the tab count — still broken on main, fixed here
A paired client working against a remote machine, slept and reopened later, comes back with every terminal tab still open and still backed by a live host PTY, but with fewer agents in the sidebar (reporter's screenshot: 6 tabs, 4 agents).
buildMirroredAgentStatusPatchdeletes a mirrored pane's agent status whenever the host snapshot carries none for it, unless the client's own byte-derived entry is still fresh. For a remote pane the client is the only writer of OSC-derived status (the host publishes nothing for OSC-driven panes — see the comment on that branch), and a laptop closed pastAGENT_STATUS_STALE_AFTER_MS(30 min) makes every such entry stale by definition. So the first snapshot after wake erases the sidebar row of every pane the client owned.Freshness is the wrong gate on that path. It exists to arbitrate two writers; in the delete branch the host published nothing, so there is nothing to arbitrate and "my status is old" silently became "delete the pane". Ownership is the right gate: a pane this renderer claimed and wrote keeps its entry and decays through the normal staleness boundary to
idle— exactly whatbuildWorktreeAgentRowsalready does for a local pane. Pane teardown releases the claim, which is how the host takes the pane back.Contract change: this reverses the stale-boundary deletion pinned by #12641, whose premise (going stale hands the pane back to the host) does not hold when the host has no value to hand it back to. That test is updated in place to assert decay-not-delete, with the rationale inline.
(a) One terminal blank/black — no longer reproduces; fixed by #11542
I could not reproduce the blank pane on current main, and mutation testing shows why: reverting #11542's
activate-first recovery inwaitForResubscribeHostSessionHandlemakes exactly one pane of six fail to resubscribe after the shared multiplex connection drops, while its five healthy siblings recover. That is the reporter's "one terminal blank". The new multi-pane harness is kept as regression coverage for the multi-tab shape this ticket adds over STA-3002.Verification
Harness:
pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts src/renderer/src/components/terminal-pane/paired-reconnect-multi-pane-materialization.test.tsBoth suites inject at the seam (host snapshot mirror; multiplex
onClose) with fake clocks — elapsed time is never the oracle, the row/handle inventory is.tabsByWorktree, and the host still publishes a live PTY for it.pnpm run typecheckclean. Full unit suite: 4282 files passed; the 3 unrelated failures (check-root-directory-entries,relay/agent-exec-handler, a flaky backpressure integration) reproduce identically with this change stashed — they are worktree/env artifacts.Known remaining gap
A pane the client has never written byte-derived status for stays host-authoritative, so it still loses its row when the host drops its own retained hook status at
getFreshRetainedAgentStatusForMobileTab's staleness check (orca-runtime.ts). Distinguishing "the host has no opinion" from "the host proved there is no agent" needs the origin marker already tracked as STA-3455; this change deliberately does not widen into that.