Skip to content

fix(kilocode): model discovery overstates the usable context window - #118868

Merged
Takhoffman merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/kilocode-primary-provider-context-window
Aug 3, 2026
Merged

fix(kilocode): model discovery overstates the usable context window#118868
Takhoffman merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/kilocode-primary-provider-context-window

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

AI-assisted.

What Problem This Solves

Fixes an issue where users on the Kilocode provider would get model context
windows larger than the model can actually accept, whenever the primary
provider serving that model publishes a smaller window than the catalog-wide
ceiling.

Kilocode's gateway returns an OpenRouter-shaped catalog. In it, context_length
is the catalog-wide ceiling across all routing candidates, while
top_provider.context_length describes the primary provider that actually
serves the request. Model discovery read only the catalog-wide value.

On the live public catalog this affects 33 of the 335 discovered models. The
overstatement is up to 3.8x, for example:

model                              catalog     primary provider
nvidia/nemotron-3-super-120b-a12b  1000000     262144
minimax/minimax-m3                 1048576     524288
thinkingmachines/inkling           1048576     524288
qwen/qwen3.6-27b                    262144     131072
z-ai/glm-5.1                        204800     200000

Why This Change Was Made

Discovery now prefers top_provider.context_length and falls back to the
catalog-wide context_length, then to the existing default. This is the same
precedence already owned by extensions/openrouter/provider-catalog.ts:197-200,
so the two OpenRouter-shaped catalogs agree.

