Skip to content

fix(remote-runtime): stop a slept paired client from erasing its own agent rows - #12664

Merged
Jinwoo-H merged 1 commit into
mainfrom
investigate/sta-3107-reconnect-terminals
Aug 5, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
investigate/sta-3107-reconnect-terminals

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

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

buildMirroredAgentStatusPatch 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. 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 past AGENT_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 what buildWorktreeAgentRows already 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 in waitForResubscribeHostSessionHandle makes 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.ts

Both suites inject at the seam (host snapshot mirror; multiplex onClose) with fake clocks — elapsed time is never the oracle, the row/handle inventory is.

  • Sidebar suite, red on main: 2 failed / 3 passed. The 3 that pass are the guardrails — a brief transport drop keeps all six rows, a pane the client never wrote status for still cedes to the host, and teardown still releases the row — so the oracle is not a rubber stamp. With the fix: 5/5 green.
  • Multi-pane materialization suite: green on main; red when fix(remote-runtime): materialize the host surface when reconnecting a terminal pane #11542 is reverted (11 of the expected 12 resubscribes; the parked pane never comes back).
  • Two independent signals prove the panes are alive when a row goes missing: the tab is still in tabsByWorktree, and the host still publishes a live PTY for it.
  • pnpm run typecheck clean. 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.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

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

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix and testing, but it omits the required Screenshots, AI Review Report, and Security Audit sections. Add all required template sections, including No visual change, the AI review and cross-platform checks, the security audit, and completed test checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the remote-runtime fix that prevents slept paired clients from deleting their own agent rows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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 (1)
src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.ts (1)

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

Condense 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

📥 Commits

Reviewing files that changed from the base of the PR and between e233d6a and a7c021c.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/paired-reconnect-multi-pane-materialization.test.ts
  • src/renderer/src/runtime/paired-reconnect-sidebar-agent-count.test.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 2496458 into main Aug 5, 2026
43 checks passed
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.

1 participant