Skip to content

fix(agents): clamp configured input caps to model windows - #144168

Merged
steipete merged 1 commit into
mainfrom
codex/fix-authored-context-cap
Sep 10, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-authored-context-cap

Conversation

@steipete

@steipete steipete commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144009, #124303

What Problem This Solves

Fixes an issue where a configured input cap larger than a model's native context window could bypass the startup minimum and overstate its compaction budget. A custom model with a 3,000-token native window and a 16,000-token input cap was admitted with a 16,000-token budget.

Why This Change Was Made

Share the existing configured-limit calculation between cache reporting and the runtime guard. Apply the configured or fixed provider ceiling before checking the minimum, while preserving exact model-row selection, omitted-cap behavior and explicit overrides above lower discovered metadata.

The shared owner retains each caller's numeric rules: the guard uses finite whole tokens, while cache reporting keeps its existing positive-number projection. The configuration schema permits positive fractional native windows.

User Impact

Startup and compaction respect configured model ceilings. A native window below the supported minimum produces the existing actionable error even when its input cap is larger.

Evidence

Eleven regression/control cases were executed once on the baseline: four failed and seven passed. The same cases then all passed with the production repair, alongside 20 existing controls for row selection, fixed windows, explicit overrides and caller budgets. Baseline routes were completed separately because the wrapper stopped after each failing route.

An initial static pass found a test-only map-spread lint issue. Replacing it with an equivalent fresh-object Object.assign mapping preserved the cases, assertions and all production bytes; all 29 final checks then passed. Runtime tests were not repeated solely for that syntax change. Independent review found no actionable findings.

Production adds 35 lines for the shared result and existing numeric rules; the row selector becomes private. Tests add 147 lines. The focused tests cover ordinary setup/compaction and metadata helpers. The additional CLI proof below exercises persisted configuration and real agent startup with a synthetic loopback provider.

Config-loaded startup and saved-state continuity

Six runs used the supported pnpm openclaw agent exec entry point. Both pinned source versions built through the normal wrapper and loaded actual config files.

Source and state Native window / input cap Result Provider requests
Baseline, fresh 3000 / 16000 Completes incorrectly 1
Baseline, fresh control 5000 / 16000 Completes 1
Candidate, baseline-created state 3000 / 16000 Existing minimum-4000 error 0
Candidate, fresh 3000 / 16000 Same error 0
Candidate, baseline-created control state 5000 / 16000 Completes with effective ctx=5000 1
Candidate, fresh control 5000 / 16000 Completes with effective ctx=5000 1

Config bytes stayed identical. The reused-state cases began with byte-identical baseline-created state, including SQLite databases. Successful runs returned the fixed mock response; rejected runs emitted the existing actionable floor error before any provider dispatch. All processes closed cleanly.

This verifies source/config startup and saved-state continuity, not npm installation, a released-package upgrade, Gateway service startup, or a live provider. Each process used isolated state and an environment allowlist, with outbound traffic restricted to the task-owned loopback provider.

The intentional behavior change is accepted on this evidence: an oversized input cap no longer masks an unsupported native window. The config format and saved config bytes are unchanged; operators receive the existing guidance to correct the model limit or select a larger model.

@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 10, 2026
@steipete
steipete marked this pull request as ready for review September 10, 2026 15:53
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 10, 2026, 12:54 PM ET / 16:54 UTC (Revision 2).

ClawSweeper review

What this changes

Shares configured context-limit calculation so agent startup and compaction clamp input budgets to model ceilings while preserving existing numeric normalization and model selection.

Merge readiness

⛔ Blocked before merge - 1 item remains

The fix remains necessary and has no blocking findings. The added config-loaded startup and saved-state evidence addresses the earlier review request; the related merged work does not fix this remaining guard inconsistency.

Priority: P2
Reviewed head: f84848cf43a065c891fe1dc4c564c68b9e2a1a81

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner repair with meaningful regression coverage and sufficient startup continuity evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied CLI observations exercise real config loading and OpenClaw startup against an isolated loopback provider: fresh and reused candidate state reject the unsupported window before I/O, while supported controls complete with the corrected budget. This resolves the prior proof gap; it does not claim a live external provider or packaged upgrade.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied CLI observations exercise real config loading and OpenClaw startup against an isolated loopback provider: fresh and reused candidate state reject the unsupported window before I/O, while supported controls complete with the corrected budget. This resolves the prior proof gap; it does not claim a live external provider or packaged upgrade.
Evidence reviewed 7 items Verified introduced production change: The pinned introduction delta extracts the existing cache calculation and makes the runtime guard consume its clamped result; exact configured-row selection remains shared.
Current main still needs the repair: Inspected fetched-main source still selects contextTokens before contextWindow without clamping the former to the latter, permitting the reported 3000/16000 configuration.
Latest release retains the same defect: The v2026.9.3 source likewise returns configured contextTokens before contextWindow without their minimum. The GitHub contents read succeeded after the local release-blob read failed.
Findings None None.
Security None None.

How this fits together

OpenClaw resolves model configuration and metadata into a usable context budget. Agent startup checks that budget against its minimum, and compaction uses it to limit conversation processing.

