Skip to content

fix(openrouter): use endpoint context limits#85949

Closed
TurboTheTurtle wants to merge 1 commit into
openclaw:mainfrom
TurboTheTurtle:fix/openrouter-top-provider-context-85921
Closed

fix(openrouter): use endpoint context limits#85949
TurboTheTurtle wants to merge 1 commit into
openclaw:mainfrom
TurboTheTurtle:fix/openrouter-top-provider-context-85921

Conversation

@TurboTheTurtle

@TurboTheTurtle TurboTheTurtle commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Prefer OpenRouter top_provider.context_length when parsing dynamic model capabilities.
  • Keep top-level context_length as the fallback when endpoint-specific metadata is absent.
  • Add regression coverage for the reported nvidia/nemotron-3-super-120b-a12b:free catalog 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.ts
  • git diff --check
  • pnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/openrouter-model-capabilities.ts src/agents/pi-embedded-runner/openrouter-model-capabilities.test.ts

Real 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/models without credentials, loaded the same model through the patched OpenRouter capability parser with a temporary OPENCLAW_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 contextWindow to the endpoint-specific 262144 token limit instead of the top-level 1000000 token catalog window, while preserving the endpoint maxTokens cap.

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>.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels May 24, 2026
@TurboTheTurtle TurboTheTurtle force-pushed the fix/openrouter-top-provider-context-85921 branch from 7699652 to f4ca87a Compare May 24, 2026 06:16
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

PR Surface
Source +1, Tests +42. Total +43 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 42 0 +42
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 44 1 +43

Summary
The PR adds OpenRouter top_provider.context_length parsing so dynamic models prefer endpoint-specific context limits, with a regression test for the Nemotron catalog shape.

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
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Summary: Small, well-targeted bug fix with source-backed root cause, focused regression coverage, and sufficient live-output proof.

What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
Sufficient (live_output): The PR body includes copied live output from a public OpenRouter catalog lookup and patched parser output showing the corrected runtime caps after the fix.

Risk before merge

  • Authenticated live OpenRouter inference was not shown, but the bug and fix are well supported by the reporter's live error, the public catalog shape, parser output, and focused tests.

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused parser and regression-test fix after normal maintainer checks, preserving the fallback to top-level context_length when endpoint-specific metadata is absent.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge
No repair lane is needed; this active PR already contains the narrow code and test change and is ready for normal maintainer review/merge gates.

Security
Cleared: The diff is limited to OpenRouter parser metadata and a focused test; it does not touch secrets, dependencies, workflows, install scripts, or other supply-chain surfaces.

Review details

Best possible solution:

Land this focused parser and regression-test fix after normal maintainer checks, preserving the fallback to top-level context_length when endpoint-specific metadata is absent.

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 top_provider.context_length in the existing OpenRouter capability parser is the narrow owner-boundary fix, and the PR keeps the top-level fallback for catalog entries without endpoint metadata.

Label changes:

  • add P1: The PR fixes an urgent OpenRouter regression that can make affected agent turns fail immediately after upgrade.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output from a public OpenRouter catalog lookup and patched parser output showing the corrected runtime caps after the fix.
  • add rating: 🦞 diamond lobster: Current PR rating is 🦞 diamond lobster because proof is 🦞 diamond lobster, patch quality is 🦞 diamond lobster, and Small, well-targeted bug fix with source-backed root cause, focused regression coverage, and sufficient live-output proof.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from a public OpenRouter catalog lookup and patched parser output showing the corrected runtime caps after the fix.

Label justifications:

  • P1: The PR fixes an urgent OpenRouter regression that can make affected agent turns fail immediately after upgrade.
  • rating: 🦞 diamond lobster: Current PR rating is 🦞 diamond lobster because proof is 🦞 diamond lobster, patch quality is 🦞 diamond lobster, and Small, well-targeted bug fix with source-backed root cause, focused regression coverage, and sufficient live-output proof.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from a public OpenRouter catalog lookup and patched parser output showing the corrected runtime caps after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output from a public OpenRouter catalog lookup and patched parser output showing the corrected runtime caps after the fix.

What I checked:

Likely related people:

  • Peter Steinberger: Blame shows the current OpenRouter dynamic capability parser, including top-level context_length and top_provider.max_completion_tokens, came in through commit 6a48258. (role: introduced current parser behavior; confidence: high; commits: 6a482584ee62; files: src/agents/pi-embedded-runner/openrouter-model-capabilities.ts, src/agents/pi-embedded-runner/openrouter-model-capabilities.test.ts, extensions/openrouter/index.ts)
  • rendrag-git: Authored the current proxy-like completions max-token clamp and tests that rely on the effective runtime context budget this PR corrects for OpenRouter. (role: recent adjacent contributor; confidence: high; commits: 1d1a7c26d886; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts)
  • Vincent Koc: Recently changed OpenRouter resolved-model normalization and provider base URL handling, adjacent to how OpenRouter dynamic models are classified and transported. (role: recent OpenRouter routing contributor; confidence: medium; commits: 791dbf4f9dde; files: extensions/openrouter/index.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 56eb23dda4dd.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Moonlit Merge Sprite

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: finds missing screenshots.
Image traits: location workflow harbor; accessory tiny test log scroll; palette plum, gold, and soft gray; mood bright-eyed; pose pointing at a small proof artifact; shell soft velvet shell; lighting cool dashboard glow; background delicate sparkle particles.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Moonlit Merge Sprite in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

🦞🔧
ClawSweeper automerge is enabled.

Draft PRs stay fix-only until GitHub marks them ready for review. Pause with /clawsweeper stop.

Automerge progress:

  • 2026-05-24 12:09:20 UTC review queued f4ca87acaa9a (queued)

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

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.
Replacement PR: #86041
Why close: this run explicitly closes the superseded source PR after the credited replacement PR is open, so review continues in one place.
Closing this source PR only because source-PR closing was explicitly enabled for this run.
Credit follows the fix over to the replacement PR. no sneaky treasure grab.
Co-author credit kept:

fish notes: model gpt-5.5, reasoning high; reviewed against d193cae.

@clawsweeper clawsweeper Bot closed this May 24, 2026
@TurboTheTurtle TurboTheTurtle deleted the fix/openrouter-top-provider-context-85921 branch May 24, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Context overflow error due to max context length being used as output length by default after upgrading to 2026.5.12 or later version

2 participants