Skip to content

Keep closed tab agents from reappearing - #6095

Merged
brennanb2025 merged 1 commit into
mainfrom
fix/closed-tab-agent-status-cache-cleanup
Jun 22, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
fix/closed-tab-agent-status-cache-cleanup

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closing a terminal tab now clears the agent-status cache for that tab in both renderer and main process, then suppresses late hook/status replays for that closed tab id during the app session. This prevents completed agent rows from returning after their terminal tab is gone.

This is a separate root-cause fix from #5914's selector-level guard.

Design Approach

  • Renderer dropAgentStatusByTabPrefix(tabId) still removes local rows, and now also records the tab as closed and sends agentStatus.dropByTabPrefix(tabId) through preload/IPC.
  • Main process validates the tab id, evicts cached status/listener/alias state under that tab, clears migration-unsupported PTY records for the tab, and ignores late hook/status writes for closed tab ids.
  • Renderer IPC ingestion also ignores late agentStatus:set events for explicitly closed tab ids.

Scratch design doc: .tmp/agent-status-cache-tab-close.md (not committed).

Pipeline Evidence

Design review: completed clean earlier in the Brennan YOLO Lite run.

Implementation: completed in the separate worktree fix-closed-tab-agent-status-cache-cleanup.

Deviation from design: manual validation proved a 15-second suppression window was too short, so the implementation uses an app-session closed-tab marker instead. Tab ids are generated per tab, so this is the safer root-cause behavior.

Completeness verification: completed clean after expanded coverage.

Code review:

  • Round 1 found behind-main integration regressions in sleeping-agent capture and web pushTarget clearing.
  • Those were fixed, the branch was rebased onto current origin/main, and Round 2 returned clean from both reviewers.

brennan-test-changes: verdict was should land.

Manual validation:

  • Fresh Electron terminal tab used the real local hook server.
  • Posted UserPromptSubmit, then Stop, and confirmed main + renderer had the row.
  • Closed the tab through the visible tab close control.
  • Confirmed tab removed, renderer row removed, main snapshot empty, and closed marker set.
  • Waited 16 seconds, posted a late hook for the same closed tab, and confirmed main + renderer stayed empty.
  • Screenshot evidence retained locally at validation-screenshots/closed-tab-agent-status-cleanup-after-late-hook-clean.png (not committed).

Accepted gaps:

  • No live SSH pass. The change uses tab/pane ids and shared renderer/main status ingestion paths, with no path, shell, or provider-specific behavior.
  • Product validation reused same-worktree Electron evidence after the final rebase because the rebased diff is the same root-cause behavior on top of current origin/main.

Validation

  • pnpm vitest run --config config/vitest.config.ts src/main/agent-hooks/migration-unsupported-pty-state.test.ts src/main/agent-hooks/server.test.ts src/main/ipc/agent-hooks.test.ts src/renderer/src/hooks/useIpcEvents.test.ts src/renderer/src/store/slices/agent-status-ack-cleanup.test.ts src/renderer/src/store/slices/agent-status-drop-ipc.test.ts src/renderer/src/web/web-preload-api.test.ts
  • pnpm typecheck
  • pnpm lint
  • git diff --check origin/main...HEAD && git diff --check

Post-PR Stabilization

Completed after the required 8-minute wait.

  • CodeRabbit: no actionable comments generated.
  • PR checks: verify passed, track-community-pr passed.

@ghost

ghost commented Jun 22, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Clear migration-unsupported PTYs by tab prefix
2 Implement closed tab suppression in AgentHookServer
3 Expose tab-prefix clearing through IPC
4 Update Preload API for tab-prefix drops
5 Track closed tabs in renderer store
6 Suppress late IPC events in renderer
Open in Stage

Chapters generated by Stage for commit 3511c31 on Jun 22, 2026 6:52pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements end-to-end tab-prefix eviction for agent status caches. A new clearMigrationUnsupportedPtysByTabPrefix function batch-removes migration-unsupported PTY entries by tab prefix. AgentHookServer gains a closedAgentStatusTabIds set; dropStatusEntriesByTabPrefix now marks the tab closed and evicts all related caches (status, prompt/tool dedupe, runtime-observed keys, and legacy pane-key aliases), while ingestTerminalStatus, ingestRemote, and the HTTP loopback handler each check this set before applying new status. A new agentStatus:dropByTabPrefix IPC channel with input validation wires these main-process functions. The preload API contract adds dropByTabPrefix(tabId) in the type definition, implementation, and a web no-op stub. The renderer store slice adds recentlyClosedAgentStatusTabIds state, guards setAgentStatus against recently closed tabs, and calls window.api.agentStatus.dropByTabPrefix from dropAgentStatusByTabPrefix. useIpcEvents adds a guard to drop late IPC push events for panes belonging to recently closed tabs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.26% 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 'Keep closed tab agents from reappearing' clearly and concisely summarizes the main change: preventing agent status rows from returning after terminal tabs are closed.
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 PR description is comprehensive and follows the template with all required sections: Summary, Screenshots (marked as no visual change), Testing (with validation commands), AI Review Report, Security Audit, and Notes.

✏️ 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 and usage tips.

@brennanb2025
brennanb2025 merged commit 3cc610b into main Jun 22, 2026
2 checks passed
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.

1 participant