mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
fix(claude): reflect fallback without changing saved models (#37958)
* fix(claude): reflect model fallback in chat and composer * test(claude): reproduce fallback display before and after * fix(i18n): ship the model fallback notice in the runtime catalog * fix(mobile): ship the model fallback notice in the runtime catalog * fix(claude): accept unnamed init models in response observations * fix(claude): keep fallback observations display-only Response model metadata must not satisfy delayed input evidence or change saved launch preferences. * test(claude): type fallback regression fixtures * test(claude): expect init model display reports --------- Co-authored-by: Vyacheslav Scherbinin <gentslava@mail.ru>
This commit is contained in:
co-authored by
Vyacheslav Scherbinin
parent
612909ada1
commit
ac6fa4ef46
@@ -56,6 +56,9 @@
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
"notice": {
|
||||
"modelFallback": "Claude switched models: {{from}} → {{to}}."
|
||||
},
|
||||
"subagentGroup": {
|
||||
"ran_one": "Ran {{count}} subagent",
|
||||
"ran_other": "Ran {{count}} subagents",
|
||||
|
||||
@@ -2901,7 +2901,8 @@
|
||||
"plan": "Plan",
|
||||
"permissionDenied": "{{agent}} denied permission. View details.",
|
||||
"safetyReview": "{{agent}} reported a safety review warning. View details.",
|
||||
"truncatedResponse": "Provider response truncated (original size: {{bytes}} bytes)."
|
||||
"truncatedResponse": "Provider response truncated (original size: {{bytes}} bytes).",
|
||||
"modelFallback": "Claude switched models: {{from}} → {{to}}."
|
||||
},
|
||||
"nativeChatProse": {
|
||||
"attachedImage": "Attached image",
|
||||
|
||||
@@ -291,7 +291,8 @@
|
||||
"stoppedManually": "Остановлено вручную",
|
||||
"permissionDenied": "{{agent}} отказал в разрешении. Подробнее.",
|
||||
"safetyReview": "{{agent}} сообщил о предупреждении проверки безопасности. Подробнее.",
|
||||
"truncatedResponse": "Ответ поставщика обрезан (исходный размер: {{bytes}} байт)."
|
||||
"truncatedResponse": "Ответ поставщика обрезан (исходный размер: {{bytes}} байт).",
|
||||
"modelFallback": "Claude переключил модель: {{from}} → {{to}}."
|
||||
},
|
||||
"orcaStop": {
|
||||
"canContinue": "Вы можете продолжить этот разговор.",
|
||||
|
||||
@@ -339,6 +339,24 @@ describe('MobileNativeChatSessionOptionPickers', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('shows the current fallback model without making a model write', () => {
|
||||
const descriptor: SessionOptionDescriptor = {
|
||||
...MODEL_DESCRIPTOR,
|
||||
transport: 'agent-session',
|
||||
valueSource: 'applied',
|
||||
reportedModel: 'claude-opus-4-8',
|
||||
kind: {
|
||||
type: 'select',
|
||||
currentValue: 'claude-opus-5-5',
|
||||
choices: [{ value: 'claude-opus-5-5', label: 'Opus 5.5' }]
|
||||
}
|
||||
}
|
||||
mount([descriptor], true)
|
||||
expect(pill('Model').props.accessibilityLabel).toBe('Model, Opus 4.8')
|
||||
expect(descriptor.kind.currentValue).toBe('claude-opus-5-5')
|
||||
expect(setOption).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the model sheet and applies a picked model', async () => {
|
||||
mount([MODEL_DESCRIPTOR, EFFORT_DESCRIPTOR])
|
||||
await act(async () => pill('Model').props.onPress())
|
||||
|
||||
+29
@@ -125,6 +125,35 @@ describe('MobileNativeChatMessage status notices', () => {
|
||||
)[0]!
|
||||
}
|
||||
|
||||
it.each([
|
||||
['en', 'Claude switched models: Claude Opus 5.5 → Claude Opus 4.8.'],
|
||||
['ru', 'Claude переключил модель: Claude Opus 5.5 → Claude Opus 4.8.']
|
||||
] as const)(
|
||||
'renders a saved fallback notice in %s without a raw JSON card',
|
||||
async (locale, words) => {
|
||||
await activateMobileUiLocale(locale)
|
||||
const head = JSON.stringify({
|
||||
type: 'fallback',
|
||||
from: { model: 'claude-opus-5-5' },
|
||||
to: { model: 'claude-opus-4-8' }
|
||||
})
|
||||
const text = renderNotice(
|
||||
{
|
||||
kind: 'status',
|
||||
text: 'Claude sent content Orca cannot display yet',
|
||||
providerFrame: {
|
||||
provider: 'claude',
|
||||
kind: 'message:assistant:content:fallback',
|
||||
payload: { head, byteLength: head.length, digest: 'fixture', truncated: false }
|
||||
}
|
||||
},
|
||||
{ hostName: null }
|
||||
)
|
||||
expect(text.props.children).toBe(words)
|
||||
expect(renderer!.root.findAll((node) => String(node.type) === 'Pressable')).toHaveLength(0)
|
||||
}
|
||||
)
|
||||
|
||||
it('names the Orca host an Orca stop came from, in desktop words', () => {
|
||||
const text = renderNotice(
|
||||
{
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
CLAUDE_MODEL_FALLBACK_COPY,
|
||||
claudeModelFallbackLabels
|
||||
} from '../../../../../src/shared/native-chat/claude-model-fallback'
|
||||
import { useContext, useId, useState } from 'react'
|
||||
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
||||
import { AlertCircle, AlertTriangle, ChevronRight, Info } from 'lucide-react-native'
|
||||
@@ -232,6 +236,16 @@ export function MobileNativeChatNoticeRow({
|
||||
{nativeChatHostStatusCopy(t)[look.presentation]}
|
||||
</Text>
|
||||
)
|
||||
case 'model-fallback':
|
||||
return (
|
||||
<Text selectable={INLINE_TEXT_SELECTION} style={aside}>
|
||||
{t(
|
||||
'chat.notice.modelFallback',
|
||||
CLAUDE_MODEL_FALLBACK_COPY,
|
||||
claudeModelFallbackLabels(look)
|
||||
)}
|
||||
</Text>
|
||||
)
|
||||
case 'plan':
|
||||
return (
|
||||
<View style={styles.card}>
|
||||
|
||||
@@ -10,10 +10,8 @@ import { BoundedMap } from '../../../src/shared/bounded-map'
|
||||
import type { RpcClient } from '../transport/rpc-client'
|
||||
import type { AgentSessionOptionCatalog } from '../../../src/shared/agent-session/options/agent-session-option-catalog-types'
|
||||
import { usesInstalledAgentModelCatalog } from '../../../src/shared/agent-session/options/agent-model-catalog-ownership'
|
||||
import {
|
||||
createStructuredAgentSessionOptionState,
|
||||
structuredAgentSessionReportsAtFence
|
||||
} from '../../../src/shared/agent-session/options/structured-agent-session-options'
|
||||
import { createStructuredAgentSessionOptionState } from '../../../src/shared/agent-session/options/structured-agent-session-options'
|
||||
import { structuredAgentSessionReportsAtFence } from '../../../src/shared/agent-session/options/structured-agent-session-runtime-reports'
|
||||
|
||||
// Matches the transcripts this view retains per chat.
|
||||
const MAX_RETAINED_CHAT_READERS = 32
|
||||
|
||||
@@ -65,7 +65,10 @@ export function claudeContextWindowHint(model: string): number | null {
|
||||
|
||||
export type ClaudeMainThreadModel = { initModel: string | null; responseModel: string | null }
|
||||
|
||||
function currentInitModel({ initModel, responseModel }: ClaudeMainThreadModel): string | null {
|
||||
export function claudeMatchingInitModel({
|
||||
initModel,
|
||||
responseModel
|
||||
}: ClaudeMainThreadModel): string | null {
|
||||
if (initModel === null || responseModel === null) {
|
||||
return initModel
|
||||
}
|
||||
@@ -93,7 +96,7 @@ export function claudeContextWindowFromResult(
|
||||
const bases = [key, ...(canonicalModel ? [canonicalModel] : [])].map(contextBaseModelId)
|
||||
return [{ key, window, bases }]
|
||||
})
|
||||
const initModel = currentInitModel(main)
|
||||
const initModel = claudeMatchingInitModel(main)
|
||||
const names = [main.responseModel ?? initModel].flatMap((model) =>
|
||||
model ? [contextBaseModelId(model)] : []
|
||||
)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { claudeRecord, claudeText } from './journal/claude-structured-item-translation'
|
||||
import { claudeMatchingInitModel } from '../claude-context-usage'
|
||||
import { isRootClaudeFrame } from '../claude-turn-opening'
|
||||
import { MAX_CONTEXT_MODEL_ID_CHARS } from '../../../shared/agent-session/agent-session-context-usage'
|
||||
import type { ClaudeSession } from './claude-structured-session-state'
|
||||
|
||||
/** Fast routing reports precede this input and cannot vouch for its execution. */
|
||||
@@ -19,6 +23,7 @@ export function beginClaudeOptionMutation(session: ClaudeSession, key: string):
|
||||
const sequence = session.optionMutationSequence
|
||||
if (key === 'model') {
|
||||
delete session.appliedOptions
|
||||
delete session.reportedOptions.reportedModel
|
||||
} else {
|
||||
if (session.reportedModelMutation === previous) {
|
||||
session.reportedModelMutation = sequence
|
||||
@@ -31,13 +36,74 @@ export function beginClaudeOptionMutation(session: ClaudeSession, key: string):
|
||||
return sequence
|
||||
}
|
||||
|
||||
/** An init names the model that runs; a control answer only acknowledges its input. */
|
||||
/** An init names execution; a control answer only acknowledges its input. */
|
||||
export function observeClaudeExecutionModel(session: ClaudeSession, model: string): boolean {
|
||||
const previous = claudeExecutionObservations(session).model
|
||||
const previousResponse = session.reportedOptions.reportedModel
|
||||
session.reportedOptions.reportedModel = model
|
||||
if (previous !== model) {
|
||||
delete session.appliedOptions
|
||||
}
|
||||
session.reportedOptions.model = model
|
||||
session.reportedModelMutation = session.optionMutationSequence
|
||||
return previous !== model
|
||||
return previous !== model || previousResponse !== model
|
||||
}
|
||||
|
||||
/** Main-thread response metadata names the model that answered, including provider fallback. */
|
||||
function readClaudeResponseModel(frame: Record<string, unknown>): string | null {
|
||||
if (!isRootClaudeFrame(frame)) {
|
||||
return null
|
||||
}
|
||||
const event = claudeRecord(frame.event)
|
||||
const message =
|
||||
frame.type === 'assistant'
|
||||
? claudeRecord(frame.message)
|
||||
: frame.type === 'stream_event' && event?.type === 'message_start'
|
||||
? claudeRecord(event.message)
|
||||
: null
|
||||
const model = message?.role === 'assistant' ? claudeText(message.model)?.trim() : null
|
||||
return model && model !== '<synthetic>' && model.length <= MAX_CONTEXT_MODEL_ID_CHARS
|
||||
? model
|
||||
: null
|
||||
}
|
||||
|
||||
function observeClaudeResponseModel(
|
||||
session: ClaudeSession,
|
||||
frame: Record<string, unknown>
|
||||
): boolean {
|
||||
const response = readClaudeResponseModel(frame)
|
||||
if (!response) {
|
||||
return false
|
||||
}
|
||||
const model =
|
||||
claudeMatchingInitModel({
|
||||
initModel:
|
||||
session.reportedModelMutation === session.optionMutationSequence
|
||||
? (session.reportedOptions.model ?? null)
|
||||
: null,
|
||||
responseModel: response
|
||||
}) ?? response
|
||||
if (model === session.reportedOptions.reportedModel) {
|
||||
return false
|
||||
}
|
||||
session.reportedOptions.reportedModel = model
|
||||
return true
|
||||
}
|
||||
|
||||
export function observeClaudeFrameModels(
|
||||
session: ClaudeSession | null,
|
||||
frame: Record<string, unknown>,
|
||||
initModel: string | null | undefined
|
||||
): Partial<ClaudeSession['reportedOptions']> | null {
|
||||
if (!session) {
|
||||
return null
|
||||
}
|
||||
const initChanged = initModel ? observeClaudeExecutionModel(session, initModel) : false
|
||||
const responseChanged = observeClaudeResponseModel(session, frame)
|
||||
return initChanged || responseChanged
|
||||
? {
|
||||
...(initChanged && initModel ? { model: initModel } : {}),
|
||||
reportedModel: session.reportedOptions.reportedModel
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import { acquired, claudeFrame, fakeClaude } from './claude-structured-session-test-support'
|
||||
import type { ClaudeStructuredSessionEvent } from './claude-structured-session-state'
|
||||
|
||||
it('publishes the main response model after fallback and restoration, ignoring child, foreign and synthetic frames', async () => {
|
||||
const claude = fakeClaude({ initModel: 'claude-opus-5-5' })
|
||||
const events: ClaudeStructuredSessionEvent[] = []
|
||||
const adapter = await acquired(claude, {}, events)
|
||||
const connection = claude.connections[0]!
|
||||
const read = () => adapter.readOptions({ sessionId: 'session-1', fence: 7 })
|
||||
try {
|
||||
claudeFrame(connection, { type: 'system', subtype: 'init', model: 'claude-opus-5-5' })
|
||||
expect((await read()).current.model).toBe('claude-opus-5-5')
|
||||
for (const patch of [
|
||||
{ parent_tool_use_id: 'child-tool' },
|
||||
{ session_id: 'another-session' },
|
||||
{ message: { role: 'assistant', model: '<synthetic>', content: [] } }
|
||||
]) {
|
||||
claudeFrame(connection, {
|
||||
type: 'assistant',
|
||||
uuid: 'ignore',
|
||||
message: { role: 'assistant', model: 'claude-opus-4-8', content: [] },
|
||||
...patch
|
||||
})
|
||||
expect((await read()).current.model).toBe('claude-opus-5-5')
|
||||
expect((await read()).current.reportedModel).toBe('claude-opus-5-5')
|
||||
}
|
||||
claudeFrame(connection, {
|
||||
type: 'assistant',
|
||||
uuid: 'fallback',
|
||||
message: {
|
||||
role: 'assistant',
|
||||
model: 'claude-opus-4-8',
|
||||
content: [
|
||||
{ type: 'fallback', from: { model: 'claude-opus-5-5' }, to: { model: 'claude-opus-4-8' } }
|
||||
]
|
||||
}
|
||||
})
|
||||
expect((await read()).current).toMatchObject({
|
||||
model: 'claude-opus-5-5',
|
||||
reportedModel: 'claude-opus-4-8',
|
||||
confirmed: expect.arrayContaining(['model'])
|
||||
})
|
||||
expect(events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: 'options-reported',
|
||||
reportedOptions: expect.objectContaining({ reportedModel: 'claude-opus-4-8' })
|
||||
})
|
||||
)
|
||||
claudeFrame(connection, { type: 'system', subtype: 'status', permissionMode: 'plan' })
|
||||
expect(events.findLast((event) => event.type === 'options-reported')).toMatchObject({
|
||||
reportedOptions: { reportedModel: 'claude-opus-4-8', reportedPermissionMode: 'plan' }
|
||||
})
|
||||
claudeFrame(connection, {
|
||||
type: 'stream_event',
|
||||
uuid: 'restored',
|
||||
event: { type: 'message_start', message: { role: 'assistant', model: 'claude-opus-5-5' } }
|
||||
})
|
||||
expect((await read()).current.reportedModel).toBe('claude-opus-5-5')
|
||||
claudeFrame(connection, { type: 'system', subtype: 'init', model: 'claude-opus-4-8' })
|
||||
expect((await read()).current).toMatchObject({
|
||||
model: 'claude-opus-4-8',
|
||||
reportedModel: 'claude-opus-4-8'
|
||||
})
|
||||
await adapter.setOption({ sessionId: 'session-1', fence: 7, key: 'model', value: 'sonnet' })
|
||||
expect((await read()).current.reportedModel).toBeUndefined()
|
||||
} finally {
|
||||
await adapter.closeAll()
|
||||
}
|
||||
})
|
||||
|
||||
it('retains the init context suffix when the response reports the same bare model', async () => {
|
||||
const claude = fakeClaude({ initModel: 'claude-opus-5-5[1m]' })
|
||||
const adapter = await acquired(claude)
|
||||
const connection = claude.connections[0]!
|
||||
try {
|
||||
claudeFrame(connection, { type: 'system', subtype: 'init', model: 'claude-opus-5-5[1m]' })
|
||||
claudeFrame(connection, {
|
||||
type: 'assistant',
|
||||
uuid: 'first-response',
|
||||
message: { role: 'assistant', model: 'claude-opus-5-5', content: [] }
|
||||
})
|
||||
expect(
|
||||
(await adapter.readOptions({ sessionId: 'session-1', fence: 7 })).current.reportedModel
|
||||
).toBe('claude-opus-5-5[1m]')
|
||||
await adapter.setOption({ sessionId: 'session-1', fence: 7, key: 'model', value: 'opus' })
|
||||
claudeFrame(connection, {
|
||||
type: 'assistant',
|
||||
uuid: 'after-context-pick',
|
||||
message: { role: 'assistant', model: 'claude-opus-5-5', content: [] }
|
||||
})
|
||||
expect(
|
||||
(await adapter.readOptions({ sessionId: 'session-1', fence: 7 })).current.reportedModel
|
||||
).toBe('claude-opus-5-5')
|
||||
} finally {
|
||||
await adapter.closeAll()
|
||||
}
|
||||
})
|
||||
@@ -16,7 +16,7 @@ import { claudeConfigDirEnvPatch } from '../claude-config-dir-pin'
|
||||
import { claudeProcessIdentity } from './claude-structured-owner-identity'
|
||||
import { ClaudePromptRegistry } from '../claude-prompt-registry'
|
||||
import { adoptClaudeStructuredSpawnOptions } from './launch/claude-structured-spawn-options'
|
||||
import { observeClaudeExecutionModel } from './claude-structured-execution-observations'
|
||||
import { observeClaudeFrameModels } from './claude-structured-execution-observations'
|
||||
import { observeClaudeFastModeFacts } from './launch/claude-structured-session-options'
|
||||
import {
|
||||
createClaudeSessionPublication,
|
||||
@@ -98,8 +98,7 @@ export async function acquireClaudeSession({
|
||||
}
|
||||
}
|
||||
const permissionChanged = observeClaudeReportedPermissionMode(observedOptions, message)
|
||||
const modelChanged =
|
||||
liveSession && init?.model ? observeClaudeExecutionModel(liveSession, init.model) : false
|
||||
const modelReport = observeClaudeFrameModels(liveSession, message, init?.model)
|
||||
if (init) {
|
||||
initProof.resolve(init)
|
||||
if (liveSession) {
|
||||
@@ -140,14 +139,15 @@ export async function acquireClaudeSession({
|
||||
}
|
||||
try {
|
||||
callbacks.deliver(attempt, sessionId, () => {
|
||||
if (liveSession && (modelChanged || permissionChanged)) {
|
||||
if (liveSession && (modelReport || permissionChanged)) {
|
||||
callbacks.emit(liveSession, input.events, {
|
||||
type: 'options-reported',
|
||||
sessionId,
|
||||
fence: liveSession.fence,
|
||||
acquisitionGeneration: liveSession.acquisitionGeneration,
|
||||
reportedOptions: {
|
||||
...(modelChanged && init?.model ? { model: init.model } : {}),
|
||||
...modelReport,
|
||||
reportedModel: liveSession.reportedOptions.reportedModel,
|
||||
reportedPermissionMode: observedOptions.reportedPermissionMode
|
||||
}
|
||||
})
|
||||
|
||||
@@ -258,6 +258,7 @@ describe('ClaudeStructuredSessionAdapter turns and controls', () => {
|
||||
expect(catalogListing).toBeUndefined()
|
||||
expect(options.current).toEqual({
|
||||
model: 'claude-sonnet-5',
|
||||
reportedModel: 'claude-sonnet-5',
|
||||
effort: 'high',
|
||||
reportedPermissionMode: undefined,
|
||||
confirmed: ['model', 'effort']
|
||||
@@ -293,6 +294,7 @@ describe('ClaudeStructuredSessionAdapter turns and controls', () => {
|
||||
])
|
||||
expect(result.current).toEqual({
|
||||
model: 'custom-model',
|
||||
reportedModel: 'custom-model',
|
||||
effort: 'high',
|
||||
reportedPermissionMode: undefined,
|
||||
confirmed: ['model', 'effort']
|
||||
|
||||
@@ -167,6 +167,7 @@ export type ClaudeSession = {
|
||||
replayContentFallbackBlocked: boolean
|
||||
options: Map<string, string>
|
||||
reportedOptions: {
|
||||
reportedModel?: string
|
||||
model?: string
|
||||
effort?: string
|
||||
fastMode?: boolean
|
||||
|
||||
@@ -77,6 +77,55 @@ describe('Claude provider fallback', () => {
|
||||
expect(items).toEqual([])
|
||||
})
|
||||
|
||||
it('journals the captured model fallback as a notice and continues the same turn', () => {
|
||||
const items: AgentJournalItemBody[] = []
|
||||
const translator = createClaudeJournalTranslator({
|
||||
sink: {
|
||||
appendItem: (_identity, body) => {
|
||||
items.push(body)
|
||||
},
|
||||
appendTombstone: vi.fn(),
|
||||
publish: vi.fn()
|
||||
}
|
||||
})
|
||||
translator.handle(
|
||||
message('assistant', 'fallback-1', [
|
||||
{ type: 'fallback', from: { model: 'claude-opus-5-5' }, to: { model: 'claude-opus-4-8' } }
|
||||
])
|
||||
)
|
||||
translator.handle(
|
||||
message('assistant', 'answer-1', [{ type: 'text', text: 'Continuing the answer.' }])
|
||||
)
|
||||
translator.handle({
|
||||
type: 'message',
|
||||
sessionId: 'orca-session',
|
||||
message: {
|
||||
type: 'result',
|
||||
subtype: 'success',
|
||||
session_id: 'provider-1',
|
||||
uuid: 'result-1',
|
||||
result: 'Continuing the answer.'
|
||||
}
|
||||
})
|
||||
|
||||
const notices = items.filter((body) => body.kind === 'status')
|
||||
expect(notices).toHaveLength(1)
|
||||
expect(notices[0]).toMatchObject({
|
||||
text: 'Claude switched models: Claude Opus 5.5 → Claude Opus 4.8.',
|
||||
tone: 'notice',
|
||||
presentation: 'turn-notice',
|
||||
providerFrame: { provider: 'claude', kind: 'message:assistant:content:fallback' }
|
||||
})
|
||||
expect(items).toContainEqual(
|
||||
expect.objectContaining({
|
||||
kind: 'message',
|
||||
role: 'assistant',
|
||||
blocks: [{ type: 'text', text: 'Continuing the answer.' }]
|
||||
})
|
||||
)
|
||||
expect(items).toContainEqual(expect.objectContaining({ kind: 'turn', state: 'completed' }))
|
||||
})
|
||||
|
||||
it('keeps provider-fallback rows distinct across acquisitions', async () => {
|
||||
const journal = await openAgentSessionJournal({
|
||||
identity: IDENTITY,
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import type { AgentJournalStatusItem } from '../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import {
|
||||
readClaudeModelFallback,
|
||||
claudeModelFallbackText
|
||||
} from '../../../../shared/native-chat/claude-model-fallback'
|
||||
import { AGENT_SESSION_TURN_NOTICE_PRESENTATION } from '../../../../shared/agent-session/journal/agent-session-turn-notice'
|
||||
import type {
|
||||
AgentJournalPlainStatusItem,
|
||||
AgentJournalStatusItem
|
||||
} from '../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import type { AgentJournalTurnScope } from '../../../../shared/agent-session/journal/agent-session-journal-turn-scope'
|
||||
import type { AgentSessionFailureRowWords } from '../../../../shared/agent-session/failures/agent-session-failure-words'
|
||||
import type { StructuredAgentSessionEventSink } from '../../../native-chat/agent-session-wire/structured-agent-session-event-sink'
|
||||
@@ -115,7 +123,11 @@ export function createClaudeProviderFrameFallback(
|
||||
append: (
|
||||
kind: string,
|
||||
payload: unknown,
|
||||
display?: string | null | (AgentSessionFailureRowWords & { tone: string }),
|
||||
display?:
|
||||
| string
|
||||
| null
|
||||
| Omit<AgentJournalPlainStatusItem, 'kind'>
|
||||
| (AgentSessionFailureRowWords & { tone: string }),
|
||||
/** Open a turn only if a row will be written. */
|
||||
beforeAppend?: () => void,
|
||||
options?: UnhandledProviderFrameJournalItemOptions,
|
||||
@@ -196,11 +208,18 @@ export function appendUnmodeledContent(
|
||||
let changed = false
|
||||
for (const part of envelope.content.filter((part) => !isModeledClaudeContent(part))) {
|
||||
const partType = claudeText(claudeRecord(part)?.type) ?? 'unknown'
|
||||
const modelFallback = envelope.role === 'assistant' ? readClaudeModelFallback(part) : null
|
||||
changed =
|
||||
fallback.append(
|
||||
`message:${envelope.role}:content:${partType}`,
|
||||
part,
|
||||
readableProviderFrameText(part) ?? CLAUDE_UNRENDERABLE_CONTENT_TEXT,
|
||||
modelFallback
|
||||
? {
|
||||
text: claudeModelFallbackText(modelFallback),
|
||||
tone: 'notice',
|
||||
presentation: AGENT_SESSION_TURN_NOTICE_PRESENTATION
|
||||
}
|
||||
: (readableProviderFrameText(part) ?? CLAUDE_UNRENDERABLE_CONTENT_TEXT),
|
||||
beforeAppend,
|
||||
undefined,
|
||||
stamp
|
||||
|
||||
@@ -198,6 +198,7 @@ export function claudeStructuredSessionOptionsFrom(
|
||||
...(changesLive ? {} : { effortFixed: true as const }),
|
||||
current: {
|
||||
model,
|
||||
reportedModel: session.reportedOptions.reportedModel,
|
||||
reportedPermissionMode: session.reportedOptions.reportedPermissionMode,
|
||||
...(effort ? { effort } : {}),
|
||||
...(fastMode !== undefined ? { fastMode } : {}),
|
||||
|
||||
+93
-62
@@ -2,6 +2,7 @@ import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
import { claudeProviderHandle } from '../../../shared/agent-session/lifecycle/agent-session-provider-handle-encoding'
|
||||
import { structuredAgentSessionHandingOver } from './structured-agent-session-handing-over'
|
||||
import { agentSessionOperationKey } from '../../../shared/agent-session/lifecycle/agent-session-operation-ledger'
|
||||
import { agentModelCatalogStore } from '../agent-model-catalog/agent-model-catalog-store'
|
||||
@@ -136,67 +137,97 @@ describe('installed catalog through Codex delivery and report settlement', () =>
|
||||
}, 10_000)
|
||||
|
||||
// Real host setup, delayed report settlement and bounded resource drains share this budget.
|
||||
it('fulfills owed model evidence from a matching delayed lifecycle report outside the delivery lock', async () => {
|
||||
const f = await createCatalogMutationFixture(stateDirectory, 'codex')
|
||||
try {
|
||||
f.rig.host.deps.adapter.open = async () => ({
|
||||
reportedOptions: { model: '', effort: 'high' }
|
||||
})
|
||||
f.rig.adapter.dispatch.mockResolvedValue({
|
||||
state: 'admitted',
|
||||
ranOptions: { effort: 'high' }
|
||||
})
|
||||
expect(
|
||||
await settled(
|
||||
f.rig.host.send(
|
||||
CALLER,
|
||||
restTestSend(
|
||||
'model arrives after admission',
|
||||
f.rig.store.requireWritableRecord(SESSION).lease.runtimeFence
|
||||
)
|
||||
),
|
||||
'model-less send acceptance'
|
||||
)
|
||||
).toMatchObject({ ok: true })
|
||||
const { conversationDelivery, sessions } = f.rig.host.collaboratorsForTests()
|
||||
await settled(conversationDelivery.loop.wake(SESSION), 'model-less admitted delivery')
|
||||
const child = sessions.get(SESSION)?.child
|
||||
if (!child?.generation) {
|
||||
throw new Error('production startup did not publish a child generation')
|
||||
it.each(['claude', 'codex'] as const)(
|
||||
'fulfills only input model evidence from a delayed %s report outside the delivery lock',
|
||||
async (agent) => {
|
||||
const f = await createCatalogMutationFixture(stateDirectory, agent)
|
||||
const model = agent === 'claude' ? CLAUDE_MODEL : CODEX_MODEL
|
||||
if (agent === 'claude') {
|
||||
const acquire = f.rig.adapter.acquire.getMockImplementation()!
|
||||
f.rig.adapter.acquire.mockImplementation(async (...args) => {
|
||||
const result = await acquire(...args)
|
||||
if (!result.link) {
|
||||
throw new Error('test acquisition did not provide a provider link')
|
||||
}
|
||||
return {
|
||||
...result,
|
||||
link: { ...result.link, handle: claudeProviderHandle('claude-provider', null) }
|
||||
}
|
||||
})
|
||||
}
|
||||
expect(child.phase).toBe('ready')
|
||||
expect(child.accountHome).toBeUndefined()
|
||||
expect(f.rig.store.requireWritableRecord(SESSION).options).toBeUndefined()
|
||||
const lifecycle = createStructuredAgentSessionLifecycleDelivery({
|
||||
handle: f.rig.host.handleAdapterEvent,
|
||||
logger: f.rig.host.deps.logger,
|
||||
drainObservedExits: async () => {}
|
||||
})
|
||||
lifecycle.deliver({
|
||||
type: 'options-reported',
|
||||
sessionId: SESSION,
|
||||
fence: child.fence,
|
||||
acquisitionGeneration: child.generation,
|
||||
reportedOptions: { model: CODEX_MODEL, effort: 'low' }
|
||||
})
|
||||
await settled(lifecycle.drain(), 'delayed lifecycle report')
|
||||
expect((await f.persisted()).records[SESSION]?.options).toEqual({
|
||||
model: CODEX_MODEL,
|
||||
effort: 'high'
|
||||
})
|
||||
await settled(conversationDelivery.loop.wake(SESSION), 'post-report delivery park')
|
||||
expect(conversationDelivery.loop.isRunning(SESSION)).toBe(false)
|
||||
expect(f.rig.adapter.dispatch).toHaveBeenCalledOnce()
|
||||
expect(
|
||||
await settled(
|
||||
f.rig.host.history({ sessionId: SESSION, direction: 'tail' }),
|
||||
'post-report ordinary history'
|
||||
)
|
||||
).toMatchObject({ ok: true })
|
||||
expect(f.rig.store.requireWritableRecord(SESSION).accountHome).toEqual(f.home)
|
||||
expect(f.probe).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
await f.dispose()
|
||||
}
|
||||
}, 10_000)
|
||||
try {
|
||||
f.rig.host.deps.adapter.open = async () => ({
|
||||
reportedOptions: { model: '', effort: 'high' }
|
||||
})
|
||||
f.rig.adapter.dispatch.mockResolvedValue({
|
||||
state: 'admitted',
|
||||
ranOptions: { effort: 'high' }
|
||||
})
|
||||
expect(
|
||||
await settled(
|
||||
f.rig.host.send(
|
||||
CALLER,
|
||||
restTestSend(
|
||||
'model arrives after admission',
|
||||
f.rig.store.requireWritableRecord(SESSION).lease.runtimeFence
|
||||
)
|
||||
),
|
||||
'model-less send acceptance'
|
||||
)
|
||||
).toMatchObject({ ok: true })
|
||||
const { conversationDelivery, sessions } = f.rig.host.collaboratorsForTests()
|
||||
await settled(conversationDelivery.loop.wake(SESSION), 'model-less admitted delivery')
|
||||
const child = sessions.get(SESSION)?.child
|
||||
if (!child?.generation) {
|
||||
throw new Error('production startup did not publish a child generation')
|
||||
}
|
||||
expect(child.phase).toBe('ready')
|
||||
expect(child.accountHome).toBeUndefined()
|
||||
expect(f.rig.store.requireWritableRecord(SESSION).options).toBeUndefined()
|
||||
const lifecycle = createStructuredAgentSessionLifecycleDelivery({
|
||||
handle: f.rig.host.handleAdapterEvent,
|
||||
logger: f.rig.host.deps.logger,
|
||||
drainObservedExits: async () => {}
|
||||
})
|
||||
if (agent === 'claude') {
|
||||
lifecycle.deliver({
|
||||
type: 'options-reported',
|
||||
sessionId: SESSION,
|
||||
fence: child.fence,
|
||||
acquisitionGeneration: child.generation,
|
||||
reportedOptions: { reportedModel: 'claude-opus-4-8' }
|
||||
})
|
||||
await settled(lifecycle.drain(), 'response model observation')
|
||||
expect(f.rig.host.readStatusSummary(SESSION)?.reportedModel).toBe('claude-opus-4-8')
|
||||
expect((await f.persisted()).records[SESSION]?.options).toBeUndefined()
|
||||
}
|
||||
lifecycle.deliver({
|
||||
type: 'options-reported',
|
||||
sessionId: SESSION,
|
||||
fence: child.fence,
|
||||
acquisitionGeneration: child.generation,
|
||||
reportedOptions: { model, effort: 'low' }
|
||||
})
|
||||
await settled(lifecycle.drain(), 'delayed lifecycle report')
|
||||
expect((await f.persisted()).records[SESSION]?.options).toEqual({
|
||||
model,
|
||||
effort: 'high'
|
||||
})
|
||||
await settled(conversationDelivery.loop.wake(SESSION), 'post-report delivery park')
|
||||
expect(conversationDelivery.loop.isRunning(SESSION)).toBe(false)
|
||||
expect(f.rig.adapter.dispatch).toHaveBeenCalledOnce()
|
||||
expect(
|
||||
await settled(
|
||||
f.rig.host.history({ sessionId: SESSION, direction: 'tail' }),
|
||||
'post-report ordinary history'
|
||||
)
|
||||
).toMatchObject({ ok: true })
|
||||
expect(f.rig.store.requireWritableRecord(SESSION).accountHome).toEqual(f.home)
|
||||
expect(f.probe).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
await f.dispose()
|
||||
}
|
||||
},
|
||||
10_000
|
||||
)
|
||||
})
|
||||
|
||||
+28
-2
@@ -5,7 +5,10 @@ import {
|
||||
hostTestRestingOptionsJournal as restingJournal,
|
||||
hostTestOptionsReadStore
|
||||
} from './structured-agent-session-host-test-data'
|
||||
import { CODEX_SESSION_OPTION_CATALOG } from '../../../shared/agent-session/options/agent-session-option-catalog-claude-codex'
|
||||
import {
|
||||
CODEX_SESSION_OPTION_CATALOG,
|
||||
CLAUDE_SESSION_OPTION_CATALOG
|
||||
} from '../../../shared/agent-session/options/agent-session-option-catalog-claude-codex'
|
||||
import {
|
||||
structuredAgentSessionMessageSelection,
|
||||
structuredAgentSessionSendSelection
|
||||
@@ -94,7 +97,10 @@ describe('a chat at rest, read by the host', () => {
|
||||
const resting = {
|
||||
child: liveOptions ? { fence: 1 } : null,
|
||||
params: { provider: record.provider },
|
||||
journal: restingJournal(items, wroteBeforeOpen)
|
||||
journal: {
|
||||
...restingJournal(items, wroteBeforeOpen),
|
||||
snapshot: () => ({ items: [], submissions: [] })
|
||||
}
|
||||
}
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this read touches only the declared context fields.
|
||||
const context = {
|
||||
@@ -111,6 +117,26 @@ describe('a chat at rest, read by the host', () => {
|
||||
return readStructuredAgentSessionOptions(context, SESSION, { readsWithoutModel: true })
|
||||
}
|
||||
|
||||
it('separates Claude fallback reports from the saved model and accepted send selection', async () => {
|
||||
const saved = { model: 'claude-opus-5-5', effort: 'high' }
|
||||
const answer = await readAtRest({ provider: 'claude', options: saved }, [], false, null, true, {
|
||||
models: [],
|
||||
current: { model: 'claude-opus-5-5', reportedModel: 'claude-opus-4-8', confirmed: ['model'] }
|
||||
})
|
||||
expect(answer.current).toMatchObject({
|
||||
model: saved.model,
|
||||
reportedModel: 'claude-opus-4-8',
|
||||
effort: saved.effort,
|
||||
acceptedInputSources: { model: 'saved', effort: 'saved' }
|
||||
})
|
||||
const state = applyStructuredAgentSessionOptions(
|
||||
createStructuredAgentSessionOptionState('claude'),
|
||||
CLAUDE_SESSION_OPTION_CATALOG,
|
||||
answer
|
||||
)
|
||||
expect(structuredAgentSessionMessageSelection(state)).toEqual({ ...saved, fastMode: 'false' })
|
||||
})
|
||||
|
||||
it.each<[string, RestingFacts, AgentJournalItemBody[], boolean, string[]]>([
|
||||
['started here names its default as its own', {}, [], false, []],
|
||||
[
|
||||
|
||||
@@ -151,6 +151,12 @@ export async function readStructuredAgentSessionOptions(
|
||||
const model = saved.model ?? (options.current.model || selected.current.model || displayDefault)
|
||||
const projected = live?.projectCurrent?.({ ...saved, ...(model ? { model } : {}) })
|
||||
const reportedEffort = projected?.confirmed?.includes('effort') ? projected.effort : undefined
|
||||
const reportedModel = live
|
||||
? (options.current.reportedModel ??
|
||||
(agent === 'claude' && options.current.confirmed?.includes('model')
|
||||
? options.current.model
|
||||
: undefined))
|
||||
: undefined
|
||||
const current = {
|
||||
...selected.current,
|
||||
...options.current,
|
||||
@@ -239,6 +245,7 @@ export async function readStructuredAgentSessionOptions(
|
||||
current: {
|
||||
...current,
|
||||
acceptedInputSources,
|
||||
...(reportedModel ? { reportedModel } : {}),
|
||||
...(reportedEffort !== undefined ? { reportedEffort } : {}),
|
||||
defaulted,
|
||||
confirmed,
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ import {
|
||||
} from './structured-agent-session-start-listing'
|
||||
import type { StructuredAgentSessionStartupAttempts } from './structured-agent-session-startup-attempt'
|
||||
import {
|
||||
noteStructuredAgentSessionRuntimePermission,
|
||||
noteStructuredAgentSessionRuntimeOptions,
|
||||
noteStructuredAgentSessionReportedOptions
|
||||
} from './structured-agent-session-ran-options'
|
||||
import type { StructuredAgentSessionAcquireAborts } from './structured-agent-session-acquire-aborts'
|
||||
@@ -151,7 +151,7 @@ function settleReady(
|
||||
)
|
||||
const sourceChild = current.child
|
||||
context.runtimeState.startupAttempts.ready(event.sessionId, child)
|
||||
noteStructuredAgentSessionRuntimePermission(current.child, event.reportedOptions, true)
|
||||
noteStructuredAgentSessionRuntimeOptions(current.child, event.reportedOptions, true)
|
||||
context.publishStatus?.(event.sessionId)
|
||||
await noteStructuredAgentSessionReportedOptions(
|
||||
context,
|
||||
@@ -206,7 +206,7 @@ export async function settleStructuredAgentSessionOptionsReported(
|
||||
) {
|
||||
return
|
||||
}
|
||||
noteStructuredAgentSessionRuntimePermission(child, event.reportedOptions)
|
||||
noteStructuredAgentSessionRuntimeOptions(child, event.reportedOptions)
|
||||
if (child.phase === 'starting') {
|
||||
const readiness = context.runtimeState.startupAttempts.readiness(event.sessionId, {
|
||||
generation: event.acquisitionGeneration,
|
||||
|
||||
@@ -26,7 +26,12 @@ export type StructuredAgentSessionHandedOptions = {
|
||||
/** Per-child reports and a handed-over turn awaiting its first model evidence. */
|
||||
const childRuns = new WeakMap<
|
||||
StructuredAgentSessionProviderChild,
|
||||
{ reported?: RanOptions; owed?: StructuredAgentSessionHandedOptions; permission?: string | null }
|
||||
{
|
||||
reported?: RanOptions
|
||||
reportedModel?: string
|
||||
owed?: StructuredAgentSessionHandedOptions
|
||||
permission?: string | null
|
||||
}
|
||||
>()
|
||||
|
||||
function currentChild(context: RanOptionsContext, sessionId: string, fence: number) {
|
||||
@@ -34,10 +39,10 @@ function currentChild(context: RanOptionsContext, sessionId: string, fence: numb
|
||||
return child?.fence === fence ? child : null
|
||||
}
|
||||
|
||||
export function structuredAgentSessionChildRan(
|
||||
export function structuredAgentSessionRuntimeModel(
|
||||
child: StructuredAgentSessionProviderChild
|
||||
): RanOptions | undefined {
|
||||
return childRuns.get(child)?.reported
|
||||
): string | undefined {
|
||||
return child.phase === 'ready' ? childRuns.get(child)?.reportedModel : undefined
|
||||
}
|
||||
|
||||
/** The current child's startup report or applied evidence; never saved intent or send authority. */
|
||||
@@ -48,17 +53,20 @@ export function structuredAgentSessionRuntimePermission(
|
||||
return child?.phase === 'ready' && mode !== undefined ? { fence: child.fence, mode } : null
|
||||
}
|
||||
|
||||
export function noteStructuredAgentSessionRuntimePermission(
|
||||
export function noteStructuredAgentSessionRuntimeOptions(
|
||||
child: StructuredAgentSessionProviderChild,
|
||||
reported: AgentSessionOptionsResult['current'],
|
||||
initial = false
|
||||
): void {
|
||||
const previous = childRuns.get(child)
|
||||
if (!initial || previous?.reportedModel === undefined) {
|
||||
childRuns.set(child, { ...previous, reportedModel: reported.reportedModel ?? reported.model })
|
||||
}
|
||||
if (
|
||||
reported.reportedPermissionMode !== undefined &&
|
||||
(!initial || previous?.permission === undefined)
|
||||
) {
|
||||
childRuns.set(child, { ...previous, permission: reported.reportedPermissionMode })
|
||||
childRuns.set(child, { ...childRuns.get(child), permission: reported.reportedPermissionMode })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import { createStructuredAgentSessionLogger } from './structured-agent-session-logger'
|
||||
import { testEventSinkLogging } from './structured-agent-session-logger-test-support'
|
||||
import { codexProviderHandle } from '../../../shared/agent-session/lifecycle/agent-session-provider-handle-encoding'
|
||||
import { releasedStructuredStatusSummary } from './structured-agent-session-status-summary'
|
||||
|
||||
const SESSION = 'status-session'
|
||||
const TURN_IDENTITY = {
|
||||
@@ -107,6 +108,24 @@ function feedFor(
|
||||
}
|
||||
|
||||
describe('StructuredAgentSessionStatusFeed', () => {
|
||||
it("retains the saved model but drops the released child's reported model", () => {
|
||||
const released = releasedStructuredStatusSummary({
|
||||
sessionId: SESSION,
|
||||
workspaceId: 'workspace-1',
|
||||
agent: 'claude',
|
||||
status: 'idle',
|
||||
latestPrompt: 'hello',
|
||||
model: 'claude-opus-5-5',
|
||||
reportedModel: 'claude-opus-4-8',
|
||||
hostExecutionOwned: true,
|
||||
hostExecutionPhase: 'ready',
|
||||
updatedAt: 1_000
|
||||
})
|
||||
|
||||
expect(released.model).toBe('claude-opus-5-5')
|
||||
expect(released).not.toHaveProperty('reportedModel')
|
||||
})
|
||||
|
||||
it('publishes provider ownership transitions without changing journal time', async () => {
|
||||
const journal = await openJournal()
|
||||
const sessions = new Map<string, Indexed>([
|
||||
|
||||
+1
@@ -27,6 +27,7 @@ export function structuredStatusSummariesEqual(
|
||||
(a.statusStartedAt !== undefined && !isIdleHeldOpenByChildWork(b))) &&
|
||||
a.latestPrompt === b.latestPrompt &&
|
||||
a.model === b.model &&
|
||||
a.reportedModel === b.reportedModel &&
|
||||
a.permissionMode === b.permissionMode &&
|
||||
a.runtimePermission?.fence === b.runtimePermission?.fence &&
|
||||
a.runtimePermission?.mode === b.runtimePermission?.mode &&
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { structuredAgentSessionRuntimePermission } from './structured-agent-session-ran-options'
|
||||
import {
|
||||
structuredAgentSessionRuntimeModel,
|
||||
structuredAgentSessionRuntimePermission
|
||||
} from './structured-agent-session-ran-options'
|
||||
import type { AgentSessionConversationView } from '../../../shared/agent-session/lifecycle/agent-session-conversation-view'
|
||||
import type { AgentSessionStatusSummary } from '../../../shared/agent-session/agent-session-wire'
|
||||
import { normalizeOptionalField } from '../../../shared/agent-status-field-normalization'
|
||||
@@ -80,6 +83,9 @@ export function structuredAgentSessionStatusSummary({
|
||||
? { rewindBlockedReason: 'outcome-unknown' as const }
|
||||
: {}),
|
||||
...(model ? { model } : {}),
|
||||
...(session.params.provider === 'claude' && session.child
|
||||
? { reportedModel: structuredAgentSessionRuntimeModel(session.child) }
|
||||
: {}),
|
||||
...(isAgentChatPermissionMode(permissionMode) ? { permissionMode } : {}),
|
||||
...(effort ? { effort } : {}),
|
||||
...(fastMode ? { fastMode } : {}),
|
||||
@@ -146,6 +152,7 @@ export function releasedStructuredStatusSummary(
|
||||
hostExecutionPhase: _hostExecutionPhase,
|
||||
stopping: _stopping,
|
||||
restartResume: _restartResume,
|
||||
reportedModel: _reportedModel,
|
||||
...retained
|
||||
} = previous
|
||||
return { ...retained, runtimePermission: null }
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import { NativeChatSessionOptionPickers } from './NativeChatSessionOptionPickers'
|
||||
import { ProviderFrameRow } from './NativeChatTranscriptChrome'
|
||||
import { defineFixture } from '../../component-fixtures/component-fixture'
|
||||
import { MessageRow } from './NativeChatMessageRow'
|
||||
import { projectStructuredItemToNativeChat } from '../../../../shared/agent-session/view/structured-agent-session-projection'
|
||||
|
||||
const head = JSON.stringify({
|
||||
type: 'fallback',
|
||||
from: { model: 'claude-opus-5-5' },
|
||||
to: { model: 'claude-opus-4-8' }
|
||||
})
|
||||
const raw = {
|
||||
text: 'Claude sent content Orca cannot display yet',
|
||||
providerFrame: {
|
||||
provider: 'claude',
|
||||
kind: 'message:assistant:content:fallback',
|
||||
payload: { head, byteLength: head.length, digest: 'fixture', truncated: false }
|
||||
}
|
||||
}
|
||||
const message = projectStructuredItemToNativeChat({
|
||||
itemId: 'fallback',
|
||||
revision: 1,
|
||||
sequence: 1,
|
||||
observedAt: 1,
|
||||
body: { kind: 'status', ...raw }
|
||||
})
|
||||
|
||||
function ModelPicker({ reportedModel }: { reportedModel?: string }) {
|
||||
return (
|
||||
<NativeChatSessionOptionPickers
|
||||
surface={{
|
||||
getSnapshot: () => [],
|
||||
subscribe: () => () => {},
|
||||
setOption: async () => ({ snapshot: [] }),
|
||||
invokeAction: async () => ({ snapshot: [] })
|
||||
}}
|
||||
isWorking={true}
|
||||
snapshot={[
|
||||
{
|
||||
id: 'model',
|
||||
label: 'Model',
|
||||
category: 'model',
|
||||
transport: 'agent-session',
|
||||
settable: false,
|
||||
valueSource: 'applied',
|
||||
reportedModel,
|
||||
kind: {
|
||||
type: 'select',
|
||||
currentValue: 'claude-opus-5-5',
|
||||
choices: [{ value: 'claude-opus-5-5', label: 'Opus 5.5' }]
|
||||
}
|
||||
}
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FallbackNotice() {
|
||||
return message ? (
|
||||
<MessageRow
|
||||
message={message}
|
||||
agentName="Claude"
|
||||
expandSignal={false}
|
||||
onScrollMessageToTop={() => {}}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
|
||||
export const fallback = defineFixture({
|
||||
width: 720,
|
||||
render: () => (
|
||||
<div className="native-chat-appearance p-4">
|
||||
<FallbackNotice />
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
export const narrow = defineFixture({ width: 320, render: fallback.render })
|
||||
|
||||
export const composer = defineFixture({
|
||||
width: 360,
|
||||
render: () => (
|
||||
<div className="native-chat-appearance p-4">
|
||||
<ModelPicker reportedModel="claude-opus-4-8" />
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
export const before = defineFixture({
|
||||
width: 720,
|
||||
render: () => (
|
||||
<div className="native-chat-appearance space-y-4 p-4">
|
||||
<ProviderFrameRow block={{ type: 'text', ...raw }} />
|
||||
<ModelPicker />
|
||||
</div>
|
||||
),
|
||||
interact: (frame) => {
|
||||
frame.querySelector('summary')?.click()
|
||||
}
|
||||
})
|
||||
|
||||
export const after = defineFixture({
|
||||
width: 720,
|
||||
render: () => (
|
||||
<div className="native-chat-appearance space-y-4 p-4">
|
||||
<FallbackNotice />
|
||||
<ModelPicker reportedModel="claude-opus-4-8" />
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
// @vitest-environment happy-dom
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { projectStructuredItemToNativeChat } from '../../../../shared/agent-session/view/structured-agent-session-projection'
|
||||
import type { AgentJournalStatusItem } from '../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { MessageRow } from './NativeChatMessageRow'
|
||||
import { i18n } from '@/i18n/i18n'
|
||||
|
||||
afterEach(async () => {
|
||||
cleanup()
|
||||
await i18n.changeLanguage('en')
|
||||
})
|
||||
|
||||
function renderStatus(body: AgentJournalStatusItem) {
|
||||
const message = projectStructuredItemToNativeChat({
|
||||
itemId: 'notice',
|
||||
sequence: 1,
|
||||
revision: 1,
|
||||
observedAt: 1,
|
||||
body
|
||||
})
|
||||
if (!message) {
|
||||
throw new Error('expected notice')
|
||||
}
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<MessageRow
|
||||
message={message}
|
||||
agentName="Claude"
|
||||
expandSignal={false}
|
||||
onScrollMessageToTop={vi.fn()}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
|
||||
it.each([
|
||||
['en', 'Claude switched models: Claude Opus 5.5 → Claude Opus 4.8.'],
|
||||
['ru', 'Claude переключил модель: Claude Opus 5.5 → Claude Opus 4.8.']
|
||||
])(
|
||||
'renders the saved fallback as a readable %s notice instead of unknown JSON',
|
||||
async (locale, words) => {
|
||||
await i18n.changeLanguage(locale)
|
||||
const head = JSON.stringify({
|
||||
type: 'fallback',
|
||||
from: { model: 'claude-opus-5-5' },
|
||||
to: { model: 'claude-opus-4-8' }
|
||||
})
|
||||
renderStatus({
|
||||
kind: 'status',
|
||||
text: 'Claude sent content Orca cannot display yet',
|
||||
providerFrame: {
|
||||
provider: 'claude',
|
||||
kind: 'message:assistant:content:fallback',
|
||||
payload: { head, byteLength: head.length, digest: 'fixture', truncated: false }
|
||||
}
|
||||
})
|
||||
expect(screen.getByText(words)).toBeInTheDocument()
|
||||
expect(screen.queryByText('Claude sent content Orca cannot display yet')).toBeNull()
|
||||
expect(screen.queryByText(head)).toBeNull()
|
||||
}
|
||||
)
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
CLAUDE_MODEL_FALLBACK_COPY,
|
||||
claudeModelFallbackLabels
|
||||
} from '../../../../shared/native-chat/claude-model-fallback'
|
||||
import { NativeChatUsageLimitAutoContinue } from './NativeChatUsageLimitAutoContinue'
|
||||
import { NativeChatUsageLimitActions } from './NativeChatUsageLimitActions'
|
||||
import { agentSessionGoalControlWords } from './agent-session-goal-control-words'
|
||||
@@ -116,6 +120,17 @@ export function NativeChatNoticeRow({
|
||||
</p>
|
||||
)
|
||||
}
|
||||
if (look.kind === 'model-fallback') {
|
||||
return (
|
||||
<p className="min-w-0 max-w-full select-text text-sm text-chat-foreground-faint [overflow-wrap:anywhere]">
|
||||
{translate(
|
||||
'components.native-chat.notices.modelFallback',
|
||||
CLAUDE_MODEL_FALLBACK_COPY,
|
||||
claudeModelFallbackLabels(look)
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
if (look.kind === 'plan') {
|
||||
return (
|
||||
<Card className="gap-3 py-3 shadow-xs">
|
||||
|
||||
+65
@@ -118,3 +118,68 @@ it('picks effort during a running turn, saves it to the chat, and captures it on
|
||||
rpc.call.mock.calls.every(([, method]) => !['turn/steer', 'turn/start'].includes(method))
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('refreshes the composer model from host execution reports without changing captured input', async () => {
|
||||
let reportedModel = 'claude-opus-5-5'
|
||||
const sent: unknown[] = []
|
||||
rpc.call.mockImplementation(async (_target, method) => {
|
||||
if (method === 'agentSession.options') {
|
||||
return {
|
||||
models: [{ id: 'claude-opus-5-5', label: 'Opus 5.5', efforts: [] }],
|
||||
current: {
|
||||
model: 'claude-opus-5-5',
|
||||
reportedModel,
|
||||
defaulted: [],
|
||||
acceptedInputSources: { model: 'saved' }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (method === 'agentSession.modelCatalog') {
|
||||
return { origin: 'unknown' }
|
||||
}
|
||||
throw new Error(`Unexpected RPC ${method}`)
|
||||
})
|
||||
function Composer({ stamp }: { stamp: string }) {
|
||||
const options = useStructuredAgentSessionOptions({
|
||||
agent: 'claude',
|
||||
sessionId,
|
||||
target,
|
||||
fence: 1,
|
||||
transportEnabled: true,
|
||||
isVisible: true,
|
||||
providerVisible: true,
|
||||
providerRunning: true,
|
||||
turnId: 'running',
|
||||
unloadedTurnRevisions: undefined,
|
||||
hostOptionStamp: stamp,
|
||||
mutate: async () => null
|
||||
})
|
||||
const capture = useStructuredAgentSessionSendOptions(sessionId, undefined, options.sendSource)
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<NativeChatSessionOptionPickers
|
||||
surface={options.optionSurface}
|
||||
snapshot={options.optionSnapshot}
|
||||
isWorking={true}
|
||||
/>
|
||||
<button onClick={() => sent.push(capture())}>Capture next message</button>
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
const { rerender } = render(<Composer stamp={reportedModel} />)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: /^Model (Claude )?Opus 5\.5$/ })).toBeTruthy()
|
||||
)
|
||||
reportedModel = 'claude-opus-4-8'
|
||||
rerender(<Composer stamp={reportedModel} />)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: /^Model (Claude )?Opus 4\.8$/ })).toBeTruthy()
|
||||
)
|
||||
fireEvent.click(screen.getByText('Capture next message'))
|
||||
expect(sent).toEqual([{ selection: { model: 'claude-opus-5-5' } }])
|
||||
reportedModel = 'claude-opus-5-5'
|
||||
rerender(<Composer stamp={reportedModel} />)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: /^Model (Claude )?Opus 5\.5$/ })).toBeTruthy()
|
||||
)
|
||||
})
|
||||
|
||||
+2
-4
@@ -11,10 +11,8 @@ import type { AgentType } from '../../../../shared/agent-status-types'
|
||||
import type { AgentSessionOptionCatalog } from '../../../../shared/agent-session/options/agent-session-option-catalog-types'
|
||||
import { usesInstalledAgentModelCatalog } from '../../../../shared/agent-session/options/agent-model-catalog-ownership'
|
||||
import { AGENT_SESSION_COHERENT_MODEL_CATALOG_CAPABILITY } from '../../../../shared/agent-session/structured-agent-session-surface-capabilities'
|
||||
import {
|
||||
structuredAgentSessionReportsAtFence,
|
||||
type StructuredAgentSessionOptionState
|
||||
} from '../../../../shared/agent-session/options/structured-agent-session-options'
|
||||
import type { StructuredAgentSessionOptionState } from '../../../../shared/agent-session/options/structured-agent-session-options'
|
||||
import { structuredAgentSessionReportsAtFence } from '../../../../shared/agent-session/options/structured-agent-session-runtime-reports'
|
||||
import type { RuntimeClientTarget } from '../../../../shared/runtime-client-target'
|
||||
import { structuredAgentSessionOptionView } from '../../../../shared/agent-session/options/structured-agent-session-option-view'
|
||||
import {
|
||||
|
||||
+3
-2
@@ -1538,7 +1538,6 @@
|
||||
"attachmentAtMost": "{{agent}} accepts at most {{limit}} images in one message, so this message was not sent.",
|
||||
"attachmentEmpty": "An image on this message is empty, so the message was not sent.",
|
||||
"attachmentInvalid": "An attachment on this message can't be sent to the agent.",
|
||||
"attachmentsExpired": "{{names}} expired.",
|
||||
"attachmentLargerThan": "An image on this message is larger than {{size}} MB, so the message was not sent.",
|
||||
"attachmentNoSource": "An image on this message has no file to send, so the message was not sent.",
|
||||
"attachmentNotAFile": "An image on this message isn't a file, so the message was not sent.",
|
||||
@@ -1548,6 +1547,7 @@
|
||||
"attachmentTotalTooLarge": "The images on this message are too large together, so the message was not sent.",
|
||||
"attachmentUnreadable": "An attachment on this message couldn't be read, so the message was not sent.",
|
||||
"attachmentUnsupportedType": "{{agent}} accepts only PNG, JPEG, GIF, and WebP images, so this message was not sent.",
|
||||
"attachmentsExpired": "{{names}} expired.",
|
||||
"backgroundTaskNotStopped": "The background task wasn't stopped.",
|
||||
"backgroundTasksNotStopped": "The background tasks weren't stopped.",
|
||||
"cancelUnconfirmed": "Cancellation was not confirmed.",
|
||||
@@ -1651,6 +1651,7 @@
|
||||
"continuedOutsideRewound": "Continued outside this chat. Earlier replies above are no longer in this conversation's history.",
|
||||
"historyItemTooLarge": "This part of the chat was too large to show.",
|
||||
"historyRepaired": "Part of this chat's history couldn't be loaded.",
|
||||
"modelFallback": "Claude switched models: {{from}} → {{to}}.",
|
||||
"orcaStopCanContinue": "You can continue in this conversation.",
|
||||
"orcaStopCrash": "Orca on {{machine}} stopped unexpectedly while this response was in progress.",
|
||||
"orcaStopQuit": "Orca on {{machine}} was closed while this response was in progress.",
|
||||
@@ -1835,6 +1836,7 @@
|
||||
"historyUnreadable": "Orca couldn't read this chat's saved history.",
|
||||
"historyUnusable": "Unable to load this chat.",
|
||||
"hostReconciling": "Orca is still checking on this chat after restarting.",
|
||||
"mailOwnerUnconfirmed": "Orca couldn't confirm this message is still meant for this chat.",
|
||||
"messageNotSaved": "Couldn't save your message.",
|
||||
"messageTooLarge": "It is over the 256 KB limit for one message.",
|
||||
"messagesUnsettled": "A message you sent earlier isn't confirmed yet.",
|
||||
@@ -1862,7 +1864,6 @@
|
||||
"reattachFiles": "Remove them and attach them again.",
|
||||
"recordFailed": "Orca couldn't save this to the chat's history.",
|
||||
"recordUnreadable": "Orca couldn't read this chat's saved state.",
|
||||
"mailOwnerUnconfirmed": "Orca couldn't confirm this message is still meant for this chat.",
|
||||
"reopenChat": "Reopen the chat to check again.",
|
||||
"restartFailed": "The agent couldn't restart.",
|
||||
"runClearWhenDone": "Run /clear when it's done.",
|
||||
|
||||
@@ -19681,7 +19681,8 @@
|
||||
"orcaStopUnnamedServer": "the remote server",
|
||||
"permissionDenied": "{{agent}} denied permission. View details.",
|
||||
"safetyReview": "{{agent}} reported a safety review warning. View details.",
|
||||
"truncatedResponse": "Provider response truncated (original size: {{bytes}} bytes)."
|
||||
"truncatedResponse": "Provider response truncated (original size: {{bytes}} bytes).",
|
||||
"modelFallback": "Claude switched models: {{from}} → {{to}}."
|
||||
},
|
||||
"composer": {
|
||||
"send": "Send",
|
||||
|
||||
@@ -19887,7 +19887,8 @@
|
||||
"orcaStopUnnamedServer": "удалённом сервере",
|
||||
"permissionDenied": "{{agent}} отказал в разрешении. Подробнее.",
|
||||
"safetyReview": "{{agent}} сообщил о предупреждении проверки безопасности. Подробнее.",
|
||||
"truncatedResponse": "Ответ поставщика обрезан (исходный размер: {{bytes}} байт)."
|
||||
"truncatedResponse": "Ответ поставщика обрезан (исходный размер: {{bytes}} байт).",
|
||||
"modelFallback": "Claude переключил модель: {{from}} → {{to}}."
|
||||
},
|
||||
"composer": {
|
||||
"send": "Отправить",
|
||||
|
||||
@@ -214,6 +214,8 @@ export type AgentSessionStatusSummary = {
|
||||
latestPrompt: string
|
||||
/** Provider model in force for the next turn; absent until the host has read the options. */
|
||||
model?: string
|
||||
/** Current child's reported execution model, independent of the next-turn selection. */
|
||||
reportedModel?: string
|
||||
/** The chat's saved permission mode; a client re-reads options when it or `model` moves. */
|
||||
permissionMode?: string
|
||||
runtimePermission?: { fence: number; mode: string | null } | null
|
||||
|
||||
@@ -44,6 +44,8 @@ export type AgentSessionOptionsResult = {
|
||||
/** Accepted input origins; an empty map excludes all display-only observations. */
|
||||
acceptedInputSources?: AgentSessionAcceptedInputSources
|
||||
model?: string
|
||||
/** Current child reports this model for display; it is never a next-turn selection. */
|
||||
reportedModel?: string
|
||||
effort?: string
|
||||
/** Child-scoped actual for display only; effort remains accepted raw input. */
|
||||
reportedEffort?: string
|
||||
|
||||
@@ -221,7 +221,11 @@ export function structuredAgentSessionOptionSnapshot(
|
||||
): SessionOptionDescriptor[] {
|
||||
const permission = structuredAgentSessionPermissionDescriptor(state)
|
||||
const options = modelOptionSnapshot(state).map((option) =>
|
||||
state.fastModeRestricted && option.id === 'fastMode' ? { ...option, settable: false } : option
|
||||
state.fastModeRestricted && option.id === 'fastMode'
|
||||
? { ...option, settable: false }
|
||||
: option.id === 'model' && state.reportedModel
|
||||
? { ...option, reportedModel: state.reportedModel }
|
||||
: option
|
||||
)
|
||||
return permission ? [...options, permission] : options
|
||||
}
|
||||
|
||||
@@ -73,12 +73,13 @@ export function structuredAgentSessionOptionStamp(
|
||||
summary:
|
||||
| Pick<
|
||||
AgentSessionStatusSummary,
|
||||
'model' | 'permissionMode' | 'effort' | 'fastMode' | 'serviceTier'
|
||||
'model' | 'reportedModel' | 'permissionMode' | 'effort' | 'fastMode' | 'serviceTier'
|
||||
>
|
||||
| undefined
|
||||
): string {
|
||||
return [
|
||||
summary?.model,
|
||||
summary?.reportedModel,
|
||||
summary?.permissionMode,
|
||||
summary?.effort,
|
||||
summary?.fastMode,
|
||||
|
||||
@@ -197,6 +197,7 @@ export function createStructuredAgentSessionOptionsReadOwner(
|
||||
...current,
|
||||
record: cloneStructuredAgentSessionOptionRecord(current.record),
|
||||
reportedPermissionMode: undefined,
|
||||
reportedModel: undefined,
|
||||
reportedEffort: undefined,
|
||||
...(current.acceptedInputSources ? { acceptedInputSources: {} } : {})
|
||||
}
|
||||
@@ -214,6 +215,7 @@ export function createStructuredAgentSessionOptionsReadOwner(
|
||||
...current,
|
||||
record: cloneStructuredAgentSessionOptionRecord(current.record),
|
||||
reportedPermissionMode: undefined,
|
||||
reportedModel: undefined,
|
||||
reportedEffort: undefined
|
||||
}
|
||||
: context.seed()
|
||||
|
||||
@@ -64,6 +64,7 @@ export type StructuredAgentSessionOptionState = {
|
||||
permissionMode: string | null
|
||||
reportedPermissionMode?: string | null
|
||||
permissionOwnSupported?: boolean | null
|
||||
reportedModel?: string
|
||||
reportedEffort?: string
|
||||
/** The host is still listing models; it only keeps a seed from settling to built-in, since controls follow their data. */
|
||||
listingInProgress?: boolean
|
||||
@@ -187,6 +188,7 @@ export function applyStructuredAgentSessionOptions(
|
||||
return {
|
||||
...state,
|
||||
optionsAnswerPresent: true,
|
||||
reportedModel: current.reportedModel,
|
||||
reportedEffort: state.record.agent === 'pi' ? current.reportedEffort : undefined,
|
||||
catalog: keepCatalog
|
||||
? state.catalog
|
||||
@@ -226,22 +228,15 @@ function structuredAgentSessionControlsModelId(
|
||||
: null
|
||||
}
|
||||
|
||||
/** Runtime reports describe the process whose options answer carried them; a newer fence has none until it answers. */
|
||||
export function structuredAgentSessionReportsAtFence<
|
||||
T extends Pick<StructuredAgentSessionOptionState, 'reportedPermissionMode' | 'reportedEffort'>
|
||||
>(state: T, answeredFence: number | null | undefined, fence: number | null): T {
|
||||
return answeredFence === fence ||
|
||||
(state.reportedPermissionMode === undefined && state.reportedEffort === undefined)
|
||||
? state
|
||||
: { ...state, reportedPermissionMode: undefined, reportedEffort: undefined }
|
||||
}
|
||||
|
||||
export function commitStructuredAgentSessionOption(
|
||||
state: StructuredAgentSessionOptionState,
|
||||
id: string,
|
||||
value: string,
|
||||
origin: 'picked' | 'seeded' = 'picked'
|
||||
): StructuredAgentSessionOptionState {
|
||||
if (id === 'model') {
|
||||
state = { ...state, reportedModel: undefined }
|
||||
}
|
||||
if (id === 'model' || id === 'effort') {
|
||||
state = { ...state, reportedEffort: undefined }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import { CLAUDE_SESSION_OPTION_CATALOG } from './agent-session-option-catalog-claude-codex'
|
||||
import {
|
||||
applyStructuredAgentSessionOptions,
|
||||
createStructuredAgentSessionOptionState,
|
||||
commitStructuredAgentSessionOption
|
||||
} from './structured-agent-session-options'
|
||||
import { structuredAgentSessionReportsAtFence } from './structured-agent-session-runtime-reports'
|
||||
import { structuredAgentSessionOptionSnapshot } from './structured-agent-session-option-snapshot'
|
||||
import { structuredAgentSessionMessageSelection } from './structured-agent-session-option-view'
|
||||
import {
|
||||
nativeChatModelPillLabel,
|
||||
sayNativeChatSessionOptionEnglish
|
||||
} from '../../native-chat/input/native-chat-session-option-labels'
|
||||
import { structuredAgentSessionOptionStamp } from './structured-agent-session-option-state'
|
||||
|
||||
it('shows the actual fallback in the shared composer pill while capturing the original model for Send', () => {
|
||||
const state = applyStructuredAgentSessionOptions(
|
||||
createStructuredAgentSessionOptionState('claude'),
|
||||
CLAUDE_SESSION_OPTION_CATALOG,
|
||||
{
|
||||
models: [{ id: 'claude-opus-5-5', label: 'Opus 5.5', isDefault: false, efforts: [] }],
|
||||
current: {
|
||||
model: 'claude-opus-5-5',
|
||||
reportedModel: 'claude-opus-4-8',
|
||||
defaulted: [],
|
||||
acceptedInputSources: { model: 'saved' }
|
||||
}
|
||||
}
|
||||
)
|
||||
const model = structuredAgentSessionOptionSnapshot(state).find((option) => option.id === 'model')!
|
||||
expect(nativeChatModelPillLabel(model, sayNativeChatSessionOptionEnglish)).toBe('Opus 4.8')
|
||||
expect(model.kind.currentValue).toBe('claude-opus-5-5')
|
||||
expect(structuredAgentSessionMessageSelection(state)).toEqual({ model: 'claude-opus-5-5' })
|
||||
expect(structuredAgentSessionReportsAtFence(state, 1, 2).reportedModel).toBeUndefined()
|
||||
expect(
|
||||
commitStructuredAgentSessionOption(state, 'model', 'claude-opus-5-5').reportedModel
|
||||
).toBeUndefined()
|
||||
const oldHost = applyStructuredAgentSessionOptions(state, CLAUDE_SESSION_OPTION_CATALOG, {
|
||||
models: [],
|
||||
current: { model: 'claude-opus-5-5' }
|
||||
})
|
||||
expect(oldHost.reportedModel).toBeUndefined()
|
||||
})
|
||||
|
||||
it('invalidates option reads when a response changes model without changing the saved selection', () => {
|
||||
const selected = { model: 'claude-opus-5-5' }
|
||||
expect(
|
||||
structuredAgentSessionOptionStamp({ ...selected, reportedModel: 'claude-opus-4-8' })
|
||||
).not.toBe(structuredAgentSessionOptionStamp({ ...selected, reportedModel: 'claude-opus-5-5' }))
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { StructuredAgentSessionOptionState } from './structured-agent-session-options'
|
||||
|
||||
/** Runtime reports describe the process whose options answer carried them; a newer fence has none until it answers. */
|
||||
export function structuredAgentSessionReportsAtFence<
|
||||
T extends Pick<
|
||||
StructuredAgentSessionOptionState,
|
||||
'reportedPermissionMode' | 'reportedModel' | 'reportedEffort'
|
||||
>
|
||||
>(state: T, answeredFence: number | null | undefined, fence: number | null): T {
|
||||
return answeredFence === fence ||
|
||||
(state.reportedPermissionMode === undefined &&
|
||||
state.reportedModel === undefined &&
|
||||
state.reportedEffort === undefined)
|
||||
? state
|
||||
: {
|
||||
...state,
|
||||
reportedPermissionMode: undefined,
|
||||
reportedModel: undefined,
|
||||
reportedEffort: undefined
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
readClaudeModelFallbackFrame,
|
||||
claudeModelFallbackText
|
||||
} from '../../native-chat/claude-model-fallback'
|
||||
import { AGENT_SESSION_TURN_NOTICE_PRESENTATION } from '../journal/agent-session-turn-notice'
|
||||
import { readWholeAgentSessionFailureFact } from '../failures/agent-session-failure'
|
||||
import type { AgentJournalStatusItem } from '../journal/agent-session-journal-types'
|
||||
import type { AgentJournalTurnScope } from '../journal/agent-session-journal-turn-scope'
|
||||
@@ -16,17 +21,22 @@ export function structuredAgentSessionStatusBlock(
|
||||
): NativeChatTextBlock {
|
||||
const failure = readWholeAgentSessionFailureFact(body.failure)
|
||||
const orcaStop = readAgentSessionOrcaStop(body.orcaStop)
|
||||
const modelFallback =
|
||||
!failure && !orcaStop && body.presentation === undefined && body.tone === undefined
|
||||
? readClaudeModelFallbackFrame(body.providerFrame)
|
||||
: null
|
||||
const presentation =
|
||||
body.presentation ??
|
||||
(modelFallback ? AGENT_SESSION_TURN_NOTICE_PRESENTATION : undefined) ??
|
||||
(body.tone === 'warning' && itemId !== undefined && isAgentSessionLegacyCompactionResult(itemId)
|
||||
? AGENT_SESSION_COMPACTION_SKIPPED_PRESENTATION
|
||||
: undefined)
|
||||
return {
|
||||
type: 'text',
|
||||
text: body.text,
|
||||
text: modelFallback ? claudeModelFallbackText(modelFallback) : body.text,
|
||||
...(presentation !== undefined ? { presentation } : {}),
|
||||
...(body.contextClear !== undefined ? { contextClear: body.contextClear } : {}),
|
||||
...(body.tone !== undefined ? { tone: body.tone } : {}),
|
||||
...(body.tone !== undefined ? { tone: body.tone } : modelFallback ? { tone: 'notice' } : {}),
|
||||
...(body.providerFrame ? { providerFrame: body.providerFrame } : {}),
|
||||
...(failure ? { failure } : {}),
|
||||
...(failure?.kind === 'usageLimitReached' && turnScope?.kind === 'turn'
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import { structuredAgentSessionStatusBlock } from '../agent-session/view/structured-agent-session-status-block'
|
||||
import { nativeChatNoticeLook } from './native-chat-notice'
|
||||
import {
|
||||
CLAUDE_MODEL_FALLBACK_FRAME_KIND,
|
||||
readClaudeModelFallbackFrame
|
||||
} from './claude-model-fallback'
|
||||
|
||||
const fallback = {
|
||||
type: 'fallback',
|
||||
from: { model: 'claude-opus-5-5' },
|
||||
to: { model: 'claude-opus-4-8' }
|
||||
}
|
||||
|
||||
function frame(value: unknown = fallback) {
|
||||
const head = JSON.stringify(value)
|
||||
return {
|
||||
provider: 'claude',
|
||||
kind: CLAUDE_MODEL_FALLBACK_FRAME_KIND,
|
||||
payload: { head, byteLength: head.length, digest: 'fixture', truncated: false }
|
||||
}
|
||||
}
|
||||
|
||||
it('upcasts the saved unknown content from an older host without rewriting its diagnostic payload', () => {
|
||||
const body = {
|
||||
kind: 'status',
|
||||
text: 'Claude sent content Orca cannot display yet',
|
||||
providerFrame: frame()
|
||||
} as const
|
||||
const block = structuredAgentSessionStatusBlock(body)
|
||||
expect(block).toEqual({
|
||||
type: 'text',
|
||||
text: 'Claude switched models: Claude Opus 5.5 → Claude Opus 4.8.',
|
||||
tone: 'notice',
|
||||
presentation: 'turn-notice',
|
||||
providerFrame: body.providerFrame
|
||||
})
|
||||
expect(nativeChatNoticeLook(block)).toEqual({
|
||||
kind: 'model-fallback',
|
||||
from: 'claude-opus-5-5',
|
||||
to: 'claude-opus-4-8'
|
||||
})
|
||||
expect(body.text).toBe('Claude sent content Orca cannot display yet')
|
||||
})
|
||||
|
||||
it.each([
|
||||
null,
|
||||
{ type: 'fallback', from: { model: 'claude-opus-5-5' } },
|
||||
{ type: 'fallback', from: { model: [] }, to: { model: 'claude-opus-4-8' } },
|
||||
{ type: 'fallback', from: { model: ' ' }, to: { model: 'claude-opus-4-8' } },
|
||||
{ ...fallback, type: 'future_event' }
|
||||
])(
|
||||
'keeps an incomplete or different event available through the generic disclosure: %j',
|
||||
(value) => {
|
||||
const body = { kind: 'status', text: 'Unknown content', providerFrame: frame(value) } as const
|
||||
expect(structuredAgentSessionStatusBlock(body)).toEqual({
|
||||
type: 'text',
|
||||
text: body.text,
|
||||
providerFrame: body.providerFrame
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it('requires a complete Claude assistant fallback frame', () => {
|
||||
const known = frame()
|
||||
for (const other of [
|
||||
{ ...known, provider: 'codex' },
|
||||
{ ...known, kind: 'message:user:content:fallback' },
|
||||
{ ...known, payload: { ...known.payload, truncated: true } },
|
||||
{ ...known, payload: { ...known.payload, head: '{' } }
|
||||
]) {
|
||||
expect(readClaudeModelFallbackFrame(other)).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ tone: 'error' },
|
||||
{ presentation: 'plan-document' },
|
||||
{ failure: { kind: 'usageLimitReached' } },
|
||||
{ orcaStop: { cause: 'quit' } }
|
||||
] as const)('does not replace another explicit status or failure: %j', (special) => {
|
||||
const block = {
|
||||
type: 'text',
|
||||
text: 'Keep this status',
|
||||
providerFrame: frame(),
|
||||
...special
|
||||
} as const
|
||||
expect(nativeChatNoticeLook(block).kind).not.toBe('model-fallback')
|
||||
})
|
||||
@@ -0,0 +1,59 @@
|
||||
import { MAX_CONTEXT_MODEL_ID_CHARS } from '../agent-session/agent-session-context-usage'
|
||||
import { labelFromModelId } from '../model-id-label'
|
||||
import type { NativeChatTextBlock } from './native-chat-types'
|
||||
|
||||
export const CLAUDE_MODEL_FALLBACK_FRAME_KIND = 'message:assistant:content:fallback'
|
||||
export const CLAUDE_MODEL_FALLBACK_COPY = 'Claude switched models: {{from}} → {{to}}.'
|
||||
|
||||
export type ClaudeModelFallback = { from: string; to: string }
|
||||
|
||||
function modelOf(value: unknown): string | null {
|
||||
if (typeof value !== 'object' || value === null || !('model' in value)) {
|
||||
return null
|
||||
}
|
||||
const model = typeof value.model === 'string' ? value.model.trim() : ''
|
||||
return model && model.length <= MAX_CONTEXT_MODEL_ID_CHARS ? model : null
|
||||
}
|
||||
|
||||
export function readClaudeModelFallback(value: unknown): ClaudeModelFallback | null {
|
||||
if (
|
||||
typeof value !== 'object' ||
|
||||
value === null ||
|
||||
!('type' in value) ||
|
||||
value.type !== 'fallback'
|
||||
) {
|
||||
return null
|
||||
}
|
||||
const from = modelOf('from' in value ? value.from : null)
|
||||
const to = modelOf('to' in value ? value.to : null)
|
||||
return from && to ? { from, to } : null
|
||||
}
|
||||
|
||||
export function readClaudeModelFallbackFrame(
|
||||
frame: NativeChatTextBlock['providerFrame']
|
||||
): ClaudeModelFallback | null {
|
||||
if (
|
||||
frame?.provider !== 'claude' ||
|
||||
frame.kind !== CLAUDE_MODEL_FALLBACK_FRAME_KIND ||
|
||||
frame.payload.truncated
|
||||
) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return readClaudeModelFallback(JSON.parse(frame.payload.head))
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function claudeModelFallbackLabels(fallback: ClaudeModelFallback): ClaudeModelFallback {
|
||||
return { from: labelFromModelId(fallback.from), to: labelFromModelId(fallback.to) }
|
||||
}
|
||||
|
||||
export function claudeModelFallbackText(fallback: ClaudeModelFallback): string {
|
||||
const labels = claudeModelFallbackLabels(fallback)
|
||||
return CLAUDE_MODEL_FALLBACK_COPY.replace('{{from}}', () => labels.from).replace(
|
||||
'{{to}}',
|
||||
() => labels.to
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { labelFromModelId } from '../../model-id-label'
|
||||
import {
|
||||
isDefaultServiceTier,
|
||||
type SessionOptionDescriptor,
|
||||
@@ -156,7 +157,20 @@ export function nativeChatModelPillLabel(
|
||||
): string {
|
||||
// The tooltip names the category; default sources still identify a model, while unknown sources do not.
|
||||
const choice = descriptor.valueSource === 'unknown' ? null : selectedNativeChatChoice(descriptor)
|
||||
return choice ? nativeChatSessionChoiceLabel(choice, say) : say('model')
|
||||
const selected = choice ? nativeChatSessionChoiceLabel(choice, say) : say('model')
|
||||
const reported = descriptor.reportedModel
|
||||
if (!reported || (choice && reported === choice.value.replace(/\[[^\]]*\]$/u, ''))) {
|
||||
return selected
|
||||
}
|
||||
const reportedChoice =
|
||||
descriptor.kind.type === 'select'
|
||||
? descriptor.kind.choices.find((entry) => entry.value === reported)
|
||||
: undefined
|
||||
const label = reportedChoice
|
||||
? nativeChatSessionChoiceLabel(reportedChoice, say)
|
||||
: labelFromModelId(reported)
|
||||
const actual = selected.startsWith('Claude ') ? label : label.replace(/^Claude /, '')
|
||||
return actual
|
||||
}
|
||||
|
||||
export function nativeChatOptionsPillTitle(
|
||||
|
||||
@@ -37,6 +37,8 @@ export type SessionOptionDescriptor = {
|
||||
currentValue: boolean
|
||||
}
|
||||
valueSource: SessionOptionValueSource
|
||||
/** Model-pill display only; currentValue remains the accepted selection. */
|
||||
reportedModel?: string
|
||||
/** Explicit lane is required: dispatched cannot distinguish PTY from structured transports. */
|
||||
transport: NativeChatLiveOptionTransport
|
||||
settable: boolean
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Shared host/command/plan notice presentation: desktop translates the copy; mobile renders it directly.
|
||||
|
||||
import { readClaudeModelFallbackFrame } from './claude-model-fallback'
|
||||
import { AGENT_SESSION_TURN_NOTICE_PRESENTATION } from '../agent-session/journal/agent-session-turn-notice'
|
||||
import {
|
||||
isAgentSessionHostStatusPresentation,
|
||||
type AgentSessionHostStatusPresentation
|
||||
@@ -24,6 +26,7 @@ export type NativeChatNoticeLook =
|
||||
/** The host's line in the reader's words, drawn faint. */
|
||||
| { kind: 'host-status'; presentation: AgentSessionHostStatusPresentation }
|
||||
| { kind: 'plan' }
|
||||
| { kind: 'model-fallback'; from: string; to: string }
|
||||
/** Faint, as a system row with no notice of its own is. */
|
||||
| { kind: 'aside' }
|
||||
| {
|
||||
@@ -69,6 +72,16 @@ export function nativeChatNoticeLook(block: NativeChatTextBlock): NativeChatNoti
|
||||
if (presentation === AGENT_SESSION_ORCA_STOP_PRESENTATION) {
|
||||
return { kind: 'line', tone: 'notice' }
|
||||
}
|
||||
const modelFallback =
|
||||
!block.failure &&
|
||||
!block.orcaStop &&
|
||||
(presentation === undefined || presentation === AGENT_SESSION_TURN_NOTICE_PRESENTATION) &&
|
||||
(block.tone === undefined || block.tone === 'notice')
|
||||
? readClaudeModelFallbackFrame(block.providerFrame)
|
||||
: null
|
||||
if (modelFallback) {
|
||||
return { kind: 'model-fallback', ...modelFallback }
|
||||
}
|
||||
// Declared notification kinds select disclosure; prose and nested failures do not.
|
||||
if (presentation === undefined && !block.failure && !block.orcaStop) {
|
||||
const frame = block.providerFrame
|
||||
|
||||
Reference in New Issue
Block a user