Repository navigation
A closed chat tab stays closed instead of coming back on the right - #27205
Conversation
…ill closing it Closing a chat tab removes it from the window at once. A tab-list frame the host publishes before it has handled the close (a working chat's status update, for one) still listed the chat, and the window appended it back at the end of the strip until the host's own removal arrived. The window now leaves out a chat whose close it has not heard back on, using the in-flight close record it already keeps, and re-reads the host's tab list once the close settles so a chat the host kept comes back.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No merge-blocking issue is established for the reviewed changes; normal checks remain appropriate. Pre-merge checks |
|
…intent Record a close intent for agent-session:<id> under the chat's host when a chat tab close begins, so a host frame sent before the host handles the close cannot re-add the chat at the end of the strip. The intent lifts when a host frame stops listing the chat, or by its TTL. Only a failed host close clears it and re-reads that worktree at the version already applied, so the chat the host kept comes back. Replaces the close-owner gate and the re-read after every close.
…lows Re-read the closed chat's worktree after every settled close, not only after a failure, so a close the host had nothing new to publish for still ends its intent; otherwise the same chat reopened within the intent's 20 s limit stayed hidden. Skip the intent for floating-panel chats, whose frames are never applied. Share one one-worktree local refresh with the Session History reopen path. Reset close intents between tests in the reopened-tab e2e file, whose harness tears the host down before a close's follow-up re-read lands.
There was a problem hiding this comment.
🔇 Additional comments (1)
src/renderer/src/lib/activate-ai-vault-structured-session.ts-272-272 (1)
272-272: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Prevent a timed-out local refresh from applying its snapshot.
If
session.tabs.listtakes more than five seconds,withStructuredSessionRestoreTimeoutrejects.refreshLocalStructuredSessionWorktreeTabsstill applies a later response when the sync generation is unchanged. The tab strip can therefore change after activation reports a restore timeout. Pass a cancellation signal or an equivalent validity check to the helper, and check it before applying the snapshot.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
032c586b-d3a7-4775-a0cf-0a48ed25b93f
📒 Files selected for processing (8)
src/renderer/src/lib/activate-ai-vault-structured-session.tssrc/renderer/src/runtime/local-structured-session-tabs-sync.tssrc/renderer/src/runtime/local-structured-session-tabs-sync/inventory-refresh.tssrc/renderer/src/runtime/local-structured-session-tabs-sync/snapshot-apply.tssrc/renderer/src/runtime/structured-agent-session-tab-retirement.test.tssrc/renderer/src/runtime/structured-agent-session-tab-retirement.tstests/e2e/structured-session-reopened-tab-close.unit.test.tstests/e2e/structured-session-tab-close-stale-frame.unit.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/runtime/local-structured-session-tabs-sync/snapshot-apply.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
…ed servers This machine's host emits its removal frame before the close answers, and the window applies it, so a local chat re-reads only when the close fails. A paired server's frames travel apart from its answer, so, as for its terminal closes, every close is followed by a read, and that read no longer joins a tab-list request that began before the close. Floating-panel chats record no intent and get no read.
…gan under Record and clear the intent with one owner captured at close start, as paired terminal closes do, so re-pairing a server mid-close cannot miss the clear, and pass that pairing to the paired re-read.
Review status: ready for a human look (not merged)The problem. If you clicked the X on a native-chat tab (Claude, most often) while the agent was still answering, the tab disappeared, came back as the last tab on the right, then disappeared again. On main this happened in 3 of 3 tries on a test Mac, for 18–40 ms each time. It happened because the window removes the tab right away, but the host keeps sending tab-list updates that still list the chat until it has handled the close. The window adds any chat it doesn't show to the end of the strip. What changes for you. A chat tab you close stays closed. If the host fails to close the chat and still has it, the chat comes back at the end of the strip. How it works now. This went through four review rounds and changed design once. The first revision added its own "hide while the close call is in flight" check. The final version reuses Orca's existing close intent, which already hides closing terminal, browser and editor tabs on paired servers:
Fixed during review
Deferred (all minor, none blocks merging)
Verified
Not verified
|
…ve-chat-tab # Conflicts: # src/renderer/src/lib/activate-ai-vault-structured-session.ts
ELI5
When you click the X on a chat tab while the agent is still answering, the tab sometimes comes back for a moment, now as the last tab on the right, and then disappears again. After this change, a closed chat tab stays closed.
What Changed
Before: close a native chat tab (most often Claude) while it is answering. The tab vanishes, then reappears at the far right of the tab strip, then vanishes again. On an idle test machine this lasted 30–60 ms. On a busy machine it can last longer, because the host's close first waits for a refresh of the terminal processes, and that refresh grows with the number of open terminals.
After: the tab disappears once and stays gone. If the host could not close the chat (it still has it), the chat comes back, so the window never hides a chat that still exists.
Why it happened. The host (the main process, or a paired server over SSH) owns the list of chat tabs. The window copies that list from the tab-list updates ("frames") the host sends, and adds any chat it doesn't already show to the end of the strip. Closing a tab removes it from the window at once and sends the close to the host. Until the host has handled that close, every frame it sends still lists the chat. A working chat sends a status update every few hundred ms, and each one carries such a frame. So the window put the chat back at the end until the host's own removal frame arrived.
Mechanism. Orca already has a record for this race on paired-host terminal, browser and editor tabs: the close intent (
web-session-close-intent.ts). Closing one of those tabs records "this tab is being closed" for that host and workspace. Every host frame is applied without that tab while the record exists. This change uses the same record for chat tabs:beginStructuredAgentSessionTabClose), the window records a close intent for host tabagent-session:<sessionId>under the chat's host (this machine or the paired server). That is the same host key and tab id that chat launches already use for their focus intent. For a paired server the record is tied to the pairing at the moment the close began, as paired terminal closes do, so re-pairing during the close can't leave it behind.prepareWebSessionTabsSnapshotBase). Frames from this machine and from paired servers both go through it, so the check happens when the frame is applied, not when it arrives.reacceptCurrentVersionon this machine, the existingacceptCurrentSnapshotfor paired servers). Without that, the unchanged list would be skipped as already applied, and the chat would stay hidden until something else changed. Older versions are still skipped. A failure because the host has no such tab is handled the same way, and the re-read simply shows nothing.local-session-tab-close-ownerkeeps its original single job: it lets the window acknowledge the close request the main process sends back to it.Why
The window has to remove the tab immediately. Waiting for the host would make closing a tab lag by a network round trip on SSH hosts. So the window's early removal has to be reconciled with the host's tab list, and only the window knows a close is pending.
Alternatives considered:
Differences from how paired-host terminal tabs use the close intent:
Known difference, intended: when a close fails, the chat comes back at the end of the strip rather than in its old position. Restoring the position needs a saved copy of the strip, and failed closes are rare. No new UI is added for that case.
Known remaining, temporary: while the host handles the close, it still re-adds the chat to the end of its own tab list whenever this window publishes its tabs. So other clients watching that host (another window, the phone, a paired desktop) may still see the chat jump to the end for the same 30–60 ms. Fixing that needs a host-side fence for chat tabs being closed, like the one terminals have. It is a separate follow-up (no ticket yet). This window no longer shows it.
Linked Issue
None. Found in daily use.
Visual Proof
A flash this short (10–40 ms) doesn't show in a screenshot, so the proof is a timeline of the real app's tab strip, recorded every time it changed. The run used a hidden window over CDP on a separate Mac, real Claude, and a real click on the tab's X. Each close was of the active middle chat
Yin[X, Y, Z], about 1 s after sending it "count from 1 to 40, one number per line", while it was still answering.Before (main at this branch's base,
180e8c186f), 3 of 3 closes came back. One of them:X, Y*, ZX, Z*X, Z*, Y(closed chat back, at the right)X, Z*The other two came back at +143 and +142 ms and were gone again 18–22 ms later.
After (this branch, final revision
cb24fcb0311), 0 of 10 closes came back:One of them:
X, Y*, ZX, Z*X, Z*(no return)A new chat opened afterwards still answered normally.
The screenshot right before the click shows the chat still answering:
Two seconds after the click, only the other two tabs remain:
Testing
I manually tested these changes (final revision, on a separate Mac; see Visual Proof)
Automated tests added/updated, or explained why not below
New
tests/e2e/structured-session-tab-close-stale-frame.unit.test.tsruns the real main-process close path against the real window store and tab mirror. Only the process boundary is stubbed.[a, c, b]. With it, the chat stays gone. It also checks that the host's removal frame ended the intent before the host stopped the chat.structured-agent-session-tab-retirement.test.ts: the intent is recorded under the right host key, survives frames that still list the chat, and ends on a frame without it. There is no re-read after a local success, and a paired success re-reads without joining an older request. A floating-panel chat gets no intent and no re-read. A failed close on this machine or a paired server clears the intent and re-reads that workspace with the current version accepted. Each of these fails with its piece removed.structured-session-reopened-tab-close.unit.test.tsnow resets close intents between tests. Its harness sends no host frames to the window, so a close there has no removal frame to end its intent, and one test's intent leaked into the next.42 related test files (every
tests/e2e/structured-session-*file, every test that imports the close intent or the retirement module, and every test that closes a chat tab) pass, 393 tests.orca-ci-checks(lint, code quality, localization, typecheck) passes.Manual: macOS, local workspace, real Claude native chat, through the app's real tab X button (final revision; the first revision was also checked live). Reopening the chat from Session History right after closing it could not be checked live: the test setup's Session History could not see real Claude transcripts. Not tested live: Codex chats, a live SSH or paired host (covered by the tests above), Linux and Windows (no platform-specific code).
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)