Skip to content

fix(agents): resolve context window for proxy models with slash in ID#92709

Closed
samson910022 wants to merge 1 commit into
openclaw:mainfrom
samson910022:fix/status-context-window-slash-resolution
Closed

fix(agents): resolve context window for proxy models with slash in ID#92709
samson910022 wants to merge 1 commit into
openclaw:mainfrom
samson910022:fix/status-context-window-slash-resolution

Conversation

@samson910022

@samson910022 samson910022 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Problem

/status shows max context = 200K (DEFAULT_CONTEXT_TOKENS) for models accessed through proxy providers like OpenRouter, regardless of the actual model's context window.

Root Cause

Two guards in resolveContextTokensForModel() (src/agents/context.ts) blocked qualified cache key lookup when the model ID contained a slash:

// Before: !ref.model.includes("/") blocked OpenRouter models
if (params.provider && ref && !ref.model.includes("/")) { ... }
if (!params.provider && ref && !ref.model.includes("/")) { ... }

OpenRouter and similar proxy providers always have slashes in their model IDs (e.g. anthropic/claude-sonnet-4), making ref.model = "anthropic/claude-sonnet-4" which contains "/". The qualified cache key was never constructed, causing a cache miss and fallback to 200K.

Fix

Removed the !ref.model.includes("/") guard from both call sites:

  1. Explicit provider path: params.provider is explicitly given by the caller, so there is no inference risk
  2. Last resort implicit provider path: bare key already failed, trying qualified key has no downside

Related

Scope

Only src/agents/context.ts. No test changes needed (existing tests already cover cache hit/miss paths).

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. size: S labels Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 13, 2026, 10:54 AM ET / 14:54 UTC.

Summary
The PR changes resolveContextTokensForModel in src/agents/context.ts so provider-qualified context-token lookup can run for model IDs that already contain slashes.

PR surface: Source +2. Total +2 across 1 file.

Reproducibility: yes. at source level: current main skips provider-qualified lookup whenever the resolved model segment contains /, while OpenRouter keeps nested slash-bearing model IDs under provider openrouter. I did not establish a live /status repro in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real /status or terminal proof showing the corrected proxy-provider context window.
  • [P1] Add focused regression coverage for slash-bearing proxy model IDs.
  • Restore the corrupted comment punctuation.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Missing: the PR body has no after-fix real /status output, terminal screenshot/live output, recording, or redacted logs from a proxy-provider setup; redact API keys, IPs, phone numbers, and non-public endpoints before posting proof. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The resolver feeds /status and persisted session context-token accounting, so a wrong cache-key path can continue to misreport effective context windows for proxy-provider sessions.
  • [P1] The PR has no after-fix real proxy-provider /status output or equivalent runtime evidence from the contributor's setup.
  • [P1] A caller path with missing modelProvider may still need separate handling if real proof shows the resolver is reached without provider context.

Maintainer options:

  1. Add resolver coverage and proof before merge (recommended)
    Cover the explicit proxy-provider slash-ID cache lookup and require redacted /status or terminal evidence from a real proxy-provider setup.
  2. Accept source-only confidence
    Maintainers could merge on source review alone, but that would intentionally waive the external-PR real behavior proof gate for a provider/session-state path.

Next step before merge

  • [P1] Contributor-supplied real behavior proof is missing on an external PR, so automation should not substitute for the reporter's setup evidence.

Security
Cleared: The live diff only changes TypeScript resolver logic and comments; it does not touch dependency, workflow, secret, package, or downloaded-code surfaces.

Review findings

  • [P2] Cover the explicit slash-model cache path — src/agents/context.ts:421
  • [P3] Restore the corrupted punctuation in comments — src/agents/context.ts:392
Review details

Best possible solution:

Land the scoped resolver fix only after adding focused regression coverage for explicit proxy-provider slash IDs and redacted real /status or terminal proof from a proxy-provider setup.

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

Yes, at source level: current main skips provider-qualified lookup whenever the resolved model segment contains /, while OpenRouter keeps nested slash-bearing model IDs under provider openrouter. I did not establish a live /status repro in this read-only review.

Is this the best way to solve the issue?

Mostly yes for the explicit-provider cache-miss root cause: the shared resolver is the right owner for status and session persistence. The PR still needs focused coverage and real behavior proof, and any missing-provider /status caller case should remain separate unless proof shows this patch must handle it too.

