fix(memory): prevent stale preflight compaction loops and assert OpenAI model list IDs#81231
fix(memory): prevent stale preflight compaction loops and assert OpenAI model list IDs#81231oxtensor wants to merge 2 commits into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: the same stale preflight compaction bug is now tracked by #81916, while this branch still undercounts legitimate latest usage plus post-usage tail pressure and lacks inspectable real behavior proof. Canonical path: Continue the stale-usage fix in #81916, preserving fresh usage/tail-pressure behavior and dropping this divergent branch. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Continue the stale-usage fix in #81916, preserving fresh usage/tail-pressure behavior and dropping this divergent branch. Do we have a high-confidence way to reproduce the issue? Yes for a source-level PR regression: applying this clamp to current main's combined-tail scenario can reduce 86,000 latest usage plus post-usage tool tail to a much smaller recent-message estimate and bypass expected preflight compaction. I did not run the original production Discord/Pi loop. Is this the best way to solve the issue? No. Bounding stale transcript usage is the right direction, but this branch caps high usage without evidence that the snapshot is stale; the marker-gated work in #81916 is the better path to finish. Security review: Security review cleared: The diff only changes estimator logic and tests, with no new dependency, workflow, permission, secret, download, install, or publishing surface. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against f74436dc81bc. |
1d670be to
efb81c1
Compare
efb81c1 to
636cdb4
Compare
ef3881b to
423c893
Compare
Summary
Fixes #81178.
Replay estimation in
agent-runner-memory.tscould reuse stale historical transcript token usage after earlier compaction events. WhentotalTokensFreshbecame missing or stale, large transcript usage tails could dominate replay estimation and repeatedly trigger unnecessary preflight compactions.This change adds bounded stale-usage handling during replay estimation so stale transcript tails no longer inflate replay token estimates after compaction. The fix is intentionally minimal and isolated to replay-estimation behavior with no API or architecture changes.
The patch also adds response-level
models.listverification coverage for:Real behavior proof
Behavior addressed
Prevents repeated unnecessary preflight compactions caused by stale transcript replay estimates after prior compaction events.
Also verifies response-level model listing includes:
Real environment tested
Local OpenClaw development environment using:
Exact steps or command run after this patch
Evidence after fix
Observed local runtime behavior after applying the patch:
After transcript compaction, replay estimation no longer reused oversized historical transcript token usage when
totalTokensFreshwas stale or missing.Replay estimation remained stable across repeated follow-up runs and no additional premature preflight compactions were triggered.
Response-level models.list output included:
Observed validation output:
Observed result after fix
Before fix:
After fix:
What was not tested
Verification