Repository navigation
perf(agents): amortize history-limit eviction with hysteresis - #115281
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 12:09 PM ET / 16:09 UTC. ClawSweeper reviewWhat this changesThis PR changes history trimming so channel sessions evict conversation turns in batches, keeping the prompt prefix stable for several turns to improve provider prompt-cache reuse. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 5 items remain Keep this PR open for maintainer review. The cache-amortization approach is focused, but it changes the meaning of existing Priority: P2 Review scores
Verification
How this fits togetherChannel and DM session settings feed a history-preparation step before each agent attempt. That step trims the message transcript used for provider requests and for compaction, affecting context size, token cost, latency, and prompt-cache stability. flowchart LR
A[Channel or DM session] --> B[History-limit setting]
B --> C[Attempt history preparation]
C --> D[Conversation history limiter]
D --> E[Provider prompt]
D --> F[Compaction input]
E --> G[Cache cost and latency]
Decision needed
Why: This is not only an internal performance optimization: it changes the effective context cap selected by existing users and can alter provider cost, latency, and model context behavior. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +17, Tests +55. Total +72 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep strict configured-limit semantics unless the responsible owner explicitly adopts bounded overage as the documented contract; if adopted, demonstrate fresh and upgrade behavior with a redacted real provider or channel trace that shows the intended cache improvement. Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction is included. The source-level mechanism is clear from the supplied current behavior and focused limiter tests, but a real history-limited provider run has not been shown. Is this the best way to solve the issue? No—not until an owner decides whether an existing configured limit remains a hard cap. Batched eviction is a plausible cache optimization, but changing that contract silently is not the narrowest safe default. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 964c5abbded4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…-20260728 * origin/main: fix(slack): cap chat.update edit text at the 4000-char limit, not the 8000 send limit (#115027) [AI-assisted] docs: recommend Node 26 in quickstart, landing, and platform install docs (#115064) refactor(workboard): tidy Control UI card execution helpers (#115195) perf(agents): amortize history-limit eviction with hysteresis (#115273) (#115281) fix: schema-version refusal blames a downgrade that never happened and cannot identify the stale install (#115232) fix: restore Fish completion after global CLI options (#115222) refactor(agents): collapse the client-tool catalog branch (#115212)
* origin/main: (199 commits) refactor(workboard): tidy Control UI card execution helpers (openclaw#115195) perf(agents): amortize history-limit eviction with hysteresis (openclaw#115273) (openclaw#115281) fix: schema-version refusal blames a downgrade that never happened and cannot identify the stale install (openclaw#115232) fix: restore Fish completion after global CLI options (openclaw#115222) refactor(agents): collapse the client-tool catalog branch (openclaw#115212) fix(macos): signed rebuild no longer stalls on app shutdown (openclaw#103957) fix(agents): prevent repeated Code Mode output across waits (openclaw#115213) refactor(ui): split Profile (identity) from Usage (statistics) (openclaw#115245) fix(channels): report a channel that cannot receive as unhealthy instead of connected (openclaw#115229) fix(cli): reject malformed infer model refs (openclaw#115225) feat(ui): finish the Lobsterdex at 42 with wild variants, squish fix, and blink variance (openclaw#115264) test(migrations): avoid mtime precision in checkpoint fixture (openclaw#115269) test(signal): verify archive limits without malformed tar (openclaw#115270) refactor(sessions): isolate legacy transcript fixtures (openclaw#115231) fix(discord): clear pending launch watchdog (openclaw#115100) fix(agents): stop quadratic subagent prompt rendering (openclaw#115263) fix(memory-core): recover dreaming cron reconciliation (openclaw#115174) fix(qa-lab): filter incompatible channel scenarios (openclaw#115087) fix(android): respect locale in compact labels test(i18n): prove iOS discovery catalog ownership ...
…etwork-none * origin/main: feat(skills): shared authoring standards make learned skills routable (#115103) fix(matrix): suppress previews for modifying hooks fix: prevent node gateway hangs and runaway local inference (#115248) refactor(ui): adopt @lit/task across remaining page surfaces (#115274) fix(slack): cap chat.update edit text at the 4000-char limit, not the 8000 send limit (#115027) [AI-assisted] docs: recommend Node 26 in quickstart, landing, and platform install docs (#115064) refactor(workboard): tidy Control UI card execution helpers (#115195) perf(agents): amortize history-limit eviction with hysteresis (#115273) (#115281)
* origin/main: (62 commits) feat(macos): enable Computer Control by default and diagnose stale Accessibility grants (openclaw#115280) fix(qa): restore full-stack scenarios and truthful suite exits (openclaw#115290) feat(memory): backfill past sessions from Control UI (openclaw#115266) docs: link macOS onboarding pages to app download (openclaw#111361) feat(skills): shared authoring standards make learned skills routable (openclaw#115103) fix(matrix): suppress previews for modifying hooks fix: prevent node gateway hangs and runaway local inference (openclaw#115248) refactor(ui): adopt @lit/task across remaining page surfaces (openclaw#115274) fix(slack): cap chat.update edit text at the 4000-char limit, not the 8000 send limit (openclaw#115027) [AI-assisted] docs: recommend Node 26 in quickstart, landing, and platform install docs (openclaw#115064) refactor(workboard): tidy Control UI card execution helpers (openclaw#115195) perf(agents): amortize history-limit eviction with hysteresis (openclaw#115273) (openclaw#115281) fix: schema-version refusal blames a downgrade that never happened and cannot identify the stale install (openclaw#115232) fix: restore Fish completion after global CLI options (openclaw#115222) refactor(agents): collapse the client-tool catalog branch (openclaw#115212) fix(macos): signed rebuild no longer stalls on app shutdown (openclaw#103957) fix(agents): prevent repeated Code Mode output across waits (openclaw#115213) refactor(ui): split Profile (identity) from Usage (statistics) (openclaw#115245) fix(channels): report a channel that cannot receive as unhealthy instead of connected (openclaw#115229) fix(cli): reject malformed infer model refs (openclaw#115225) ...
What Problem This Solves
Channel
historyLimit/dmHistoryLimitsessions get a per-turn sliding window: once past the limit, every new user turn shifts the outbound prompt's start by one message, so the provider prompt cache never hits again for the life of the session (~0% prefix-cache hits, paid every turn).Closes #115273.
Why This Change Was Made
limitHistoryTurns(src/agents/embedded-agent-runner/history.ts) now applies hysteresis instead of exact-limit trimming: the window may grow toceil(limit × 1.5), and the keep count is derived with mod arithmetic so the absolute window start stays byte-identical for a full eviction batch of consecutive turns, then cuts back toward the limit in one step — amortizing one cache break over many turns, the same way compaction amortizes its boundary break. The function stays a pure, deterministic function of the message list and limit; no state, no timestamps.User Impact
Long channel sessions with a history limit regain provider prompt-cache reuse (lower cost and latency). Named tradeoff: the model temporarily sees up to 50% more turns than the configured limit; it never sees fewer. The compaction-execution caller sees the same bounded growth (slightly larger summarization input), which is harmless.
Evidence
node scripts/run-vitest.mjs src/agents/embedded-agent-runner.limithistoryturns.test.ts— 16 tests passed, covering below-limit passthrough, stable window start between cuts, single-step cutback on crossing 1.5×, repeated growth in steps, prelude/summary preservation, and tool-call histories.attempt-history-prepare.ts,compaction-session-execution.ts); neither depends on exact-limit trimming.