feat(compaction): support percentage strings for token thresholds#87932
feat(compaction): support percentage strings for token thresholds#87932tanshanshan wants to merge 5 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 29, 2026, 9:07 PM ET / 01:07 UTC. Summary PR surface: Source +43, Other +92. Total +135 across 6 files. Reproducibility: yes. at source level: PR head accepts percentage strings in the schema, while current settings and memory-core readers still treat these fields as numeric-only. I did not run a live mixed-model gateway compaction scenario in this read-only review. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Choose one backward-compatible relative-threshold config contract, then update schema, types, help/docs, agent settings, memory-core flush planning, manual compaction behavior, focused tests, and real-run proof together. Do we have a high-confidence way to reproduce the issue? Yes at source level: PR head accepts percentage strings in the schema, while current settings and memory-core readers still treat these fields as numeric-only. I did not run a live mixed-model gateway compaction scenario in this read-only review. Is this the best way to solve the issue? No as submitted: percentage strings are a plausible API, but accepting them at the schema boundary before every consumer resolves them is not the narrowest maintainable fix. The safer path is one maintainer-chosen API with complete reader, docs, tests, and proof coverage. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 54b09580f61b. Label changesLabel justifications:
Evidence reviewedPR surface: Source +43, Other +92. Total +135 across 6 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (1 earlier review cycle)
|
Allow percentage strings (e.g. "40%") for: - reserveTokens - keepRecentTokens - reserveTokensFloor - softThresholdTokens Percentages resolve at runtime against the active model's context window. Integer values keep the current behavior (backward compatible). Fixes openclaw#87136
…lper Move the inline percentage-parsing function from agent-runner-memory.ts into src/config/token-threshold.ts for reuse. Fixes openclaw#87136
Address oxlint errors: Expected { after if condition, use Number.parseInt instead of global parseInt.
ClawSweeper P1: preserve existing default thresholds. When unset, return the documented absolute default (e.g. 20000, 4000) instead of a context-window percentage to avoid changing existing behavior. Fixes openclaw#87136
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This pull request has been automatically marked as stale due to inactivity. |
Summary
reserveTokens,keepRecentTokens,reserveTokensFloor,softThresholdTokens) use absolute token counts that don't scale with the model's context window. Switching from a 1M-token model to a 200K-token model causessoftThresholdTokens=400000to exceed the entire context window, triggering memory flush on every turn."40%") for these four parameters, resolved at runtime against the active model's context window. Int values keep the current behavior.zod-schema.agent-defaults.ts(schema),types.agent-defaults.ts(types),agent-runner-memory.ts(applyresolveTokenThreshold),schema.help.ts(help text),token-threshold.ts(resolver).Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Motivation
When switching models with different context windows (e.g. DeepSeek 1M → GLM-5.1 200K), absolute token thresholds don't scale.
contextThreshold(0.75) andmaxHistoryShare(0.8) already use ratios correctly — these four parameters should too. The current workaround (manual JSON edit + gateway restart per model switch) is error-prone and unsustainable.Real behavior proof (required for external PRs)
Behavior addressed: Percentage strings (e.g.
"40%") for compaction token thresholds resolve at runtime against the active model's context window. Int values keep current behavior.Real environment tested: Linux (x86_64), Node.js 22.22, OpenClaw local checkout on
fix/compaction-percentage-thresholds-87136branch.Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix:
"40%"with 1M context window →400000tokens ✓"40%"with 200K context window →80000tokens ✓400000passes through unchanged ✓undefinedfalls back to default (4000/20000) ✓"not-a-percent","40.5%","abc","") fall back to default ✓"40%"config scales correctly across model switches (1M vs 200K) ✓What was not tested: Live compaction with percentage config and model switching on a real gateway. The proof exercises
resolveTokenThresholdthrough real production code, which is the same resolveragent-runner-memory.tscalls during memory preflight/flush planning.Diagram
Security Impact (required)
Repro + Verification
Environment
Steps
fix/compaction-percentage-thresholds-87136branchnode --import tsx scripts/compaction-percentage-proof.mjsExpected
Math.floor((contextWindow × pct) / 100)Actual
All 18 proof checks pass.
Evidence
Human Verification (required)
Compatibility / Migration
Risks and Mitigations
None — additive feature, existing int configs unchanged. Percentage strings are a new opt-in format.
Fixes #87136