fix(native-chat): /fork during a reply forks through the newest finished response (#42215)

* fix(native-chat): say /fork is refused while the agent replies, and to run it again

The old notice read as a promise to fork later. Like the common pattern, a running turn is not forkable and nothing is deferred, so the copy now names the agent and tells the user to run /fork again.

* chore(fixtures): show the /fork refusal notice at a narrow composer width

* Revert "chore(fixtures): show the /fork refusal notice at a narrow composer width"

This reverts commit 4ae7756dfd.

* fix(native-chat): /fork during a reply forks through the newest finished response

Like /btw and the common pattern for a fork that names no response, a running reply no longer refuses /fork when a finished response exists; only a first reply or an agent that forks only its latest turn still refuses, with the retry wording.
This commit is contained in:
Brennan Benson
2026-11-13 19:43:31 -08:00
committed by GitHub
parent cdf1f8f272
commit 14e0ef51d9
14 changed files with 97 additions and 23 deletions
@@ -0,0 +1,48 @@
// @vitest-environment happy-dom
import { act, renderHook } from '@testing-library/react'
import { expect, it, vi } from 'vitest'
import { useNativeChatSideChat } from '../../messages/actions/use-native-chat-side-chat'
import type { NativeChatPaneFork } from '../../messages/actions/use-native-chat-fork'
import type { NativeChatSideChatForkPoint } from '../../messages/actions/native-chat-side-chat-fork-point'
import { nativeChatForkCommand } from './use-native-chat-structured-composer-transport'
function paneFork(ids: string[]): NativeChatPaneFork {
const rowAction = {
support: { kind: 'known', fork: 'checkpoint' },
pendingItemId: null,
request: vi.fn()
} as const
return {
...rowAction,
contextFloorSequence: 0,
forkableItemIds: new Set(ids),
rowAction,
forkLatest: vi.fn(() => 'started' as const)
}
}
function runForkWhileReplying(fork: NativeChatPaneFork, point: NativeChatSideChatForkPoint) {
const { result } = renderHook(() => useNativeChatSideChat(fork))
act(() => result.current?.reportForkPoint(point))
return nativeChatForkCommand({ fork, sideChat: result.current }, true, 'codex')?.run()
}
it('forks a replying chat through its newest finished response', () => {
const fork = paneFork(['reply-1', 'reply-2-streaming'])
const notice = runForkWhileReplying(fork, { kind: 'ready', throughItemId: 'reply-1' })
expect(notice).toBeNull()
expect(fork.request).toHaveBeenCalledWith('reply-1')
expect(fork.forkLatest).not.toHaveBeenCalled()
})
it('refuses without forking when the running reply is the only one', () => {
const fork = paneFork(['reply-1-streaming'])
const notice = runForkWhileReplying(fork, { kind: 'reply-running' })
expect(notice).toEqual(expect.any(String))
expect(fork.request).not.toHaveBeenCalled()
expect(fork.forkLatest).not.toHaveBeenCalled()
})
@@ -7,10 +7,7 @@ import type { NativeChatOptionPickerRequest } from '@/components/native-chat/ses
import type { NativeChatStructuredComposerTransport } from '@/components/native-chat/composer/submit/native-chat-structured-composer-transport'
import type { NativeChatStructuredViewProps } from '@/components/native-chat/native-chat-view-types'
import type { useStructuredAgentSession } from '@/components/native-chat/session/structured/use-structured-agent-session'
import type {
NativeChatPaneFork,
NativeChatPaneForks
} from '@/components/native-chat/messages/actions/use-native-chat-fork'
import type { NativeChatPaneForks } from '@/components/native-chat/messages/actions/use-native-chat-fork'
import type { AgentType } from '../../../../../../shared/agent-status/contracts/agent-status-types'
import type { AgentSessionThreadGoalChange } from '../../../../../../shared/agent-session/agent-session-thread-goal-wire'
import { translate } from '@/i18n/i18n'
@@ -36,9 +33,10 @@ function nativeChatSessionAttachmentNotReadyNotice(
)
}
function nativeChatForkCommand(
fork: NativeChatPaneFork | undefined,
isWorking: boolean
export function nativeChatForkCommand(
{ fork, sideChat }: NativeChatPaneForks,
isWorking: boolean,
agent: AgentType
): NativeChatStructuredComposerTransport['fork'] {
// Offered once the host and agent confirm they can fork, as the response action is enabled.
if (fork?.support.kind !== 'known') {
@@ -46,10 +44,21 @@ function nativeChatForkCommand(
}
return {
run: () => {
// Like `/btw`, a running reply forks through the newest finished one; refused, never deferred,
// where there is none (a first reply, or an agent that forks only its latest turn).
if (isWorking) {
const throughItemId = sideChat?.finishedForkItemId
if (throughItemId) {
if (fork.pendingItemId !== null) {
return translate('components.native-chat.fork.pending', 'Forking this chat…')
}
void fork.request(throughItemId)
return null
}
return translate(
'components.native-chat.fork.commandWorking',
'Wait for the response to finish, then fork.'
'Can’t fork while {{agent}} is replying. Run /fork again when it finishes.',
{ agent: structuredAgentLabel(agent) }
)
}
const outcome = fork.forkLatest()
@@ -120,7 +129,7 @@ export function useNativeChatStructuredComposerTransport(args: {
})
}
: undefined,
fork: nativeChatForkCommand(fork, controller.isWorking),
fork: nativeChatForkCommand({ fork, sideChat }, controller.isWorking, props.agent),
capturePresentation: controller.capturePresentation,
...(sideChat ? { sideChat } : {}),
send: (text, attachments, ...request) => {
@@ -14,6 +14,8 @@ import type { NativeChatForkSurface } from './use-native-chat-fork'
export type NativeChatSideChat = {
/** Why no side chat can start now. */
notReadyReason: string | null
/** The newest finished response a fork can copy through now; a running reply never is one. */
finishedForkItemId: string | null
/** Starts one; the reason when it can't start now, else whether it started (with a question:
* whether the question went out). */
open: (question: string) => Promise<{ refused: string } | { started: boolean }>
@@ -32,6 +34,11 @@ export function useNativeChatSideChat(
if (!fork) {
return undefined
}
// A rewind may have dropped the reported response before the list said so.
const finishedForkItemId =
point.kind === 'ready' && fork.forkableItemIds.has(point.throughItemId)
? point.throughItemId
: null
const start = (): { refused: string } | { throughItemId: string } => {
// Another fork from this chat is still opening.
if (fork.support.kind === 'unknown' || fork.pendingItemId !== null) {
@@ -42,14 +49,14 @@ export function useNativeChatSideChat(
)
}
}
// A rewind may have dropped the reported response before the list said so.
return point.kind === 'ready' && fork.forkableItemIds.has(point.throughItemId)
? { throughItemId: point.throughItemId }
return finishedForkItemId
? { throughItemId: finishedForkItemId }
: { refused: sideChatRefusal(point.kind === 'ready' ? { kind: 'no-reply' } : point, t) }
}
const now = start()
return {
notReadyReason: 'refused' in now ? now.refused : null,
finishedForkItemId,
reportForkPoint,
open: async (question) => {
const next = start()
+2 -1
View File
@@ -20221,7 +20221,8 @@
"unconfirmedDetail": "Der Chat wurde möglicherweise dennoch geöffnet. Prüfe den Sitzungsverlauf, bevor du erneut abzweigst.",
"failed": "{{agent}} konnte diesen Chat nicht abzweigen",
"hostUnsupported": "Auf diesem Host läuft eine ältere Orca-Version. Aktualisiere Orca auf dem Host und versuche es erneut.",
"failedDetail": "Dein Chat ist unverändert. Versuche es erneut."
"failedDetail": "Dein Chat ist unverändert. Versuche es erneut.",
"commandWorking": "Abzweigen ist nicht möglich, während {{agent}} antwortet. Führe /fork erneut aus, wenn die Antwort fertig ist."
},
"cardKindHidden": {
"description": "Das kannst du jederzeit hier ändern:",
+1 -1
View File
@@ -21532,7 +21532,7 @@
"hostUnsupported": "This host runs an older Orca. Update Orca on the host, then try again.",
"failedDetail": "Your chat is unchanged. Try again.",
"commandDescription": "Fork this chat from its latest response",
"commandWorking": "Wait for the response to finish, then fork.",
"commandWorking": "Can’t fork while {{agent}} is replying. Run /fork again when it finishes.",
"commandNothing": "There’s no response to fork yet.",
"commandTakesNoText": "Send /fork on its own, then write in the new chat."
},
+2 -1
View File
@@ -20018,7 +20018,8 @@
"unconfirmedDetail": "Es posible que se haya abierto. Revisa el historial de sesiones antes de volver a intentarlo.",
"failed": "{{agent}} no pudo crear una rama de este chat",
"hostUnsupported": "Este host ejecuta una versión anterior de Orca. Actualiza Orca en el host y vuelve a intentarlo.",
"failedDetail": "Tu chat no ha cambiado. Inténtalo de nuevo."
"failedDetail": "Tu chat no ha cambiado. Inténtalo de nuevo.",
"commandWorking": "No se puede crear una rama mientras {{agent}} responde. Vuelve a ejecutar /fork cuando termine."
},
"cardKindHidden": {
"description": "Puedes cambiar esto en cualquier momento en",
+2 -1
View File
@@ -20291,7 +20291,8 @@
"unconfirmedDetail": "La conversation s’est peut-être ouverte malgré tout. Consultez l’historique des sessions avant de réessayer.",
"failed": "{{agent}} n’a pas pu créer de branche de cette conversation",
"hostUnsupported": "Cet hôte utilise une ancienne version d’Orca. Mettez Orca à jour sur l’hôte, puis réessayez.",
"failedDetail": "Votre conversation est inchangée. Réessayez."
"failedDetail": "Votre conversation est inchangée. Réessayez.",
"commandWorking": "Impossible de créer une branche pendant que {{agent}} répond. Relancez /fork quand la réponse est terminée."
},
"cardKindHidden": {
"description": "Vous pouvez modifier cela à tout moment dans",
+2 -1
View File
@@ -19511,7 +19511,8 @@
"unconfirmedDetail": "チャットが開いている可能性があります。再度分岐する前にセッション履歴を確認してください。",
"failed": "{{agent}} はこのチャットを分岐できませんでした",
"hostUnsupported": "このホストでは古いバージョンの Orca が実行されています。ホストの Orca を更新して再試行してください。",
"failedDetail": "チャットは変更されていません。もう一度お試しください。"
"failedDetail": "チャットは変更されていません。もう一度お試しください。",
"commandWorking": "{{agent}} の応答中は分岐できません。応答が終わったら、もう一度 /fork を実行してください。"
},
"cardKindHidden": {
"description": "いつでも次の場所で変更できます:",
+2 -1
View File
@@ -19508,7 +19508,8 @@
"unconfirmedDetail": "채팅이 열렸을 수 있습니다. 다시 분기하기 전에 세션 기록을 확인하세요.",
"failed": "{{agent}}이(가) 이 채팅을 분기하지 못했습니다",
"hostUnsupported": "이 호스트에서 이전 버전의 Orca가 실행 중입니다. 호스트의 Orca를 업데이트하고 다시 시도하세요.",
"failedDetail": "채팅은 변경되지 않았습니다. 다시 시도하세요."
"failedDetail": "채팅은 변경되지 않았습니다. 다시 시도하세요.",
"commandWorking": "{{agent}}이(가) 응답하는 동안에는 분기할 수 없습니다. 응답이 끝나면 /fork를 다시 실행하세요."
},
"cardKindHidden": {
"description": "다음에서 언제든 변경할 수 있습니다:",
+2 -1
View File
@@ -21673,7 +21673,8 @@
"unconfirmed": "{{agent}} não conseguiu confirmar a ramificação",
"unconfirmedDetail": "Ela pode ter sido aberta. Confira o histórico de sessões antes de tentar novamente.",
"failed": "{{agent}} não conseguiu ramificar este chat",
"failedDetail": "Seu chat não foi alterado. Tente novamente."
"failedDetail": "Seu chat não foi alterado. Tente novamente.",
"commandWorking": "Não é possível criar uma ramificação enquanto {{agent}} responde. Execute /fork novamente quando terminar."
},
"cardKindHidden": {
"description": "Você pode alterar isso a qualquer momento em",
+2 -1
View File
@@ -20877,7 +20877,8 @@
"unconfirmed": "{{agent}} не удалось подтвердить создание ответвления",
"unconfirmedDetail": "Возможно, оно всё же открылось. Проверьте историю сеансов, прежде чем повторить попытку.",
"failed": "{{agent}} не удалось создать ответвление этого чата",
"failedDetail": "Ваш чат не изменился. Попробуйте ещё раз."
"failedDetail": "Ваш чат не изменился. Попробуйте ещё раз.",
"commandWorking": "Нельзя создать ответвление, пока {{agent}} отвечает. Запустите /fork снова, когда ответ завершится."
},
"cardKindHidden": {
"description": "Вы можете изменить это в любое время в разделе",
+2 -1
View File
@@ -20196,7 +20196,8 @@
"unconfirmed": "{{agent}} çatallamayı doğrulayamadı",
"unconfirmedDetail": "Yine de açılmış olabilir. Yeniden çatallamadan önce Oturum Geçmişini kontrol edin.",
"failed": "{{agent}} bu sohbeti çatallayamadı",
"failedDetail": "Sohbetiniz değişmedi. Tekrar deneyin."
"failedDetail": "Sohbetiniz değişmedi. Tekrar deneyin.",
"commandWorking": "{{agent}} yanıt verirken çatallanamaz. Yanıt bittiğinde /fork komutunu yeniden çalıştırın."
},
"cardKindHidden": {
"description": "Bunu istediğiniz zaman şuradan değiştirebilirsiniz:",
+2 -1
View File
@@ -19911,7 +19911,8 @@
"unconfirmedDetail": "它可能已經開啟。請先檢查工作階段歷史記錄,再建立分支。",
"failed": "{{agent}} 無法從此聊天建立分支",
"hostUnsupported": "此主機執行的是舊版 Orca。請更新主機上的 Orca 後再試一次。",
"failedDetail": "聊天未變更。請再試一次。"
"failedDetail": "聊天未變更。請再試一次。",
"commandWorking": "{{agent}} 回覆期間無法建立分支。回覆結束後,請再次執行 /fork。"
},
"cardKindHidden": {
"description": "你可以隨時在此處變更",
+2 -1
View File
@@ -19773,7 +19773,8 @@
"unconfirmedDetail": "它可能已经打开。请先检查会话历史,再创建分支。",
"failed": "{{agent}} 无法从此聊天创建分支",
"hostUnsupported": "此主机运行的是旧版 Orca。请更新主机上的 Orca 后重试。",
"failedDetail": "聊天未发生更改。请重试。"
"failedDetail": "聊天未发生更改。请重试。",
"commandWorking": "{{agent}} 回复期间无法创建分支。回复结束后,请再次运行 /fork。"
},
"cardKindHidden": {
"description": "你可以随时在此处更改",