The same normalization was applied to src/agents/model-scan.ts in
8fa1b82e42a35447482f2722df75128916d0c059 (#110855). The Kilocode reader was
not covered there; this completes it.

Completion-token handling is deliberately left unchanged. The live Kilocode
catalog exposes no top-level max_completion_tokens or max_output_tokens
field at all, so the existing top_provider.max_completion_tokens read is
already the only available source and adding a fallback chain would encode a
field the data never carries.

No config, Plugin SDK, protocol, persistence, migration, or feature surface
changes.

User Impact

Kilocode models are registered with the context window the serving provider
actually offers, so context budgeting and model metadata stop overstating what
a request can use on the 33 affected models. Models whose primary provider
matches the catalog value are unchanged.

Evidence

Live public catalog, no key and no inference call:
curl -H "Accept: application/json" https://api.kilo.ai/api/gateway/models
returned 346 rows; 340 carry top_provider.context_length.

The real catalog response was then fed through the actual
discoverKilocodeModels() implementation, changing only the production file
between the two runs. registered is the contextWindow discovery assigns:

Before (current main):

ROWS=346 MODELS=335 DIVERGENT=33
minimax/minimax-m3       catalog=1048576  provider=524288  registered=1048576
thinkingmachines/inkling catalog=1048576  provider=524288  registered=1048576
stepfun/step-3.7-flash   catalog=262144   provider=256000  registered=262144
qwen/qwen3.6-27b         catalog=262144   provider=131072  registered=262144
z-ai/glm-5.1             catalog=204800   provider=200000  registered=204800

After (this branch):

ROWS=346 MODELS=335 DIVERGENT=33
minimax/minimax-m3       catalog=1048576  provider=524288  registered=524288
thinkingmachines/inkling catalog=1048576  provider=524288  registered=524288
stepfun/step-3.7-flash   catalog=262144   provider=256000  registered=256000
qwen/qwen3.6-27b         catalog=262144   provider=131072  registered=131072
z-ai/glm-5.1             catalog=204800   provider=200000  registered=200000

Tests, run on Node 24.18.1:

  • extensions/kilocode/provider-models.test.ts: 13/13 pass.
  • Whole extensions/kilocode/ folder: 35/35 pass across 4 files.
  • Control run: with the production file reverted to main and the new tests
    kept, the precedence test fails with contextWindow 1048576 instead of
    524288, so the added coverage is load-bearing rather than self-confirming.

Regression coverage added: primary-provider precedence, and independent
fallback to the catalog-wide value when the provider value is zero, negative,
fractional, non-finite, null, or a string.

oxfmt --check, direct oxlint on both touched files, and git diff --check
are clean.

Scope

Production delta: +6/-1 in extensions/kilocode/provider-models.ts. Tests add
53 lines. Changelog not required: this corrects existing internal catalog
normalization without changing commands or configuration.

The Kilocode gateway publishes an OpenRouter-shaped catalog in which
`context_length` is the catalog-wide ceiling while `top_provider.context_length`
describes the primary provider that actually serves the request. Discovery read
only the catalog-wide value, so models whose primary provider offers a smaller
window were registered with a context window larger than requests can use.

Prefer the primary-provider window and fall back to the catalog-wide value,
matching the precedence already owned by
`extensions/openrouter/provider-catalog.ts`.

Completion-token handling is left alone on purpose: the live Kilocode catalog
exposes no top-level `max_completion_tokens` or `max_output_tokens`, so the
existing `top_provider` read is already the only available source.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 3:02 PM ET / 19:02 UTC.

ClawSweeper review

What this changes

Updates Kilocode model discovery to prefer a valid primary-provider context window over the catalog-wide ceiling, with fallback coverage for unusable provider values.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still registers Kilocode models from the catalog-wide context value, while this narrow patch applies the established primary-provider precedence and adds focused regression coverage. The branch remains necessary and has no actionable correctness or security finding from this review.

Priority: P2
Reviewed head: 1919aab2e8310047c75282eafa7a97cae5cb2044

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, contract-aligned repair with concrete live behavior evidence and load-bearing regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.
Evidence reviewed 7 items Current behavior: The current Kilocode converter uses only the catalog-wide context_length for contextWindow, so a smaller valid value under top_provider is ignored.
Existing canonical sibling policy: The OpenRouter provider catalog already prefers a positive safe-integer top_provider.context_length, then falls back to the catalog-wide value and default; the proposed precedence matches that implementation.
Related merged implementation: Current src/agents/model-scan.ts uses the same independent primary-provider context fallback, and commit 8fa1b82e42a35447482f2722df75128916d0c059 is contained by local main.
Findings None None.
Security None None.

How this fits together

The Kilocode provider plugin fetches its public model catalog and converts each row into OpenClaw model metadata used for context budgeting. The discovered context window then informs how much input OpenClaw considers usable for a selected Kilocode model.

flowchart LR
  A[Kilocode model catalog] --> B[Kilocode provider discovery]
  B --> C[Validate context limits]
  C --> D[Choose primary-provider limit]
  D --> E[Fallback to catalog limit]
  E --> F[OpenClaw model metadata]
  F --> G[Context budgeting]
Loading

Before merge

  • Resolve merge risk (P1) - build-artifacts and check-lint were still in progress for the reviewed head; merge should wait for their current-head outcomes.
  • Complete next step (P2) - No repair lane is needed: this is an already-focused contributor fix with no actionable review finding; wait for active checks and ordinary maintainer review.
Agent review details

Security

None.

PR surface

Source +5, Tests +53. Total +58 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 1 53 0 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 1 +58

Review metrics

Metric Value Why it matters
Production vs test delta production +6/-1; tests +53 The small production increase is justified by carrying the established provider-limit precedence into the Kilocode catalog reader, with focused regression coverage for valid and invalid values.

Root-cause cluster

Relationship: canonical
Canonical: #118868
Summary: This PR owns the remaining Kilocode-specific instance of the provider-limit normalization already merged for OpenRouter scans.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the existing narrow precedence correction after the active checks finish, keeping the same positive-safe-integer fallback contract used by OpenRouter and model scanning.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the existing narrow precedence correction after the active checks finish, keeping the same positive-safe-integer fallback contract used by OpenRouter and model scanning.

Do we have a high-confidence way to reproduce the issue?

Yes, by source: a catalog row with a valid smaller top_provider.context_length currently produces the larger catalog-wide context window at extensions/kilocode/provider-models.ts:114. The submitted before/after public-catalog output also exercises that exact discovery path, although this runner could not independently resolve the API host.

Is this the best way to solve the issue?

Yes. Reusing the already-shipped OpenRouter and model-scan precedence is the narrowest maintainable fix; it corrects the producer of the metadata without adding a configuration or compatibility path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c37cfb0f260f.

Labels

Label changes:

  • add P2: This is a bounded provider-metadata bug that can overstate usable context for affected Kilocode models but does not indicate data loss, security exposure, or an availability outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.

Label justifications:

  • P2: This is a bounded provider-metadata bug that can overstate usable context for affected Kilocode models but does not indicate data loss, security exposure, or an availability outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after live public-catalog output fed through the actual discovery implementation, showing the registered context window changes to the primary-provider value; no sensitive data is present in the supplied transcript.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Local blame assigns the current Kilocode conversion block to Vincent's recent provider-area commit, and the extension history shows repeated provider and plugin maintenance work. (role: recent area contributor; confidence: high; commits: 8987e93c65e8, b88f80940add, 21728777dfa0; files: extensions/kilocode/provider-models.ts)
  • mushuiyu886: Authored the merged OpenRouter scan normalization that establishes the same provider-limit precedence and previously contributed a focused Kilocode catalog repair. (role: adjacent implementation contributor; confidence: high; commits: 8fa1b82e42a3, e3a1c64d7b08; files: src/agents/model-scan.ts, extensions/kilocode/provider-models.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

@Takhoffman Takhoffman self-assigned this Aug 3, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

Land-ready for PR #118868.

  • Reviewed and prepared head: 1919aab2e8310047c75282eafa7a97cae5cb2044.
  • ClawSweeper exact-head review: no actionable findings; current-head review comment 5170572558 is clear, and no separate Rank-up moves: list was present.
  • Focused proof: scripts/pr review-tests 118868 extensions/kilocode/provider-models.test.ts — 13 tests passed; git diff --check origin/main...HEAD passed.
  • Hosted exact-head CI: openclaw/ci-gate, build-artifacts, check-lint, and preflight are successful in CI run 30842897375.
  • Canonical preparation: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 118868 passed with hosted_exact_or_recent_parent; the prepared head equals the live PR head and no patch was pushed.
  • Review artifacts were validated with scripts/pr review-validate-artifacts 118868.

Known proof gap: no separate Testbox lease was needed because the exact-head hosted CI gate was already green. The standard canonical squash path will attribute the merge to @Takhoffman; no additional graph co-author trailer for the merger was requested.

@Takhoffman
Takhoffman merged commit 38aa704 into openclaw:main Aug 3, 2026
94 of 101 checks passed
@Takhoffman

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
* commit 'efcced7207baa0b1b1db5e8e1836673a24212657':
  test(agents): prove process control roundtrip (#118843)
  test(qa): add memory redaction boundary coverage (#118916)
  fix(kilocode): model discovery overstates the usable context window (#118868)
  fix(media): isolate generated-provider text from delivery directives (#118780)
  test(gateway): add node control-plane QA coverage (#118784)
  fix(config): reject unsupported diagnostics otel grpc (#93087)
  fix(providers): recognize configured media credentials across provider boundaries (#118761)
  refactor: delete dead post-landing plugin/hooks scaffolding (#118920)
  fix(cron): deliver child results after heartbeat-only parent responses (#118743)
  fix(ci): keep Matrix chunk tests aligned with inventory (#118917)
  fix(tts): preserve hidden speech answers when synthesis fails (#118690)
vincentkoc added a commit that referenced this pull request Aug 3, 2026
…-worker-update-20260803

* origin/main: (48 commits)
  test(ui): add shell and PWA primary QA proof (#118788)
  test(qa): cover CLI distribution workflows (#118948)
  chore(i18n): refresh native locales (#118883)
  test(qa): prove plugin tool ownership in gateway flow (#118958)
  docs: correct onboarding risk flags and Google Chat credential shapes (#118936)
  fix(imessage): honor explicitly enabled accounts during startup (#118944)
  test(gateway): cover client transport defaults (#118798)
  fix(signal): normalize accounts during noninteractive setup (#118932)
  fix(msteams): enable channels for federated environment credentials (#118931)
  fix(openai): enforce final transcript bounds before callback delivery (#118928)
  test(tasks): cover plugin-managed flows (#118919)
  test(agents): prove process control roundtrip (#118843)
  test(qa): add memory redaction boundary coverage (#118916)
  fix(kilocode): model discovery overstates the usable context window (#118868)
  fix(media): isolate generated-provider text from delivery directives (#118780)
  test(gateway): add node control-plane QA coverage (#118784)
  fix(config): reject unsupported diagnostics otel grpc (#93087)
  fix(providers): recognize configured media credentials across provider boundaries (#118761)
  refactor: delete dead post-landing plugin/hooks scaffolding (#118920)
  fix(cron): deliver child results after heartbeat-only parent responses (#118743)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
…penclaw#118868)

The Kilocode gateway publishes an OpenRouter-shaped catalog in which
`context_length` is the catalog-wide ceiling while `top_provider.context_length`
describes the primary provider that actually serves the request. Discovery read
only the catalog-wide value, so models whose primary provider offers a smaller
window were registered with a context window larger than requests can use.

Prefer the primary-provider window and fall back to the catalog-wide value,
matching the precedence already owned by
`extensions/openrouter/provider-catalog.ts`.

Completion-token handling is left alone on purpose: the live Kilocode catalog
exposes no top-level `max_completion_tokens` or `max_output_tokens`, so the
existing `top_provider` read is already the only available source.
xialonglee pushed a commit to xialonglee/openclaw that referenced this pull request Aug 11, 2026
…penclaw#118868)

The Kilocode gateway publishes an OpenRouter-shaped catalog in which
`context_length` is the catalog-wide ceiling while `top_provider.context_length`
describes the primary provider that actually serves the request. Discovery read
only the catalog-wide value, so models whose primary provider offers a smaller
window were registered with a context window larger than requests can use.

Prefer the primary-provider window and fall back to the catalog-wide value,
matching the precedence already owned by
`extensions/openrouter/provider-catalog.ts`.

Completion-token handling is left alone on purpose: the live Kilocode catalog
exposes no top-level `max_completion_tokens` or `max_output_tokens`, so the
existing `top_provider` read is already the only available source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: kilocode P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants