Skip to content

Respect explicit compaction reserve tokens - #94798

Closed
nblue1-ui wants to merge 1 commit into
openclaw:mainfrom
nblue1-ui:fix-reserve-tokens-explicit-floor
Closed

nblue1-ui wants to merge 1 commit into
openclaw:mainfrom
nblue1-ui:fix-reserve-tokens-explicit-floor

Conversation

@nblue1-ui

@nblue1-ui nblue1-ui commented Jun 19, 2026 •

Copy link
Copy Markdown

Summary

  • Respect an explicitly configured agents.defaults.compaction.reserveTokens when reserveTokensFloor is omitted.
  • Keep reserveTokensFloor as a lower bound only when it is explicitly configured.
  • Align agent settings, runtime memory flush planning, memory-core flush plans, Codex context projection, Codex native startup binding, tests, and config docs.

Real behavior proof

  • Behavior or issue addressed: A real OpenClaw setup had reserveTokens: 8192 configured, but hidden default reserveTokensFloor: 20000 behavior could still be applied in runtime and Codex budget paths. That made the configured reserve misleading and could shrink usable prompt budget unexpectedly.
  • Real environment tested: Local OpenClaw install on Linux/WSL2, package [email protected], with equivalent dist patches applied before preparing this source PR. Source branch head for this PR proof: 286494ff8278da50f5669c50fb23043177fbfd3c.
  • Exact steps or command run after this patch: Ran copied live terminal commands against the installed OpenClaw setup: node -p "require('/home/nblue/.npm-global/lib/node_modules/openclaw/package.json').version", jq '.agents.defaults.compaction | {reserveTokens, reserveTokensFloor}' /home/nblue/.openclaw/openclaw.json, and rg -n "DEFAULT_RESERVE_TOKENS|resolveCompactionSettings|reserveTokensFloor" /home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-settings-*.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-runner.runtime-*.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/extensions/memory-core/index.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/thread-lifecycle-*.js.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): Copied live terminal output from the real setup:
$ node -p "require('/home/nblue/.npm-global/lib/node_modules/openclaw/package.json').version"
2026.6.1

$ jq '.agents.defaults.compaction | {reserveTokens, reserveTokensFloor}' /home/nblue/.openclaw/openclaw.json
{
  "reserveTokens": 8192,
  "reserveTokensFloor": null
}

$ rg -n "DEFAULT_RESERVE_TOKENS|resolveCompactionSettings|reserveTokensFloor" /home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-settings-*.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-runner.runtime-*.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/extensions/memory-core/index.js /home/nblue/.npm-global/lib/node_modules/openclaw/dist/thread-lifecycle-*.js
/home/nblue/.npm-global/lib/node_modules/openclaw/dist/thread-lifecycle-DIl_avGC.js:82: const configuredReserveTokensFloor = toNonNegativeInt(asRecord(compaction)?.reserveTokensFloor);
/home/nblue/.npm-global/lib/node_modules/openclaw/dist/extensions/memory-core/index.js:81: const reserveTokensFloor = normalizeNonNegativeInt(compactionDefaults?.reserveTokensFloor) ?? normalizeNonNegativeInt(compactionDefaults?.reserveTokens) ?? 2e4;
/home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-settings-BrNIdcFH.js:24: const configuredReserveTokensFloor = toNonNegativeInt(compactionCfg?.reserveTokensFloor);
/home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-settings-BrNIdcFH.js:33: const targetReserveTokens = configuredReserveTokens !== void 0 ? Math.max(configuredReserveTokens, configuredReserveTokensFloor ?? 0) : Math.max(currentReserveTokens, reserveTokensFloor);
/home/nblue/.npm-global/lib/node_modules/openclaw/dist/agent-runner.runtime-CCReftdY.js:676: const reserveTokensFloor = memoryFlushPlan?.reserveTokensFloor ?? configuredReserveTokensFloor ?? configuredReserveTokens ?? 2e4;
  • Observed result after fix: In the real setup, reserveTokens: 8192 with no configured floor is no longer forced through the hidden 20000 floor in the patched runtime paths. The source PR now also covers the Codex native startup binding path that ClawSweeper flagged after the first pass.
  • What was not tested: I did not run a full end-to-end GitHub Actions runner locally; this PR body proof addresses the external PR real-behavior gate, while the source tests and type checks below cover regression behavior.
  • Proof limitations or environment constraints: The proof is from a local installed OpenClaw package with equivalent dist patches applied before this source PR. It is copied live terminal output, not a screenshot.
  • Before evidence (optional but encouraged): Prior behavior was max(reserveTokens, default reserveTokensFloor) in several paths, so reserveTokens: 8192 could become an effective 20000 reserve when the floor was omitted.

Tests and validation

Focused commands run locally in /home/nblue/.openclaw/workspace/openclaw-upstream:

node scripts/run-vitest.mjs run extensions/codex/src/app-server/startup-binding.test.ts src/agents/agent-settings.test.ts extensions/codex/src/app-server/context-engine-projection.test.ts extensions/memory-core/index.test.ts
node scripts/run-vitest.mjs run src/auto-reply/reply/agent-runner-memory.test.ts
corepack pnpm exec oxfmt --check extensions/codex/src/app-server/startup-binding.ts extensions/codex/src/app-server/startup-binding.test.ts src/agents/agent-settings.ts src/agents/agent-settings.test.ts src/auto-reply/reply/agent-runner-memory.ts src/auto-reply/reply/agent-runner-memory.test.ts extensions/memory-core/src/flush-plan.ts extensions/memory-core/index.test.ts extensions/codex/src/app-server/context-engine-projection.ts extensions/codex/src/app-server/context-engine-projection.test.ts docs/reference/session-management-compaction.md src/config/schema.help.ts src/config/types.agent-defaults.ts
corepack pnpm tsgo:core
corepack pnpm tsgo:extensions

Regression coverage added or updated:

  • Explicit reserveTokens no longer gets raised by the implicit default floor.
  • Explicit reserveTokensFloor still acts as a lower bound.
  • Explicit floor is capped on small-context models before it is used as a lower bound.
  • Memory flush planning falls back to explicit reserveTokens before 20000.
  • Codex context projection mirrors the same rule.
  • Codex native startup binding mirrors the same rule.

Risk checklist

Did user-visible behavior change? Yes

Did config, environment, or migration behavior change? Yes

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core agents Agent runtime and tooling extensions: codex size: S triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 26, 2026, 12:51 AM ET / 04:51 UTC.

Summary
This PR changes compaction reserve resolution so explicit agents.defaults.compaction.reserveTokens is not raised by the implicit 20,000-token floor when reserveTokensFloor is omitted, across agent settings, memory flush, Codex projection/native startup, tests, and docs.

PR surface: Source +10, Tests +84, Docs +5. Total +99 across 12 files.

Reproducibility: yes. at source level: current main and v2026.6.10 raise explicit reserveTokens by the implicit floor when reserveTokensFloor is omitted. I did not execute tests because this review is read-only.

Review metrics: 1 noteworthy metric.

  • Compaction config semantics: 1 existing default interaction changed. Explicit reserveTokens below 20,000 would no longer be raised when reserveTokensFloor is omitted, which matters for upgrade behavior.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until stronger 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 terminal output from a real source or installed runtime command that executes the resolver or agent compaction path and prints the effective reserve for omitted-floor and explicit-floor configs.
  • Get maintainer confirmation for the omitted-floor semantic change, or preserve the shipped implicit floor by default.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body includes terminal output from a patched install, but it only shows config and rg matches rather than executing the changed resolver or an agent/compaction path that prints the effective reserve. 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] Existing users with reserveTokens below 20,000 and no reserveTokensFloor would get a smaller effective reserve on upgrade, changing compaction timing and output/tool headroom.
  • [P1] The current documented opt-out is reserveTokensFloor: 0; making omitted floor behave like opt-out creates a second meaning for existing config.
  • [P1] The supplied proof does not execute the changed resolver or a real agent/compaction path, so the effective runtime value is not shown after the patch.
  • [P1] Adjacent compaction PRs remain open, so maintainers should reconcile this semantic change with small-context caps and runtime override persistence before merge.

Maintainer options:

  1. Preserve the shipped floor by default (recommended)
    Keep reserveTokensFloor as the default lower bound and require users who want a smaller reserve to set the documented reserveTokensFloor: 0 opt-out.
  2. Accept the semantic change deliberately
    Maintainers may choose that explicit reserveTokens should override the implicit floor, but the PR should then include runtime proof and release-note context for the upgrade-visible behavior change.
  3. Pause behind compaction direction
    Hold this PR until the related compaction-budget PRs settle if maintainers want one coordinated public contract for reserve floors, caps, and overrides.

Next step before merge

  • [P1] Manual review is needed because the remaining blockers are maintainer acceptance of compatibility-sensitive config semantics and contributor-supplied runtime proof, not a narrow automated repair.

Security
Cleared: The diff stays in TypeScript runtime logic, docs, and tests, with no dependency, workflow, secret, permission, package, or external code-execution changes.

Review findings

  • [P1] Keep the shipped floor unless the user opts out — src/agents/agent-settings.ts:80
Review details

Best possible solution:

Preserve the shipped implicit-floor behavior by default unless maintainers explicitly approve the semantic change; if approved, add runtime proof that prints the effective reserve and reconcile the overlapping compaction PRs before merge.

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

Yes, at source level: current main and v2026.6.10 raise explicit reserveTokens by the implicit floor when reserveTokensFloor is omitted. I did not execute tests because this review is read-only.

Is this the best way to solve the issue?

No, not yet: the implementation is plausible and covers sibling paths, but the existing documented solution is reserveTokensFloor: 0, so changing omitted-floor semantics needs maintainer approval and stronger runtime proof.

Full review comments:

  • [P1] Keep the shipped floor unless the user opts out — src/agents/agent-settings.ts:80
    Latest release docs already define the implicit 20,000-token floor and the supported opt-out is reserveTokensFloor: 0. Changing reserveTokens alone to bypass the floor silently gives existing configs a smaller effective reserve on upgrade and creates a second meaning for omitted reserveTokensFloor.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.84

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority agents compaction behavior change with limited blast radius but real operator-visible config impact.
  • merge-risk: 🚨 compatibility: The PR changes how existing reserveTokens config is interpreted for users who omit reserveTokensFloor.
  • merge-risk: 🚨 availability: Reducing effective reserve headroom can shift compaction thresholds and overflow/retry behavior in existing agent runs.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes terminal output from a patched install, but it only shows config and rg matches rather than executing the changed resolver or an agent/compaction path that prints the effective reserve. 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 +10, Tests +84, Docs +5. Total +99 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 26 16 +10
Tests 4 91 7 +84
Docs 1 8 3 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 125 26 +99

What I checked:

  • Repository policy read and applied: Root plus scoped docs, extensions, and agents AGENTS.md were read; config/default behavior is compatibility-sensitive and Codex-related review required direct upstream source inspection. (AGENTS.md:10, 751a6c23f098)
  • Current main still enforces the implicit floor: Current main computes targetReserveTokens with Math.max(configuredReserveTokens ?? currentReserveTokens, reserveTokensFloor), so explicit reserveTokens below the floor is still raised. (src/agents/agent-settings.ts:79, 751a6c23f098)
  • Latest release documents and ships the existing floor contract: Tag v2026.6.10 documents the 20,000-token default floor and the reserveTokensFloor: 0 opt-out, and its settings code still applies the floor to explicit reserves. Public docs: docs/reference/session-management-compaction.md. (docs/reference/session-management-compaction.md:340, aa69b12d0086)
  • PR diff changes the central settings behavior: The PR changes the agent settings path to lower-bound explicit reserveTokens only when reserveTokensFloor is configured; that is the upgrade-visible semantic change. (src/agents/agent-settings.ts:77, 286494ff8278)
  • Codex sibling paths were inspected: OpenClaw Codex projection and startup binding both consume the same reserve semantics, and upstream Codex source confirms the app-server text cap and token-usage context-window surfaces used by these guards. (codex-rs/protocol/src/user_input.rs:8, 92d2e1df7079)
  • Real behavior proof is still thin: The PR body includes copied terminal output from a patched install, but the command only prints package version, config JSON, and rg matches from built files; it does not execute a resolver, agent turn, or compaction path that prints the effective reserve. (286494ff8278)

