fix: apply contextTokens cap to model for auto-compaction threshold#39099
Closed
MumuTW wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix: apply contextTokens cap to model for auto-compaction threshold#39099MumuTW wants to merge 1 commit intoopenclaw:mainfrom
MumuTW wants to merge 1 commit intoopenclaw:mainfrom
Conversation
The library's auto-compaction uses `model.contextWindow` to decide when to compact (`contextTokens > contextWindow - reserveTokens`). When the user sets `agents.defaults.contextTokens` (e.g. 160 000) but the model's native context window is much larger (e.g. 1M for Gemini Flash), the library never triggers auto-compaction because usage never exceeds the native limit. This means the safeguard compaction extension never fires and the compaction counter stays at 0. Create an `effectiveModel` with the capped `contextWindow` in both `run.ts` and `compact.ts` so the library threshold respects the configured limit. Fixes openclaw#38905
Contributor
Greptile SummaryThis PR fixes a bug where the Key changes:
Confidence Score: 5/5
Last reviewed commit: 26f658e |
5 tasks
steipete
added a commit
that referenced
this pull request
Mar 7, 2026
Land #39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
Contributor
|
Landed on What we did:
SHA details:
Thanks @MumuTW for the fix. |
mrosmarin
added a commit
to mrosmarin/openclaw
that referenced
this pull request
Mar 7, 2026
* main: (133 commits) reduce image size, offer slim image (openclaw#38479) fix(security): harden install base drift cleanup fix(agents): respect explicit provider baseUrl in merge mode (openclaw#39103) fix(agents): apply contextTokens cap for compaction threshold (openclaw#39099) fix(exec): block dangerous override-only env pivots fix(security): stage installs before publish fix(daemon): normalise whitespace in checkTokenDrift to prevent false-positive warning (openclaw#39108) fix(security): harden fs-safe copy writes refactor: dedupe bluebubbles webhook auth test setup refactor: dedupe discord native command test scaffolding refactor: dedupe anthropic probe target test setup refactor: dedupe minimax provider auth test setup refactor: dedupe runtime snapshot test fixtures fix: harden zip extraction writes fix(tests): stabilize diffs localReq headers (supersedes openclaw#39063) fix: harden workspace skill path containment fix(agents): land openclaw#38935 from @MumuTW fix(models): land openclaw#38947 from @davidemanuelDEV fix(gateway): land openclaw#39064 from @Narcooo fix(models-auth): land openclaw#38951 from @MumuTW ...
vincentkoc
pushed a commit
to BryanTegomoh/openclaw-fork
that referenced
this pull request
Mar 8, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
openperf
pushed a commit
to openperf/moltbot
that referenced
this pull request
Mar 8, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
mcaxtr
pushed a commit
to mcaxtr/openclaw
that referenced
this pull request
Mar 8, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
Saitop
pushed a commit
to NomiciAI/openclaw
that referenced
this pull request
Mar 8, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
GordonSH-oss
pushed a commit
to GordonSH-oss/openclaw
that referenced
this pull request
Mar 9, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
jenawant
pushed a commit
to jenawant/openclaw
that referenced
this pull request
Mar 10, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
4 tasks
dhoman
pushed a commit
to dhoman/chrono-claw
that referenced
this pull request
Mar 11, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
senw-developers
pushed a commit
to senw-developers/va-openclaw
that referenced
this pull request
Mar 17, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
V-Gutierrez
pushed a commit
to V-Gutierrez/openclaw-vendor
that referenced
this pull request
Mar 17, 2026
…aw#39099) Land openclaw#39099 by @MumuTW. Co-authored-by: MumuTW <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
agents.defaults.contextTokenscap to the model object passed topi-coding-agent, so the library's auto-compaction threshold uses the effective limit instead of the native model context windowcontextTokens(e.g. 160k) is much smaller than the model's native context window (e.g. 1M for Gemini Flash), the library never triggers auto-compaction becausecontextTokens > contextWindow - reserveTokensis never true — the safeguard extension never fires and the compaction counter stays at 0run.ts(main agent run path) andcompact.ts(explicit/compactcommand path)Changes
src/agents/pi-embedded-runner/run.ts: CreateeffectiveModelwith cappedcontextWindowfromresolveContextWindowInfo, pass it torunEmbeddedAttemptinstead of the raw modelsrc/agents/pi-embedded-runner/compact.ts: Same pattern — computeeffectiveModelearly, use it for bothcreateOpenClawCodingTools(modelContextWindowTokens) andcreateAgentSessionsrc/agents/pi-embedded-runner/compact.hooks.test.ts: Add missingDEFAULT_CONTEXT_TOKENSto thedefaults.jsmockTest plan
pnpm test -- --run src/agents/pi-embedded-runner/compact.hooks.test.ts src/agents/context-window-guard.test.ts— 12 tests passpnpm test -- --run src/agents/pi-embedded-runner/run.overflow-compaction.test.ts src/agents/pi-embedded-runner/run.overflow-compaction.loop.test.ts— 16 tests passpnpm tsgo— cleanFixes #38905