Skip to content

fix(remote-runtime): stop the host tab mirror from fighting renderer-owned agent status - #12641

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/remote-tab-status-title-flap
Aug 5, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/remote-tab-status-title-flap

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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 Terminal showing 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:

  1. The snapshot has no field for the generated title. Rebuilding the tab from it silently dropped the agent-derived label, so the tab fell back to Terminal.
  2. Status was decided by comparing timestamps from two different machines. The client's updatedAt and the host's updatedAt come 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 a done status 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.

  • New renderer-owned agent status registry (renderer-owned-agent-status-registry.ts). A pane claims authority at the same place shouldOwnAgentStatusInRenderer is 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.
  • The mirror respects that fence. For a pane the client provably owns, a fresh client entry survives both the overwrite path and the delete path of a host snapshot, while still adopting the host's identity fields (worktree, tab id, provider session). The entry still decays through the normal freshness boundary, so an agent that dies silently hands the pane back to the host.
  • Mirrored tabs now carry the client's generatedTitle through snapshot rebuilds, and unified tabEqual compares generatedLabel so the two label surfaces cannot silently diverge.
  • The host stops inventing a finished state. Only shell/management title evidence may downgrade a published status to 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 of pty.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 blocked states 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 (statusState flipping to done while the generated title stayed). Restored: 8 passed.
  • orca-runtime-mobile-agent-status-title-truthfulness.test.ts — asserts the host does not publish done off 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 ten agent-status-* slice tests: 15 files, 726 tests, all passing.

pnpm run typecheck (node + cli + web) passes. oxlint is clean on all changed files. oxfmt --check is clean on the changed lines — it flags one pre-existing formatting deviation in orca-runtime.ts at line ~10679, which is present unmodified on main and 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.

…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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, implementation, testing, and deferred work, but it omits the required template sections for screenshots, AI review, and security audit. Add the required template sections, state whether visual changes exist, document cross-platform AI review coverage, and include a security audit summary.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the remote-runtime fix that prevents host tab mirroring from overriding renderer-owned agent status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)

3600-3608: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive the registration condition from shouldOwnAgentStatusInRenderer.

Line 3600 already computes runtimeEnvironmentId !== null as shouldOwnAgentStatusInRenderer. Lines 3605-3608 repeat the same predicate. shouldOwnAgentStatusInRenderer gates the onAgentStatus wiring 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)
       : null
src/main/runtime/orca-runtime-mobile-agent-status-title-truthfulness.test.ts (1)

1-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between eebaf47 and 214a4f2.

📒 Files selected for processing (7)
  • src/main/runtime/orca-runtime-mobile-agent-status-title-truthfulness.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.test.ts
  • src/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.ts
  • src/renderer/src/runtime/web-session-tabs-sync-remote-status-title-flap.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts

@Jinwoo-H
Jinwoo-H merged commit 003114d into main Aug 5, 2026
43 checks passed
Jinwoo-H added a commit that referenced this pull request Aug 5, 2026
…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.
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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.

2 participants