Likely related people:

  • vincentkoc: Current-main blame and recent history place the central reserve-floor helper and Codex reserve-resolution lines under Vincent Koc's recent compaction/settings work. (role: recent area contributor; confidence: high; commits: 497d53d821e6, aa69b12d0086; files: src/agents/agent-settings.ts, extensions/codex/src/app-server/context-engine-projection.ts, extensions/codex/src/app-server/startup-binding.ts)
  • steipete: Shortlog history shows the heaviest recent contribution across the agent runtime, memory flush, and compaction-adjacent files involved in this review. (role: major adjacent contributor; confidence: high; commits: cdaa70facb9b, bb0bfabec85d, e0dfc776bba8; files: src/auto-reply/reply/agent-runner-memory.ts, extensions/memory-core/src/flush-plan.ts, docs/reference/session-management-compaction.md)
  • Takhoffman: Recent history includes context-window and compaction-limit work near the same prompt budget and reserve-token invariants. (role: adjacent context-limit contributor; confidence: medium; commits: 4f00b769251d, cfae8fd1e927; files: src/auto-reply/reply/agent-runner-memory.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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 19, 2026
@nblue1-ui
nblue1-ui force-pushed the fix-reserve-tokens-explicit-floor branch from e01778c to a508b20 Compare June 19, 2026 05:19
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 19, 2026
@nblue1-ui
nblue1-ui force-pushed the fix-reserve-tokens-explicit-floor branch from a508b20 to 0be3fbd Compare June 19, 2026 05:39
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 19, 2026
@nblue1-ui

Copy link
Copy Markdown
Author

Follow-up for the latest ClawSweeper finding: the Codex native startup binding path has now been aligned too.

Latest head: 0be3fbd09057515eb71b62ba4425614f2cab3cfe

Changes added after the previous review:

  • extensions/codex/src/app-server/startup-binding.ts now respects explicit reserveTokens when reserveTokensFloor is omitted instead of applying the hidden 20000 default floor.
  • extensions/codex/src/app-server/startup-binding.test.ts adds regression coverage for both:
    • reserveTokens without reserveTokensFloor -> explicit reserve is used.
    • reserveTokens with explicit reserveTokensFloor -> floor remains a lower bound.

Re-run verification on this head:

node scripts/run-vitest.mjs run extensions/codex/src/app-server/startup-binding.test.ts src/agents/agent-settings.test.ts extensions/codex/src/app-server/context-engine-projection.test.ts extensions/memory-core/index.test.ts
node scripts/run-vitest.mjs run src/auto-reply/reply/agent-runner-memory.test.ts
corepack pnpm exec oxfmt --check extensions/codex/src/app-server/startup-binding.ts extensions/codex/src/app-server/startup-binding.test.ts src/agents/agent-settings.ts src/agents/agent-settings.test.ts src/auto-reply/reply/agent-runner-memory.ts src/auto-reply/reply/agent-runner-memory.test.ts extensions/memory-core/src/flush-plan.ts extensions/memory-core/index.test.ts extensions/codex/src/app-server/context-engine-projection.ts extensions/codex/src/app-server/context-engine-projection.test.ts docs/reference/session-management-compaction.md src/config/schema.help.ts src/config/types.agent-defaults.ts
corepack pnpm tsgo:core
corepack pnpm tsgo:extensions

All of the above passed locally.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 19, 2026
@nblue1-ui
nblue1-ui force-pushed the fix-reserve-tokens-explicit-floor branch from 0be3fbd to 286494f Compare June 19, 2026 05:54
@nblue1-ui

Copy link
Copy Markdown
Author

Stale label cleanup note:

status: needs proof is still attached, but the latest head has passed the proof gate.

Current head: 286494ff8278da50f5669c50fb23043177fbfd3c

Observed checks on this head:

  • Real behavior proof: success
  • auto-response: success
  • Local PR body policy evaluation: passed, reason: External PR includes after-fix real behavior proof.

I attempted to remove status: needs proof directly through the GitHub API, but the token only has pull-level access to openclaw/openclaw labels and GitHub returned 403 Must have admin rights to Repository.

Please remove the stale status: needs proof label or let the status automation refresh it for the current head.

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 22, 2026
@clawsweeper clawsweeper Bot added the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Jun 26, 2026
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Maintainer decision: preserve the shipped implicit reserveTokensFloor contract and close this proposal.

When reserveTokensFloor is omitted, OpenClaw's documented default floor remains 20,000 tokens; the supported explicit opt-out is reserveTokensFloor: 0. Making an explicit reserveTokens silently disable the omitted floor would change existing configs on upgrade and create a second meaning for omission across agent settings, memory flush, Codex projection, and Codex native-thread rotation.

#100621 landed the actual small-context fix as 62d957634c53: cap the final effective reserve when the active context window is known, without changing omitted-floor semantics. I also checked upstream Codex's context-window and auto-compaction threshold contract; it does not require this OpenClaw config reinterpretation.

The supported alternative is to set reserveTokensFloor: 0 when an operator intentionally wants the lower explicit reserve. Concrete evidence that would change this decision would be an explicit maintainer product decision to alter the shipped contract, with an upgrade/migration plan and end-to-end proof across all four sibling consumers.

Thank you @nblue1-ui for the careful cross-surface implementation and tests.

@steipete steipete closed this Jul 6, 2026
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 extensions: codex extensions: memory-core Extension: memory-core merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants