Skip to content

fix(native-chat): an older Orca's write no longer reopens every closed chat - #43306

Open
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/tab-flood-fix
Open

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/tab-flood-fix

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

An older Orca (v1.4.259 or earlier) can write a chat after an upgrade, for example after a downgrade and a re-upgrade. On the next launch Orca keeps that chat, which is intended. But if the chat store had never recorded which chat tabs were open, Orca also opened a tab for every chat the profile had ever had, so every chat the user had closed came back. On one profile that was 10,817 tabs across 1,709 workspaces, and Orca froze.

Tracked in #42783. #43007 already stopped the trigger for stores copied by internal builds; this closes the remaining hole on main.

User-facing change

When an older Orca's write is kept, only that chat opens, next to the chats that were already open. Chats the user closed stay closed.

How

  • The pass that keeps an older Orca's chats (journal-legacy-reconcile.ts) no longer seeds the tab index with every chat record and no longer marks the index as recorded. It adds a tab only for the chat it kept.
  • While the index is unrecorded, the window's own saved tabs decide what's shown. On open, the chat store now treats tabs saved under an unrecorded index as shown beside those (agent-session-record-rows.ts, AgentSessionRecordStore.open). Besides this pass, only the v1.4.220 JSON import left such rows: a chat created while that import was pending, which its comment says shows "beside" the profile's tabs. That is the same meaning. Ordinary tab writes clear the rows whenever the index is unrecorded.
  • Commands already carry those ids to the writer, so the first tab-index write records exactly what the window shows plus the kept chat.

Verification

  • journal-legacy-reconcile.test.ts, new test.
  • agent-session-record-store-tab-table.test.ts, new test.
    • Setup: an unrecorded store holding the older Orca's tab, opened with the window showing one chat.
    • Result: both chats show, and the first tab write records both across a restart. A closed chat stays hidden.
    • Without the store half, only the window's chat shows.
  • The old assertion that a pass sets session_tabs_recorded encoded the bug, so it is removed.
  • The fallback ids stop riding on commands once the index is recorded (review finding).
  • pnpm check:changed: 35/35 passed on Omarchy.

…d chat

When an older Orca wrote a chat after an upgrade, the next launch kept it and,
if the chat store had never recorded its tab index, opened a tab for every chat
record, so every chat the user ever closed came back. The pass now adds only the
kept chat's tab and leaves the index unrecorded; on open the store shows those
tabs beside what the window shows, and the first tab write records exactly that.
The fallback ids stop riding on commands once the index is recorded.

Tracked in #42783.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Legacy reconciliation no longer writes the recorded-tabs marker or adds tab entries for recorded sessions. The session store now identifies tab-table entries from stores without that marker and combines their session IDs with legacy tab IDs. Transactions expose those fallback IDs until session tabs are published. Tests cover reconciliation and store reopening before and after tab initialization.

Merge Risk: Minimal · up to 5848b

An older Orca's write no longer reopens every previously closed chat. Only the kept chat opens, alongside chats already open in the window. Added tests cover reconciliation and store reopening. No concrete remaining defect or performance regression was found, so merging looks low-risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its subject: an older Orca's write no longer reopens every closed chat. The changeset matches: the legacy reconcile pass now adds a tab only for the kept chat, and the stor…
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 The description covers the problem, the user-facing change, the mechanism, verification steps, and the test results. It follows the template's intent. The ELI5, Linked Issue, Risk level, and Visual Pr…
Full details: Title check

Explanation

The title names the fix and its subject: an older Orca's write no longer reopens every closed chat. The changeset matches: the legacy reconcile pass now adds a tab only for the kept chat, and the store stops reopening closed chats. The title uses the conventional fix(native-chat) prefix and is specific. It is 75 characters, slightly long, but it is still clear.

Full details: Description check

Explanation

The description covers the problem, the user-facing change, the mechanism, verification steps, and the test results. It follows the template's intent. The ELI5, Linked Issue, Risk level, and Visual Proof sections are not filled in, and the Testing checkboxes are unchecked. These gaps are non-critical for a PASS. The author links #42783 and mentions #43007 but does not use the template's 'Fixes #' line.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45657809-2322-472e-a836-6e90791b8320
Commits

Reviewing files that changed from the base of the PR and between 11403c1 and 5848b5f.

Files selected for processing: 8

  • config/main-blocking-sqlite-baseline.txt
  • src/main/native-chat/agent-session-journal/database/journal-legacy-reconcile.test.ts
  • src/main/native-chat/agent-session-journal/database/journal-legacy-reconcile.ts
  • src/main/runtime/agent-session/records/agent-session-record-rows.ts
  • src/main/runtime/agent-session/records/agent-session-record-store-tab-table.test.ts
  • src/main/runtime/agent-session/records/agent-session-record-store.ts
  • src/main/runtime/agent-session/records/agent-session-store-state.ts
  • src/main/runtime/agent-session/records/agent-session-store-transactions.ts

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

@brennanb2025

brennanb2025 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Review status: ready

Problem. An older Orca (≤ v1.4.259) can write a chat after an upgrade, for example after a downgrade and a re-upgrade. If the chat store never recorded its tab index, the next launch opened a tab for every chat the profile ever had, so every closed chat came back. One profile got 10,817 tabs and froze.

User-facing change. Only the chat the older Orca wrote opens, next to the chats that were already open. Closed chats stay closed.

Review (2 passes, fresh Claude + Codex pair each).

  • Pass 1 found two problems, both fixed:
    • the fallback tab ids were carried on every command even after the index was recorded (perf);
    • the store half of the fix had no test.
  • Pass 2 checked the repair diff: both reviewers clean, no findings.
  • Perf screen: no work grows with chats or tabs on a repeated trigger. The fallback ids now stop once the index is recorded.
  • Orca shows each visible chat as a tab, so "show every chat" is the flood. When no server tab state exists, it falls back to the window's own tabs plus the kept chat.

Verified.

  • Two new tests, each failing when its half of the fix is reverted:
    • reconcile pass: 22 tabs instead of 3 when reverted;
    • store open: the kept chat is missing when reverted.
  • check:changed: 35/35 on Omarchy. CI is green.
  • Real-app QA on this Mac, old 9bf84179da3 vs new 5848b5f7e09. Flow: packaged v1.4.259 made 6 Claude chats and closed 5; build X upgraded; the tab index was cleared to model a store that never recorded tabs; v1.4.259 continued the open chat; build X upgraded again, then restarted. All quits were graceful.
    • Old: all 5 closed chats came back (10 tabs in the worktree, 11 in the store).
    • New: only the open chat and the kept copy holding the v1.4.259 turn ("Reply with OK again" → "OK") show. The same set came back after a restart.

Old (main), every chat reopened:
old: flood

New (this PR), only the open chat and the kept chat:
new: fixed

Deferred / noted.

  • In QA, a chat created on the new build before the downgrade didn't come back. That comes from the QA step that clears the tab index by hand: in a real store, creating a chat records the index. v1.4.259 then drops that chat from the window's saved tabs. Not a bug in this PR.
  • A kept chat (as itself) shows under its derived tab id rather than the id the older Orca saved. This was the same before the PR.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

DONE: clean

Perf scan: PR #43306 (5848b5f7e09 against 9bf84179da3)

Findings: none. The PR adds no repeated work that grows with the fleet. It removes an O(all records) tab insert from the startup reconcile, and it stops sending the client fallback ids with every store command once the tab index is recorded. The only new per-store work runs once and is bounded by the number of chats an older Orca wrote during a downgrade (A below). It is not bounded by total chats (R).

Nothing was run: no pnpm, benchmarks or timing. All counts below come from reading the source.

Populations used

  • R: chat records in the store. 10,817 on the reported profile, about 10⁴ for the reference fleet, 10⁵ at 10×.
  • A: chats the legacy reconcile adopts. These are chats an older Orca created or continued after a downgrade (absorbChat, journal-legacy-reconcile.ts:147-180). A ≤ R, and in practice A is much smaller.
  • C: client fallback tab ids (legacySessionTabIds). This is the number of open chat tabs, a few hundred at the reference fleet.
  • T: rows in agent_session_tabs.

Pricing for each changed trigger

Trigger (thread) Base Head N → 10N
Legacy reconcile pass, at startup and only when the original journal changed (Electron main, sync SQLite) recordTabIndex read all R records and did up to R INSERT agent_session_tabs once per store. The flood then made T = R permanently. O(A) inserts: one addTab per adopted chat only (journal-legacy-reconcile.ts:199-207). The main-blocking SQLite baseline drops from 32 to 30. Base: 10,817 → ~108k inserts. Head: does not depend on R. Improvement
Store load, once per open (loadAgentSessionStoreRows, agent-session-record-rows.ts:161-165) Read T tab rows and built the table, then threw it away when the index was unrecorded. Same read, plus entries() and sessionIds() copies (O(T)) only when the index is unrecorded. In that case T ≤ A plus whatever was already there. O(T) once per open, does not repeat. Not a finding
Store open (agent-session-record-store.ts:93) Passed C through as-is. One Set union, O(C+L) where L = unrecorded tab sessions ≤ A. A few hundred to a few thousand string inserts, once per open. Not a finding
legacySessionTabIds getter, read on each reserve / found / tabs-initialize / tabs-show / tab-visibility command (agent-session-store-transactions.ts:92-94) Always returned C. Every command carried C (copied into command payloads and receipts). O(1) getter. Returns C∪L only while sessionTabs === null, then []. Per-command payload goes from C to 0 after recording. Improvement
Writer's legacy record load per tab command (journal-writer-store-mutation.ts:71-74) json_each loaded C record ids while the index was unrecorded. Loads C+L while unrecorded. Recording happens on the first initializeSessionTabs at restoration (structured-session-tab-restoration.ts:48). Adopted chats have records, so entries().length > 0 and the window closes after one command. Bounded by C+A for one startup command. Not a finding
AgentSessionRecordTabs.legacyTabIds Set, built at construction (agent-session-tab-table.ts:189) O(C) once O(C+L) once Not a finding
copyAgentSessionStoreCache on each command Spread The spread copies only the unrecordedTabSessionIds reference, so O(1). Retains L strings for the store's lifetime, bounded by A. Not a finding

