Skip to content

fix(agents): cap effective compaction reserve - #100621

Merged
steipete merged 2 commits into
mainfrom
codex/pr-87927-review
Jul 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/pr-87927-review

Conversation

@steipete

@steipete steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

For a known 16K model context, OpenClaw capped reserveTokensFloor but then restored the uncapped 16,384-token runtime default through the final Math.max. The shared compaction predicate therefore returned true from the first token.

This supersedes #87927 with the proven narrow fix. The original recent-tail cap was not replayed: agent-core treats keepRecentTokens as a cut-point target rather than a hard upper bound, so claiming it prevented every post-compaction overflow would be incorrect.

Why This Change Was Made

The final effective reserve now uses the same known-context maximum already applied to the floor and preemptive compaction. Explicit reserves are capped too, while floor-disabled low reserves, unknown contexts, and large contexts preserve their existing behavior.

User Impact

Small-context local models no longer enter compaction from token one because the runtime default or an oversized configured reserve consumed the whole context window. Existing keepRecentTokens semantics remain unchanged.

Evidence

  • Exact runtime proof with real SettingsManager, applyAgentCompactionSettingsFromConfig, and agent-core shouldCompact: before reserveTokens=16384, shouldCompact(1)=true; after reserveTokens=8384, shouldCompact(1)=false.
  • pnpm test src/agents/agent-settings.test.ts --reporter=dot — 31 tests passed on Blacksmith Testbox.
  • Config baseline generation check, docs MDX check, docs formatting, targeted oxfmt, and targeted oxlint passed.
  • Fresh Codex autoreview: clean, no accepted/actionable findings.

Co-authored with and changelog credit preserved for @vincentkoc.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Jul 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agents): cap effective compaction reserve This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready review completed at exact head 254903be6e616220743742f5d2752930b241bfd2.

What was reviewed:

  • Verified the changed settings path end to end: applyAgentCompactionSettingsFromConfig combines current/default/configured reserve and the floor, then applies overrides through the real agent-core SettingsManager.
  • Checked callers in embedded turn setup, post-resource-loader reapplication, and compaction setup; checked the sibling preemptive-compaction threshold.
  • Inspected agent-core shouldCompact: it triggers when usage exceeds contextWindow - reserveTokens, proving the current 16K default can compact from token one and the final effective-reserve cap is the correct owner-boundary fix.
  • Rejected the original fix(agents): cap compaction budgets for small contexts #87927 keepRecentTokens cap. That value is a cut target, not a hard upper bound; whole messages/turns and split-turn summaries can exceed it.

Proof:

  • Blacksmith Testbox lease tbx_01kwtwkx54z39tm1wdw5emacvp: focused settings suite passed 31/31.
  • Exact runtime proof with a 16,384-token context: before the patch reserve was 16,384 and shouldCompact(1) was true; after the patch reserve is 8,384 and shouldCompact(1) is false.
  • Generated config baseline, docs MDX, docs formatting, targeted oxfmt, and targeted oxlint passed.
  • Broad Testbox pnpm check:changed passed in 9m32s.
  • Fresh autoreview found no actionable issues and rated the patch correct with 0.98 confidence.
  • Exact-head hosted CI: https://github.com/openclaw/openclaw/actions/runs/28770203645

Known proof gap: no live Ollama generation. The changed contract is directly exercised at the real settings-manager and compaction-predicate boundary.

@steipete
steipete merged commit 62d9576 into main Jul 6, 2026
97 checks passed
@steipete
steipete deleted the codex/pr-87927-review branch July 6, 2026 05:49
@steipete

steipete commented Jul 6, 2026

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 docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant