From e7fe60ce272dbb8dbf46de111f769f78ccdebeda Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:11:25 -0800 Subject: [PATCH] Offer forks on all completed copied replies --- .../use-mobile-native-chat-fork.test.tsx | 3 ++- .../native-chat-side-chat-fork-point.test.ts | 19 ++++++++++---- ...ructured-agent-session-launch-fork.test.ts | 26 +++++++++++++------ .../native-chat/native-chat-fork-offer.ts | 9 +++---- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/mobile/src/session/native-chat/use-mobile-native-chat-fork.test.tsx b/mobile/src/session/native-chat/use-mobile-native-chat-fork.test.tsx index 447a3a0c84a..3f27f2acd33 100644 --- a/mobile/src/session/native-chat/use-mobile-native-chat-fork.test.tsx +++ b/mobile/src/session/native-chat/use-mobile-native-chat-fork.test.tsx @@ -294,6 +294,7 @@ it('offers an inherited OpenCode tip after the child advances and submits its di }) await settle() expect(latest?.offerFor(copied)).toBe('reserved') + expect(latest?.offerFor(older)).toBe('reserved') expect(latest?.offerFor(own)).toBe('available') await act(async () => { renderer!.update( @@ -303,7 +304,7 @@ it('offers an inherited OpenCode tip after the child advances and submits its di ) }) expect(latest?.offerFor(copied)).toBe('available') - expect(latest?.offerFor(older)).toBe('reserved') + expect(latest?.offerFor(older)).toBe('available') await act(async () => { renderer!.update( createElement(ForkProbe, { diff --git a/src/renderer/src/components/native-chat/messages/actions/native-chat-side-chat-fork-point.test.ts b/src/renderer/src/components/native-chat/messages/actions/native-chat-side-chat-fork-point.test.ts index 768a1d31e81..50fe5836ab7 100644 --- a/src/renderer/src/components/native-chat/messages/actions/native-chat-side-chat-fork-point.test.ts +++ b/src/renderer/src/components/native-chat/messages/actions/native-chat-side-chat-fork-point.test.ts @@ -144,11 +144,14 @@ describe('the side chat fork point the transcript finds while laying out', () => }) }) -it('offers only the copied fork-point tip while a later child response is running', () => { +it('offers inherited ancestor replies in a fork of a fork while the child is running', () => { const { input, latestTurnKey } = conversation( [ { ask: 'older-user', replies: [row('legacy:opencode:source:reply-0', 'assistant', 1)] }, - { ask: 'inherited-user', replies: [row('legacy:opencode:source:reply-1', 'assistant', 3)] }, + { + ask: 'inherited-user', + replies: [row('legacy:opencode:parent-fork:reply-1', 'assistant', 3)] + }, { ask: 'own-user', replies: [row('legacy:opencode:child:reply-2', 'assistant', 6)] } ], true @@ -164,7 +167,7 @@ it('offers only the copied fork-point tip while a later child response is runnin } }, { - itemId: 'legacy:opencode:source:reply-1', + itemId: 'legacy:opencode:parent-fork:reply-1', sequence: 3, body: { kind: 'message', role: 'assistant', blocks: [{ type: 'text', text: 'copied' }] } }, @@ -194,7 +197,13 @@ it('offers only the copied fork-point tip while a later child response is runnin turnWorking: false, inLatestTurn: false } - expect(nativeChatRowOffersFork(olderRow, chat)).toBe(false) + expect(nativeChatRowOffersFork(olderRow, chat)).toBe(true) + expect( + nativeChatRowOffersFork(olderRow, { + ...chat, + support: { kind: 'known', fork: 'tip' } + }) + ).toBe(false) // Checkpoint providers still offer earlier inherited replies without original-tip support. expect( nativeChatRowOffersFork(olderRow, { @@ -210,7 +219,7 @@ it('offers only the copied fork-point tip while a later child response is runnin ).toEqual({ kind: 'reply-running' }) expect( buildNativeChatTranscript({ ...input, forkOffer: { chat, latestTurnKey } }).forkPoint - ).toEqual({ kind: 'ready', throughItemId: 'legacy:opencode:source:reply-1' }) + ).toEqual({ kind: 'ready', throughItemId: 'legacy:opencode:parent-fork:reply-1' }) expect( buildNativeChatTranscript({ ...input, diff --git a/src/renderer/src/lib/agent-session/launch/structured-agent-session-launch-fork.test.ts b/src/renderer/src/lib/agent-session/launch/structured-agent-session-launch-fork.test.ts index 7e605c92189..d4b06325f99 100644 --- a/src/renderer/src/lib/agent-session/launch/structured-agent-session-launch-fork.test.ts +++ b/src/renderer/src/lib/agent-session/launch/structured-agent-session-launch-fork.test.ts @@ -325,7 +325,7 @@ it('reconciles a lost create first and retains uncertainty when a later proof ca }) }) -it('rederives a restored tip fork requirement from the child before resubmitting', async () => { +it('rederives a restored ancestor fork requirement from the child before resubmitting', async () => { const call = await remoteForkTransport() const prior = inheritedIntent() const restored = restoreStructuredAgentSessionLaunchIntent({ @@ -359,18 +359,28 @@ it('rederives a restored tip fork requirement from the child before resubmitting body: { kind: 'message', role: 'assistant', blocks: [] } }, { - itemId: 'orca:forked-from', + itemId: 'parent-fork-u2', sequence: 3, - body: { kind: 'status', presentation: 'forked-from', text: 'Forked from source' } - }, - { - itemId: 'child-u2', - sequence: 4, body: { kind: 'message', role: 'user', blocks: [] } }, { - itemId: 'legacy:opencode:child:reply-2', + itemId: 'legacy:opencode:parent-fork:reply-2', + sequence: 4, + body: { kind: 'message', role: 'assistant', blocks: [] } + }, + { + itemId: 'orca:forked-from', sequence: 5, + body: { kind: 'status', presentation: 'forked-from', text: 'Forked from source' } + }, + { + itemId: 'child-u3', + sequence: 6, + body: { kind: 'message', role: 'user', blocks: [] } + }, + { + itemId: 'legacy:opencode:child:reply-3', + sequence: 7, body: { kind: 'message', role: 'assistant', blocks: [] } } ] diff --git a/src/shared/native-chat/native-chat-fork-offer.ts b/src/shared/native-chat/native-chat-fork-offer.ts index 7c08130ea1a..7cd0f25f753 100644 --- a/src/shared/native-chat/native-chat-fork-offer.ts +++ b/src/shared/native-chat/native-chat-fork-offer.ts @@ -48,15 +48,13 @@ export function nativeChatForkInventory( items: readonly Pick[] ): { forkableItemIds: ReadonlySet; inheritedThroughSequence: number } { const forkableItemIds = new Set() - // The inherited tip is the last root response before the divider, not every copied response. let inheritedThroughSequence = 0 - let lastRootReplySequence = 0 for (const item of items) { if ( item.body.kind === 'status' && item.body.presentation === AGENT_SESSION_FORKED_FROM_PRESENTATION ) { - inheritedThroughSequence = lastRootReplySequence + inheritedThroughSequence = item.sequence } if ( item.body.kind === 'message' && @@ -64,7 +62,6 @@ export function nativeChatForkInventory( isRootAgentJournalItem(item) ) { forkableItemIds.add(item.itemId) - lastRootReplySequence = item.sequence } } return { forkableItemIds, inheritedThroughSequence } @@ -124,11 +121,11 @@ export function nativeChatRowOffersFork( (chat.support.kind === 'unknown' || chat.support.fork === 'checkpoint' || row.inLatestTurn || - (chat.support.inheritedOriginal === true && sequence === chat.inheritedThroughSequence)) + (chat.support.inheritedOriginal === true && sequence <= (chat.inheritedThroughSequence ?? 0))) ) } -/** Only a nonlatest inherited tip needs the host's original-resolution extension. */ +/** Nonlatest copied replies of tip-only agents need the host's original-resolution extension. */ export function nativeChatForkRequiresInheritedOriginal( items: readonly AgentJournalRenderItem[], fork: 'tip' | 'checkpoint',