Pre-existing (not caused by this PR, does not block it)

journal-writer-store-mutation.ts:68-70 calls loadAgentSessionStoreTabs(db) on every command that has identity.tabs (reserve, found and all tab commands). That reads all T tab rows on Electron main per command. On profiles already flooded before this fix (T ≈ 10,817, index already recorded), this PR does not shrink T. Each reserve or found still reads about 10⁴ rows. The PR stops new floods but does not repair existing ones.

Regression classes the diff touches

  • Sync SQLite on Electron main: matched. The reconcile and store load run sync SQLite on main, but the reconcile goes from O(R) to O(A) and the load adds no SQL. Disproved as a regression; the baseline count drops 32 → 30.
  • Hot-path rescans: matched (Set union, entries()). Each is a single linear pass, once per open, with no nested scan. Disproved.
  • Per-entity state outlives the entity: matched (new unrecordedTabSessionIds field). It is an immutable array captured once at load, with no per-entity map or listener added. Disproved.
  • Re-reading unchanged input: the per-command tab read above is pre-existing and unchanged by the diff.
  • No other class has matching code.

The six questions

  1. Unused work paid before the skip gate: reviewed. After recording, the getter returns [] before any payload is built, which is less unused work than the base.
  2. Ownership multiplying work: reviewed. One store transactions object and one record-tabs Set per store, with no per-tab or per-chat owners added.
  3. Which thread pays: reviewed. Electron main, sync node:sqlite. Reconcile SQL drops from O(R) to O(A); load SQL is unchanged.
  4. Growth and progress: reviewed. The unrecorded window ends at the first initializeSessionTabs, which writes AGENT_SESSION_TABS_RECORDED. Work no longer grows with R.
  5. Execution host: not applicable. This is local SQLite store open and reconcile only, with no SSH or Windows-specific spawning or probes.
  6. Obsolete work stops: reviewed. The fallback ids stop being sent once the index is recorded, and no timers or listeners were added.

Coverage and remaining gaps

  • Paths examined: reconcile absorbChats → absorbChat → adoptChat / addTab, store load and open, the getter, every legacySessionTabIds consumer (record-tabs, founding store, reserve), the command keys and writer mutation load, and the cache copy.
  • Evidence: source reading only. No runtime profile, and no N/10N count harness was run.
  • Gap: I didn't measure the upper bound of A on a real downgrade profile. Even so, it stays at or below the base's R.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready (updated)

This supersedes the earlier status comment. Problem, change and Claude-run evidence are unchanged; see above.

What's new since that comment.

  • Review pass 3: a fresh Claude + Codex pair reviewed the final head 5848b5f7e09. Both READY, no findings. The head differs from the pass-2 tree only by the ratchet baseline line (32 → 30 blocking sqlite calls in journal-legacy-reconcile.ts), and both reviewers confirmed the count.
  • Full perf-scan by a separate fresh perf reviewer (comment above): verdict clean, surfaces startup-migration and hot-path.
  • QA with Codex chats on this Mac, same flow as the Claude run, old 9bf84179da3 vs new 5848b5f7e09.
    • Old: all 5 closed Codex chats came back (9 chat tabs in the worktree, 10 rows in the store).
    • New: shows only the open chat, the kept copy holding the v1.4.259 turn, and one empty chat that was open since before the test (3 tabs). The same set came back after a restart.
    • The chat started on the new build before the downgrade is again not shown. As in the Claude run, that comes from the QA step that clears the tab index by hand.
  • A Windows low spec attempt didn't run: the driver was stopped by qa-drive's policy on its first command, before any app action, so it gave no verdict. The Mac Codex run replaced it.

Verified overall.

  • 2 regression tests.
  • check:changed 35/35.
  • CI green.
  • Real-app QA for Claude and Codex chats.
  • Perf-scan clean.

This branch has not been deployed

No deployments
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