fix: respect session context window in preflight compaction#80222
fix: respect session context window in preflight compaction#80222moeedahmed wants to merge 3 commits into
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. source-reproducible. Current main computes the preflight threshold from the resolved model/config window only, so the PR's 149k/272k scenario can compact against a 128k resolved window while the active session still has headroom. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land the focused preflight gate fix after normal maintainer review and merge gates, preserving valid active-session context windows while keeping byte safeguards intact. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible. Current main computes the preflight threshold from the resolved model/config window only, so the PR's 149k/272k scenario can compact against a 128k resolved window while the active session still has headroom. Is this the best way to solve the issue? Yes. The PR changes the narrow threshold input, validates the persisted value, and leaves the existing compaction trigger, byte safeguard, and execution paths intact. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 605a2c87ae80. |
|
I’m seeing what looks like the same issue on OpenClaw 2026.5.12 with Telegram + Codex runtime.
But compaction still appears around this range, and the compact message can report: That suggests This PR’s fix direction, using the active session’s persisted |
|
Heads up: this PR needs to be updated against current |
Summary
Fixes preflight compaction thresholding so sessions use the active session's persisted
contextTokenswhen it is larger than the resolved model context window.This prevents safeguard compaction from firing too early in long-context sessions, for example compacting around ~148k tokens in an active 272k-token session.
Why
A session can persist the actual active context window on the
SessionEntry. When preflight compaction resolves a smaller context window from model/config routing, the threshold can be too low and compaction can run unnecessarily even though the active session still has substantial headroom.Change
entry.contextTokenswhen present and valid.Test
npm test -- --run src/auto-reply/reply/agent-runner-memory.test.tsResult: 16/16 passed.
Real behavior proof
Behavior or issue addressed: Preflight safeguard compaction could fire too early in a long-context Telegram session, compacting around 90k-150k tokens even though the active session had a 272k-token context window.
Real environment tested: Moeed's live OpenClaw 2026.5.5 gateway on macOS, Telegram System topic, using the installed runtime hotfix that matches this source change.
Exact steps or command run after the patch: Applied the source-equivalent installed runtime hotfix, restarted the gateway, sent normal Telegram System-topic replies, inspected the active session store, and scanned the live gateway log for post-hotfix compaction notices/triggers.
Evidence after fix: Copied live terminal output from the real OpenClaw setup:
Installed runtime marker check from the same machine:
Observed result after fix: Normal Telegram replies continued in the System topic while the session sat around 161k/272k tokens, and the gateway log scan found no post-hotfix
preflightCompaction triggered,Compacting context, orContext compactedevents during the verification window.What was not tested: I did not force the session above the real 272k-token threshold; the verification focused on the false-positive early-compaction case that this patch fixes.