Repository navigation
feat(native-chat): ask Claude to name its own structured chat - #19941
brennanb2025 wants to merge 15 commits into
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a focused, well-tested feature that asks Claude to name its own structured chat on the first accepted turn, reusing existing patterns end to end.
- SDK control request —
generateSessionTitleadded toClaudeControlSurfacebehind the sametypeofprobe used forgetSettings/cancelAsyncMessage, returning a discriminatednamed | declined | unsupportedresult. - Supporting refactor —
claudeDispatchTypedTextextracted fromclaudeDispatchMessageContentso the naming path shares one definition of "the text Claude reads";DISPATCH_ACK_TIMEOUT_MSmoved into the dispatch module. - The feature —
ClaudeConversationNamingwrapsdispatch; after the first accepted turn a fire-and-forgetgenerateSessionTitle(text, { persist: true })runs off the send path, gated by connection-open / not-closing / per-sessionWeakSet/ existing-record-name / non-empty text. - Runtime wiring —
readConversationName/storeConversationNamedeps wired to the record store, deliberately bypassingrenameStructuredAgentSessionTabso the vault stays the only live display path.
I verified the load-bearing external contracts the design rests on. Query.generateSessionTitle(description, { persist }) is real at runtime in the SDK sdk.mjs (0.3.251 — it forwards subtype: "generate_session_title" with persist: t?.persist and returns response.title), and it is genuinely absent from the shipped .d.ts, so the typeof guard is required rather than defensive. The AI Vault scanner (src/main/ai-vault/session-scanner-primary-parsers.ts) already reads type: 'ai-title' records and prefers the latest one over the first prompt, so the persist: true → ai-title → vault → tab path exists in the repo today.
ℹ️ One residual risk is inherent to the design, not addressable in code
The end-to-end effect depends on the CLI honoring persist: true by actually appending the ai-title record. The flag is confirmed forwarded and the vault read path exists, but there is no guard for a CLI whose generate_session_title returns a title without persisting it — that variety would leave Orca's record with a name the tab never agrees with. The ablation tests pin that persist: true is sent, which is the right and only reproducible check; the author already flagged the missing live capture. Nothing to change.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ementation `sliceAtCodeUnitLimit` lived in src/main/ai-vault, and src/shared never imports src/main, so a shared consumer could not reach it. Rather than add a second copy, it moves to src/shared and ai-vault imports and re-exports it, leaving every existing importer of that module untouched. Separated from the feature that needs it: this is the only change here to a subsystem the rest of the branch does not touch.
Adds the normalized conversation name and the record field that stores it, so Orca has a durable note that it already named a session and does not name it again on a later acquisition. No name is generated yet, and nothing displays this field: the AI Vault path stays the home for the name a user sees. - `agent-session-conversation-name` bounds and flattens the text once, at 200 characters, cutting on a character boundary. - `AgentSessionRecord.conversationName` carries it, validated on load. - `setAgentSessionRecordConversationName` sets or clears it, unfenced: the name is a durable note, not ownership, so writing it never contends with the writer lease.
…sion logic Pure move, no behavior change. `reserveOwner`'s transaction body sequenced decisions that all live in agent-session-reservation-admission and then applied the winning one; it now sits there as `commitAgentSessionReservation`, and the store keeps the transaction boundary and a one-line delegation. Takes agent-session-record-store.ts from 300/300 to 279/300, which is what the conversation-name field needs to land. Every existing test passes unedited. The module header said nothing in it mutates; that is now qualified rather than left false, since the committer writes the state it is handed.
`setConversationName` is the one writer for the record field, so a producer never reaches the record shape itself. It normalizes at the boundary, so no caller can persist a name the loader would then reject as unreadable. Unfenced by design: the name is durable memory that Orca already named this session, not ownership, so naming never contends with the writer lease. No name generation and no provider code yet.
…nt tab The replacement tab open-coded `'Claude Chat' : 'Codex Chat'` while every other publisher already calls `defaultAgentChatLabel`. One writer for the placeholder.
3504ade to
92c79ec
Compare
The shipped Query declaration omits generateSessionTitle, so it is probed with a typeof guard like the other runtime-only capabilities here and routed through runClaudeControl for the deadline. Its three outcomes stay distinct: only a declined title is worth asking for again, and a CLI without the request must never be asked twice.
claudeDispatchMessageContent already joined a body's text blocks the way Claude reads them; lifting that out lets a second caller ask for the same text instead of re-deriving it. Exporting the ack-timeout default lets the dispatch caller move without carrying the constant with it.
Every structured Claude chat has read Claude Chat forever because nothing ever named one. The name's home is the provider, not Orca: with persist: true the CLI appends an ai-title record to its own transcript, which the AI Vault scanner already reads to title the tab. So Orca asks once per session, off the send path, and the record write is only its memory that it asked -- never a display source. A conversationName already on the record means an earlier session asked, so a resumed conversation is never re-asked or re-charged. A declined title leaves only the in-memory flag, so a later acquisition may ask again on its already-open connection; an absent request is not retried for the life of the session.
f79b1d2 to
a569dfa
Compare
…9941b # Conflicts: # src/main/claude/claude-structured-dispatch.ts # src/main/claude/claude-structured-session-adapter.ts # src/main/claude/claude-structured-session-state.ts # src/main/claude/claude-structured-session-test-support.ts # src/main/runtime/agent-session-record-conversation-name.test.ts # src/shared/agent-session-conversation-name.test.ts # src/shared/agent-session-conversation-name.ts
|
Too many files changed for review (561 files, 100 file limit). |
|
Rebased onto Resolution summary:
Validation:
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the incremental delta since the prior review is a merge of origin/main onto the review branch, which forced the naming code to adapt to the base's dispatch-admission refactor rather than a pure rebase.
- Naming trigger moved from
acceptedtoadmitted—dispatchClaudeTurnnow returnsadmittedsynchronously once the transport takes the message, withaccepted(carryingproviderIdentity) settling out-of-band viaonDispatchSettledLate. The trigger had to move, sincedispatchTurnno longer seesacceptedon the normal path; firing onadmittedpreserves the "name it once, off the send path" contract and still rides the same open connection after the turn message, so ordering holds. - Dispatch signature simplified —
dispatchClaudeTurnis now two-arg; thedispatchAckTimeoutMsdep was dropped and the ack timeout internalized in the dispatch module. Both call sites (structured-session-adapter.tsand the naming wrapper) were updated. - Test fixtures/support updated — the
admittedoutcome, the removed dep, and anoverridesOrOnDispatchSettledLatepositional parameter onadapterFor/acquired(disambiguated bytypeof === 'function') so the naming tests can injectreadConversationName/storeConversationNamewithout breaking existing positional call sites.
I traced the two remaining dispatchClaudeTurn callers and the AgentSessionDispatchOutcome state machine; the only edge the new trigger introduces is a missed naming when send throws but the waiter has already settled (the rare accepted-in-catch path), which a later acquisition retries — consistent with the feature's documented best-effort policy, not a regression.
The one residual risk carried forward from the prior review is unchanged and inherent to the design: the end-to-end effect still depends on the CLI honoring persist: true.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Main landed its own canonical conversation-name module and refactored the Claude dispatch ack path. Resolutions, file by file: - shared/agent-session-conversation-name(.test).ts: took main's stricter guard, which additionally requires the name be normalization-idempotent. - claude-structured-dispatch/session-state.ts: took main's removal of the ack-timeout window, kept this branch's conversation-name deps. - conversation-naming.ts: ported onto main's two-arg dispatchClaudeTurn and widened the naming gate to main's new 'admitted' state. - session-test-support.ts: kept this branch's general overrides bag and migrated main's positional onDispatchSettledLate callers onto it.
The chat asks the provider for a title and the AI Vault scanner can read it back, but nothing displayed it: the vault title pipeline was terminal-only at both ends. A structured chat is a unified agent-session tab with no TerminalTab behind it, so it produced no title request and could not be written back to. Publish the provider conversation id as a new optional field on the agent-session tab contract, sourced from the head of the record's provider handle chain so a fork is never presented as its origin, and omitted until the provider proves one. Teach the collector to treat a chat as a candidate source under the existing Claude/Codex gate, and the write-back to name the unified row when no terminal tab owns the id. Persist the conversation id so a restored chat keeps its name and can still refresh it. Reuses the mechanism from #17092.
The store action had no test of its own, so neither the terminal write-back nor the new chat branch was pinned.
Also corrects the re-publish comment: that branch is no longer a strict no-op, it now carries a newly proven conversation.
The helper returned the broad snapshot-tab union, so passing it to the narrowed agent-tab parameter failed tc:node. The narrow parameter is correct; the fixture was the loose end.
Two independent merges of main landed on this branch. The reviewer's used a main 30 commits older, so this branch's merge wins where they disagree. Five of their seven conflict resolutions were already byte-identical to ours; the two that differed: - conversation-naming.ts: they narrowed the naming gate to 'admitted' only. 'accepted' is still reachable — the recovery path where the write throws after the replay already settled, which is a delivered turn — so that turn would never be named. Kept the both-states gate. - session-test-support.ts: they kept both calling conventions behind a runtime type test on a polymorphic parameter. Kept the single overrides bag with the callers migrated, one convention instead of two. Their helper bodies had auto-merged in around the conflict and were left referencing a parameter that no longer exists; removed both.
|
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 (33)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change adds Claude session-title generation with named, declined, and unsupported outcomes. Structured Claude sessions now perform one asynchronous naming attempt and persist successful names. Runtime tabs publish provider conversation identities from session handle chains. Renderer state mirrors those identities, requests AI Vault titles for eligible structured chats, preserves titles across republishes, and resolves displayed labels from manual or provider names. Tests cover control requests, naming, publication, persistence, synchronization, and tab presentation. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Structured chat titles remain synchronized with the current provider conversation, including when a tab is republished for a different session. The change is ready to merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the implementation, rationale, testing, risks, and scope. However, it marks Linked Issue as N/A despite the template requiring an issue link, and it omits the required pnpm build checklist item.
✨ 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the incremental delta since the prior review adds the surfacing half of the feature: publishing the provider conversation id onto the session tab and routing structured chat tabs through the existing AI Vault title pipeline so the resolved name actually appears in the tab strip.
- Provider conversation id published on the tab —
RuntimeMobileSessionAgentTab.providerSessionIdcarries the head of the record's handle chain (Claude session id, Codex thread id);refreshStructuredProviderSessionsre-reads it on every re-publish so a conversation proven after tab minting still reaches the client. - AI Vault title pipeline extended to chat tabs —
structuredAgentSessionTitleTabsand request collection now include chat tabs with a provenagentSessionProviderSessionId, re-read on the same live cadence as terminal sessions;setAiVaultTabTitlewrites a resolved name onto the unified chat row. - Tab strip resolves the provider name —
tab-bar-item-surfaceand the drag label routeagent-sessiontabs throughresolveUnifiedTabLabel, so the resolvedaiVaultTitle(and a manual rename) shows in the strip. - Mirror and persistence —
buildMirroredAgentTabscarriesproviderSessionIdonto the unified tab and preserves an already-resolved title across republishes;workspace-session-schemapersistsagentSessionProviderSessionIdacross restarts. - Naming trigger widened to the recovery path —
dispatchTurnnow fires onacceptedas well asadmitted, closing the missed-naming edge the prior review noted (write throws after the replay already settled). - Test-support refactor — the
overridesOrOnDispatchSettledLatepositional parameter onadapterFor/acquiredis replaced by a namedoverridesobject plus an explicitonDispatchSettledLate.
I traced the end-to-end path the surfacing half opens. acquireOwner → proveOwner persists the handle-chain head during attach, before publishStructuredAgentSessionTab mints the tab, so a freshly created chat is published with its providerSessionId; restored chats already carry the durable chain; and republishStructuredProviderSessions covers the narrow "proven after mint" edge on any re-publish. On the renderer, the request append and the providerSession.key: 'session_id' label match the existing terminal-backed path for both Claude and Codex, and the sync's identity/refresh logic (aiVaultTitleByTabId, refresh: true) treats a chat exactly like a live terminal session. Fork handling is covered in both directions (headStructuredProviderSessionId reads only the chain head; preservesExistingTitle drops a title resolved for a different conversation), and the tests are exact rather than loose — they pin the omitted-field vs blank-id distinction, the fork cases, and the same-array identity guard that stops an idle pass from bumping the snapshot version.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Closing: superseded. Structured chats (Claude and Codex) will be named by a user-configurable agent from the Chat settings page, stored on the session record, and shown on the tab, the sidebar row and AI Vault from that one field. That work replaces this approach. |

