Skip to content

A closed chat tab stays closed instead of coming back on the right - #27205

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/fix-native-chat-tab
Oct 11, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/fix-native-chat-tab

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​487 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​485
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​25 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84

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:

  • When a chat tab close begins (beginStructuredAgentSessionTabClose), the window records a close intent for host tab agent-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.
  • The filter runs where every frame is applied (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.
  • The intent ends when a host frame stops listing the chat, which is the host's own removal. It also has the existing 20 s time limit (sized from the paired-server close call's 15 s budget plus 5 s; a close on this machine has no budget of its own).
  • On success on this machine, nothing else happens. The host removes the chat and sends the frame without it before it answers the close, and the window applies that frame, which ends the intent.
  • On success on a paired server, the window re-reads that one workspace's tab list, as it already does after a paired terminal close. The server's frames travel separately from its answer, so this guarantees a read taken after the close. The read waits for any tab-list request that began before the close instead of joining it, since that older answer would still list the chat.
  • On failure, the window clears the intent, since the host may still have the chat, and re-reads that one workspace. The re-read is allowed to re-apply the version the window already has (reacceptCurrentVersion on this machine, the existing acceptCurrentSnapshot for 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.
  • Floating-panel chats record no intent and get no re-read: frames for the floating panel are never applied, so nothing there can re-add a chat, and nothing would ever end the intent.
  • The one-workspace re-read on this machine is the same function the Session History reopen already used to refresh a workspace, now shared.

local-session-tab-close-owner keeps 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:

  • Hide the chat for exactly as long as the close call is in flight (the first revision of this PR). Rejected. It added a second "hide a closed tab" mechanism beside the close intent. It relied on the host's frames and its close reply arriving in order, which is unverified for paired servers. It checked paired frames when they arrived rather than when they were applied, so a frame held up by terminal recovery could still bring the chat back. It also re-read the tab list of every workspace after every close.
  • Wait for the host before removing the tab. Rejected: visible lag on remote hosts, and closing a tab would depend on the host answering.
  • Have the host drop the chat from its tab list first, before its other close steps. Rejected for this PR. When another client (the phone) closes a chat, the host first passes the close to the desktop window, which still shows the tab. If the host dropped the chat first, the window's next tab publication could add it back. It also can't stop frames already on their way to the window.
  • Have the close reply carry the version of the host's removal, and hide until the window reaches it. Rejected: it needs a new wire field that older hosts don't send, so the window needs the close intent anyway.

Differences from how paired-host terminal tabs use the close intent:

  • Intended: chats don't make the intent permanent when the host answers "no such tab"; they clear it and re-read like any other failure. The permanent rule exists for terminals a host keeps listing after it lost their process. A chat the host doesn't have isn't in its frames, so the re-read shows nothing.
  • Same mechanism on paired servers: chats re-read the workspace after every close, as paired terminals do. The difference, intended: the chat re-read accepts the version the window already has, because a failed chat close changes nothing the host publishes, so the unchanged list would otherwise be skipped.
  • Intended: chats on this machine re-read only after a failed close. This machine's host sends its removal frame before it answers, and the window applies it, so a read after success would only cost another terminal-process check on the host.

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 Y in [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:

ms after click tab strip
0 X, Y*, Z
+86 X, Z*
+158 X, Z*, Y (closed chat back, at the right)
+180 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:

  • 5 closes of the active middle chat while it answered;
  • 2 closes of a lone chat while it answered;
  • 3 closes of an idle chat that had already answered.

One of them:

ms after click tab strip
0 X, Y*, Z
+92 X, Z*
+138 X, Z* (no return)

A new chat opened afterwards still answered normally.

The screenshot right before the click shows the chat still answering:

PR: chat answering just before its tab is closed

Two seconds after the click, only the other two tabs remain:

PR: two seconds after the close, 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.ts runs the real main-process close path against the real window store and tab mirror. Only the process boundary is stubbed.

    • The host holds the close and sends a frame that still lists the chat. Without the close intent the strip becomes [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.
    • The host fails the close. Without the same-version re-read, the chat stays hidden. With it, the chat comes back.
    • A paired server's frame that still lists the closing chat doesn't bring it back.
    • Each was checked to fail with its piece of the fix removed (the intent, the clear on failure, the same-version re-read).
  • 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.ts now 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Paired servers (including SSH hosts running an Orca server): the same intent applies to their frames, keyed by that server. Chats on a plain SSH host with no Orca server have no host to close on, so nothing changes for them. Wire format unchanged, so mixed client and host versions are unaffected.
  • Reopening the same chat from Session History while its close is still in flight: the host's close stops that chat regardless, so the window keeps it hidden and the reopen reports that it could not open the chat. Once the host's removal frame has arrived, the intent is gone and reopening works.
  • Mobile: unchanged. The phone doesn't remove tabs before the host does, so it never had this flash in its own strip.
  • Performance: on this machine, no extra read after a successful close, and one single-workspace tab-list read (which includes a terminal-process check for that workspace on the host) after a failed one. On a paired server, one single-workspace read per close, as for paired terminal closes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3e998670-cdd8-417b-a5a0-1efaf3743c39

📥 Commits

Reviewing files that changed from the base of the PR and between cb24fcb and 139ab21.


📒 Files selected for processing (1)
  • src/renderer/src/lib/activate-ai-vault-structured-session.ts

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



📝 Walkthrough

Walkthrough

Retirement now returns a shared promise that reports whether host-tab closure succeeded. Close handling records a close intent and clears it if closure fails, then refreshes the applicable local or paired-host snapshot. Snapshot application can reapply an equal-version publication when requested. Tests cover close-intent behavior, stale snapshots, failed closes, and reopened tabs.


Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 139ab

No merge-blocking issue is established for the reviewed changes; normal checks remain appropriate.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description covers the user impact, implementation, rationale, alternatives, visual proof, testing, limitations, and checklist. However, the required Linked Issue section contains “None,” while th… Add the actual linked issue number or URL in the Linked Issue section. If the author is a maintainer, state the applicable maintainer exception instead.
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly summarizes the primary user-facing fix: a closed chat tab no longer reappears at the end of the tab strip.
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.

Full details: Description check

Explanation

The description covers the user impact, implementation, rationale, alternatives, visual proof, testing, limitations, and checklist. However, the required Linked Issue section contains “None,” while the repository template requires an actual issue link unless the author is a maintainer.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR








  • Autofix · 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.

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

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

🔇 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.list takes more than five seconds, withStructuredSessionRestoreTimeout rejects. refreshLocalStructuredSessionWorktreeTabs still 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
📥 Commits

Reviewing files that changed from the base of the PR and between 5fced77 and 6ee4815.

📒 Files selected for processing (8)
  • src/renderer/src/lib/activate-ai-vault-structured-session.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/inventory-refresh.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/snapshot-apply.ts
  • src/renderer/src/runtime/structured-agent-session-tab-retirement.test.ts
  • src/renderer/src/runtime/structured-agent-session-tab-retirement.ts
  • tests/e2e/structured-session-reopened-tab-close.unit.test.ts
  • tests/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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

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:

  • Closing a chat records an intent for that chat, under the host it lives on.
  • Every host tab-list update is applied without that chat until the host sends one that no longer lists it, or until 20 s pass.
  • On this machine, a failed close clears the intent and re-reads that one workspace.
  • On a paired server, the window re-reads that one workspace after every close, as paired terminal closes already do.

Fixed during review

  • Replaced the PR's own hide with the existing close intent. The old hide was checked when an update arrived rather than when it was applied, so a delayed paired-server update could still bring the chat back. It also re-read every workspace's tab list after every close.
  • A close intent left behind by one test leaked into the next and made CI fail. No effect in the app.
  • Floating-panel chats no longer record an intent that nothing would ever end.
  • The one-workspace re-read now shares the function Session History already used.
  • No extra re-read after a successful close on this machine. The host already sends its removal before it answers.
  • On a paired server, the re-read waits for any tab-list request started before the close instead of joining it.
  • The paired close intent is tied to the pairing in effect when the close started.

Deferred (all minor, none blocks merging)

  • Other screens. While the host handles the close, another window, the phone or a paired desktop may still see the chat jump to the end briefly. That needs a fix on the host side and is a separate follow-up; there's no ticket yet. Inferred from the code, not seen live.
  • Deleting a worktree with open chats now makes one tab-list read per chat that fails because the worktree is gone. It only adds console warnings.
  • Re-pairing during a successful paired close can leave a tiny stale record (capped) and allow one flash.
  • Reopening a chat from Session History while its close is still running shows the existing "not available yet, retry in a moment" message; a retry works.

Verified

  • Live, on a separate Mac with real Claude, through a real click on the tab's X, recording the tab strip on every change:
    • main at this branch's base: the closed chat came back on the right in 3 of 3 closes made while it was answering;
    • this branch at cb24fcb0311: it came back in 0 of 10 closes (7 while answering, 3 idle);
    • a new chat answered normally afterwards.
    • Timelines and screenshots are in the PR description.
  • Tests: 42 related test files and 393 tests pass. Each piece of the fix was removed in turn to check that a test fails without it. orca-ci-checks and CI pass on cb24fcb0311.
  • Readiness checklist on the final diff: no P0 or P1 findings, and nothing on main overlaps.

Not verified

  • Reopening from Session History live: the test setup's Session History couldn't see real Claude transcripts.
  • A live paired server or SSH host: covered by unit and end-to-end tests only.
  • Codex chats, Linux and Windows: not run live. There is no platform-specific code.

…ve-chat-tab

# Conflicts:
#	src/renderer/src/lib/activate-ai-vault-structured-session.ts
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