Repository navigation
feat(chat): fork-on-send — switch harness mid-conversation via linked sessions - #6329
saddlepaddle wants to merge 2 commits into
Conversation
…nscript seed Implements protocol §7 forkSession: new session inheriting scope/cwd with forkedFromSessionId lineage (additive 0001 migration), journal projected to markdown via projectTranscriptForHandoff (tail-truncating), delivered as a <prior_conversation> preamble on the fork's first prompt only — adapters stay ignorant. Router resolves cwd from the source session's scope. 138 tests green. Claude-Session: https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h
The harness chip becomes a live picker: selecting the other harness arms the composer (visible hint — next message continues in a new linked session seeded with this transcript); send calls forkSession, routes the prompt via the existing first-prompt handoff, and follows to the fork. SessionPicker shows fork lineage and moves New session to the top; ⌘⇧T opens chat-v3 when the flag is on (legacy chat otherwise). Claude-Session: https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h
📝 WalkthroughWalkthroughChat V3 now supports harness-based session forking. The runtime stores fork lineage, projects prior transcripts into a handoff seed, and sends that seed with the first prompt in the forked session. The UI adds harness selection, fork status, provenance, transport wiring, and feature-flagged pane creation. ChangesChat V3 session forking
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant SessionView
participant ChatV3Pane
participant ChatRouter
participant ChatCommands
User->>SessionView: Select harness and submit prompt
SessionView->>ChatV3Pane: Send fork request
ChatV3Pane->>ChatRouter: Call forkSession
ChatRouter->>ChatCommands: Create linked session and queue handoff
ChatV3Pane->>ChatRouter: Send prompt to forked session
ChatCommands->>ChatCommands: Prepend handoff seed once
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 5
🧹 Nitpick comments (1)
packages/chat-runtime/src/commands/handoff/handoff.test.ts (1)
48-48: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSynchronize each scripted turn before asserting.
Replace all three
Bun.sleep(30)calls with a condition-based wait for the expected completion event. Do not wait only forstatus === "idle"because the session can already be idle before a new prompt starts.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/chat-runtime/src/commands/handoff/handoff.test.ts` at line 48, Replace all three Bun.sleep(30) calls in the handoff test with condition-based waits that observe the expected completion event for each scripted turn. Ensure each wait is tied to the current prompt’s completion rather than only status === "idle", which may already be true before the prompt begins.Source: Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:
- Around line 54-60: Add aria-pressed={selected} to each harness Button in the
SessionHeader harness picker so assistive technology can identify the selected
harness while preserving the existing variant styling.
- Line 7: Move the shared HARNESSES configuration and HarnessId type from
NewSessionView into the highest shared Chat V3 module, then update imports in
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:7-7,
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx:12-12,
and
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx:3-3
to use that shared module; remove ownership of the configuration from
NewSessionView while preserving existing exports and behavior.
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx:
- Around line 102-106: The fork-send flow currently reports success before the
fork completes, causing the composer to clear the draft on failure. In
SessionView’s onSend handler, return the asynchronous fork result so success is
reported only after completion; in ChatV3Pane’s fork handler, propagate
failures, and preserve the promise at the call site instead of discarding it
with void. Apply these changes at SessionView.tsx lines 102-106, ChatV3Pane.tsx
lines 37-49, and ChatV3Pane.tsx lines 79-81.
In `@packages/chat-runtime/src/commands/commands/commands.ts`:
- Around line 172-184: Update the handoff logic around pendingSeeds and the
first prompt submission so every first prompt consumes its seed, including
prompts whose first content item is non-text or whose content is empty. Define a
valid preamble insertion strategy for prompts without a text item, and delete
the seed only after require(...).prompt(...) completes successfully; retain the
existing text-item preamble composition for prompts that begin with text.
In `@packages/chat-runtime/src/commands/handoff/handoff.ts`:
- Around line 29-31: Update the handoff truncation logic around maxChars in
packages/chat-runtime/src/commands/handoff/handoff.ts: reserve the truncation
marker’s length when calculating the retained tail, and reject or normalize
negative limits so the final transcript never exceeds maxChars. In
packages/chat-runtime/src/commands/handoff/handoff.test.ts lines 126-128, add an
assertion that the truncated output length is less than or equal to maxChars.
---
Nitpick comments:
In `@packages/chat-runtime/src/commands/handoff/handoff.test.ts`:
- Line 48: Replace all three Bun.sleep(30) calls in the handoff test with
condition-based waits that observe the expected completion event for each
scripted turn. Ensure each wait is tied to the current prompt’s completion
rather than only status === "idle", which may already be true before the prompt
begins.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 22cbbe01-7503-4e25-84ac-55657175a8da
📒 Files selected for processing (16)
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionPicker/SessionPicker.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/hooks/useSessionClient/useSessionClient.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/useWorkspaceHotkeys/useWorkspaceHotkeys.tspackages/chat-runtime/src/commands/commands/commands.tspackages/chat-runtime/src/commands/handoff/handoff.test.tspackages/chat-runtime/src/commands/handoff/handoff.tspackages/chat-runtime/src/commands/handoff/index.tspackages/chat-runtime/src/db/drizzle/0001_third_warlock.sqlpackages/chat-runtime/src/db/drizzle/meta/0001_snapshot.jsonpackages/chat-runtime/src/db/drizzle/meta/_journal.jsonpackages/chat-runtime/src/db/schema/schema.tspackages/chat-runtime/src/journal/epoch/epoch.tspackages/chat-runtime/src/router/router/router.ts
| import { Button } from "@superset/ui/button"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import type { ReactNode } from "react"; | ||
| import { HARNESSES, type HarnessId } from "../NewSessionView"; |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Move shared harness configuration out of NewSessionView.
HARNESSES and HarnessId now serve three Chat V3 consumers. A component file must not own shared configuration.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx#L7-L7: import harness configuration from a shared Chat V3 module.apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx#L12-L12: importHarnessIdfrom the shared module.apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L3-L3: importHarnessIdfrom the shared module.
As per coding guidelines, promote components, utilities, hooks, constants, and configuration shared by two or more consumers to the highest shared parent.
📍 Affects 3 files
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx#L7-L7(this comment)apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx#L12-L12apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L3-L3
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx
at line 7, Move the shared HARNESSES configuration and HarnessId type from
NewSessionView into the highest shared Chat V3 module, then update imports in
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:7-7,
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx:12-12,
and
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx:3-3
to use that shared module; remove ownership of the configuration from
NewSessionView while preserving existing exports and behavior.
Source: Coding guidelines
| <Button | ||
| className="h-6 px-2 font-mono text-xs" | ||
| key={candidate} | ||
| onClick={() => onHarnessSelect(candidate)} | ||
| size="sm" | ||
| variant={selected ? "secondary" : "ghost"} | ||
| > |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Expose the selected harness state to assistive technology.
The selected state exists only in variant. When the picker is active, the static harness badge is hidden. Screen readers cannot identify the selected harness.
Add aria-pressed={selected} to each harness button.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx
around lines 54 - 60, Add aria-pressed={selected} to each harness Button in the
SessionHeader harness picker so assistive technology can identify the selected
harness while preserving the existing variant styling.
| onSend={(content) => { | ||
| if (pendingHarness && onForkSend) { | ||
| onForkSend(content, pendingHarness); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Do not clear the draft before the fork request succeeds.
SessionView returns null before forkAndSend completes. Composer treats null as a successful submission and deletes the source draft. If forkSession rejects, the user loses the message and no fork exists.
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx#L102-L106: make the fork-send path report success only after the fork completes.apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L37-L49: propagate fork failure so the composer can retain the draft and show an error.apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L79-L81: preserve the asynchronous result instead of discarding it withvoid.
📍 Affects 2 files
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx#L102-L106(this comment)apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L37-L49apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx#L79-L81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx
around lines 102 - 106, The fork-send flow currently reports success before the
fork completes, causing the composer to clear the draft on failure. In
SessionView’s onSend handler, return the asynchronous fork result so success is
reported only after completion; in ChatV3Pane’s fork handler, propagate
failures, and preserve the promise at the call site instead of discarding it
with void. Apply these changes at SessionView.tsx lines 102-106, ChatV3Pane.tsx
lines 37-49, and ChatV3Pane.tsx lines 79-81.
| const seed = pendingSeeds.get(parsed.sessionId); | ||
| let content = parsed.content; | ||
| const first = content[0]; | ||
| if (seed !== undefined && first?.type === "text") { | ||
| pendingSeeds.delete(parsed.sessionId); | ||
| content = [ | ||
| { ...first, text: composeHandoffPreamble(seed, first.text) }, | ||
| ...content.slice(1), | ||
| ]; | ||
| } | ||
| return options.live | ||
| .require(parsed.sessionId) | ||
| .prompt(parsed.content, parsed.clientId), | ||
| ); | ||
| .prompt(content, parsed.clientId); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Consume the handoff seed on the fork’s first prompt.
Line 175 consumes the seed only when the first content item is text. If the fork’s first prompt starts with non-text content, the seed remains pending and is added to a later prompt. This violates the first-prompt handoff contract.
Consume the seed for every first prompt. Define how to prepend the preamble when the prompt has no text item. Remove the seed only after the prompt submission succeeds.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/chat-runtime/src/commands/commands/commands.ts` around lines 172 -
184, Update the handoff logic around pendingSeeds and the first prompt
submission so every first prompt consumes its seed, including prompts whose
first content item is non-text or whose content is empty. Define a valid
preamble insertion strategy for prompts without a text item, and delete the seed
only after require(...).prompt(...) completes successfully; retain the existing
text-item preamble composition for prompts that begin with text.
| const maxChars = options?.maxChars ?? MAX_CHARS; | ||
| if (text.length > maxChars) { | ||
| text = `[earlier conversation truncated]\n\n${text.slice(text.length - maxChars)}`; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep the handoff transcript within maxChars.
Line 31 retains maxChars characters and then adds the truncation marker. The result exceeds the configured limit. Reserve space for the marker before slicing.
packages/chat-runtime/src/commands/handoff/handoff.ts#L29-L31: include the marker length in the retained-tail budget and reject or normalize negative limits.packages/chat-runtime/src/commands/handoff/handoff.test.ts#L126-L128: assert that output length is less than or equal tomaxChars.
📍 Affects 2 files
packages/chat-runtime/src/commands/handoff/handoff.ts#L29-L31(this comment)packages/chat-runtime/src/commands/handoff/handoff.test.ts#L126-L128
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/chat-runtime/src/commands/handoff/handoff.ts` around lines 29 - 31,
Update the handoff truncation logic around maxChars in
packages/chat-runtime/src/commands/handoff/handoff.ts: reserve the truncation
marker’s length when calculating the retained tail, and reject or normalize
negative limits so the final transcript never exceeds maxChars. In
packages/chat-runtime/src/commands/handoff/handoff.test.ts lines 126-128, add an
assertion that the truncated output length is less than or equal to maxChars.
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
There was a problem hiding this comment.
13 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/useWorkspaceHotkeys/useWorkspaceHotkeys.ts">
<violation number="1" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/useWorkspaceHotkeys/useWorkspaceHotkeys.ts:74">
P3: Keep `NEW_CHAT` on the existing `addChatV3Tab` opener rather than duplicating its tab construction. Menu and hotkey Chat V3 creation can otherwise drift when that opener gains required setup.</violation>
</file>
<file name="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx">
<violation number="1" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx:104">
P2: A failed fork silently drops the composed message: this branch returns `null`, causing `Composer` to clear the source draft while the async `forkSession` rejection is discarded. Handle and surface fork errors, and retain the draft until the fork succeeds.</violation>
</file>
<file name="packages/chat-runtime/src/commands/commands/commands.ts">
<violation number="1" location="packages/chat-runtime/src/commands/commands/commands.ts:164">
P2: `pendingSeeds` grows without bound: a forked session's transcript is stored here and only removed when that session later issues a text-first prompt. If a user forks a session but never sends a message in it (navigating away, closing the pane), the map entry is retained for the life of the process, and repeated forks that are never prompted leak memory indefinitely. Consider cleaning up the entry when the forked session is closed/discarded, or storing the seed on the session record so it is lifecycle-bound rather than in a parallel in-memory map.</violation>
<violation number="2" location="packages/chat-runtime/src/commands/commands/commands.ts:175">
P1: Forks sent with an attachment-first prompt omit the prior conversation, then leak it into a later prompt; consume the seed on every first prompt by prepending a text preamble or injecting into the first text part anywhere in `content`.</violation>
<violation number="3" location="packages/chat-runtime/src/commands/commands/commands.ts:176">
P2: A synchronous harness prompt failure consumes the handoff before the model receives it, so retrying loses fork context; delete `pendingSeeds` only after `live.prompt()` succeeds.</violation>
</file>
<file name="packages/chat-runtime/src/commands/handoff/handoff.ts">
<violation number="1" location="packages/chat-runtime/src/commands/handoff/handoff.ts:23">
P2: Fork handoff drops rendered reasoning and plans, so target harness lacks work already considered or planned; project these transcript item kinds too rather than silently skipping them.</violation>
<violation number="2" location="packages/chat-runtime/src/commands/handoff/handoff.ts:26">
P2: An unknown `fromItemId` silently seeds the fork with the entire latest conversation instead of failing, so edit/regenerate can branch from the wrong point; surface a missing boundary and reject the fork.</violation>
<violation number="3" location="packages/chat-runtime/src/commands/handoff/handoff.ts:31">
P3: The truncation marker `[earlier conversation truncated]\n\n` is prepended after slicing exactly `maxChars` characters from the tail, so the final string exceeds `maxChars` by the marker's length. Reserve space for the marker before slicing so the output actually respects the configured limit.</violation>
</file>
<file name="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx">
<violation number="1" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:7">
P3: HARNESSES and HarnessId are now imported into three different Chat V3 consumers from NewSessionView, a component file. Since this configuration is shared by multiple consumers, consider promoting it to a shared Chat V3 module instead of leaving it owned by a single component.</violation>
<violation number="2" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:51">
P3: The harness picker added here (HARNESSES.map -> Button with `variant={selected ? "secondary" : "ghost"}`) is a near-exact copy of the same picker already built in NewSessionView.tsx. Per the team's guidance to avoid duplicating business logic, extract a shared HarnessPicker component (taking `value`, `onSelect`, and the selected-value logic) and use it in both SessionHeader and NewSessionView so future harness additions/UI changes stay consistent in one place.</violation>
<violation number="3" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx:54">
P3: The selected harness is only conveyed visually via the button variant. Add `aria-pressed={selected}` to each harness button so assistive technology can identify which harness is currently selected.</violation>
</file>
<file name="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx">
<violation number="1" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx:40">
P2: When the user forks to another harness, the composed message is cleared synchronously (SessionView's onSend returns null, which Composer treats as a successful send), but forkAndSend awaits forkSession without any error handling and the promise is discarded via `void`. If the fork mutation rejects (e.g. transport failure), the typed message is lost with no feedback and an unhandled promise rejection fires in the renderer. Please wrap the forkSession call in try/catch (or attach a .catch) and surface the failure to the user (e.g. keep the draft / show an error) instead of silently discarding the input.</violation>
<violation number="2" location="apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/ChatV3Pane.tsx:45">
P2: pendingFirstPrompt is a parent-level ChatV3Pane state that persists across sessionId changes and is only reset once a SessionView actually dispatches the first prompt. After a fork, setPendingFirstPrompt(content) is armed but the prompt is not sent until the new session reports 'ready'. If the user selects a different session from the picker in that window, the leftover pendingFirstPrompt will be sent to whichever session is mounted next, delivering a message intended for the fork to the wrong conversation. Consider clearing pendingFirstPrompt on any session selection / when onSessionIdChange targets a session other than the fork result, or moving the prompt handoff to be scoped to the specific target session id.</violation>
</file>
Architecture diagram
sequenceDiagram
participant UI as Desktop UI
participant ChatV3 as ChatV3 Pane
participant SessionView as SessionView
participant Composer as Composer
participant SessionHeader as SessionHeader
participant SessionPicker as SessionPicker
participant Transport as ChatTransport
participant Router as tRPC Router
participant Commands as Commands
participant Handoff as Handoff Module
participant Journal as Journal
participant Live as LiveSession
participant DB as Database
participant Harness as External Harness
Note over UI,Harness: Fork-on-Send Flow (Happy Path)
UI->>SessionPicker: Select session
UI->>SessionHeader: Click harness button (e.g., codex)
SessionHeader->>SessionView: onHarnessSelect(nextHarness)
SessionView->>SessionView: setPendingHarness(nextHarness)
SessionView->>Composer: Render hint banner "continues in codex"
UI->>Composer: Type message and press Send
alt Pending harness selected
Composer->>SessionView: onForkSend(content, pendingHarness)
SessionView->>ChatV3: forkAndSend(content, nextHarness)
ChatV3->>Transport: forkSession({sessionId, harness: nextHarness})
Transport->>Router: forkSession.mutate(input)
Router->>Router: resolveCwd(source.scopeId)
Router->>Commands: forkSession({...input, cwd})
Commands->>Live: get(source.sessionId)
Live-->>Commands: source session state
Commands->>DB: readSince(sessionId, {epoch, seq:0})
DB-->>Commands: Replay envelopes
Commands->>Handoff: projectTranscriptForHandoff(envelopes)
Handoff->>Handoff: Tail-truncate at 30k chars
Handoff-->>Commands: Seed markdown string
Commands->>Journal: open({sessionId, scopeId, harness, forkedFromSessionId})
Journal->>DB: Insert chat_sessions_local row with forkedFromSessionId
DB-->>Journal: OK
Journal-->>Commands: {epoch}
Commands->>Live: create({sessionId, scopeId, harness, cwd})
Live-->>Commands: OK
Note over Commands: Store seed in pendingSeeds map
Commands-->>Router: {sessionId, epoch}
Router-->>Transport: Result
Transport-->>ChatV3: forked.sessionId
ChatV3->>ChatV3: setPendingFirstPrompt(content)
ChatV3->>SessionView: onSessionIdChange(forked.sessionId)
SessionView->>Composer: Send first prompt with seed via sendPrompt()
Composer->>Transport: prompt({sessionId: forked, content})
Transport->>Router: prompt.mutate(input)
Router->>Commands: prompt(input)
Commands->>Commands: Check pendingSeeds[forked.sessionId]
alt Seed exists (first prompt)
Commands->>Handoff: composeHandoffPreamble(seed, userText)
Handoff-->>Commands: <prior_conversation>\n...\n</prior_conversation>\n\nuserText
Commands->>Commands: Replace first text block with preamble
Commands->>Commands: Delete pendingSeeds entry
end
Commands->>Live: require(sessionId).prompt(content)
Live->>Harness: Forward prompt
Harness-->>Live: Response
Live-->>Commands: Result
Commands-->>Router: PromptResult
else No pending harness
Composer->>SessionView: session.sendPrompt(content)
SessionView->>Transport: prompt({sessionId, content})
Transport->>Router: prompt.mutate(input)
Router->>Commands: prompt(input)
Commands->>Live: require(sessionId).prompt(content)
Live->>Harness: Forward prompt
Harness-->>Live: Response
Live-->>Commands: Result
Commands-->>Router: PromptResult
end
Note over SessionPicker: SessionPicker shows lineage
SessionPicker->>DB: listSessions(scopeId)
DB-->>SessionPicker: Sessions with forkedFromSessionId
SessionPicker->>SessionPicker: Display "forked from <id>" for forked sessions
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| const seed = pendingSeeds.get(parsed.sessionId); | ||
| let content = parsed.content; | ||
| const first = content[0]; | ||
| if (seed !== undefined && first?.type === "text") { |
There was a problem hiding this comment.
P1: Forks sent with an attachment-first prompt omit the prior conversation, then leak it into a later prompt; consume the seed on every first prompt by prepending a text preamble or injecting into the first text part anywhere in content.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/commands/commands/commands.ts, line 175:
<comment>Forks sent with an attachment-first prompt omit the prior conversation, then leak it into a later prompt; consume the seed on every first prompt by prepending a text preamble or injecting into the first text part anywhere in `content`.</comment>
<file context>
@@ -111,13 +123,66 @@ export function createCommands(options: CommandsOptions): ChatCommands {
+ const seed = pendingSeeds.get(parsed.sessionId);
+ let content = parsed.content;
+ const first = content[0];
+ if (seed !== undefined && first?.type === "text") {
+ pendingSeeds.delete(parsed.sessionId);
+ content = [
</file context>
| onSend={(content) => session.sendPrompt(content)} | ||
| onSend={(content) => { | ||
| if (pendingHarness && onForkSend) { | ||
| onForkSend(content, pendingHarness); |
There was a problem hiding this comment.
P2: A failed fork silently drops the composed message: this branch returns null, causing Composer to clear the source draft while the async forkSession rejection is discarded. Handle and surface fork errors, and retain the draft until the fork succeeds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionView/SessionView.tsx, line 104:
<comment>A failed fork silently drops the composed message: this branch returns `null`, causing `Composer` to clear the source draft while the async `forkSession` rejection is discarded. Handle and surface fork errors, and retain the draft until the fork succeeds.</comment>
<file context>
@@ -71,13 +86,26 @@ export function SessionView({
- onSend={(content) => session.sendPrompt(content)}
+ onSend={(content) => {
+ if (pendingHarness && onForkSend) {
+ onForkSend(content, pendingHarness);
+ return null;
+ }
</file context>
| let content = parsed.content; | ||
| const first = content[0]; | ||
| if (seed !== undefined && first?.type === "text") { | ||
| pendingSeeds.delete(parsed.sessionId); |
There was a problem hiding this comment.
P2: A synchronous harness prompt failure consumes the handoff before the model receives it, so retrying loses fork context; delete pendingSeeds only after live.prompt() succeeds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/commands/commands/commands.ts, line 176:
<comment>A synchronous harness prompt failure consumes the handoff before the model receives it, so retrying loses fork context; delete `pendingSeeds` only after `live.prompt()` succeeds.</comment>
<file context>
@@ -111,13 +123,66 @@ export function createCommands(options: CommandsOptions): ChatCommands {
+ let content = parsed.content;
+ const first = content[0];
+ if (seed !== undefined && first?.type === "text") {
+ pendingSeeds.delete(parsed.sessionId);
+ content = [
+ { ...first, text: composeHandoffPreamble(seed, first.text) },
</file context>
| } else if (item.kind === "tool_call") { | ||
| lines.push(`[tool] ${item.toolKind} ${item.title} (${item.status})`); | ||
| } | ||
| if (options?.untilItemId && item.id === options.untilItemId) break; |
There was a problem hiding this comment.
P2: An unknown fromItemId silently seeds the fork with the entire latest conversation instead of failing, so edit/regenerate can branch from the wrong point; surface a missing boundary and reject the fork.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/commands/handoff/handoff.ts, line 26:
<comment>An unknown `fromItemId` silently seeds the fork with the entire latest conversation instead of failing, so edit/regenerate can branch from the wrong point; surface a missing boundary and reject the fork.</comment>
<file context>
@@ -0,0 +1,38 @@
+ } else if (item.kind === "tool_call") {
+ lines.push(`[tool] ${item.toolKind} ${item.title} (${item.status})`);
+ }
+ if (options?.untilItemId && item.id === options.untilItemId) break;
+ }
+ let text = lines.join("\n\n");
</file context>
| lines.push(`User: ${text}`); | ||
| } else if (item.kind === "agent_message") { | ||
| lines.push(`Assistant: ${item.text}`); | ||
| } else if (item.kind === "tool_call") { |
There was a problem hiding this comment.
P2: Fork handoff drops rendered reasoning and plans, so target harness lacks work already considered or planned; project these transcript item kinds too rather than silently skipping them.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/commands/handoff/handoff.ts, line 23:
<comment>Fork handoff drops rendered reasoning and plans, so target harness lacks work already considered or planned; project these transcript item kinds too rather than silently skipping them.</comment>
<file context>
@@ -0,0 +1,38 @@
+ lines.push(`User: ${text}`);
+ } else if (item.kind === "agent_message") {
+ lines.push(`Assistant: ${item.text}`);
+ } else if (item.kind === "tool_call") {
+ lines.push(`[tool] ${item.toolKind} ${item.title} (${item.status})`);
+ }
</file context>
| if (isChatV3Enabled) { | ||
| store.getState().addTab({ | ||
| panes: [ | ||
| { kind: "chat-v3", data: { sessionId: null } as ChatV3PaneData }, |
There was a problem hiding this comment.
P3: Keep NEW_CHAT on the existing addChatV3Tab opener rather than duplicating its tab construction. Menu and hotkey Chat V3 creation can otherwise drift when that opener gains required setup.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/useWorkspaceHotkeys/useWorkspaceHotkeys.ts, line 74:
<comment>Keep `NEW_CHAT` on the existing `addChatV3Tab` opener rather than duplicating its tab construction. Menu and hotkey Chat V3 creation can otherwise drift when that opener gains required setup.</comment>
<file context>
@@ -56,13 +59,23 @@ export function useWorkspaceHotkeys({
+ if (isChatV3Enabled) {
+ store.getState().addTab({
+ panes: [
+ { kind: "chat-v3", data: { sessionId: null } as ChatV3PaneData },
+ ],
+ });
</file context>
| )} | ||
| {session?.harness && onHarnessSelect && ( | ||
| <div className="flex items-center gap-1"> | ||
| {HARNESSES.map((candidate) => { |
There was a problem hiding this comment.
P3: The harness picker added here (HARNESSES.map -> Button with variant={selected ? "secondary" : "ghost"}) is a near-exact copy of the same picker already built in NewSessionView.tsx. Per the team's guidance to avoid duplicating business logic, extract a shared HarnessPicker component (taking value, onSelect, and the selected-value logic) and use it in both SessionHeader and NewSessionView so future harness additions/UI changes stay consistent in one place.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx, line 51:
<comment>The harness picker added here (HARNESSES.map -> Button with `variant={selected ? "secondary" : "ghost"}`) is a near-exact copy of the same picker already built in NewSessionView.tsx. Per the team's guidance to avoid duplicating business logic, extract a shared HarnessPicker component (taking `value`, `onSelect`, and the selected-value logic) and use it in both SessionHeader and NewSessionView so future harness additions/UI changes stay consistent in one place.</comment>
<file context>
@@ -23,23 +25,45 @@ const CONNECTION_LABELS: Record<StreamStatus, string> = {
)}
+ {session?.harness && onHarnessSelect && (
+ <div className="flex items-center gap-1">
+ {HARNESSES.map((candidate) => {
+ const selected = candidate === (pendingHarness ?? session.harness);
+ return (
</file context>
| import { Button } from "@superset/ui/button"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import type { ReactNode } from "react"; | ||
| import { HARNESSES, type HarnessId } from "../NewSessionView"; |
There was a problem hiding this comment.
P3: HARNESSES and HarnessId are now imported into three different Chat V3 consumers from NewSessionView, a component file. Since this configuration is shared by multiple consumers, consider promoting it to a shared Chat V3 module instead of leaving it owned by a single component.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx, line 7:
<comment>HARNESSES and HarnessId are now imported into three different Chat V3 consumers from NewSessionView, a component file. Since this configuration is shared by multiple consumers, consider promoting it to a shared Chat V3 module instead of leaving it owned by a single component.</comment>
<file context>
@@ -1,8 +1,10 @@
+import { Button } from "@superset/ui/button";
import { cn } from "@superset/ui/utils";
import type { ReactNode } from "react";
+import { HARNESSES, type HarnessId } from "../NewSessionView";
const STATUS_LABELS: Record<SessionStatus, string> = {
</file context>
| {HARNESSES.map((candidate) => { | ||
| const selected = candidate === (pendingHarness ?? session.harness); | ||
| return ( | ||
| <Button |
There was a problem hiding this comment.
P3: The selected harness is only conveyed visually via the button variant. Add aria-pressed={selected} to each harness button so assistive technology can identify which harness is currently selected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatV3Pane/components/SessionHeader/SessionHeader.tsx, line 54:
<comment>The selected harness is only conveyed visually via the button variant. Add `aria-pressed={selected}` to each harness button so assistive technology can identify which harness is currently selected.</comment>
<file context>
@@ -23,23 +25,45 @@ const CONNECTION_LABELS: Record<StreamStatus, string> = {
+ {HARNESSES.map((candidate) => {
+ const selected = candidate === (pendingHarness ?? session.harness);
+ return (
+ <Button
+ className="h-6 px-2 font-mono text-xs"
+ key={candidate}
</file context>
| let text = lines.join("\n\n"); | ||
| const maxChars = options?.maxChars ?? MAX_CHARS; | ||
| if (text.length > maxChars) { | ||
| text = `[earlier conversation truncated]\n\n${text.slice(text.length - maxChars)}`; |
There was a problem hiding this comment.
P3: The truncation marker [earlier conversation truncated]\n\n is prepended after slicing exactly maxChars characters from the tail, so the final string exceeds maxChars by the marker's length. Reserve space for the marker before slicing so the output actually respects the configured limit.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/commands/handoff/handoff.ts, line 31:
<comment>The truncation marker `[earlier conversation truncated]\n\n` is prepended after slicing exactly `maxChars` characters from the tail, so the final string exceeds `maxChars` by the marker's length. Reserve space for the marker before slicing so the output actually respects the configured limit.</comment>
<file context>
@@ -0,0 +1,38 @@
+ let text = lines.join("\n\n");
+ const maxChars = options?.maxChars ?? MAX_CHARS;
+ if (text.length > maxChars) {
+ text = `[earlier conversation truncated]\n\n${text.slice(text.length - maxChars)}`;
+ }
+ return text;
</file context>
|
This PR has had no activity for 53 days and will close in 7 days unless there is new activity. If this contribution is still important or relevant, please leave a comment to keep it open. If it closes, you are welcome to reopen it or ask a maintainer to reopen it. Thank you for contributing! |
|
This PR was automatically closed due to inactivity to help keep the review queue manageable. This does not mean the contribution was rejected. If this contribution is still important or relevant, please reopen it or leave a comment asking a maintainer to reopen it. Thank you for contributing! |
Implements protocol §7 forkSession end to end, per the design ratified in plans/chat-harness-adapters.md §4b.
Runtime: forkSession creates a new session inheriting scope/cwd with forkedFromSessionId lineage (additive 0001 migration); the source journal projects to markdown (projectTranscriptForHandoff, tail-truncating at 30k chars) and rides as a <prior_conversation> preamble on the fork's first prompt only — composed above the adapters, which stay ignorant. Router resolves cwd from the source session's scope. 138 runtime tests green.
Pane: the harness chip is now a live picker — selecting the other harness arms the composer with a visible hint ("next message continues in codex — a new linked session seeded with this transcript"); send forks, routes the prompt through the existing first-prompt handoff, and follows to the new session. SessionPicker shows "forked from " lineage and moves + New session to the top; ⌘⇧T opens chat-v3 when the chat-v3 flag is on. 124 desktop v2-workspace tests green.
Honest-handoff semantics per design: the fork seeds the account of the conversation (rendered transcript), never the source model's working memory — no harness can read another's native store. Same primitive later powers edit-a-message and regenerate.
Known nit: on fork-send the source session's composer draft isn't cleared (you navigate away; the draft remains under the old session's key). IOU-ledger item.
https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h
Summary by cubic
Enable fork-on-send: switch harness mid-chat by forking a linked session that inherits scope/cwd and seeds only the next message with a tail‑truncated transcript. Updates the Chat V3 UI to pick a harness, show a hint, and auto-follow to the new session.
New Features
forkSessionto create a new session withforkedFromSessionId; projects the source transcript to markdown (30k char tail) and injects it as a<prior_conversation>preamble on the first prompt only; router resolvescwdfrom the source session; adapters stay unchanged.FEATURE_FLAGS.CHAT_V3is on.Migration
forked_from_session_idtochat_sessions_local(run DB migration 0001).Written for commit 3a605c8. Summary will update on new commits.
Summary by CodeRabbit