Full review comments:

  • [P2] Cover the explicit slash-model cache path — src/agents/context.ts:421
    The PR removes the guard for provider=openrouter plus a slash-bearing model, but existing tests only cover neighboring model-only slash IDs and bare provider-qualified lookups. Add a focused regression that primes MODEL_CONTEXT_TOKEN_CACHE with openrouter/anthropic/... and proves resolveContextTokensForModel returns that window for the explicit provider path.
    Confidence: 0.88
  • [P3] Restore the corrupted punctuation in comments — src/agents/context.ts:392
    The patch changes several explanatory comment arrows/dashes into ??, which makes the cache-key invariant harder to read exactly where the branch is subtle. Restore the intended punctuation while keeping the logic change.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR targets a bounded agents context-window correctness bug affecting proxy-provider status and session accounting.
  • merge-risk: 🚨 session-state: The resolver feeds persisted session context-token accounting and status context-window display.
  • merge-risk: 🚨 auth-provider: The changed lookup depends on provider/model routing for proxy providers such as OpenRouter.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body has no after-fix real /status output, terminal screenshot/live output, recording, or redacted logs from a proxy-provider setup; redact API keys, IPs, phone numbers, and non-public endpoints before posting proof. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +2. Total +2 across 1 file.

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

What I checked:

  • Repository policy read: Root and scoped agents policy were read fully; their review-depth, proof, and agents-test guidance shaped this review. (AGENTS.md:1, eb1b640854bb)
  • Live PR diff: The current PR head modifies only src/agents/context.ts and removes both slash guards from the qualified-cache lookup paths. (src/agents/context.ts:421, b79687dcfe7a)
  • Current main behavior: Current main still requires !ref.model.includes("/") before trying the provider-qualified cache key, so explicit provider openrouter plus model anthropic/... skips the intended cache entry. (src/agents/context.ts:421, eb1b640854bb)
  • OpenRouter model shape: OpenRouter dynamic models keep nested model IDs while reporting provider openrouter, matching the provider/model shape the PR is trying to resolve. (extensions/openrouter/index.ts:79, eb1b640854bb)
  • Caller surface: Agent run persistence calls resolveContextTokensForModel with providerUsed and modelUsed, so this resolver affects persisted session context-token accounting. (src/auto-reply/reply/agent-runner.ts:1885, eb1b640854bb)
  • Coverage gap: Existing tests cover neighboring model-only slash and bare provider-qualified cases, but not explicit provider openrouter with a slash-bearing model segment through the changed branch. (src/auto-reply/status.test.ts:2167, eb1b640854bb)

Likely related people:

  • Peter Lindsey: Local blame attributes the current resolver implementation and slash guard to this recent main commit. (role: recent area contributor; confidence: medium; commits: 690f27749c2c; files: src/agents/context.ts)
  • steipete: Recent verified commits touch runtime model context-token caps and adjacent context-cache behavior. (role: adjacent context-cache contributor; confidence: medium; commits: 58d2b9dd46cc, 3bf92944b2d3, 50265c8b1fa0; files: src/agents/context.ts)
  • 0x4C33: The provider-qualified context-window lookup behavior appears in the merged status fix history for this resolver area. (role: context-resolution contributor; confidence: medium; commits: f3be1c828c6d; files: src/agents/context.ts, src/auto-reply/status.test.ts)
  • RichardCao: Recent merged fallback context-window recomputation work uses the same status and resolver semantics. (role: adjacent status contributor; confidence: medium; commits: a835c200f306; files: src/agents/context.ts, src/auto-reply/status.test.ts)
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.

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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 13, 2026
… OpenRouter proxy models)

Remove the `!ref.model.includes("/")` guard in `resolveContextTokensForModel()` which blocked qualified cache key lookup for models like `anthropic/claude-sonnet-4` accessed through proxy providers.

Two call sites fixed:
1. Explicit provider path (params.provider && ref) -- safe because provider is explicitly given
2. Last resort implicit provider path (!params.provider && ref) -- bare key already failed, trying qualified key has no downside

Fixes: max context showing DEFAULT_CONTEXT_TOKENS (200K) instead of actual model's context window for proxy models
@samson910022

Copy link
Copy Markdown
Contributor Author

Superseded by #92772 from the comprehensive branch \ ix/comprehensive-context-window-resolution\ which includes all 7 layers of fixes.

samson910022 pushed a commit to samson910022/openclaw that referenced this pull request Jun 14, 2026
…t window resolution

When a session entry has model="openrouter/anthropic/claude-sonnet-4" but
entry.modelProvider is empty, buildStatusMessage() previously set
contextLookupProvider = undefined, causing resolveContextTokensForModel()
to skip the provider-qualified cache key lookup.

Now extract the embedded provider (first slash segment) and pass it to the
resolution chain so the correct context window is found.

Combined with PR openclaw#92424's resolveFreshModel() fix and PR openclaw#92709's
slash-guard removal in resolveContextTokensForModel(), this gives
comprehensive coverage for proxy model context window resolution.

Refs: openclaw#39857, openclaw#90889, openclaw#92424, openclaw#92709
@samson910022
samson910022 deleted the fix/status-context-window-slash-resolution branch June 16, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants