Skip to content

fix(compaction): recover overflow from sparse assistant history - #122159

Merged
vincentkoc merged 1 commit into
mainfrom
fix/compaction-sparse-usage
Aug 11, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/compaction-sparse-usage

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Related: #121867

What Problem This Solves

Fixes an issue where overflow recovery could crash instead of compacting when persisted or seeded assistant history contained a row without provider usage metadata.

The failure was reproduced in the exact-SHA qualification for 1383144b027a6b10c746636687182064d24b3bf9: candidate, baseline, and runtime-pair QA all failed compaction-retry-mutating-tool after auto-compaction threw Cannot read properties of undefined (reading 'contextUsage').

Qualification: https://github.com/openclaw/openclaw/actions/runs/31512918029

Why This Change Was Made

The compaction usage classifier now treats an assistant row with no usage block as sparse history and continues scanning for the preceding valid usage snapshot. Deliberate zero/unavailable context markers and legacy CLI barriers keep their existing invalidation behavior.

This is the focused mainline extraction of the compaction repair authored by @steipete in 4726adbc6339567679895a5d3d530b4ba6602eff; the earlier combined release repair landed only on a release-integration branch in #121867.

User Impact

Long-running agents can recover from context overflow when history contains sparse assistant rows instead of terminating the run with an internal compaction error.

Evidence

  • Current-main regression before the repair: focused test failed at isUnavailableContextBarrier with undefined.contextUsage.
  • Focused AgentCore compaction test: 32/32 passed after the repair.
  • AgentCore compaction sibling suite: 61/61 passed.
  • Existing zero/unavailable and legacy CLI barrier tests remain green.
  • Exact-head Blacksmith Testbox pnpm check:changed: passed.
  • Prior product-equivalent head Blacksmith Testbox private-QA build: passed; the final head only removes the release-owned changelog entry.
  • Testbox run: https://github.com/openclaw/openclaw/actions/runs/31521475716
  • Exact-head compaction-retry-mutating-tool no longer crashes: auto-compaction succeeded, the retry performed one write, and the terminal reply completed. The scenario then reported a harness-only assertion failure because its current causal check also includes successful preflight compaction-summary requests that occur before the injected overflow; no QA harness changes are included in this focused product repair.
  • Exact-head local ClawSweeper fallback: complete with high confidence; patch correct; no findings, security concerns, maintainer decision, or rank-up moves.
  • git diff --check, privacy scan, and targeted oxfmt: passed.
  • Production: +7/-3; tests: +21/-0.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc vincentkoc self-assigned this Aug 11, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 11, 2026
@vincentkoc
vincentkoc force-pushed the fix/compaction-sparse-usage branch from bcd2483 to f6490a2 Compare August 11, 2026 17:12
@vincentkoc
vincentkoc marked this pull request as ready for review August 11, 2026 17:34
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@vincentkoc
vincentkoc force-pushed the fix/compaction-sparse-usage branch 2 times, most recently from cfffbdb to c8b96ed Compare August 11, 2026 18:00
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 11, 2026, 2:08 PM ET / 18:08 UTC.

ClawSweeper review

What this changes

This PR makes context compaction ignore sparse assistant-history rows without provider usage and adds a regression test proving that an earlier valid usage snapshot is retained.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still dereferences a missing assistant usage block in the shared compaction scan; this branch fixes that owner boundary and adds focused regression coverage. Remove the release-owned changelog edit before merge.

Priority: P1
Reviewed head: c8b96ed6f3000866c31b1c9c6b62387cfcedb247

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with a regression test; only the release-owned changelog edit should be removed.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body additionally records an exact-head overflow-recovery trace and focused Testbox validation.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body additionally records an exact-head overflow-recovery trace and focused Testbox validation.
Evidence reviewed 5 items Current-main defect: The shared barrier classifier dereferences message.usage before its sibling usage reader can reject a sparse assistant row; both reverse scans call this classifier.
Owner and caller path: Compaction preparation projects persisted entries and estimates their context budget; automatic overflow recovery invokes this preparation before emitting a retry outcome.
Focused regression coverage: The branch test constructs a persisted-style assistant row without usage, verifies both usage lookup and token estimation scan to the earlier valid snapshot, and therefore reaches the former dereference path.
Findings 1 actionable finding [P3] Remove the release-owned changelog entry
Security None None.

How this fits together

Agent Core projects persisted session history into model context, estimates its token budget, and prepares compaction before retrying an overflowed request. Assistant usage snapshots guide that estimate, which determines whether recovery can continue.

flowchart LR
  A[Persisted session history] --> B[Session context projection]
  B --> C[Usage snapshot scan]
  C --> D{Usage present?}
  D -->|Sparse row| E[Scan older assistant rows]
  D -->|Explicit unavailable marker| F[Estimate transcript]
  E --> G[Prepare compaction]
  F --> G
  G --> H[Overflow retry]
Loading

Before merge

  • Remove the release-owned changelog entry (P3) - CHANGELOG.md is release-owned for normal mainline work, while this PR body already carries the user-facing release-note context. Drop this entry so release generation remains the sole owner of release notes.

Findings

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:72
Agent review details

Security

None.

PR surface

Source +4, Tests +21, Docs +1. Total +26 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 3 +4
Tests 1 21 0 +21
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 29 3 +26

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +7/-3 (net +4); tests +21/-0; release changelog +1 The runtime growth is a narrowly scoped missing-state guard; the added test covers both reverse scans, while the release-owned changelog line should not land in this PR.

Technical review

Best possible solution:

Merge the narrow sparse-history guard and regression test after removing the release-owned CHANGELOG.md entry; retain the established zero/unavailable and legacy-CLI barriers.

Do we have a high-confidence way to reproduce the issue?

Yes—current main reads message.usage.contextUsage before checking whether usage exists, and the branch's sparse-row test reaches that shared scan path. This read-only review did not execute the test.

Is this the best way to solve the issue?

Yes for the runtime behavior: the guard belongs in the shared barrier classifier used by both reverse scans, preserving explicit unavailable and legacy-CLI semantics. The submitted release-note edit is not part of that fix.

Full review comments:

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:72
    CHANGELOG.md is release-owned for normal mainline work, while this PR body already carries the user-facing release-note context. Drop this entry so release generation remains the sole owner of release notes.
    Confidence: 0.98

Overall correctness: patch is correct
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2c636dda0ca4.

Labels

Label changes:

  • add P1: A sparse persisted assistant row can make overflow recovery terminate instead of compacting and retrying a long-running agent request.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body additionally records an exact-head overflow-recovery trace and focused Testbox validation.

Label justifications:

  • P1: A sparse persisted assistant row can make overflow recovery terminate instead of compacting and retrying a long-running agent request.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body additionally records an exact-head overflow-recovery trace and focused Testbox validation.

Evidence

What I checked:

Likely related people:

  • Shakker: Current-main blame assigns the barrier classifier, including the unsafe dereference, to this commit history root. (role: current-line author; confidence: medium; commits: 2bfb44ea2efa; files: packages/agent-core/src/harness/compaction/compaction.ts)
  • steipete: Recent Agent Core compaction fixes and the linked release-repair discussion identify sustained work on this owner boundary. (role: recent compaction contributor; confidence: high; commits: 5d191c3984cb, d7a444b08a29, fa0fcef9f624; files: packages/agent-core/src/harness/compaction/compaction.ts, packages/agent-core/src/harness/session/session.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Remove the CHANGELOG.md entry; the PR body already provides the needed release-note context.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@vincentkoc
vincentkoc force-pushed the fix/compaction-sparse-usage branch from c8b96ed to b5a7005 Compare August 11, 2026 18:11
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@vincentkoc
vincentkoc merged commit 7fe75ac into main Aug 11, 2026
116 checks passed
@vincentkoc
vincentkoc deleted the fix/compaction-sparse-usage branch August 11, 2026 18:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…claw#122159)

Prevent overflow recovery from dereferencing missing assistant usage metadata while preserving explicit unavailable and legacy CLI barriers.

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant