Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
...Pre-flight compaction (runPreflightCompactionIfNeeded) is skipped on every turn after the first API response because totalTokensFresh is permanently set to true and never reset between turns.
The guard at the top of the function:
if (!(entry.totalTokensFresh === false || !hasPersistedTotalTokens)) return entry;
requires totalTokensFresh === false to proceed when hasPersistedTotalTokens is true. But after the first successful API response, totalTokensFresh is set to true (line ~1912 in agent-runner.runtime) and is only ever set back to false when a brand new session is created (line ~2400). This means:
• Turn 1: fresh session → totalTokensFresh: false → pre-flight runs ✅
• Turn 2+: after API response → totalTokensFresh: true → early return, pre-flight skipped ❌
The pre-flight compaction check never evaluates the token threshold on subsequent turns, regardless of how large the context grows.
Steps to reproduce
- Configure agents.defaults.contextTokens to a value below the model's native context window (e.g., 120000)
- Set compaction.mode: "safeguard"
- Start a conversation and use enough turns to exceed the configured threshold
- Observe via /verbose or logVerbose output that preflightCompaction check logs show persistedFresh=true on every turn after the first
- Pre-flight compaction never triggers — the function returns early before reaching shouldRunPreflightCompaction()
Expected behavior
totalTokensFresh should be reset to false after being consumed by the pre-flight check (or at the start of each new turn), so the guard allows re-evaluation on subsequent turns.
Actual behavior
totalTokensFresh stays true permanently after the first API response, causing the early return to fire on every subsequent turn.
OpenClaw version
2026.4.9 (confirmed identical in 2026.4.11)
Operating system
Linux 6.17.0-1007-oracle (arm64)
Install method
npm global
Model
anthropic/claude-opus-4-6
Provider / routing chain
anthropic (direct)
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Relevant code locations:
• Early return guard: agent-runner.runtime.js → runPreflightCompactionIfNeeded() (line ~1333 in 4.9, ~1368 in 4.11)
• Set to true after API response: agent-runner.runtime.js (line ~1912 in 4.9)
• Set to false only on new session: agent-runner.runtime.js (line ~2400 in 4.9)
Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
...Pre-flight compaction (runPreflightCompactionIfNeeded) is skipped on every turn after the first API response because totalTokensFresh is permanently set to true and never reset between turns.
The guard at the top of the function:
if (!(entry.totalTokensFresh === false || !hasPersistedTotalTokens)) return entry;requires totalTokensFresh === false to proceed when hasPersistedTotalTokens is true. But after the first successful API response, totalTokensFresh is set to true (line ~1912 in agent-runner.runtime) and is only ever set back to false when a brand new session is created (line ~2400). This means:
• Turn 1: fresh session → totalTokensFresh: false → pre-flight runs ✅
• Turn 2+: after API response → totalTokensFresh: true → early return, pre-flight skipped ❌
The pre-flight compaction check never evaluates the token threshold on subsequent turns, regardless of how large the context grows.
Steps to reproduce
Expected behavior
totalTokensFresh should be reset to false after being consumed by the pre-flight check (or at the start of each new turn), so the guard allows re-evaluation on subsequent turns.
Actual behavior
totalTokensFresh stays true permanently after the first API response, causing the early return to fire on every subsequent turn.
OpenClaw version
2026.4.9 (confirmed identical in 2026.4.11)
Operating system
Linux 6.17.0-1007-oracle (arm64)
Install method
npm global
Model
anthropic/claude-opus-4-6
Provider / routing chain
anthropic (direct)
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Relevant code locations:
• Early return guard: agent-runner.runtime.js → runPreflightCompactionIfNeeded() (line ~1333 in 4.9, ~1368 in 4.11)
• Set to true after API response: agent-runner.runtime.js (line ~1912 in 4.9)
• Set to false only on new session: agent-runner.runtime.js (line ~2400 in 4.9)