Repository navigation
fix(native-chat): an older Orca's write no longer reopens every closed chat - #43306
brennanb2025 wants to merge 1 commit into
Conversation
…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.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
DONE: clean Perf scan: PR #43306 (
|
| 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 (
Setunion,entries()). Each is a single linear pass, once per open, with no nested scan. Disproved. - Per-entity state outlives the entity: matched (new
unrecordedTabSessionIdsfield). 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
- 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. - Ownership multiplying work: reviewed. One store transactions object and one record-tabs Set per store, with no per-tab or per-chat owners added.
- Which thread pays: reviewed. Electron main, sync
node:sqlite. Reconcile SQL drops from O(R) to O(A); load SQL is unchanged. - Growth and progress: reviewed. The unrecorded window ends at the first
initializeSessionTabs, which writesAGENT_SESSION_TABS_RECORDED. Work no longer grows with R. - Execution host: not applicable. This is local SQLite store open and reconcile only, with no SSH or Windows-specific spawning or probes.
- 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, everylegacySessionTabIdsconsumer (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.
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.
Verified overall.
|


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
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.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.Verification
journal-legacy-reconcile.test.ts, new test.agent-session-record-store-tab-table.test.ts, new test.session_tabs_recordedencoded the bug, so it is removed.pnpm check:changed: 35/35 passed on Omarchy.