ELI5
Every native chat is called "Claude Chat", forever. Nothing has ever tried to name one.
This asks Claude for a title after the first message. Claude's own CLI writes that title into its transcript, and the AI Vault already reads titles from there to label tabs — so the name appears without Orca publishing it anywhere itself.
Scope: Claude structured chat only. Codex never names a thread itself, so it needs a real model turn and its own design. That work does not exist yet, and Codex chats will still read "Codex Chat" after this lands.
What Changed
Three commits, each readable on its own.
1 — the SDK control request. The Agent SDK exposes
generateSessionTitleat runtime but does not declare it, so it is probed withtypeofand bound, the same way this file already handles other optional capabilities. It returns three states:named,declined(the CLI answered with nothing usable),unsupported(the method is absent). Fixture updates ride along because the new required surface member breaks three hand-built fake connections.2 — a supporting refactor.
claudeDispatchTypedTextis lifted out ofclaudeDispatchMessageContentso the naming path reuses the single definition of "the text Claude reads from a dispatch" rather than growing a parallel one.3 — the feature. After the first accepted turn, and only then, a fire-and-forget attempt runs. Guards in order: connection open, not closing → per-session in-memory flag → the record already has a name → the first message actually has usable text. Then
generateSessionTitle(text, { persist: true }).Why the name is not published to the tab
persist: trueis the whole design. It makes the CLI append anai-titlerecord to its own transcript, which the AI Vault scanner already parses and feeds to the tab title. So the provider owns the name, one reader surfaces it, and Orca publishes nothing.The record write here is Orca's memory that it already named this session — not a display source. It is what stops a later acquisition asking again and re-charging the user. Two useful consequences: the name is visible in the user's own Claude CLI, not just in Orca; and Session History and the tab agree by construction, because both read the same provider record.
The
conversationNamefield this writes to landed in #19908, now merged.Linked Issue
N/A — first producer for the structured-chat naming work.
Visual Proof
A structured Claude chat's tab label changes from "Claude Chat" to the generated title once the vault picks up the transcript record (its refresh is 20s while a title is missing). Not captured here because it needs a real Claude account and a live session; the behaviour is pinned by tests instead, including that
persist: trueis actually sent.Testing
Typecheck:
tc:node,tc:cli,tc:webclean, run sequentially (pnpm tcruns the three concurrently on this repo).Tests: 7 new in
claude-structured-conversation-naming.test.ts, 2 new inclaude-agent-sdk-control-requests.test.ts. Focused suites 95/95. Claude suite 829 passed, 5 skipped.Ablations: 9 gates, each reverted → run → restored → re-run, with the guard symbol grepped back after every restore. Flipping
persist: truetofalsereddens 3 of 7 naming tests, and dropping the forwarding in the control surface reddens a test that asserts the argument handed to a mockedQuery— so a silent drop of that flag, which would leave the feature inert while everything else stayed green, cannot pass.One pre-existing failure: a Claude TUI resume integration test fails on
ps -axo …. It fails identically without this change — environmental.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Retry policy, stated plainly
named→ the record write is the durable "already named"; no later session re-asks.declined/unsupported→ an in-memory flag only. A later acquisition may retry. Deliberate: this is one control request on a connection already open, not a spawned process, so a retry is cheap. Making it never retry would need a durable marker.Rebased onto main
This PR was originally based on #19908's branch. Now that #19908 has merged, the base is
mainand the branch carries a merge of main whose conflicts were resolved file by file — main is authoritative for the shared normalizer (including its canonical-form validator), while this PR's naming wiring, typed-text extraction and control-surface fixtures are preserved.Not in this PR
Codex structured chat, as above. Also note a separate follow-up is in flight to make record loading repair a noncanonical optional field rather than discard the whole session record.
Agent skill upstream boundary
Notes
unsupportedand nothing happens.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm testpass locally