Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
v0.46.6.1 fix(gateway): give routed Claude 5 models output headroom (#4087) (#4190)
Javier Aldapef4b233e8e35d
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex 3fa709a390..bb7b6cce1d 100644--- a/scripts/module-size-limits.tsv+++ b/scripts/module-size-limits.tsv@@ -9,7 +9,7 @@ src/core/postgres-engine.ts 5770 ratchet peel target: containment sprint C15; grsrc/core/pglite-engine.ts 5660 ratchet peel target: containment sprint C15; grown v0.46.11.0 five-issue wavesrc/core/migrate.ts 668 region-exempt append-only MIGRATIONS array grows freely; runner logic is ratchetedsrc/commands/sync.ts 4300 ratchet peel target: containment sprint C13-C14; grown v0.46.11.0 five-issue wave-src/core/ai/gateway.ts 4116 ratchet watchlist+src/core/ai/gateway.ts 4117 ratchet watchlistsrc/cli.ts 3337 ratchet watchlistsrc/core/cycle.ts 2933 ratchetsrc/commands/serve-http.ts 2836 ratchetdiff --git a/src/core/ai/gateway.ts b/src/core/ai/gateway.tsindex 4dc872ef59..4edaadc889 100644--- a/src/core/ai/gateway.ts+++ b/src/core/ai/gateway.ts@@ -2730,7 +2730,8 @@ export interface ChatToolDef {*//*** Default per-call max output tokens. Thinking-by-default Claude 5 models- * (`anthropic:claude-*-5`) burn a large chunk of the budget on internal+ * (`anthropic:claude-*-5`, including routed forms like+ * `openrouter:anthropic/claude-*-5`) burn a large chunk of the budget on internal* reasoning before emitting any text, so a 4096 default leaves them with empty* final text on the subagent tool loop. Give those models headroom; providers* bill actual tokens, not the cap, so it is free for the models that don't use@@ -2741,7 +2742,7 @@ export interface ChatToolDef {*/const DEFAULT_MAX_OUTPUT_TOKENS = 4096;const THINKING_MODEL_MAX_OUTPUT_TOKENS = 32000;-const THINKING_BY_DEFAULT_MODEL_RE = /^anthropic[:/]claude-[a-z0-9]+-5(?:[.-]|$)/i;+const THINKING_BY_DEFAULT_MODEL_RE = /(?:^|[:/])anthropic[:/]claude-[a-z0-9]+-5(?:[.-]|$)/i;function defaultMaxOutputTokens(modelStr: string | undefined): number {return modelStr && THINKING_BY_DEFAULT_MODEL_RE.test(modelStr)? THINKING_MODEL_MAX_OUTPUT_TOKENSdiff --git a/test/ai/gateway-tool-loop.test.ts b/test/ai/gateway-tool-loop.test.tsindex 4e6fb60c04..adafe277c5 100644--- a/test/ai/gateway-tool-loop.test.ts+++ b/test/ai/gateway-tool-loop.test.ts@@ -271,7 +271,7 @@ describe('gateway.toolLoop (v0.38 D11 — provider-agnostic loop control)', () =).rejects.toThrow(/non-idempotent.*pending/i);});- it('defaults max output tokens per model: 4096 for non-thinking, 32000 for Claude 5', async () => {+ it('defaults max output tokens per model: 4096 for non-thinking, 32000 for routed Claude 5', async () => {const seen: Array<number | undefined> = [];__setChatTransportForTests(async (opts) => {seen.push(opts.maxTokens);@@ -289,10 +289,13 @@ describe('gateway.toolLoop (v0.38 D11 — provider-agnostic loop control)', () =await toolLoop({ model: 'anthropic:claude-sonnet-4-6', initialMessages: [{ role: 'user', content: 'hi' }], tools: [], toolHandlers: new Map() });await toolLoop({ model: 'anthropic:claude-sonnet-5', initialMessages: [{ role: 'user', content: 'hi' }], tools: [], toolHandlers: new Map() });await toolLoop({ model: 'anthropic:claude-fable-5', initialMessages: [{ role: 'user', content: 'hi' }], tools: [], toolHandlers: new Map() });+ await toolLoop({ model: 'openrouter:anthropic/claude-sonnet-5', initialMessages: [{ role: 'user', content: 'hi' }], tools: [], toolHandlers: new Map() });+ await toolLoop({ model: 'openrouter:openai/gpt-5.2', initialMessages: [{ role: 'user', content: 'hi' }], tools: [], toolHandlers: new Map() });// Non-thinking / non-Claude-5 stay 4096 (safe under openai-compat caps);- // thinking-by-default Claude 5 models get 32000 headroom.- expect(seen).toEqual([4096, 4096, 32000, 32000]);+ // thinking-by-default Claude 5 models get 32000 headroom, even when+ // reached through an OpenRouter provider prefix.+ expect(seen).toEqual([4096, 4096, 32000, 32000, 32000, 4096]);});it('hits max_turns when the model keeps calling tools', async () => {