From ce783c056c96b8c27bea5c95e656168ee656378c Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Sun, 22 Nov 2026 10:28:26 +0100 Subject: [PATCH 1/3] mason: log each Anthropic server fallback step Reuse the hidden usage marker's validation for closed per-attempt INFO metadata on both OpenCode generations. Keep notice deduplication and describe the next step as trying the requested model again, rather than staying on fallback. --- CHANGELOG.md | 4 + packages/opencode/src/index.ts | 44 ++---- packages/opencode/src/server-fallback.ts | 145 +++++++++++++----- .../src/tests/opencode2-adapter.test.ts | 129 ++++++++++++++++ ...al-and-server-fallback.integration.test.ts | 78 +++++++--- .../src/tests/server-fallback.test.ts | 15 ++ packages/opencode/src/v2/wire.ts | 35 ++++- 7 files changed, 354 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c87398ba..a9fd1bc7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This repo is a CortexKit-maintained Anthropic auth monorepo for OpenCode and Pi. The OpenCode package is a fork of the original `@ex-machina/opencode-anthropic-auth` plugin, so older entries below the initial CortexKit release are inherited from upstream package history. +## Unreleased + +- OpenCode 1 and 2: every step served by Anthropic's safety fallback now writes one log line with per-attempt token counts; OpenCode 2 previously logged nothing. Addresses #861. + ## 2.16.4 - Updates common-auth to 0.56.3 and claustrum-client to 0.21.0. diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index 8969f8827..d39379276 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -359,6 +359,7 @@ import { type RpcServerAdoption, } from './rpc/server-registry.ts' import { + logServedServerFallback, resolveContentFilterFallbackMode, type ServerSideFallbackOutcome, } from './server-fallback.ts' @@ -968,7 +969,7 @@ function buildServerFallbackNotice( requestedModelId: string, targetModelId: string, ): string { - return `Anthropic safety fallback active: ${fallbackModelLabel(requestedModelId)} → ${fallbackModelLabel(targetModelId)}. Follow-up requests may remain on the fallback model for about one hour.` + return `Anthropic's safety fallback served this step on ${fallbackModelLabel(targetModelId)}; the next step tries ${fallbackModelLabel(requestedModelId)} again.` } function buildServerRestoredNotice(requestedModelId: string): string { @@ -5414,6 +5415,7 @@ const anthropicAuthPlugin = async ( storage: AccountStorage | null, auth: { access?: string; refresh?: string }, ) { + logServedServerFallback(plan.sessionId, outcome) if (outcome.fallback && outcome.targetModel) { const previousTarget = serverFallbackTargets.get(plan.recoveryKey) serverFallbackTargets.delete(plan.recoveryKey) @@ -5433,16 +5435,6 @@ const anthropicAuthPlugin = async ( ) { return } - logger.info( - 'fable-fallback', - 'Anthropic server-side safety fallback active', - { - session: plan.sessionId, - requestedModel: plan.requestedModel, - targetModel: outcome.targetModel, - handoff: outcome.handoff, - }, - ) publishFableRecoveryNotice( { sessionId: plan.sessionId, @@ -10038,22 +10030,20 @@ const anthropicAuthPlugin = async ( ...(serverFallbackModel ? { serverSideFallbackModel: serverFallbackModel, - ...(fablePlan - ? { - onServerSideFallbackOutcome: ( - outcome: ServerSideFallbackOutcome, - ) => { - if (fableRequest) - fableRequest.serverFallback = outcome.fallback - observeServerFallbackOutcome( - fablePlan, - outcome, - storage, - auth, - ) - }, - } - : {}), + onServerSideFallbackOutcome: ( + outcome: ServerSideFallbackOutcome, + ) => { + if (fableRequest) + fableRequest.serverFallback = outcome.fallback + if (fablePlan) + observeServerFallbackOutcome( + fablePlan, + outcome, + storage, + auth, + ) + else logServedServerFallback(sessionId, outcome) + }, } : {}), }) diff --git a/packages/opencode/src/server-fallback.ts b/packages/opencode/src/server-fallback.ts index 42590f1c9..9be119406 100644 --- a/packages/opencode/src/server-fallback.ts +++ b/packages/opencode/src/server-fallback.ts @@ -1,4 +1,6 @@ import { + logger, + normalizeAnthropicModelId, resolveClaudeModelCapabilities, SERVER_FALLBACK_USAGE_MARKER_TEXT, SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX, @@ -14,45 +16,73 @@ export { SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX, } -function usageMarkerSignature(usage: Record | undefined) { +type ServerSideFallbackIteration = { + model: string + input_tokens: number + output_tokens: number + cache_read_input_tokens?: number + cache_creation_input_tokens?: number + cache_creation?: { + ephemeral_5m_input_tokens?: number + ephemeral_1h_input_tokens?: number + } +} + +function tokenCount(value: unknown): value is number { + return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 +} + +function validateFallbackUsage(usage: Record | undefined) { const raw = usage?.iterations if (!Array.isArray(raw) || raw.length === 0 || raw.length > 8) return - const iterations: Record[] = [] + const iterations: Array< + ServerSideFallbackIteration & { type: 'message' | 'fallback_message' } + > = [] for (const value of raw) { const iteration = asRecord(value) if ( !iteration || (iteration.type !== 'message' && iteration.type !== 'fallback_message') || - !safeModelId(iteration.model) + !safeModelId(iteration.model) || + !tokenCount(iteration.input_tokens) || + !tokenCount(iteration.output_tokens) ) return - const clean: Record = { + const clean: (typeof iterations)[number] = { type: iteration.type, model: iteration.model, + input_tokens: iteration.input_tokens, + output_tokens: iteration.output_tokens, } for (const field of [ - 'input_tokens', - 'output_tokens', 'cache_read_input_tokens', 'cache_creation_input_tokens', - ]) { + ] as const) { const count = iteration[field] - if (count === undefined && field.startsWith('cache_')) continue - if ( - typeof count !== 'number' || - !Number.isSafeInteger(count) || - count < 0 - ) - return + if (count === undefined) continue + if (!tokenCount(count)) return clean[field] = count } + const cacheCreation = asRecord(iteration.cache_creation) + for (const field of [ + 'ephemeral_5m_input_tokens', + 'ephemeral_1h_input_tokens', + ] as const) { + const count = cacheCreation?.[field] + if (!tokenCount(count)) continue + clean.cache_creation ??= {} + clean.cache_creation[field] = count + } iterations.push(clean) } if (!iterations.some((iteration) => iteration.type === 'fallback_message')) return const payload = JSON.stringify({ iterations }) if (payload.length > 4096) return - return SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX + payload + return { + iterations, + signature: SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX + payload, + } } export type ContentFilterFallbackMode = 'server' | 'legacy' @@ -64,6 +94,42 @@ export type ServerSideFallbackOutcome = { fallback: boolean handoff: boolean stopReason: string + iterations: ServerSideFallbackIteration[] +} + +const LOGGABLE_STOP_REASONS = new Set([ + 'end_turn', + 'max_tokens', + 'stop_sequence', + 'tool_use', + 'pause_turn', + 'refusal', + 'model_context_window_exceeded', +]) + +export function logServedServerFallback( + session: string | null, + outcome: ServerSideFallbackOutcome, +) { + if (!outcome.fallback || !outcome.targetModel) return + logger.info( + 'server-fallback', + 'Anthropic server-side safety fallback served step', + { + session, + requestedModel: safeModelId( + normalizeAnthropicModelId(outcome.requestedModel), + ) + ? outcome.requestedModel + : 'unknown', + servedModel: outcome.targetModel, + handoff: outcome.handoff, + stopReason: LOGGABLE_STOP_REASONS.has(outcome.stopReason) + ? outcome.stopReason + : 'unknown', + iterations: outcome.iterations, + }, + ) } type ServerSideFallbackMarker = { @@ -291,7 +357,10 @@ export function createServerSideFallbackStreamRewriter(options: { } } - const complete = (stopReason: string) => { + const complete = ( + stopReason: string, + usage: ReturnType, + ) => { if (completed) return completed = true const targetModel = @@ -307,6 +376,8 @@ export function createServerSideFallbackStreamRewriter(options: { fallback: Boolean(targetModel), handoff: Boolean(handoff), stopReason, + iterations: + usage?.iterations.map(({ type: _type, ...counts }) => counts) ?? [], }) } @@ -357,31 +428,29 @@ export function createServerSideFallbackStreamRewriter(options: { hasCompletedToolUse = true } } else if (type === 'message_delta') { - observeIterations(asRecord(data?.usage)) + const usage = asRecord(data?.usage) + observeIterations(usage) const delta = asRecord(data?.delta) const stopReason = stringField(delta, 'stop_reason') - if (stopReason) complete(stopReason) + const fallbackUsage = + stopReason && !usageMarkerEmitted + ? validateFallbackUsage(usage) + : undefined + if (stopReason) complete(stopReason, fallbackUsage) let usageMarker = '' - if ( - stopReason && - !usageMarkerEmitted && - maxBlockIndex < Number.MAX_SAFE_INTEGER - ) { - const signature = usageMarkerSignature(asRecord(data?.usage)) - if (signature) { - usageMarkerEmitted = true - const index = ++maxBlockIndex - usageMarker = - hiddenThinkingFrames( - index, - SERVER_FALLBACK_USAGE_MARKER_TEXT, - signature, - ) + - sseFrame('content_block_stop', { - type: 'content_block_stop', - index, - }) - } + if (fallbackUsage && maxBlockIndex < Number.MAX_SAFE_INTEGER) { + usageMarkerEmitted = true + const index = ++maxBlockIndex + usageMarker = + hiddenThinkingFrames( + index, + SERVER_FALLBACK_USAGE_MARKER_TEXT, + fallbackUsage.signature, + ) + + sseFrame('content_block_stop', { + type: 'content_block_stop', + index, + }) } if ( stopReason === 'refusal' && diff --git a/packages/opencode/src/tests/opencode2-adapter.test.ts b/packages/opencode/src/tests/opencode2-adapter.test.ts index 95082e0dc..c3755264a 100644 --- a/packages/opencode/src/tests/opencode2-adapter.test.ts +++ b/packages/opencode/src/tests/opencode2-adapter.test.ts @@ -98,6 +98,7 @@ const ENV_KEYS = [ 'ANTHROPIC_DEFAULT_OPUS_MODEL', 'ANTHROPIC_DEFAULT_HAIKU_MODEL', 'ANTHROPIC_DEFAULT_FABLE_MODEL', + 'OPENCODE_ANTHROPIC_AUTH_CONTENT_FILTER_FALLBACK', ] const savedEnv = new Map() const routingKey = Symbol.for('cortexkit.routing') @@ -938,6 +939,134 @@ describe('OpenCode 2 native Anthropic adapter: request shape', () => { ).toHaveLength(3) }) + test('logs one INFO record with only validated metadata for each server fallback step', async () => { + const wire = createNativeWirePolicy() + const { source } = makeSource({ + options: { serverSideFallbackEnabled: true }, + responseOptions: wire.responseOptions, + }) + const native = createNativeAnthropicAdapter({ source }) + const host = new Host(native.adapter) + const info = spyOn(core.logger, 'info').mockImplementation(() => {}) + const requestedModel = 'claude-opus-5-5' + const servedModel = 'claude-opus-4-8' + const responseText = 'Distinctive fallback response text, not log data' + const stopReasonText = 'Unrecognized stop reason, not log data' + const iterations = [ + { + model: requestedModel, + input_tokens: 100, + output_tokens: 0, + cache_read_input_tokens: 0, + cache_creation_input_tokens: 390, + cache_creation: { + ephemeral_5m_input_tokens: 90, + ephemeral_1h_input_tokens: 300, + }, + }, + { + model: servedModel, + input_tokens: 120, + output_tokens: 80, + cache_read_input_tokens: 380, + cache_creation_input_tokens: 10, + }, + ] + const scope = scopeOf({ modelID: `${requestedModel}[1m]` }) + try { + for (const step of ['handoff', 'sticky', 'primary', 'dated-alias']) { + const modelID = + step === 'dated-alias' ? 'claude-haiku-4-5' : scope.modelID + const { attempt, final } = await host.run( + { ...scope, modelID }, + hostRequest({ ...sonnetPayload(), model: modelID, stream: true }), + ) + const frames = [ + sse('message_start', { + type: 'message_start', + message: { + model: + step === 'sticky' + ? servedModel + : step === 'dated-alias' + ? 'claude-haiku-4-5-20251001' + : requestedModel, + }, + }), + ...(step === 'handoff' + ? [ + sse('content_block_start', { + type: 'content_block_start', + index: 0, + content_block: { + type: 'fallback', + from: { model: requestedModel }, + to: { model: servedModel }, + }, + }), + sse('content_block_stop', { + type: 'content_block_stop', + index: 0, + }), + ] + : []), + sse('content_block_start', { + type: 'content_block_start', + index: 1, + content_block: { type: 'text', text: '' }, + }), + sse('content_block_delta', { + type: 'content_block_delta', + index: 1, + delta: { type: 'text_delta', text: responseText }, + }), + sse('content_block_stop', { type: 'content_block_stop', index: 1 }), + sse('message_delta', { + type: 'message_delta', + delta: { + stop_reason: step === 'sticky' ? stopReasonText : 'end_turn', + }, + usage: { + iterations: + step === 'handoff' || step === 'sticky' + ? [ + { ...iterations[0], type: 'message', text: responseText }, + { ...iterations[1], type: 'fallback_message' }, + ] + : [], + }, + }), + sse('message_stop', { type: 'message_stop' }), + ] + const response = await native.adapter.rewriteResponse?.({ + ...attempt, + attempt, + request: final, + response: sseResponse(frames.join('')), + }) + expect(await response?.text()).toContain(responseText) + } + const records = info.mock.calls.filter( + ([channel]) => channel === 'server-fallback', + ) + expect(records.map(([, , payload]) => payload)).toEqual( + [true, false].map((handoff) => ({ + session: scope.sessionID, + requestedModel: scope.modelID, + servedModel, + handoff, + stopReason: handoff ? 'end_turn' : 'unknown', + iterations, + })), + ) + expect(JSON.stringify(records)).not.toContain(responseText) + expect(JSON.stringify(records)).not.toContain(stopReasonText) + } finally { + info.mockRestore() + native.dispose() + } + }) + test('OAuth send carries the Claude Code wire shape, signed body and betas', async () => { const { source } = makeSource() const native = createNativeAnthropicAdapter({ source }) diff --git a/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts b/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts index 996b2d63f..3c8d16824 100644 --- a/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts +++ b/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts @@ -1,6 +1,7 @@ -import { describe, expect, mock } from 'bun:test' +import { describe, expect, mock, spyOn } from 'bun:test' import { type AccountStorage, + logger, tokenFingerprint, } from '@cortexkit/anthropic-auth-core' import { @@ -141,19 +142,33 @@ describe('auth.loader', () => { }), { models: {} }, ) - const response = await result.fetch(MESSAGES_URL, { - method: 'POST', - body: JSON.stringify({ - model: 'claude-fable-5', - stream: true, - messages: [{ role: 'user', content: 'hello' }], - }), - }) - const responseText = await response.text() + const info = spyOn(logger, 'info').mockImplementation(() => {}) + try { + const response = await result.fetch(MESSAGES_URL, { + method: 'POST', + body: JSON.stringify({ + model: 'claude-fable-5', + stream: true, + messages: [{ role: 'user', content: 'hello' }], + }), + }) + const responseText = await response.text() - expect(sentBody?.fallbacks).toBe('default') - expect(responseText).not.toContain('"type":"fallback","from"') - expect(responseText).toContain(SERVER_FALLBACK_SIGNATURE_PREFIX) + expect(sentBody?.fallbacks).toBe('default') + expect(responseText).not.toContain('"type":"fallback","from"') + expect(responseText).toContain(SERVER_FALLBACK_SIGNATURE_PREFIX) + const records = info.mock.calls.filter( + ([channel]) => channel === 'server-fallback', + ) + expect(records.map(([, , payload]) => payload)).toEqual([ + expect.objectContaining({ + session: null, + servedModel: 'claude-opus-5', + }), + ]) + } finally { + info.mockRestore() + } }) const assertServerFallbackTransitions = async (modelId: string) => { @@ -320,14 +335,31 @@ describe('auth.loader', () => { }), } - const fallbackResponse = await result.fetch(MESSAGES_URL, request) - const fallbackResponseText = await fallbackResponse.text() - expect(fallbackResponseText).toContain('fallback answer') - expect(fallbackResponseText).not.toContain('"type":"fallback","from"') - expect(fallbackResponseText).toContain(SERVER_FALLBACK_SIGNATURE_PREFIX) - expect(requestBodies).toHaveLength(1) - expect(requestBodies[0]?.fallbacks).toBe('default') - expect(requestBetas[0]?.split(',')).toContain(SERVER_SIDE_FALLBACK_BETA) + const info = spyOn(logger, 'info').mockImplementation(() => {}) + try { + const fallbackResponse = await result.fetch(MESSAGES_URL, request) + const fallbackResponseText = await fallbackResponse.text() + expect(fallbackResponseText).toContain('fallback answer') + expect(fallbackResponseText).not.toContain('"type":"fallback","from"') + expect(fallbackResponseText).toContain(SERVER_FALLBACK_SIGNATURE_PREFIX) + expect(requestBodies).toHaveLength(1) + expect(requestBodies[0]?.fallbacks).toBe('default') + expect(requestBetas[0]?.split(',')).toContain(SERVER_SIDE_FALLBACK_BETA) + + modelRequest = 0 + const nextResponse = await result.fetch(MESSAGES_URL, request) + await expect(nextResponse.text()).resolves.toContain('fallback answer') + expect(requestBodies[1]?.fallbacks).toBe('default') + expect( + info.mock.calls.filter( + ([channel, message]) => + channel === 'server-fallback' || + message === 'Anthropic server-side safety fallback active', + ), + ).toHaveLength(2) + } finally { + info.mockRestore() + } const switched = await waitForSidebarState((state) => Boolean( state.fableRecoveries?.some( @@ -399,9 +431,7 @@ describe('auth.loader', () => { noReply: true, parts: [ expect.objectContaining({ - text: expect.stringContaining( - `Anthropic safety fallback active: ${label} → Opus 5`, - ), + text: `Anthropic's safety fallback served this step on Opus 5; the next step tries ${label} again.`, }), ], }), diff --git a/packages/opencode/src/tests/server-fallback.test.ts b/packages/opencode/src/tests/server-fallback.test.ts index 8263c6915..5aa53c6a2 100644 --- a/packages/opencode/src/tests/server-fallback.test.ts +++ b/packages/opencode/src/tests/server-fallback.test.ts @@ -23,6 +23,10 @@ const iterations = [ cache_read_input_tokens: 400_000, cache_creation_input_tokens: 500, output_tokens: 0, + cache_creation: { + ephemeral_5m_input_tokens: 0, + ephemeral_1h_input_tokens: 500, + }, }, { type: 'fallback_message', @@ -402,8 +406,10 @@ describe('createServerSideFallbackStreamRewriter', () => { test('exposes terminal fallback iterations in a separate complete hidden marker without changing billed usage', async () => { for (const handoff of [true, false]) { const { beforeTerminal, terminal } = usageStream(terminalUsage, handoff) + const outcomes: ServerSideFallbackOutcome[] = [] const rewriter = createServerSideFallbackStreamRewriter({ requestedModel: 'claude-opus-5-5', + onOutcome: (outcome) => outcomes.push(outcome), }) const early = rewriter.push(beforeTerminal) expect(early).toContain('fallback answer') @@ -439,6 +445,11 @@ describe('createServerSideFallbackStreamRewriter', () => { ), ), ).toEqual({ iterations }) + expect(outcomes).toEqual([ + expect.objectContaining({ + iterations: iterations.map(({ type: _type, ...counts }) => counts), + }), + ]) expect(frames[3].usage).toEqual(terminalUsage) const wrapped = createStrippedStream( new Response(beforeTerminal + terminal), @@ -451,10 +462,12 @@ describe('createServerSideFallbackStreamRewriter', () => { }) test('bounds fallback usage metadata and ignores unknown fields', () => { + const outcomes: ServerSideFallbackOutcome[] = [] const rewrite = (usage: unknown) => { const { beforeTerminal, terminal } = usageStream(usage) const rewriter = createServerSideFallbackStreamRewriter({ requestedModel: 'claude-opus-5-5', + onOutcome: (outcome) => outcomes.push(outcome), }) return rewriter.push(beforeTerminal + terminal) + rewriter.flush() } @@ -495,6 +508,7 @@ describe('createServerSideFallbackStreamRewriter', () => { expect(rewrite({ ...terminalUsage, iterations: invalid })).not.toContain( SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX, ) + expect(outcomes.at(-1)?.iterations).toEqual([]) } }) @@ -569,6 +583,7 @@ describe('createServerSideFallbackStreamRewriter', () => { fallback: true, handoff: true, stopReason: 'end_turn', + iterations: [], }, ]) }) diff --git a/packages/opencode/src/v2/wire.ts b/packages/opencode/src/v2/wire.ts index d8ec299a3..8e980fe89 100644 --- a/packages/opencode/src/v2/wire.ts +++ b/packages/opencode/src/v2/wire.ts @@ -2,6 +2,7 @@ import { type NativeAccountSnapshot, readThreeWayBoolean, remapModelId, + resolveClaudeModelCapabilities, } from '@cortexkit/anthropic-auth-core' import type { Plugin } from '@opencode/plugin' import type { Registration } from '@opencode/plugin/promise/registration' @@ -11,13 +12,25 @@ import { BillingLineageTracker, } from '../billing-lineage' import { LANE_START_REQUEST_HEADER, LANE_START_TEXT } from '../lane-start' -import { resolveContentFilterFallbackMode } from '../server-fallback' +import { + logServedServerFallback, + resolveContentFilterFallbackMode, + type ServerSideFallbackOutcome, +} from '../server-fallback' import type { NativeAnthropicRequestContext, NativeAnthropicResponseContext, } from './adapter' import type { NativeSourceProvenance } from './source' +function serverSideFallbackEnabled() { + return ( + resolveContentFilterFallbackMode( + process.env.OPENCODE_ANTHROPIC_AUTH_CONTENT_FILTER_FALLBACK, + ) === 'server' + ) +} + /** * Claude Code's billing header names the user prompt a request belongs to and * the provider request-id of the previous request for that prompt. Track that @@ -152,10 +165,7 @@ export function createNativeWirePolicy() { midConversationEffortEnabled: false, turnEndNoteEnabled: true, turnEndNote: snapshot.policyStorage.turnEndNote, - serverSideFallbackEnabled: - resolveContentFilterFallbackMode( - process.env.OPENCODE_ANTHROPIC_AUTH_CONTENT_FILTER_FALLBACK, - ) === 'server', + serverSideFallbackEnabled: serverSideFallbackEnabled(), laneStart, billingLineage: lineage ? { @@ -167,10 +177,21 @@ export function createNativeWirePolicy() { } }, responseOptions( - input: NativeAnthropicResponseContext, + input: Pick< + NativeAnthropicResponseContext, + 'attemptId' | 'modelID' | 'sessionID' | 'kind' + >, ) { + const model = remapModelId(input.modelID) + // A dated model alias can differ from the requested ID without a fallback. + const canFallback = + serverSideFallbackEnabled() && + resolveClaudeModelCapabilities(model)?.serverSideFallback === true return { - serverSideFallbackModel: remapModelId(input.modelID), + serverSideFallbackModel: model, + onServerSideFallbackOutcome(outcome: ServerSideFallbackOutcome) { + if (canFallback) logServedServerFallback(input.sessionID, outcome) + }, laneStart: laneAttempts.has(input.attemptId), onMessageStart(message: Record) { if (input.kind === 'primary' && typeof message.id === 'string') { From 13d6ce0bd16a97ff8d39ca15665e621290124d50 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Sun, 22 Nov 2026 10:30:14 +0100 Subject: [PATCH 2/3] Changelog wording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9fd1bc7d..744e548f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This repo is a CortexKit-maintained Anthropic auth monorepo for OpenCode and Pi. ## Unreleased -- OpenCode 1 and 2: every step served by Anthropic's safety fallback now writes one log line with per-attempt token counts; OpenCode 2 previously logged nothing. Addresses #861. +- OpenCode 1 and 2: every step served by Anthropic's safety fallback now writes one log line with per-attempt token counts; OpenCode 2 previously logged nothing. The safety-fallback notice no longer says follow-up requests stay on the fallback model. ## 2.16.4 From 0d8b5c22f7e1fdd1126a95d888c7a24b4129ff11 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Sun, 22 Nov 2026 10:36:03 +0100 Subject: [PATCH 3/3] Keep the 'Anthropic safety fallback' phrase in the notice --- packages/opencode/src/index.ts | 2 +- .../src/tests/refusal-and-server-fallback.integration.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index d39379276..16a69311c 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -969,7 +969,7 @@ function buildServerFallbackNotice( requestedModelId: string, targetModelId: string, ): string { - return `Anthropic's safety fallback served this step on ${fallbackModelLabel(targetModelId)}; the next step tries ${fallbackModelLabel(requestedModelId)} again.` + return `Anthropic safety fallback served this step on ${fallbackModelLabel(targetModelId)}; the next step tries ${fallbackModelLabel(requestedModelId)} again.` } function buildServerRestoredNotice(requestedModelId: string): string { diff --git a/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts b/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts index 3c8d16824..83bd6b382 100644 --- a/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts +++ b/packages/opencode/src/tests/refusal-and-server-fallback.integration.test.ts @@ -431,7 +431,7 @@ describe('auth.loader', () => { noReply: true, parts: [ expect.objectContaining({ - text: `Anthropic's safety fallback served this step on Opus 5; the next step tries ${label} again.`, + text: `Anthropic safety fallback served this step on Opus 5; the next step tries ${label} again.`, }), ], }),