Skip to content

Fix stale working spinners on remote terminal tabs - #25205

Closed
thefrikidude wants to merge 4 commits into
stablyai:mainfrom
thefrikidude:codex/fix-remote-terminal-stale-spinner
Closed

thefrikidude wants to merge 4 commits into
stablyai:mainfrom
thefrikidude:codex/fix-remote-terminal-stale-spinner

Conversation

@thefrikidude

Copy link
Copy Markdown
Contributor

ELI5

A remote client can keep showing a working spinner after an agent has finished. This change refreshes stale terminal titles and status from the host so completed agents stop looking busy.

What Changed

  • Reconcile existing runtime pane titles when a remote host snapshot arrives, including tabs in inactive workspaces.
  • Remove titles belonging to panes absent from the current layout and ignore orphan titles when calculating activity.
  • Allow host status to replace expired client entries even when the client entry has a greater timestamp.
  • Add regression coverage for stale titles, completion, split panes, and status updates after the client window becomes visible.

Why

Saved spinner titles could outlive the activity that produced them. Updating the tab title alone left those pane titles behind.

This uses the existing remote snapshot flow. Valid numeric runtime pane IDs are refreshed rather than removed globally, because local terminal replay still uses them. The existing fresh byte-stream ownership protection is preserved.

Linked Issue

Fixes #25136

Visual Proof

After: normal completion tested with two source-built Orca instances on one Mac.

Screen.Recording.2026-10-04.at.2.05.26.PM.mov

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Manual testing: connected two Orca instances on macOS, ran an agent task on the host, and confirmed the loader cleared on both instances after completion.

Automated validation:

  • 139 tests passed across nine focused test files.
  • Changed-code quality gate passed.
  • Coverage includes expired client status, stale numeric titles, orphan pane titles, working split-pane siblings, and completion after visibility resume.

Full validation:

  • pnpm lint passed.
  • pnpm typecheck passed after correcting regression-test typings.
  • All 139 focused tests passed again.
  • Full-suite retry used two workers and stopped on failure: 8,035 tests passed, but the cross-version harness lacked release tags and a browser-pane test reported document is not defined.
  • pnpm build failed during the mobile web step because dependencies including react-native-web and expo-router were missing. Desktop bundles and the web client built successfully.

AI Disclosure

Developed with assistance from OpenAI Codex (GPT-6), including implementation, regression tests, and code review.

Review

  • Cross-platform: no new OS-specific calls, paths, or shortcuts.
  • Local/remote/SSH: title reconciliation is scoped to remote mirrors; local mirror titles are preserved. SSH was considered but not manually tested.
  • Agents/integrations: the fix uses generic terminal status and title handling.
  • Performance: reconciliation runs during accepted host snapshots and copies title records only when changed.
  • UI: existing styling is unchanged; macOS completion behavior was manually checked.
  • Security: no new permissions, credentials, network endpoints, or wire fields.

Agent skill upstream boundary

  • Not applicable; no upstream agent-skill code was copied.

Notes

Linux, Windows, SSH, and mobile manual verification remain pending. Existing visibility-resume subscriptions are retained; this does not keep hidden windows continuously synchronized.

Author X handle: @thefrikidude

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4ee5f08c-281b-46ae-ab50-146b29fda87a
Commits

Reviewing files that changed from the base of the PR and between 9d07d05 and e0e8adc.

Files selected for processing: 9
  • src/renderer/src/lib/worktree-status.ts
  • src/renderer/src/runtime/web-session-tabs-sync-completion-on-reveal.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-stale-spinner.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.ts
  • src/renderer/src/runtime/web-session-tabs-sync/runtime-pane-title-patch.ts
  • src/renderer/src/runtime/web-session-tabs-sync/state.ts
  • src/shared/runtime-pane-title-leaf-id.test.ts
  • src/shared/runtime-pane-title-leaf-id.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

Host snapshots now reconcile mirrored runtime-pane titles and agent status. The title patch handles freshness, client ownership, pending placeholders, orphan panes, and local terminal mode. Worktree status detection skips pane titles that do not map to the current layout. Tests cover stale spinner repair, split-pane activity, batched snapshots, and updates after the document becomes visible again.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to e0e8a

Live panes with gapped IDs may lose their activity title. This bounded limitation warrants owner awareness, but the investigated legacy-title case does not leave the working spinner active.

Security architecture risk: Low · up to 6e5e9

Remote hosts can now repair saved terminal titles and expired activity status while fresh local activity remains protected. The reviewed change is narrowly scoped, but incomplete recovery and environment coverage limits assurance.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly reached state is saved pane-title evidence for mirrored tabs processed from host snapshots. Effects include inactive workspaces supplied in an inventory; one reconciliation invocation does not independently cover every workspace. No new privileged command path was identified in this state-flow extension.

