Repository navigation
Description
Version
OpenClaw 2026.5.2
Summary
When models.providers.<provider>.models[].id is configured as a bare model id (e.g. claude-opus-4.7-1m-internal) but the runtime resolves the model id in provider/model form (e.g. github-copilot/claude-opus-4.7-1m-internal), resolveContextWindowInfo fails to find the configured entry due to strict m.id === modelId equality. It then silently falls back to the plugin's default contextWindow (128k for github-copilot), and that 128k is propagated through agentMeta.contextTokens into sessions.json, capping the session at 128k even though the user configured 1M / 936k.
Repro
~/.openclaw/openclaw.json:
{
"models": {
"providers": {
"github-copilot": {
"models": [
{
"id": "claude-opus-4.7-1m-internal",
"api": "anthropic-messages",
"contextWindow": 1000000,
"contextTokens": 936000,
"maxTokens": 64000
}
]
}
}
},
"agents": {
"list": [
{
"id": "my-agent",
"model": { "primary": "github-copilot/claude-opus-4.7-1m-internal" }
}
]
}
}openclaw models listcorrectly showsCtx 914k/977k(cache +resolveContextTokensForModelwork fine).- After any agent run,
agents/<agentId>/sessions/sessions.jsonentry hascontextTokens: 128000. - Status card /
/statusshowsContext: xx/128k.
Root cause
src/agents/pi-embedded-runner/run/setup.ts:126 calls:
const ctxInfo = resolveContextWindowInfo({
cfg: params.cfg,
provider: params.provider,
modelId: params.modelId, // can be "github-copilot/claude-opus-4.7-1m-internal"
modelContextTokens: readPiModelContextTokens(params.runtimeModel),
modelContextWindow: params.runtimeModel.contextWindow, // plugin default 128_000
defaultTokens: DEFAULT_CONTEXT_TOKENS,
});params.modelId may be in provider/model form (it is set in pi-embedded-runner/run.ts and forwarded as-is by callers like auto-reply/reply/agent-runner-execution.ts and cron/isolated-agent/run-executor.ts).
src/agents/context-window-guard.ts resolveContextWindowInfo:
const match = models.find((m) => m?.id === params.modelId);This strict equality fails when m.id is bare and params.modelId is provider/model. It then falls back to params.modelContextWindow (the plugin default 128k), which gets stored as agentMeta.contextTokens and persisted into sessions.json via persistRunSessionUsage.
pi-embedded-runner/model.ts already uses matchesProviderScopedModelId for the inverse direction (candidate has provider/ prefix, requested is bare). The two helpers should be symmetric.
Suggested fix
src/agents/context-window-guard.ts, treat provider/model and bare ids as equivalent under the matching provider:
- const match = models.find((m) => m?.id === params.modelId);
+ const providerPrefix = params.provider ? `${params.provider}/` : '';
+ const stripPrefix = (id: string) =>
+ providerPrefix && id.startsWith(providerPrefix) ? id.slice(providerPrefix.length) : id;
+ const requestedBare = stripPrefix(params.modelId);
+ const match = models.find((m) => {
+ if (!m?.id) return false;
+ if (m.id === params.modelId) return true;
+ return stripPrefix(m.id) === requestedBare;
+ });This restores the user-configured contextTokens=936000 regardless of whether the runtime forwards a bare or provider-scoped id.
Workaround (no source patch)
Duplicate each large-context model entry under both <id> and <provider>/<id> form in models.providers.<provider>.models[] until upstream is fixed:
{ "id": "claude-opus-4.7-1m-internal", "contextWindow": 1000000, "contextTokens": 936000, ... },
{ "id": "github-copilot/claude-opus-4.7-1m-internal", "contextWindow": 1000000, "contextTokens": 936000, ... }Verified to restore Context: xx/936k end-to-end on 2026.5.2 without dist changes.
Related code paths
src/agents/context-window-guard.ts—resolveContextWindowInfostrict matchsrc/agents/pi-embedded-runner/run/setup.ts:126— call sitesrc/agents/pi-embedded-runner/run.ts:~507—resolveEffectiveRuntimeModel({ modelId })src/auto-reply/reply/agent-runner.runtime—contextTokensUsed = runResult.meta.agentMeta.contextTokens ?? resolveContextTokensForModel(...), thenpersistRunSessionUsagesrc/agents/pi-embedded-runner/model.ts—matchesProviderScopedModelId(the existing helper for the inverse direction)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 3, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 31, 2026, 1:00 AM ET / 05:00 UTC.
Summary
Codex review failed: codex execution failed.
Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.
Ways to help us reproduce this
Next step
Review did not complete, so no work-lane recommendation was made.
Review details
Best possible solution:
Retry the Codex review after fixing the execution failure.
Do we have a high-confidence way to reproduce the issue?
Unclear. The review failed before ClawSweeper could establish a reproduction path.
Is this the best way to solve the issue?
Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.
AGENTS.md: unclear because the file could not be read completely.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against e1a98171417c.
Label changes
Label changes:
issue-rating: 🦪 silver shellfish: Current issue advisory state selects this label.clawsweeper:needs-info: Current issue advisory state selects this label.P2: Current review triage priority is none.clawsweeper:no-new-fix-pr: Current issue advisory state no longer selects this label.clawsweeper:source-repro: Current issue advisory state no longer selects this label.clawsweeper:linked-pr-open: Current issue advisory state no longer selects this label.impact:session-state: Current review selected no impact labels.impact:auth-provider: Current review selected no impact labels.issue-rating: 🦞 diamond lobster: Current issue advisory state no longer selects this label.Evidence reviewed
What I checked:
Likely related people:
How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.barnacle-openclaw commentedon May 30, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
steipete commentedon Jun 1, 2026
Fixed on current main by f18fd20 (
fix(agents): match provider-scoped context ids).resolveContextWindowInfonow matches bare configured model IDs against provider-scoped runtime IDs, and the inverse form, before falling back to the provider default window.Proof run on branch
inferenceat 7562afd:Result: 3 Vitest shards passed. The regression tests cover both
tinyvsopenrouter/tinyandopenrouter/tinyvstiny, preserving the configuredcontextTokenspath instead of capping at the default. Closing as fixed on main.