PR #9830 review: stop duplicating a chat's tab after it is resumed on iOS
Summary
When a desktop chat is resumed on iOS, the host closes the desktop chat and opens a new one on the same agent session with no terminal id. The desktop then showed two tabs: the original pane recovered onto the iOS chat, and the tab sync also adopted the iOS chat as a new tab. The PR adds two passes to useSyncChatSessionTabs: it moves a pane whose chat the host closed onto the newest open chat on the same agent session, and it closes any chat pane that repeats another pane's chat. In chat-runtime, createSession now writes the resumed harnessSessionId when the row is created, so the match works at once.
Verdict
minor issues The approach is sound and well tested at the util level, all CI is green, and the host change is small and correct; the open points are edge cases in which pane is kept and an untested wiring block.
Findings
minoruseSyncChatSessionTabs.ts:126-150: retarget, dedupe and tab selection are inline and untested
The new block mutates two stores, closes panes, and fixes the selection, but only the pure utils have tests (the PR notes this). The selection fix also runs only when kept.store === index: when the removed duplicate is in the right-sidebar store and the kept pane is in the main store (or the reverse), the closed tab's store picks a neighbour and the kept pane is not revealed.
Fix: move the block into a util such as dedupeChatPanes(paneStores, sessions) and test it with real createWorkspaceStore instances, including the cross-store case. For that case, focus the kept pane with focusPane in its own store when the removed tab was active.
minorduplicateChatPanes.ts:38-44: the kept pane is chosen by tab order, not by the chat's terminal
Among panes that are not "under the session id", the first in store/tab order wins. The function does not see the host's terminalId for the chat, so it can keep a pane whose terminal does not match the chat and close the pane that the host bound the chat to. Probe (local, not committed): pane A on T1 shows host-closed S1; pane B on T2 shows live S2 on the same agent session with terminalId: "T2". chatPanesResumedElsewhere moves A to S2 (because T2 ≠ T1), then duplicateChatPanes closes B (the T2 pane) and keeps A. Today this needs two desktop panes on one agent session, which focusChatSession mostly prevents, so it is an edge case.
Fix: in chatPanesResumedElsewhere, skip the retarget when resumed.terminalId is already claimed by another pane (the same claim rule chatSessionsToAdopt uses); or pass the listed sessions to duplicateChatPanes and prefer the pane whose terminalId equals the chat's terminalId before falling back to tab order.
nitchatPanesResumedElsewhere.ts:24-29, duplicateChatPanes.ts:10-15: JSDoc length
AGENTS.md asks for comments only where code cannot say it, usually 1-2 lines. The "own terminal is the pane's own recovery" point is a real trap and earns a line; the rest repeats the function names and could move to the PR description.
Checked and found correct: the host change (commands.ts:671) only seeds the column, and the journal still overwrites it when the agent reports its id (journal.ts:419-439); forks and rewinds pass fresh fork ids, so seeding them is harmless. closePane({ intent: "remove" }) does not stop the chat. No tRPC shape change, no user-facing strings, structure follows the folder rules.
Evidence
Host (chat-runtime): regression test proves the fix
With the one-line commands.ts change reverted locally, the new test "a resumed chat lists its agent session before the agent starts" fails (17 pass, 1 fail). With the PR code it passes. Full chat-runtime suite: 526 pass, 2 skip, 0 fail.
Desktop utils: probe of the kept-pane choice
Throwaway bun test against the two new utils (deleted after the run). Output: moves 1 closed terminal ["T2"] kept terminal ["T1"], which is the scenario in the second finding.
Desktop app (end-to-end): not verified
Desktop dev app at this head, relaunched with a CDP port (renderer localhost:3005). It comes up signed in, but has no project, workspace or agent credentials, so the flow (start chat → host restart → iOS resume → back to desktop) could not be run. Attempt 1: the app already running in the box had no window on the display and no debug port. Retry: relaunched with RENDERER_REMOTE_DEBUG_PORT; the screenshot above is the result. The duplicate-tab fix itself is not verified end-to-end by this review; the author's page has before/after recordings.
iOS: not run
The PR changes no mobile code; the iOS side is only the existing resumeChat call, and no simulator was started.
Questions for the author
- If iOS resumes the chat under a different agent config (account) than the desktop pane, host
createSessiondoes not treat the iOS chat as "already running" (runsConfig), so the pane's own recovery may start a third chat on its terminal after the retarget. Does the pane's in-flight recovery still commit over the retargetedsessionId, and if so do we get the adopted tab back? chatPanesResumedElsewhereneeds the closed chat to be in the listed page (CHAT_ADOPT_SESSIONS_LIMIT). In a busy workspace the old row can drop off and only the dedupe heals it, after the pane commits. Is that acceptable?- Is there any flow where one chat is meant to show in two panes (e.g. main area and right sidebar)? The dedupe now closes one of them on every sync.
Test / CI notes
| What | Result at 07b4e665 |
|---|---|
| GitHub CI (Lint, Typecheck, Test, Sherif, Build CLI, deploys) | All success; CodeRabbit still running; E2E Mobile skipped |
bun test useSyncChatSessionTabs | 16 pass, 0 fail |
bun test desktop v2-workspace | 1275 pass, 0 fail |
bun test packages/chat-runtime | 526 pass, 2 skip, 0 fail |
Revert commands.ts:671, run resumeSession.test.ts | new test fails as expected (restored after) |
tsc --noEmit desktop, chat-runtime | exit 0, exit 0 |
biome check changed dirs | clean |