Skip to content

Hide stale mobile agent rows after terminals close - #6222

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/issue-6072-mobile-stale-agent-rows
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/issue-6072-mobile-stale-agent-rows

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6072

Summary

Fixes mobile/worktree activity projection so stale persisted terminal tabs and hydrated hook snapshots no longer make a worktree look active after its matching live terminal is gone.

Design approach:

  • Treat live renderer leaves and connected PTYs as the only evidence for liveTerminalCount, attached PTY state, active status, previews, and agent rows in getWorktreePs().
  • Preserve persisted session tabs for restoration/opening surfaces, but stop promoting those saved rows into current activity.
  • Filter hook/OSC agent rows by the current live pane key or connected PTY id instead of attaching every row with the same worktree id.
  • Keep connected PTY evidence for headless/daemon/mobile terminals so real live agents without a mounted renderer leaf still appear.

Review And Implementation

Design review:

  • A read-only design reviewer returned ready after checking stale persisted tabs, live PTY preservation, SSH/cross-platform assumptions, and cache invalidation behavior.
  • Earlier reviewer attempts using other local agent providers failed or stalled because of local agent credential/runtime issues; the reviewed design was checked manually before implementation.

Implementation:

  • Updated src/main/runtime/orca-runtime.ts to build per-call live evidence from current leaves and connected PTYs.
  • Updated agent-row attachment to require a live pane key or live PTY id match.
  • Removed dead persisted-tab status promotion code.
  • Added deterministic runtime tests covering the stale-row repro and the positive connected-PTY/no-renderer-leaf case.
  • Added missing zh localization parity generated by pnpm run sync:localization-catalog so full lint can pass.

Completeness verification:

  • A read-only verifier reported COMPLETE against the design.

Performance audit:

  • Touched hot path: getWorktreePs(), used by mobile/worktree polling and CLI projection.
  • Audit result: PERF PASS.
  • No polling, subprocesses, disk reads, or long-lived caches were added.
  • Live evidence is built per call from already-held in-memory maps, which avoids stale cache invalidation failure modes.
  • Deterministic tests cover the stale persisted-tab/hydrated-hook invalidation behavior without timers.

Code review loop:

  • Round 1 found one real comment-placement issue, fixed before commit. Other findings were checked and confirmed false positives by code inspection and typecheck.
  • Round 2 returned one clean review and one false-positive concern about hook snapshot shape; existing types and tests covered the path.
  • No unresolved actionable review findings remain.

Merge-confidence validation:

  • The dedicated test subagent stalled locally; I completed local validation instead and treated that as a process deviation.
  • Electron identity validation confirmed the app was running from this branch/worktree:
    • Branch: brennanb2025/issue-6072-mobile-stale-agent-rows
    • Worktree: /Users/thebr/orca/workspaces/orca/issue-6072-mobile-stale-agent-rows
  • Contextual screenshot evidence was captured locally at .tmp/evidence/issue-6072-electron-identity.png and was not committed.

Repro Evidence

Before the fix, the deterministic runtime test reproduced the issue:

  • runtime.listTerminals("id:repo-1::/tmp/worktree-a") returned [].
  • runtime.getWorktreePs() incorrectly returned liveTerminalCount: 1, hasAttachedPty: true, status: "active", and a stale done agent row.

After the fix, that same seeded persisted-tab plus hydrated-hook scenario reports inactive/zero-live/no-agent projection.

Validation

Ran locally:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts -t "stale persisted tabs|connected PTYs without a mounted renderer leaf|hook-reported status|saved session tabs with live PTYs"
  • git diff --check
  • pnpm exec oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts
  • pnpm run typecheck:node
  • pnpm run typecheck
  • pnpm run lint

Post-PR stabilization:

  • Required 8-minute wait completed after opening the PR.
  • CodeRabbit reported no actionable comments.
  • PR checks passed: verify and track-community-pr.
  • No stabilization fixes were needed after PR creation.

Residual Risks

  • No full mobile emulator product-surface repro was captured; deterministic runtime projection tests are the primary behavior proof.
  • The merge-confidence validation subagent stalled locally, so validation was completed manually with local checks and Electron identity evidence.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The primary change refactors how getWorktreePs() in orca-runtime.ts determines live terminal and agent activity. Two new Set objects (liveAgentPaneKeys, liveAgentPtyIds) are populated from runtime leaves and attached PTY records. The previous session-tabs-based inference loop and the getSavedTabWorktreeStatus helper are removed. attachAgentRowsToSummaries receives a new liveEvidence parameter and gains an eligibility filter that skips agent rows whose pane key or PTY id is absent from the live-evidence sets. Two tests are added to cover stale-persisted (done-state) and headless-connected PTY scenarios. Additionally, a createMultiple translation key is added to zh.json.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Hide stale mobile agent rows after terminals close' directly and clearly describes the primary change: preventing stale agent rows from appearing after terminals close.
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.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering all required template sections with detailed information about the implementation, testing, and validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseding this with #11464. This PR had the right diagnosis for #6072 and pioneered the read-time filter strategy in attachAgentRowsToSummaries() — credit for the approach. Since it was written, main drifted too far to rebase cleanly: #9874 independently landed the saved-tab/liveTerminalCount half of this diff, getWorktreePs() gained freshPtyLiveness gating and mirroredWorktreeIdByTabId, and the runtime tests now pin an SSH contract (no-local-PTY remote agents must stay visible) that this PR's hard live-PTY requirement would break. #11464 reimplements the surviving half against current main with a remote-row exemption and a connected-PTY rescue. This PR can be closed once #11464 lands.

@nwparker

nwparker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue(s) for this PR were fixed by another change that has already been merged.

Superseding merge: #11464

Thank you for the contribution! If anything remains unaddressed, please open a new issue or PR against current main.

@nwparker nwparker closed this Aug 3, 2026
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]: Mobile keeps showing old agent rows after terminals are closed

2 participants