Trust Boundaries and Controls

  • observed — Host-controlled title evidence is matched by host tab and layout leaf before updating an existing mirrored title slot. Status identities are separately remapped to mirrored pane keys. Missing eligible surfaces cause slot deletion rather than arbitrary title assignment.
  • observed — Fresh renderer-owned byte-stream status fences both title replacement and competing host status. The existing exceptions for blocked status or interactive prompts remain. Freshness rejects restored-unconfirmed entries and uses observed evidence time; regression assertions distinguish expired client status from a fresh writer.

Resilience and Maintainability Implications

  • observed — The existing commit wrapper rethrows producer failures before patch completion, but contains subscriber failures after the patch lands and post-commit freshness/notification bookkeeping failures. This keeps those later failures from being treated as an uncommitted reconciliation.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "Fix stale working spinners on remote terminal tabs" matches the main change: reconciling stale saved runtime pane titles and status from the host so completed agents stop showing a working …
Description check Passed The description follows the template. It has an ELI5 section, a What Changed list, a Why section, a Linked Issue (Fixes #25136), Visual Proof with a video link, Testing details, an AI Disclosure, Revi…
Linked Issues check Passed [#25136] Requirements are covered by the reviewed head.

1. Stale or orphan pane titles must not drive activity. isRuntimePaneTitleOrphan (src/shared/runtime-pane-title-leaf-id.ts) reports a title o…
Out of Scope Changes check Passed Every changed area maps to #25136 or supports its implementation:
- runtime-pane-title-leaf-id.ts and its tests: orphan detection for the stale-title requirement.
- runtime-pane-title-patch.ts: ho…
Full details: Title check

Explanation

The title "Fix stale working spinners on remote terminal tabs" matches the main change: reconciling stale saved runtime pane titles and status from the host so completed agents stop showing a working spinner on remote tabs. It is short, specific, and uses an active verb. It omits the mechanism, but that is acceptable.

Full details: Description check

Explanation

The description follows the template. It has an ELI5 section, a What Changed list, a Why section, a Linked Issue (Fixes #25136), Visual Proof with a video link, Testing details, an AI Disclosure, Review notes, the upstream boundary checkbox, Notes, and a checklist. Some items remain open: the Visual Proof section has only an After clip and no Before, and the Linked Issue line is a bare link that should be checked. The checklist shows unchecked lint/typecheck/test/build, and the Testing section reports the build failed in the mobile web step. The Testing section does not give concrete reviewer steps. These gaps are non-critical relative to the overall completeness.

Full details: Linked Issues check

Explanation

[#25136] Requirements are covered by the reviewed head.

  1. Stale or orphan pane titles must not drive activity. isRuntimePaneTitleOrphan (src/shared/runtime-pane-title-leaf-id.ts) reports a title orphaned when its resolved leaf is absent from the layout. Unresolvable IDs are orphaned unless they are integer IDs below FIRST_PANE_ID (1). worktree-status.ts skips orphaned titles, so the tab-title fallback runs when every title is orphaned.

  2. Frozen legacy keys must be refreshed or removed on host snapshots. buildMirroredRuntimePaneTitlePatch (src/renderer/src/runtime/web-session-tabs-sync/runtime-pane-title-patch.ts) runs for active and inactive mirrored tabs. Numeric key "1" resolves to the leftmost leaf in replay order. When that leaf has an accepted host surface, the title is replaced with the normalized host title. Otherwise it is deleted when orphaned. Unplaceable IDs below FIRST_PANE_ID are kept.

  3. Host done must replace expired client status. The agent-status-patch.ts change lets the host entry override the client entry only when the client entry is expired. Fresh client-owned status is preserved.

  4. Prompt resync after the window becomes visible. The PR reuses the existing visibility-resume subscription. web-session-tabs-sync-completion-on-reveal.test.tsx covers completion published after hide and reveal for active and background workspaces. The PR states that hidden windows are not continuously synchronized. This is a documented limit, not a closed gap.

Tests cover stale numeric titles, orphan removal, split-pane siblings, pending-handle placeholders, fresh client-status fences, local mode, and completion after reveal.

Residual risk, not a failure: for key "1" in a layout with a live leaf, the title is kept unchanged when the host surface has an empty title or a fresh client fence applies. The stale spinner title could then persist in those cases. The reviewed evidence did not establish whether the author intended this. The focused tests I inspected did not show this case directly.

I used three repository reads. I did not inspect worktree-status.ts or the test files directly. Their conclusions rest on the supplied summary.

Full details: Out of Scope Changes check

Explanation

Every changed area maps to #25136 or supports its implementation:

  • runtime-pane-title-leaf-id.ts and its tests: orphan detection for the stale-title requirement.
  • runtime-pane-title-patch.ts: host-snapshot reconciliation of saved titles, including inactive tabs.
  • agent-status-patch.ts: expired client status replaced by host status.
  • apply-final-patch.ts: wires the title patch into the final patch. It is skipped in local PTY mode, which the PR justifies by local terminal replay still using numeric IDs.
  • state.ts: adds the runtimePaneTitlesByTabId state and batch-key types needed by the patch.
  • worktree-status.ts: skips orphaned titles during status evaluation.
  • Regression tests: cover the changed behavior.

No unrelated feature, refactor, or wire-format change is evident in the supplied summary. The PR description states that no new permissions, endpoints, or wire fields are added. The FIRST_PANE_ID constant is reused, not changed.

Full details: Docstring Coverage

Explanation

Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pullfrog pullfrog 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.

Important

One existing test regresses: the new layout-leaf guard in worktree-status.ts drops live pane titles, not just removed ones.

Reviewed changes

  • Reconcile mirrored runtime pane titles — new runtime-pane-title-patch.ts refreshes/deletes runtimePaneTitlesByTabId from accepted host surface titles, skipped for terminalPtyMode === 'local'.
  • Host status over expired client rows — an existing mirrored agentStatusByPaneKey row no longer blocks a host entry on timestamp alone once it is no longer fresh.
  • Worktree dot ignores layout-orphan pane titles — tabHasStatus filters pane titles by collectRuntimePaneLeafIds(layout.root) and falls through to the tab title when none survive.
  • State plumbing + tests — runtimePaneTitlesByTabId added to sync state/batch keys, plus stale-spinner and completion-on-reveal coverage.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/renderer/src/lib/worktree-status.ts Outdated
: freshPaneIds
const leafId = resolveRuntimePaneTitleLeafIdFromRoot(tabLayoutRoot, runtimePaneId)
// A removed pane's last title is no longer evidence for this tab.
if (layoutLeafIds && (leafId === null || !layoutLeafIds.has(leafId))) {

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.

This guard drops every runtime pane title whose id does not resolve to a current leaf, but resolveRuntimePaneTitleLeafIdFromRoot returns null for ids it simply cannot place — not only for removed panes. It has no single-leaf special case and no sparse-slot recovery, so a live pane title is discarded. The row builder resolves those same ids via resolveLeafIdForTitleFallback (leafIds.length === 1 → leafIds[0], otherwise resolveRuntimePaneTitleLeafIdFromSparseSlots), so the worktree dot now disagrees with the sidebar rows.

Technical details
# Live pane titles dropped as layout orphans

## Affected sites
- `src/renderer/src/lib/worktree-status.ts:102` — skips any entry with `leafId === null || !layoutLeafIds.has(leafId)`. `leafId === null` also covers ids that cannot be resolved (single-leaf layouts, gapped PaneManager ids, the `-(leafIndex+1)` parked slots), not just leaves removed from the layout.
- `src/renderer/src/runtime/web-session-tabs-sync/runtime-pane-title-patch.ts:54` — same resolver, so a mirrored tab with a single leaf and a sparse/gapped runtime slot (`leafId === null`) has no `hostSurface` and gets its title deleted rather than refreshed.

## Evidence
- `pnpm test src/renderer/src/lib/worktree-status-spinner-launch-agent.test.ts` fails at line 121: `expected 'active' to be 'working'`. The fixture (`worktree-status-spinner-launch-agent.test.ts:112`) uses a single-leaf layout with pane id `0` and a spinner pane title; base returned `working`, the PR returns `active`.
- The row builder's `resolveLeafIdForTitleFallback` (`components/sidebar/worktree-title-derived-agent-rows.ts:301-351`) deliberately handles both cases: `if (args.leafIds.length === 1) return args.leafIds[0]` and sparse-slot PTY recovery. `PaneManager.nextPaneId = FIRST_PANE_ID` and ids are never reused (`nextPaneId` only increments), so a current pane's id is commonly non-contiguous after any in-session close.

## Required outcome
- A pane title whose id is a live pane in a single-leaf tab, or is recoverable through the durable PTY→leaf bindings, must still count as current evidence.
- Orphan detection should only fire when the id resolves to a leaf that is provably absent from the current layout.

## Suggested approach (optional)
- Skip only on `leafId !== null && !layoutLeafIds.has(leafId)`; let `leafId === null` fall through to the existing title/single-unmapped handling.
- Or reuse `resolveLeafIdForTitleFallback` here so the dot and row builder share one resolution rule.
- If the intended scope really is "any unresolvable id is an orphan", update `worktree-status-spinner-launch-agent.test.ts:112` and explain the dot/row divergence in the test.

Only titles whose pane is provably gone (a leaf id missing from the layout, or an
out-of-range numeric slot) are dropped; legacy and parked ids below FIRST_PANE_ID
stay live, so the worktree dot agrees with the sidebar rows again.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013M6h74D6AvPqqNHRAddayF
@thefrikidude

Copy link
Copy Markdown
Contributor Author

Fixed the regression the review flagged. A pane title is now dropped only when its pane is provably gone: a leaf id missing from the layout, or an out-of-range numeric slot. Ids below FIRST_PANE_ID (parked/legacy slots) that the layout cannot place stay live, so the worktree dot agrees with the sidebar rows again. The same rule now guards the title-deleting patch. worktree-status-spinner-launch-agent.test.ts passes, and I added unit tests for the new helper. Known limit: a live pane whose id is gapped after a close is still treated as removed, because recovering it needs the PTY bindings. Could a maintainer approve the CI runs?

@Fede654

Fede654 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for working on this. I had opened #34129 for a related completion symptom; comparing it with your change and the host fix in #29538 uncovered a regression in my approach. I'm withdrawing that competing implementation and sharing the regression case here instead.

stateStartedAt cannot safely replace updatedAt as the ordering key for these mirrored transitions. Running the existing orca-runtime-mobile-agent-status-ordering.test.ts scenario on main at dc735050b3c6 and recording the projected rows produced:

Host publication state updatedAt stateStartedAt evidenceObservedAt
trailing Muse spinner working 1700000004534 1700000004534 absent
settled title / hook completion done 1700000004800 1700000000000 1700000000000

The earlier state-start time on the final done is intentional: #29538 advances its delivery timestamp while preserving the hook's original time. My state-start comparator incorrectly rejected that valid completion.

I replayed those two projected rows through the real renderer snapshot/store harness in web-session-tabs-sync-remote-status-title-flap.test.ts. Results on Linux (the new case plus the 10 existing harness tests):

This is a focused comparison of the merge conditions, not validation of either complete PR, and not a live paired-app test. It confirms that your condition preserves this existing host-side fix; it does not distinguish the two proposals or establish that either resolves every case in #25136.

If useful, this test can be added inside the existing remote status/title suite (reusing its helpers). The values above come from the host regression fixture based on #28102, rather than an assumed ordering of state-start times:

it('accepts the host completion after a trailing Muse spinner', () => {
  const store = seedPairedClientStore()
  const rows = [
    {
      state: 'working',
      updatedAt: T0 + 4_534,
      stateStartedAt: T0 + 4_534
    },
    {
      state: 'done',
      updatedAt: T0 + 4_800,
      stateStartedAt: T0,
      evidenceObservedAt: T0
    }
  ] as const

  for (const [index, row] of rows.entries()) {
    applyHostSnapshot(
      store,
      makeHostSnapshot({
        snapshotVersion: index + 1,
        hostNow: row.updatedAt,
        includeAgentStatus: true,
        agentStatusOverrides: row
      }),
      row.updatedAt
    )
    expect(store.getState().agentStatusByPaneKey[MIRROR_PANE_KEY]?.state).toBe(row.state)
  }
})

Shared with the author's authorization; investigation and test execution assisted by OpenAI Codex. Thank you for the existing implementation and reproduction work.

main moved tab-has-live-pty and runtime-pane-title-leaf-id into shared/ and
regrouped the remote runtime client modules. Use the shared import paths in
worktree-status and runtime-pane-title-patch, and point the two new tests at
the modules' new homes (snapshot-api, state, terminal-surface-id,
use-web-session-tabs-sync, the frame-ordering test harness and
web-runtime-terminal-creation).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
nwparker added a commit that referenced this pull request Oct 28, 2026
Adapt the remote completion repair from #25205 while preserving sparse runtime pane slots through existing PTY bindings.

Co-authored-by: Manan Chataut <[email protected]>
nwparker added a commit that referenced this pull request Oct 28, 2026
* fix(remote): reconcile stale paired agent status and pane titles

Adapt the remote completion repair from #25205 while preserving sparse runtime pane slots through existing PTY bindings.

Co-authored-by: Manan Chataut <[email protected]>

* fix(remote): preserve pane identity when reconciling moved titles

Use mounted manager identities and retained PTY bindings ahead of replay order; keep fresh byte-stream ownership on the correct moved pane.

* fix(remote): release byte status fence after host approval

* fix(remote): tighten paired title removal and test the timing fence

- Share the byte-write timing decision (resolveRendererOwnedAgentStatusTiming) between pty-connection and the flap test so reverting it fails a test.
- Only delete a saved pane title when its durable leaf is absent from both the host layout and local panes; unresolved or surface-less slots are kept.
- Share the client-fence predicate (clientAgentStatusFencesHost) between status and title reconciliation.
- Cover removed-leaf spinner fallback in worktree status and a client split absent from a pre-split host snapshot.

* fix(remote): correct fence predicate and title test types

---------

Co-authored-by: Manan Chataut <[email protected]>
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.

[Bug]: [Urgent] Remote client keeps showing the working spinner after the agent is done

2 participants