diff --git a/src/web-ui/src/flow_chat/components/ChatInput.tsx b/src/web-ui/src/flow_chat/components/ChatInput.tsx index 1cfa42fd54..4b12facab5 100644 --- a/src/web-ui/src/flow_chat/components/ChatInput.tsx +++ b/src/web-ui/src/flow_chat/components/ChatInput.tsx @@ -244,7 +244,7 @@ import type { SessionPermissionMode } from '@/infrastructure/api/service-api/Age import { isSessionInUseError } from '@/infrastructure/api/errors/TauriCommandError'; import { isPeerDeviceModeActive } from '@/infrastructure/peer-device/peerModeFlag'; import { usePeerDeviceModeOptional } from '@/infrastructure/peer-device/peerDeviceContextState'; -import { isBtwSessionDraft } from '../utils/modelSelectionTarget'; +import { isBtwParentBackedSession, isBtwSessionDraft } from '../utils/modelSelectionTarget'; import { hasSessionStarted, isSessionBindingLocked } from '../utils/sessionLifecycle'; import { canTreatMissingPermissionModeAsDefault, @@ -724,6 +724,7 @@ export const ChatInput: React.FC = ({ const hasEffectiveTargetSession = effectiveTargetSession !== undefined; const peer = usePeerDeviceModeOptional(); const isBtwDraftTarget = isBtwSessionDraft(effectiveTargetSession); + const isBtwParentBackedTarget = isBtwParentBackedSession(effectiveTargetSession); const btwDraftSettingsInherited = isBtwDraftTarget && Boolean(peer?.peerMode.active) && (effectiveTargetSession?.config.modelPoolId ? peer?.currentPeerCapabilities?.btwModelPoolSelectionV1 !== true @@ -2613,6 +2614,7 @@ export const ChatInput: React.FC = ({ void (async () => { try { const permissionSessionId = isBtwDraftTarget + || isBtwParentBackedTarget ? effectiveTargetSession?.parentSessionId : effectiveTargetSessionId; if (!permissionSessionId) return; const response = await readComposerPermissionMode({ @@ -2692,6 +2694,7 @@ export const ChatInput: React.FC = ({ effectiveTargetSession?.externalHistory, effectiveTargetSession?.externalContinuationPermissionMode, isBtwDraftTarget, + isBtwParentBackedTarget, isAcpTargetSession, t, hasEffectiveTargetSession, diff --git a/src/web-ui/src/flow_chat/utils/modelSelectionTarget.test.ts b/src/web-ui/src/flow_chat/utils/modelSelectionTarget.test.ts new file mode 100644 index 0000000000..013c97cea7 --- /dev/null +++ b/src/web-ui/src/flow_chat/utils/modelSelectionTarget.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from 'vitest'; +import { isBtwParentBackedSession, isBtwSessionDraft } from './modelSelectionTarget'; + +describe('BTW session target classification', () => { + it('keeps a transient BTW child parent-backed after a provisional turn exists', () => { + const child = { + sessionKind: 'btw', + parentSessionId: 'parent-1', + isTransient: true, + isHistorical: false, + dialogTurns: [{ id: 'provisional-turn' }], + }; + + expect(isBtwSessionDraft(child)).toBe(false); + expect(isBtwParentBackedSession(child)).toBe(true); + }); + + it.each([ + ['a historical BTW child', { sessionKind: 'btw', parentSessionId: 'parent-1', isTransient: true, isHistorical: true }], + ['a durable child', { sessionKind: 'btw', parentSessionId: 'parent-1', isTransient: false, isHistorical: false }], + ['a BTW child without a parent', { sessionKind: 'btw', isTransient: true, isHistorical: false }], + ])('does not mark %s as parent-backed', (_label, session) => { + expect(isBtwParentBackedSession(session)).toBe(false); + }); +}); diff --git a/src/web-ui/src/flow_chat/utils/modelSelectionTarget.ts b/src/web-ui/src/flow_chat/utils/modelSelectionTarget.ts index ba2d2a705e..ed3a2db36b 100644 --- a/src/web-ui/src/flow_chat/utils/modelSelectionTarget.ts +++ b/src/web-ui/src/flow_chat/utils/modelSelectionTarget.ts @@ -3,6 +3,7 @@ export type SessionModelSelectionTarget = { isTransient?: boolean; agentBackedTransient?: boolean; sessionKind?: string; + parentSessionId?: string; isHistorical?: boolean; lastSubmittedMode?: string; dialogTurns?: readonly unknown[]; @@ -14,6 +15,14 @@ export function isBtwSessionDraft(session: SessionModelSelectionTarget | undefin && !session.lastSubmittedMode && session.dialogTurns?.length === 0); } +/** Temporary BTW children execute through their parent until they are saved as a fork. */ +export function isBtwParentBackedSession(session: SessionModelSelectionTarget | undefined): boolean { + return Boolean(session?.sessionKind === 'btw' + && session.isTransient === true + && !session.isHistorical + && session.parentSessionId); +} + /** Whether the visible selector has a real runtime session to update. */ export function shouldSyncSessionModelSelection( session: T | undefined,