Repository navigation
refactor(agent-session): keep which conversation each chat tab shows in one host table - #22709
Conversation
There was a problem hiding this comment.
Important
Two functional regressions to fix before merge: session.tabs.move mistranslates chat tab ids for every paired client that does not advertise session.tabs.chat-tab-id.v1 (all of them today), and a second /clear on a replacement is refused agent_session_conflict.
Reviewed changes
- Publish the record id: new
structuredAgentSessionSurfaceTabIdreadsrecord.surfaceTabIdand falls back to the derivedstructured-agent-session-<sessionId>;publishStructuredAgentSessionTab, the restore-once publisher, the hook status address, worker pane keys,findStructuredAgentSessionTaband the CLIhandleall move onto it. - Compatibility projection: new host capability
session.tabs.chat-tab-id.v1;projectSessionTabChatIdsrewrites every id-bearing snapshot field toagent-session:<sessionId>for a paired client that does not advertise it, andresolveClientSessionTabIdmaps that spelling back on activate/close/refuse and inresolveMobileSessionHostTabId. /clearkeeps its tab: the replacement inherits the source'ssurfaceTabId, admission exempts the declared replacement, andreplaceConversationInSnapshotstops renaming.- Derivation ratchet: pins the remaining
structuredAgentSessionTabIdcallers to the four that translate older state.
Two notes that are minor enough to leave inline rather than block: the fold in replaceConversationInSnapshot does not clean group references, and the helper's early fallback can key a status row by the derived string during teardown.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
b4a3297 to
38f8746
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe runtime replaces the visible-session index and record-level tab IDs with a persisted tab table. Create reservations check that requested IDs are unheld; publication assigns the tab ID, which create and attach responses can return. Clear commands move tab mappings to replacement sessions, and close rollback can restore a captured tab ID. The changes also add table persistence and lifecycle tests, remove legacy backfilling, and update record validation. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Concurrent chat operations can leave a created chat without a visible tab or restore a stale tab after a failed close. Resolve the create race before merging and assess the close/clear interleaving. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The new ownership model reduces the chance that an old conversation and its replacement claim the same tab. The main access checks remain in place, but this is a persistent lifecycle change, and recovery and compatibility paths are not fully established by the available evidence. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the required change, rationale, testing, visual proof, compatibility, and checklist areas. However, the required linked issue is missing; it states "No issue" instead of providing a
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
…in one host table The host now persists one table in the agent-session store, from chat tab id to the conversation that tab currently shows. It replaces both the visible-session list and the per-record surfaceTabId, so there is one answer to "which chats have a tab, and under what id". - /clear moves the tab's entry from the old conversation to its replacement in the same transaction that commits the clear. No record carries a copied tab id, so a tab id names one conversation by construction, and the lookup from a conversation to its tab returns at most one id. - A create that reserved a tab id claims it in its reservation transaction; uniqueness is a key check on the table. A create that fails releases its claim, and hiding a chat frees its id. - Showing a chat with no entry gives it today's id, structured-agent-session-<sid>, unless a cleared chat's tab kept that id; then it gets a fresh one. - A close that does not land puts the tab back under the id it had. - Stores written by older builds are seeded on read from the visible list and, for chats that have one, the record's surfaceTabId. That field is no longer part of the record type, is never written, and is read only by this seed when the file has no table. The visible list is still written, derived from the table, for older builds. Tab snapshots, status keys and worker pane keys are unchanged. Co-Authored-By: Claude <[email protected]>
38f8746 to
c48ed35
Compare
…shed A create that reserved a tab id put it in the tab table at reservation, and table membership is visibility. A create that stopped before its tab was published (a crash, or a failure after the provider started) left an entry that the next launch either restored as a tab nobody asked to see again or kept forever with no way to close it. Reservation now only refuses an id another chat's tab holds; the id is taken when the tab is published, so there is nothing to release on failure. The create reply now reads the tab id after publishing, so an unreserved create answers with the id its tab was given, as it did before the table, and agrees with a replay of the same create. Co-Authored-By: Claude <[email protected]>
…first tab id A chat cleared on an older build shows a later conversation of its /clear chain in the tab that was opened for the first one, and clients key that tab, its read state and its status by the first conversation's id. Seeding gave it the latest conversation's derived id instead, so the stored id disagreed with the one clients hold and with what a /clear on this build leaves behind. Seeding now follows the source records' committed clears back to the chain's first conversation and gives the chat showing the chain that conversation's id. Those chats seed first, so a cleared conversation reopened from history takes a fresh id when its own is held. A seeded chat is no longer dropped when every candidate id is taken, and the table keeps the visible list's order. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Important
This rewrite replaces the record-pinned id with a single host sessionTabs table and resolves both prior threads cleanly. One logic gap remains before merge: on a failed create, the tab release is keyed to the request rather than to whether the reservation actually claimed an entry, so a failed re-create can delete a tab the create never owned.
Reviewed changes
This run re-reviewed c48ed35 against the prior pullfrog review at b4a3297; the delta is a full reimplementation, not a rebase.
- Introduced one host-owned table.
AgentSessionTabTable(tabId → sessionIdplus a reverse index) now owns chat-tab membership and id; it replaces the record'ssurfaceTabIdand the visible-conversation set, andagent-session-visible-tab-index.tsis deleted. /clearmoves the entry.commitConversationCommandRecordcallsmove(sessionId, replacementSessionId)so the tab keeps its id and place, and a chain of clears is admitted by construction instead of by a one-hop exemption.- Removed the client-side new id entirely.
structuredAgentSessionSurfaceTabId, thesession.tabs.chat-tab-id.v1capability and its projection are gone; the snapshot still names chat tabsagent-session:<sessionId>, sosession.tabs.movesees matching ids again. - Reserved creates claim and release in the reservation transaction.
claimReservedTabshows the reserved id; failure settlement hides it; a failed close restores the exact prior id. - Reworked persistence and tests. The store persists
sessionTabswhile still writingvisibleSessionIdsfor older builds, and seeds from a legacy file using each visible record'ssurfaceTabId; new end-to-end tests cover repeated clears, reveal, close, restart, and seeding.
ℹ️ Nitpicks
getSessionTabId(agent-session-record-store.ts:137) reads the table unfiltered whilelistVisibleSessionIdsfilters byrecords.has, so seeding an entry for a session with no readable record makes the two accessors disagree about whether a chat has a tab. Harmless today (the close restore throwsagent_session_identity_requiredand is warned), but filtering both the same way would keep the contract single-valued.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f7ef3560-aba7-4827-97ef-a69a214cac7c
📒 Files selected for processing (12)
src/main/native-chat/agent-session-wire/structured-agent-session-acquisition-options.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.tssrc/main/native-chat/agent-session-wire/structured-agent-session-attach.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/runtime/agent-session-record-store-tab-table.test.tssrc/main/runtime/agent-session-reservation-admission.tssrc/main/runtime/agent-session-tab-table.tssrc/main/runtime/orca-runtime-restore-structured-agent-session-tabs-once.tssrc/main/runtime/rpc/methods/structured-agent-session-create.tssrc/main/runtime/rpc/methods/structured-chat-tab-table.test.tssrc/shared/agent-launch-intent.tssrc/shared/agent-session-wire.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/shared/agent-session-wire.ts
- src/main/native-chat/agent-session-wire/structured-agent-session-attach.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| const holder = state.sessionTabs?.sessionIdFor(request.surfaceTabId) | ||
| if (holder !== undefined && holder !== request.sessionId) { | ||
| throw new Error('agent_session_conflict') | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
sed -n '150,215p' src/main/runtime/agent-session-reservation-admission.ts
sed -n '240,275p' src/main/runtime/agent-session-reservation-admission.ts
sed -n '110,175p' src/main/runtime/rpc/methods/structured-agent-session-create.ts
sed -n '1,118p' src/main/runtime/agent-session-tab-table.ts
rg -n 'settleFailedAcquisition|agent_session_operation_unknown|commitStructuredAgentSessionCreate|reserveOwner' src/main/native-chat/agent-session-wire src/main/runtime/rpc/methods src/main/runtime/agent-session-record-store.tsRepository: stablyai/orca
Length of output: 18441
🏁 Script executed:
rg -n -C 8 "class AgentSessionRecordStore|reserveOwner|settleFailedAcquisition|withTransaction|transaction|publishStructuredAgentSessionTab|setAgentSessionTabVisibility|attach\(" src/main/runtime src/main/native-chat/agent-session-wire -g '*.ts'
printf '\n--- record store ---\n'
sed -n '1,290p' src/main/runtime/agent-session-record-store.ts
printf '\n--- attach flow ---\n'
sed -n '1,330p' src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
printf '\n--- runtime publish binding ---\n'
rg -n -C 12 "publishStructuredAgentSessionTab|setAgentSessionTabVisibility" src/main/runtime src/main/native-chat -g '*.ts'Repository: stablyai/orca
Length of output: 45666
🏁 Script executed:
printf '%s\n' '--- store symbols ---'
rg -n "export class AgentSessionRecordStore|reserveOwner|settleFailedAcquisition|transactionQueue|run|enqueue|withTransaction" src/main/runtime/agent-session-record-store.ts src/main/runtime/agent-session-store-transaction-queue.ts
printf '%s\n' '--- store reserve/settlement ---'
sed -n '150,275p' src/main/runtime/agent-session-record-store.ts
printf '%s\n' '--- transaction queue ---'
cat -n src/main/runtime/agent-session-store-transaction-queue.ts
printf '%s\n' '--- attach flow symbols ---'
rg -n "performAttach|settleFailedAcquisition|releaseAcquisition|onAttached|catch|attach" src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
printf '%s\n' '--- attach flow relevant sections ---'
sed -n '70,205p' src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
sed -n '235,290p' src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
printf '%s\n' '--- publication implementation ---'
rg -n -C 15 "publishStructuredAgentSessionTab" src/main/runtime -g '*.ts' -g '!*.test.ts'Repository: stablyai/orca
Length of output: 45074
🏁 Script executed:
printf '%s\n' '--- attach flow post-acquisition ---'
cat -n src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts | sed -n '190,300p'
printf '%s\n' '--- host attach implementation ---'
rg -n -C 12 "async attach|attach\\(" src/main/native-chat/agent-session-wire/structured-agent-session-host.ts src/main/native-chat/agent-session-wire/structured-agent-session-attach.ts src/main/native-chat/agent-session-wire -g '*.ts' -g '!*.test.ts' | head -n 260
printf '%s\n' '--- provider acquisition and release bindings ---'
rg -n -C 10 "acquireOwner|releaseAcquisition|settlePostAcquisitionAttachFailure|providerChildPhase" src/main/native-chat/agent-session-wire -g '*.ts' -g '!*.test.ts'Repository: stablyai/orca
Length of output: 42649
Claim surfaceTabId before spawning, and settle a loser after publication conflict.
reserveOwner serializes transactions, but assertReservedTabUnheld only reads state.sessionTabs; it does not claim the ID. Two creates with different session IDs can therefore reserve the same surfaceTabId.
Each host.attach can acquire the provider and record a successful operation before tab publication. The first publication claims the tab. The second can receive agent_session_conflict. commitStructuredAgentSessionCreate converts that error to agent_session_operation_unknown, but no post-acquisition settlement or provider release runs after host.attach returns.
The failure is not that nothing is persisted. The losing record and successful operation remain persisted, but the provider and record can remain without a visible tab.
Keep a transient pending claim from reserveOwner through publication. If publication fails after attach, use the post-acquisition failure path to release the provider, settle the record, and clear the pending claim. Do not silently allocate a fresh ID, because that changes the caller's requested surfaceTabId and removes the before-spawn refusal contract.
…untime and at seeding A cleared conversation reopened from history got a random tab id at runtime but a deterministic `-reopened` id when the table is seeded from an older store. One rule now serves both, so a table dropped by an older build and seeded again gives that chat the id it already had.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the two commits pushed since the prior pullfrog review at c48ed35; both prior findings are resolved and the delta introduces no new issues.
- A reserved chat tab id is now taken when the tab is published, not at reservation.
assertReservedTabUnheldonly checks the table,createAgentSessionRecordno longer writessurfaceTabId, and the failed-create release path (releaseTab/releaseFailedCreateTab) is gone, so a failed create can no longer hide a tab it never claimed. - The create commit half publishes the reserved id and reads it back.
publishStructuredAgentSessionTabthreads the reservedtabIdintosetSessionTabVisibility, andcommitStructuredAgentSessionCreateanswers withhost.getSessionTabId(...)after publication. - Seeding follows a
/clearchain to its first conversation.seedFromVisibleSessionsseeds a chain's tab under the chain root's id, with a deterministic<derived>-reopenedfallback so a colliding visible session is never dropped, matching whatmove+showwould have produced. - Close rollback restores the exact prior id.
readPersistedTabIdreadsstore.getSessionTabIdbefore hiding and passes it back on a failed close.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
A commit landed while the prior review was posting; this run covers only that new commit (33815fa).
- The reopened cleared-chat id is now deterministic and shared.
AgentSessionTabTable.showand the seed'sassignboth call a newreopenedTabIdhelper, so a table dropped by an older build reseeds a reopened cleared conversation under the same id the runtime had assigned;randomUUID()is gone fromshow. - New coverage pins the invariant. The added test drives create → clear → reveal → clear, drops
sessionTabs, reloads the store, and asserts the current chat and the reopened conversation keep the same ids.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…-identity-p2-published-id # Conflicts: # src/main/runtime/agent-session-record-store-file.ts # src/main/runtime/agent-session-record-store-surface-tab-id.test.ts # src/main/runtime/agent-session-record-store.ts
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the only commit pushed since the prior pullfrog review at 33815fa; it is a merge of main (8009939) with conflict resolution in three files the PR also touches. The PR's own logic is byte-for-byte unchanged, and the resolution is clean.
- Merged
main's persisted-lease refactor into the store file.agent-session-record-store-file.tsnow decodes records throughisPersistedAgentSessionRecord+normalizeLegacyHandoffRecordand threadslegacyHandoffLeasesNormalizedintoneedsRewrite. It composes correctly with the PR's table:parseAgentSessionTabTablestill runs,state.sessionTabsis still set, andgetVisibleSessionTabIndex().presentstill meanssessionTabs !== null. - Narrowed an attach param to
'native'.AgentSessionAttachParams.runtimeKindno longer references the removed runtime-kind union; the PR'ssurfaceTabIdparam is intact.
Verified against the merged tree: structured-chat-tab-table, agent-session-record-store-tab-table, structured-agent-session-acquisition-options, structured-agent-session-close, structured-session-worktree-teardown and the store/reservation/legacy-handoff suites all pass (151 tests), and pnpm run typecheck:node ends EXIT 0. No new inline comments.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏





ELI5
A chat tab and the conversation it shows are two different things. After
/clear, the same tab shows a new conversation. Until now the host kept this link in two places: a list of which conversations have a tab, and a tab id written onto each conversation's record. This PR replaces both with one table owned by the host: "tab X currently shows conversation Y"./clearjust moves tab X to point at the new conversation.What Changed
Users should see no change. Tabs, their order, their read/unread state and their status dots behave as they do on main. This change lays the ground for the later step, in which every client starts using the host's tab id.
How it works:
sessionTabs, a list of{ tabId, sessionId }. In memory it keeps a reverse index, so a lookup from a conversation to its tab takes constant time and returns at most one id. A conversation with an entry has a visible tab, so this table replaces the old visible-conversation list./clearmoves the entry. The transaction that commits the clear moves the tab's entry from the old conversation to the new one. The tab keeps its id and its position. No record carries a copied id, so one tab id can only ever name one conversation.agent.launchoragentSession.create) takes it when its tab is published, the same moment every other chat gets its entry. The reservation only checks that no other chat's tab holds the id, and refuses it if one does; the old scan over every record is gone. A create that stops before its tab is published, whether it fails or the app quits, leaves nothing in the table, so there is nothing to release and nothing for the next launch to restore. Closing a chat frees its id. If two creates race for one id, both pass the check and the second fails to publish its tab, answering that the outcome is unknown. Its provider keeps running without a tab until the app quits; nothing is persisted for it, so the next launch does not restore it. No shipped client sends a reserved chat tab id yet, and client-minted ids make a collision a client bug, not a user path.structured-agent-session-<sessionId>. There is one exception. When a cleared conversation is reopened, its tab id is already held by the tab now showing its replacement, so the reopened one getsstructured-agent-session-<sessionId>-reopened(with a number added if that is taken too). Seeding from an older store file uses the same rule, so the id survives an older build dropping the table. Ids never contain:.Deliberately not in this PR:
agent-session:<sessionId>.replaceConversationInSnapshotis unchanged.Publishing the host id, one inbound conversion point, and the move of the status and worker keys all ship with the desktop change that uses them.
The
surfaceTabIdrecord field (added in #22616) is no longer part of the record type and is never written on new records. It is read in one place only: when the host loads a store file that has nosessionTabs, it seeds the table from the visible list, using each visible chat'ssurfaceTabIdif it has one and today's derived id otherwise. A chat cleared on an older build is the exception: its tab was opened for the first conversation of its/clearchain, and clients still hold that tab under the first conversation's id, so it seeds under that id, found by following the committed clears on the source records. Those chats seed first, so a cleared conversation reopened from history gets the same-reopenedid when its own is held, as it does on this build. Once the table is on disk, the field is never read again. Records that already carry it keep it unchanged through rewrites; nothing drops it and nothing reads it. A malformed value no longer marks the record unreadable. #22616 is in no release:v1.4.210and the newest tag,v1.4.211, both lack it.Why
The first version of this PR copied the tab id from the cleared conversation's record onto its replacement's record. Records are never deleted, so after a
/cleartwo records claimed one tab, and every lookup had to guess which one was current. That caused three bugs:/clearwas refused as a conflict, because the exemption covered only one hop, and the chat then refused every send.That version also published the new id before any client could read it. It then had to convert ids back to the old spelling at each call site, which broke two things: tab reorder from a paired client, where the tab order list was never converted, and the old-mobile close check, which ran before the conversion.
A table keyed by tab id rules out the first set of bugs by construction: each id has one owner, and
/clearchanges which conversation that owner points to rather than creating a second holder. Waiting to publish removes the second set. Nothing outside the host reads the new id until the client that uses it ships with the one conversion point.The table also absorbs the visible-conversation list rather than sitting next to it. Two lists that both mean "this chat has a tab" can disagree.
Linked Issue
No issue. This is the second step of the chat tab identity series, after #22616.
Visual Proof
N/A. Nothing users see changes. The table is host bookkeeping, and the snapshot, status keys and read-state keys are unchanged.
Testing
New tests use a real store on disk, the real structured host, the real runtime and the real RPC handlers. Only the provider process is faked. They are in
rpc/methods/structured-chat-tab-table.test.tsandagent-session-record-store-tab-table.test.ts. They cover:/clearthree times in a row, then a send: every clear succeeds, the tab follows each replacement, and the send is accepted.sessionTabsand is loaded again; the current chat and the reopened conversation seed under the ids they had.:, the visible order is kept, and a second read gives the same ids.surfaceTabIdon a record is ignored.The last two exercise code this PR does not change. They pin that the table does not disturb those paths and have no ablation.
Ablation. For each mechanism, the code was deleted on a committed tree and the targeted files were run, then the code was restored. Also, with the production code of the first version of this change put back and the new tests kept, 4 of 42 tests fail: the id is taken at reservation, an unreserved create's reply lacks its id, and a create that stopped before publishing is restored as a visible chat.
/clearmoves the table entrysurfaceTabId/clearchain seed under the chain's first id/cleardrops the old conversation's reverse entryAlso run:
pnpm tc.agent-session-pty-write-enforcement.test.ts> "withholds orchestration Enter after the pointer lease fence moves", which fails the same way onmain.tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.tsandcross-version-session-tabs-retirement-proof.unit.test.ts, each run alone: passed.oxlinton the changed files, andcheck:code-quality:changed: 0 findings.AI Disclosure
Written with Claude.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
agentSession.create/ attachtabId(and theagent.launchoutcome'stabId), which is already optional. It now comes from the table and is present when the chat has a tab. A create reads it after its tab is published, so a create that reserved nothing answers with the derived id, as on main, and a retry of the same create answers the same. No released client reads it.sessionTabsand keep readingvisibleSessionIds, which is still written, derived from the table. If an older build rewrites the file it drops the table. The next load of this build seeds it again, with the same ids for every chat except three kinds: a chat created with a reserved id, which gets the derived id; a cleared conversation reopened from history whose replacement's tab has since closed, which gets its own derived id back; and, in that same case, a replacement later reopened from history, which reseeds under the first conversation's id instead of its own. Nothing reads the host's id yet, so none of these is visible to a user; the step that publishes the host's id has to settle them./clearmoves the entry in place.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)