Skip to content

fix(sidebar): prevent closed-tab agent rows from returning - #9008

Closed
craftowen wants to merge 1 commit into
stablyai:mainfrom
craftowen:fix/closed-agent-retention-race
Closed

craftowen wants to merge 1 commit into
stablyai:mainfrom
craftowen:fix/closed-agent-retention-race

Conversation

@craftowen

@craftowen craftowen commented Jul 16, 2026 •

Copy link
Copy Markdown

Summary

Prevents a cleanly completed agent row from being resurrected in the sidebar after its terminal tab has already been closed.

ELI5

When you finished an agent and closed its tab, a stale "done" card could pop back into the list on its own. This makes the closed card stay gone.

Root cause & fix

A race: PTY cleanup removes the live agent row before closeTab plants its durable retention suppressor, so the next retention effect saw a completed row with no suppressor yet and re-retained it as a stale "done" card. The fix threads recentlyClosedAgentStatusTabIds into collectRetainedAgentsOnDisappear, which now skips re-retaining any done row whose tab id is marked recently-closed. It is an additive guard param with an early continue, so existing retention paths are untouched.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23. Rebase was clean (base 7ab601487c, head 300618a0bb).

  • On branch: useRetainedAgents.test.ts — Test Files 1 passed (1); Tests 7 passed (7).
  • Reverting only the fix file (useRetainedAgents.ts) to origin/main while keeping the new test: 2 failed | 5 passed (7). Failing assertions:
    • collectRetainedAgentsOnDisappear > does not retain a done row after its tab closed without a live suppressor — toRetain expected [], got 1 entry.
    • useRetainedAgentsSync > does not re-retain when status removal and tab closure commit before the next retention effect — retainedAgentsByPaneKey[paneKey] expected undefined.
On branch:  Test Files 1 passed (1) | Tests 7 passed (7)
Fix reverted: Test Files 1 failed (1) | Tests 2 failed | 5 passed (7)
  • Lint: oxlint on the changed file — clean, no warnings/errors.

Trade-offs

None — pure fix.

Regression risk

Effectively zero. The change is an additive parameter plus an early continue that fires only on the buggy branch (done row whose tab is recently-closed); all other retention paths are byte-identical, as proven by the 5 unchanged tests that still pass with the fix reverted. Pure renderer store logic — no cross-platform, SSH, or Git concerns.

Original fix by @craftowen (addresses the Ctrl+W repro in #8970). Validated, rebased, and reviewed via automated bug-bash triage; original fix design preserved.

@craftowen
craftowen force-pushed the fix/closed-agent-retention-race branch 2 times, most recently from 5c8d585 to 300618a Compare July 20, 2026 07:43
@craftowen craftowen changed the title fix(sidebar): prevent closed agents from returning fix(sidebar): prevent closed-tab agent rows from returning Jul 20, 2026
@craftowen
craftowen marked this pull request as ready for review July 20, 2026 07:44
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Retention synchronization now passes recently closed agent status tab identifiers to the disappearance collector. The collector accepts the new input and skips re-retaining vanished agents whose tabs were recently closed. Tests update collector calls, add shared store setup, and cover hook synchronization during teardown and subsequent retention effects.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and validation, but it omits required template sections like Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing template sections, especially the testing checklist, AI review report, security audit, screenshots/no visual change, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately reflects the main change: preventing closed-tab agent rows from reappearing.

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.

@nwparker
nwparker force-pushed the fix/closed-agent-retention-race branch from 300618a to d981f89 Compare July 23, 2026 11:48
@craftowen craftowen closed this Jul 24, 2026
@craftowen
craftowen deleted the fix/closed-agent-retention-race branch July 24, 2026 02:29
nwparker added a commit that referenced this pull request Jul 24, 2026
nwparker added a commit that referenced this pull request Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Heads-up @craftowen: this got auto-closed but the underlying bug (#8970) was never actually fixed on main, so I relanded your fix as #10334 (merged) with full credit to you. Thanks again! 🙏

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

2 participants