Skip to content

fix(agents): preserve fresh usage after compaction#93084

Merged
vincentkoc merged 3 commits into
mainfrom
clownfish/ghcrawl-156678-autonomous-smoke
Jun 14, 2026
Merged

fix(agents): preserve fresh usage after compaction#93084
vincentkoc merged 3 commits into
mainfrom
clownfish/ghcrawl-156678-autonomous-smoke

Conversation

@openclaw-clownfish

@openclaw-clownfish openclaw-clownfish Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix embedded compaction cleanup so it clears stale pre-compaction assistant usage without wiping fresh post-compaction assistant usage.
  • Keep the existing compaction end completed payload behavior intact.
  • Add focused regression coverage for stale retained usage versus fresh assistant usage after compaction.

Credit

Clownfish replacement for #50795. This carries forward attribution for @Hollychou924 in #50845, @leno23 in #82874, @de1tydev in #69270, and @425072024 in #91468.

Validation

  • pnpm -s vitest run src/agents/embedded-agent-subscribe.handlers.compaction.test.ts
  • pnpm check:changed

Clownfish 🐠 replacement reef notes:

fish notes: model gpt-5.5, reasoning xhigh; reviewed against 0f37405.

Fixes #50795

@openclaw-clownfish openclaw-clownfish Bot added the clownfish Tracked by Clownfish automation label Jun 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 14, 2026, 7:30 PM ET / 23:30 UTC.

Summary
The PR extracts compaction usage cleanup into a shared helper, applies it to replay and live compaction cleanup, adds stale/fresh usage regression coverage, and edits CHANGELOG.md.

PR surface: Source +11, Tests +213, Docs 0. Total +224 across 5 files.

Reproducibility: yes. Source inspection shows current main runs the cleanup after final compaction and unconditionally zeroes every assistant usage snapshot; I did not run a live TUI/gateway reproduction in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Remove the CHANGELOG.md hunk before merge.

Risk before merge

  • [P1] The branch still edits release-owned CHANGELOG.md, which should be removed before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Land the shared helper and focused handler tests after dropping the CHANGELOG.md hunk; keep release-note context in the PR body or squash message.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] A narrow automated repair can remove only the release-owned changelog hunk; no product decision is needed for that cleanup.

Security
Cleared: No concrete security or supply-chain concern was found; the diff does not touch credentials, dependencies, CI execution, publishing, or permission boundaries.

Review findings

  • [P3] Remove the release-owned changelog edit — CHANGELOG.md:28
Review details

Best possible solution:

Land the shared helper and focused handler tests after dropping the CHANGELOG.md hunk; keep release-note context in the PR body or squash message.

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

Yes. Source inspection shows current main runs the cleanup after final compaction and unconditionally zeroes every assistant usage snapshot; I did not run a live TUI/gateway reproduction in this read-only review.

Is this the best way to solve the issue?

Mostly yes. The runtime change targets the live compaction handler and shares the replay sanitizer invariant, but the release-owned changelog edit is not part of the correct fix.

Full review comments:

  • [P3] Remove the release-owned changelog edit — CHANGELOG.md:28
    CHANGELOG.md is release-owned in this repo, and normal fix PRs should keep release-note context in the PR body or squash message instead. Please drop this hunk before merge.
    Confidence: 0.91

Overall correctness: patch is correct
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This fixes a normal-priority agent session accounting bug where post-compaction context usage can be reported as zero.
  • 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: The author is an OpenClaw automation bot, so the external contributor real-behavior proof gate does not apply; the PR body and CI provide supplemental validation signal.
Evidence reviewed

PR surface:

Source +11, Tests +213, Docs 0. Total +224 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 89 78 +11
Tests 1 214 1 +213
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 304 80 +224

Acceptance criteria:

  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Commit 7e0b3f16e3bd changed the old subscribe compaction cleanup to preserve assistant usage shape by zeroing snapshots, which is the behavior this PR narrows. (role: introduced behavior; confidence: high; commits: 7e0b3f16e3bd; files: src/agents/pi-embedded-subscribe.handlers.compaction.ts, src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.splits-long-single-line-fenced-blocks-reopen.test.ts, src/agents/embedded-agent-subscribe.handlers.compaction.ts)
  • vignesh07: Commit 6bf5e76be666 added the replay-side stale pre-compaction usage snapshot pattern that this PR promotes into a shared helper. (role: adjacent boundary-pattern contributor; confidence: high; commits: 6bf5e76be666; files: src/agents/pi-embedded-runner.sanitize-session-history.test.ts, src/agents/embedded-agent-runner/replay-history.ts)
  • ragesaq: Current-main blame attributes the renamed compaction handler, replay sanitizer, and agent-core compaction timestamp/usage paths to a15427d605. (role: recent current-main area contributor; confidence: medium; commits: a15427d605fe; files: src/agents/embedded-agent-subscribe.handlers.compaction.ts, src/agents/embedded-agent-runner/replay-history.ts, packages/agent-core/src/harness/messages.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Jun 14, 2026
@vincentkoc
vincentkoc merged commit 9ba6ed1 into main Jun 14, 2026
204 of 214 checks passed
@vincentkoc
vincentkoc deleted the clownfish/ghcrawl-156678-autonomous-smoke branch June 14, 2026 23:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 15, 2026
* fix(compaction): preserve fresh usage after compaction

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

* fix(compaction): satisfy stale usage timestamp narrowing

* fix(clownfish): address review for ghcrawl-156678-autonomous-smoke (1)

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: de1ty <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

Co-authored-by: Zhao Shiqi <[email protected]>

---------

Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: 吴杨帆 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Zhao Shiqi <[email protected]>
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Jun 17, 2026
* fix(compaction): preserve fresh usage after compaction

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

* fix(compaction): satisfy stale usage timestamp narrowing

* fix(clownfish): address review for ghcrawl-156678-autonomous-smoke (1)

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: de1ty <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

Co-authored-by: Zhao Shiqi <[email protected]>

---------

Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: 吴杨帆 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Zhao Shiqi <[email protected]>
crh-code pushed a commit to crh-code/openclaw that referenced this pull request Jun 18, 2026
* fix(compaction): preserve fresh usage after compaction

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

* fix(compaction): satisfy stale usage timestamp narrowing

* fix(clownfish): address review for ghcrawl-156678-autonomous-smoke (1)

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: de1ty <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

Co-authored-by: Zhao Shiqi <[email protected]>

---------

Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: 吴杨帆 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Zhao Shiqi <[email protected]>
badgerbees pushed a commit to badgerbees/openclaw that referenced this pull request Jul 8, 2026
* fix(compaction): preserve fresh usage after compaction

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

* fix(compaction): satisfy stale usage timestamp narrowing

* fix(clownfish): address review for ghcrawl-156678-autonomous-smoke (1)

Co-authored-by: HollyChou <[email protected]>

Co-authored-by: de1ty <[email protected]>

Co-authored-by: 吴杨帆 <[email protected]>

Co-authored-by: Zhao Shiqi <[email protected]>

---------

Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: 吴杨帆 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Zhao Shiqi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clownfish Tracked by Clownfish automation P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

Bug: Context token count always shows 0 after compaction

1 participant