flowchart TD
  A[Selected model configuration] --> C[Shared configured limit calculation]
  B[Provider ceiling rules] --> C
  C --> D[Effective context budget]
  D --> E[Startup minimum check]
  E --> F[Run agent or show existing error]
  D --> G[Compaction budget]
Loading

Before merge

  • Resolve merge risk (P1) - Existing configurations whose oversized input cap masks a native window below 4000 tokens will stop at startup and require correcting the model limit or choosing a larger model; the PR explicitly accepts this behavior and supplies fresh-state and saved-state evidence.
Agent review details

Security

None.

PR surface

Source +35, Tests +147. Total +182 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 69 34 +35
Tests 3 147 0 +147
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 216 34 +182

Review metrics

Metric Value Why it matters
Production and regression coverage production net +35 lines; tests +147 lines Production growth is justified by sharing the existing calculation while preserving caller-specific numeric rules.
Config-loaded startup evidence 6 CLI runs across baseline, fresh candidate, and reused state The evidence covers intentional rejection and a working control without rewriting saved configuration.

Merge-risk options

Maintainer options:

  1. Retain the accepted minimum-window enforcement (recommended)
    Accept the documented rejection of inconsistent limits, supported by fresh-state and baseline-created-state startup evidence and unchanged config bytes.

Technical review

Best possible solution:

Keep one configured-limit calculation for reporting and runtime budgets, retaining the accepted minimum-window enforcement and existing actionable error.

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

Yes: current-main source admits contextTokens=16000 over contextWindow=3000, and the supplied baseline CLI evidence demonstrates that path. This read-only review did not execute tests or target code.

Is this the best way to solve the issue?

Yes: reusing the existing configured-limit owner fixes the runtime discrepancy while retaining row selection, omitted-cap behavior, provider ceilings, and caller normalization.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 680fc46558fd.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied CLI observations exercise real config loading and OpenClaw startup against an isolated loopback provider: fresh and reused candidate state reject the unsupported window before I/O, while supported controls complete with the corrected budget. This resolves the prior proof gap; it does not claim a live external provider or packaged upgrade.

Label justifications:

  • P2: This repairs a bounded custom-model startup and compaction-budget inconsistency.
  • merge-risk: 🚨 compatibility: Previously admitted configurations with a masked sub-4000 native window will now receive the existing startup error.
  • 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 supplied CLI observations exercise real config loading and OpenClaw startup against an isolated loopback provider: fresh and reused candidate state reject the unsupported window before I/O, while supported controls complete with the corrected budget. This resolves the prior proof gap; it does not claim a live external provider or packaged upgrade.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied CLI observations exercise real config loading and OpenClaw startup against an isolated loopback provider: fresh and reused candidate state reject the unsupported window before I/O, while supported controls complete with the corrected budget. This resolves the prior proof gap; it does not claim a live external provider or packaged upgrade.

Evidence

What I checked:

  • Verified introduced production change: The pinned introduction delta extracts the existing cache calculation and makes the runtime guard consume its clamped result; exact configured-row selection remains shared. (src/agents/context-resolution.ts:180, f84848cf43a0)
  • Current main still needs the repair: Inspected fetched-main source still selects contextTokens before contextWindow without clamping the former to the latter, permitting the reported 3000/16000 configuration. (src/agents/context-window-guard.ts:41, 680fc46558fd)
  • Latest release retains the same defect: The v2026.9.3 source likewise returns configured contextTokens before contextWindow without their minimum. The GitHub contents read succeeded after the local release-blob read failed. (src/agents/context-window-guard.ts, 1391f7cd2d40)
  • Production callers and implementation boundary: Setup applies the resolved budget before its existing blocking error; compaction takes the minimum of the caller budget and this same resolved ceiling. Native-model-owned setup returns before this policy, and the changed scenarios concern OpenClaw-owned custom models, establishing no Codex dependency gate. (src/agents/embedded-agent-runner/run/setup.ts:269, f84848cf43a0)
  • Existing minimum and numeric contracts: Local-model documentation specifies the 4000-token hard floor. The configuration schema permits positive fractional contextWindow values while contextTokens must be a positive integer; the guard retains its finite whole-token normalization. Public docs: docs/gateway/local-models.md. (docs/gateway/local-models.md:285, f84848cf43a0)
  • Earlier proof request addressed: The supplied complete PR body records six supported CLI runs against actual configuration and isolated state: baseline 3000/16000 dispatched once; candidate fresh and baseline-created state rejected before dispatch; both 5000/16000 controls completed with ctx=5000. Config bytes remained unchanged. This addresses the prior startup/upgrade-context request without claiming packaged installation or live-provider validation. Captured context sourceRevision: 8048a1bcb379f990ce98580a0ddc006a78be054388000fbc6178323b0c2f1be2. (f84848cf43a0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-10T16:01:52.604Z sha f84848c :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 10, 2026
@steipete
steipete merged commit acef89b into main Sep 10, 2026
258 checks passed
@steipete
steipete deleted the codex/fix-authored-context-cap branch September 10, 2026 17:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: M 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.

1 participant