fix(openrouter): use endpoint context limits#85949
Conversation
7699652 to
f4ca87a
Compare
|
Codex review: needs maintainer review before merge. Latest ClawSweeper review: 2026-05-24 06:25 UTC / May 24, 2026, 2:25 AM ET. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
PR Surface View PR surface stats
Summary Reproducibility: yes. The reporter's live error, current public OpenRouter catalog, and current-main parser path together reproduce the bad budget calculation without needing private credentials. PR rating What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land this focused parser and regression-test fix after normal maintainer checks, preserving the fallback to top-level Do we have a high-confidence way to reproduce the issue? Yes. The reporter's live error, current public OpenRouter catalog, and current-main parser path together reproduce the bad budget calculation without needing private credentials. Is this the best way to solve the issue? Yes. Preferring Label changes:
Label justifications:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 56eb23dda4dd. |
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Moonlit Merge Sprite Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
|
@clawsweeper automerge |
|
🦞🔧
Draft PRs stay fix-only until GitHub marks them ready for review. Pause with Automerge progress:
|
|
ClawSweeper 🐠 reef update Thanks for the work on this. ClawSweeper did not have permission to update this branch directly, so it opened a narrow replacement PR instead. that's a branch access thing, not a knock on the contribution. Why replacement: ClawSweeper could not update the source PR branch directly; GitHub did not grant sufficient push rights to the bot for that branch.
fish notes: model gpt-5.5, reasoning high; reviewed against d193cae. |
Summary
top_provider.context_lengthwhen parsing dynamic model capabilities.context_lengthas the fallback when endpoint-specific metadata is absent.nvidia/nemotron-3-super-120b-a12b:freecatalog shape.Fixes #85921.
Verification
node scripts/run-vitest.mjs src/agents/pi-embedded-runner/openrouter-model-capabilities.test.ts src/agents/pi-embedded-runner/model.test.ts src/agents/openai-transport-stream.test.tsgit diff --checkpnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/openrouter-model-capabilities.ts src/agents/pi-embedded-runner/openrouter-model-capabilities.test.tsReal behavior proof
Behavior addressed: dynamic OpenRouter models with a larger top-level catalog context length but a smaller routed endpoint context length no longer carry the larger top-level value into OpenClaw's effective runtime context budget. That prevents the OpenAI-compatible transport from treating the full endpoint context as available output budget for the reported model.
Real environment tested: local macOS OpenClaw checkout on this PR branch, plus a live public OpenRouter catalog lookup for
nvidia/nemotron-3-super-120b-a12b:free.Exact steps or command run after this patch: fetched
https://openrouter.ai/api/v1/modelswithout credentials, loaded the same model through the patched OpenRouter capability parser with a temporaryOPENCLAW_STATE_DIR, then printed the raw catalog fields and parsed runtime caps.Evidence after fix:
{ "modelId": "nvidia/nemotron-3-super-120b-a12b:free", "raw": { "context_length": 1000000, "top_provider": { "context_length": 262144, "max_completion_tokens": 262144 } }, "parsed": { "contextWindow": 262144, "maxTokens": 262144 } }Observed result after fix: the parser now resolves the runtime
contextWindowto the endpoint-specific262144token limit instead of the top-level1000000token catalog window, while preserving the endpointmaxTokenscap.What was not tested: authenticated live OpenRouter inference was not run; the reported failure is proven from the public live catalog shape, the parser output, and the focused transport/model tests.
Authorship note: Please preserve author attribution for Andy Ye 35905412+TurboTheTurtle@users.noreply.github.com when squashing or reworking this PR, or include
Co-authored-by: Andy Ye <35905412+TurboTheTurtle@users.noreply.github.com>.