Repository navigation
fix(remote-runtime): stop the host tab mirror from fighting renderer-owned agent status - #12641
Conversation
…owned agent status
A remote-paired terminal tab flickered several times per second between the
agent's generated title with a running status and a plain "Terminal" tab
reading "Done - Claude", because two writers owned the same state.
The paired client derives agent status from the terminal byte stream, but every
host session.tabs snapshot rebuilt the mirrored tab without the client's
generated title and re-decided status by comparing `updatedAt` stamps taken on
two different machines. The host also read a neutral live title ("Terminal") as
proof the agent had finished, synthesised a `done` entry, and dated it with the
pane's last-output time — so the host frame advanced with every output byte and
always looked newer. Neither writer could win, so the UI alternated forever.
The fix removes the second writer instead of arbitrating two clocks:
- new renderer-owned-agent-status-registry: a pane claims authority where
shouldOwnAgentStatusInRenderer is decided and proves it on the first
byte-derived write; registration returns an identity-checked release so a
superseded mount's late dispose cannot strip a live pane's claim
- mirror keeps a fresh client-owned entry (overwrite and delete paths) while
still adopting host identity fields; host `blocked`/interactivePrompt states
pierce the fence because they only reach the host over its HTTP agent hook
- mirrored tabs carry the client generatedTitle, and unified tabEqual compares
generatedLabel so the two label surfaces cannot diverge
- host projection: only shell/management title evidence may downgrade a
published status to `done`, and the identity-only fallback is dated by its
title evidence instead of pty.lastOutputAt
Purely local and plain SSH panes have a single writer and are unaffected.
📝 WalkthroughWalkthroughThe runtime now retains agent status for neutral titles and timestamps identity-only completion from title or hook evidence. Runtime-backed PTYs register, confirm, and release renderer-owned status authority. Remote tab synchronization preserves fresh client status and generated titles, while host blocked or prompt states can override it. New tests cover projection, registry lifecycle, synchronization interleavings, freshness, teardown, and pane isolation. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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.
🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
3600-3608: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDerive the registration condition from
shouldOwnAgentStatusInRenderer.Line 3600 already computes
runtimeEnvironmentId !== nullasshouldOwnAgentStatusInRenderer. Lines 3605-3608 repeat the same predicate.shouldOwnAgentStatusInRenderergates theonAgentStatuswiring at line 3810 and the fact-consumer wiring at line 3333. If that predicate later gains a condition, the registration would claim panes whose status the renderer no longer owns.Bind the two conditions to one source.
♻️ Proposed refactor
const shouldOwnAgentStatusInRenderer = runtimeEnvironmentId !== null // Why: the host also mirrors agent status for this pane through session.tabs. // Claiming here (decided once at transport creation, like the side-effect // authority below) lets the mirror keep this renderer's byte-derived status // instead of overwriting/deleting it on every republication. const releaseRendererOwnedAgentStatusPane = - runtimeEnvironmentId !== null + shouldOwnAgentStatusInRenderer && runtimeEnvironmentId !== null ? registerRendererOwnedAgentStatusPane(cacheKey, runtimeEnvironmentId) : nullsrc/main/runtime/orca-runtime-mobile-agent-status-title-truthfulness.test.ts (1)
1-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the file header comment.
Keep the regression intent in one concise line. The current five-line comment explains test behavior in detail.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d4c2832a-cb83-4c16-9a4f-33c343de0516
📒 Files selected for processing (7)
src/main/runtime/orca-runtime-mobile-agent-status-title-truthfulness.test.tssrc/main/runtime/orca-runtime.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.test.tssrc/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.tssrc/renderer/src/runtime/web-session-tabs-sync-remote-status-title-flap.test.tssrc/renderer/src/runtime/web-session-tabs-sync.ts
…agent rows (#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 #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 #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.
|
thanks for reporting. looking into it |
…owned agent status (stablyai#12641) A remote-paired terminal tab flickered several times per second between the agent-generated title with a running status, and the plain title "Terminal" with "Done - Claude" in the sidebar. Two writers owned the same state. For remote panes the client parses agent status out of the terminal byte stream, while every host tab snapshot rebuilt the mirrored tab WITHOUT the client's generated title and re-decided status by comparing timestamps taken on two different machines. The host also treated a neutral live title ("Terminal") as proof the agent had finished, and re-stamped that conclusion with the pane's last-output time — so it advanced with every output byte and always looked newer. Neither writer could ever win. This removes the second writer rather than trying to arbitrate two clocks: the client is authoritative for panes whose status it parses (only while attached, released on teardown), the host no longer invents a finished state from a neutral title, and the generated title is carried through snapshot rebuilds. The client was chosen as the authority because the host snapshot format carries no generated title at all — making the host authoritative would permanently lose generated titles on paired clients. Purely local and plain SSH panes are structurally unaffected: they have only one writer. Verified with a reproduction that is red on main (frames show done -> working -> done with the label flipping on every publication) and green with the fix. Independent review additionally found and fixed a defect where a superseded pane's late cleanup could permanently strip a live pane's authority, reinstating the very flap being fixed. Deferred follow-up STA-3455: host `blocked`/interactive-prompt states can still pierce the fence and fall back to cross-machine timestamps; fixing that properly needs an origin marker on the status entry.
…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.
The bug
On a remote-paired session, a terminal tab flickered several times per second. It alternated between the agent's generated title (e.g. "Configurar y entender los comprobantes") with a running status, and a plain tab titled
Terminalshowing Done - Claude in the sidebar — while the agent was still working.Why it happened
Two different places were both writing the same piece of state, and they disagreed forever.
On a paired client, the browser/renderer reads agent status out of the terminal's byte stream — that is how it knows the agent is working and what to call the tab. Meanwhile, the host machine publishes a periodic snapshot of its tabs. Every time that snapshot arrived, the client rebuilt the mirrored tab from it, and two things went wrong:
Terminal.updatedAtand the host'supdatedAtcome from two different wall clocks, so "whichever is newer wins" is not a meaningful comparison.The host made this worse in two ways. It treated a neutral live terminal title (
Terminal) as proof the agent had finished, and synthesised adonestatus from it. It then stamped that synthetic status with the pane's last output time — which advances with every byte the agent prints. So the more actively the agent worked, the fresher the host's "it's done" frame looked, and it always outranked the client's real status.The result: the client wrote "working + generated title", the next host snapshot overwrote it with "done + Terminal", the client's byte stream wrote it back, and so on. Neither writer could win, so the tab alternated indefinitely.
What this PR does
It removes the second writer rather than trying to arbitrate two clocks.
renderer-owned-agent-status-registry.ts). A pane claims authority at the same placeshouldOwnAgentStatusInRendereris decided, and proves the claim on its first byte-derived write. Teardown cedes authority back to the host. Registration returns an identity-checked release, so when a pane is replaced, the superseded mount's late cleanup cannot strip the live pane's claim.generatedTitlethrough snapshot rebuilds, and unifiedtabEqualcomparesgeneratedLabelso the two label surfaces cannot silently diverge.done(the same predicate the terminal-status API already uses); a merely neutral title proves nothing. And the identity-only fallback is now dated by the title evidence that produced it (lastOscTitleEpochMs) instead ofpty.lastOutputAt, so it no longer advances with the byte stream.Why the client, and not the host, was made authoritative
The host snapshot format carries no generated title at all. Making the host authoritative would have fixed the flapping by permanently losing generated titles on every paired client — every remote tab would just read
Terminal. The client is the only writer that has the information, so it owns the state.Host
blockedstates and interactive prompts deliberately pierce the fence: those reach the host over its HTTP agent hook and never appear in the PTY byte stream, so the client genuinely cannot observe them.Local and plain SSH panes are unaffected — they have only one writer, so none of this arbitration applies to them.
Verification
Two new tests were confirmed to be genuine oracles on this branch (reverted the production change, watched them fail, restored it, watched them pass):
web-session-tabs-sync-remote-status-title-flap.test.ts— replays host snapshots against live client byte status and asserts the status/label sequence never oscillates. With the fence disabled: 2 failed / 6 passed, failing exactly on the symptom (statusStateflipping todonewhile the generated title stayed). Restored: 8 passed.orca-runtime-mobile-agent-status-title-truthfulness.test.ts— asserts the host does not publishdoneoff a neutral title. With the host change reverted: 1 failed / 5 passed. Restored: 6 passed.Full run of the flap repro, the new registry test, the host truthfulness test,
pty-connection.test.ts,web-session-tabs-sync.test.ts, and all tenagent-status-*slice tests: 15 files, 726 tests, all passing.pnpm run typecheck(node + cli + web) passes.oxlintis clean on all changed files.oxfmt --checkis clean on the changed lines — it flags one pre-existing formatting deviation inorca-runtime.tsat line ~10679, which is present unmodified onmainand is nowhere near this diff, so it was left alone rather than mixed into this PR.Deliberately deferred follow-up
Host
blocked/ interactive-prompt states still pierce the fence and fall back to cross-machine timestamp comparison. That path is much rarer and is not what caused the reported flapping, but it is the same class of bug. Fixing it properly needs an origin marker on the status entry so the client can tell a host-originated state from its own — that is a shared-type change with a wider blast radius, so it is tracked separately rather than bundled here.