Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/pool/failover-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ export class FailoverRunner {
model,
repaired,
oauth401CooldownMs: this.config.oauth_401_cooldown_ms,
signatureRepair: signatureRepairEnabled(this.config),
signatureRepair: signatureRepairEnabled(this.config) || attemptMeta?.foreignThinking === true,
},
this.scheduler?.accountQuota,
)
Expand Down
3 changes: 3 additions & 0 deletions src/lib/protocol/handle-protocol.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,9 @@ export function createHandleProtocol(deps) {
sessionId: attemptSessionId,
cliHop: true,
cragPrint: true,
// CRAG replays caller thinking unfiltered; signatures this pool never
// issued make an "Invalid signature" 400 safe to strip and retry.
foreignThinking: owned.converted + owned.dropped > 0,
callerCwd: callerEnvironment?.cwd,
preparedHop,
transportRouting,
Expand Down
67 changes: 67 additions & 0 deletions test/unit/failover-runner.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2232,3 +2232,70 @@ test('a slot that cannot refresh its credential hops and cools down', async () =
assert.equal(scheduler.cooldowns[0].update.reason, 'credential_refresh_failed')
assert.equal(scheduler.cooldowns[0].update.status, 'cooldown')
})

test('signature 400 on a hop that replayed foreign thinking is stripped and retried with the switch off', async () => {
const scheduler = new Scheduler([candidate(1)])
const runner = new FailoverRunner({ scheduler })
const seen = []
const result = await runner.run({
requestId: 'req-foreign-sig',
canonicalBody: {
model: 'claude-opus-test',
thinking: { type: 'adaptive' },
messages: [
{ role: 'user', content: 'q' },
{
role: 'assistant',
content: [
{ type: 'thinking', thinking: '', signature: 'other-pool-signature' },
{ type: 'text', text: 'keep' },
],
},
{ role: 'user', content: 'next' },
],
},
model: 'claude-opus-test',
applyAttempt: (body, _selected, extra) => {
seen.push(extra.repairs)
return { body, meta: { foreignThinking: true } }
},
callAttempt: ({ body }) => {
if (seen.length === 1) {
return {
ok: false,
status: 400,
terminalState: 'error',
body: { error: { message: 'messages.1.content.0: Invalid `signature` in `thinking` block' } },
}
}
assert.deepEqual(body.messages[1].content, [{ type: 'text', text: 'keep' }])
return success('stripped')
},
})
assert.equal(result.ok, true)
assert.equal(seen.length, 2)
assert.deepEqual(seen[1], [{ action: 'repair-and-retry', reason: 'signature_repairable' }])
})

test('signature 400 without foreign thinking still surfaces with the switch off', async () => {
const scheduler = new Scheduler([candidate(1)])
const runner = new FailoverRunner({ scheduler })
let calls = 0
const result = await runner.run({
requestId: 'req-own-sig',
canonicalBody: { model: 'claude-opus-test', messages: [{ role: 'user', content: 'q' }] },
model: 'claude-opus-test',
applyAttempt: (body) => ({ body, meta: { foreignThinking: false } }),
callAttempt: () => {
calls++
return {
ok: false,
status: 400,
terminalState: 'error',
body: { error: { message: 'Invalid `signature` in `thinking` block' } },
}
},
})
assert.equal(result.status, 400)
assert.equal(calls, 1)
})
Loading