Skip to content

fix(compaction): show the summarizer the audited latest ask - #130620

Merged
roboclaw-bot merged 4 commits into
mainfrom
fix/compaction-latest-ask-visible-to-summarizer
Aug 27, 2026
Merged

roboclaw-bot merged 4 commits into
mainfrom
fix/compaction-latest-ask-visible-to-summarizer

Conversation

@VACInc

@VACInc VACInc commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

A long tool-heavy turn could hit the context limit and then fail both automatic and manual compaction with latest_user_ask_not_reflected. The quality guard audited the latest user request from the pre-partition window, while recent-turn preservation removed that request—and sometimes its completing assistant response—from the messages given to the summarizer. If the bounded verbatim suffix then dropped the request, the guard demanded a fact the producer never saw and cancelled compaction.

The original patch handed only the bounded request to the summarizer. Autoreview found that an all-preserved window could still skip the summarizer and that request-only context could resurrect completed work. ClawSweeper then found the remaining inverse: even with the full turn visible, an accepted summary could still list a completed request under ## Pending user asks.

Final live Gateway proof exposed one more boundary: when the retention cut split a long completed turn, the summarizer saw only its prefix while the terminal assistant response stayed in the retained suffix. The audit therefore treated the boundary request as unresolved and accepted a split-turn summary that revived it under pending work.

Why This Change Was Made

The quality producer receives the full prepared context whenever it is already generating a summary. An all-preserved window remains model-free when its audited request survives verbatim; if bounded preservation would hide the request, the same prepared context is summarized instead of returning a doomed fallback.

For genuine split turns, Agent Core now records whether that exact cut turn completes in its retained suffix. The safeguard carries that cut-scoped fact into retention and audits every generated ## Pending user asks section, including the separately generated split-turn summary. A bad first summary is rejected with a concrete reason and corrected within the existing bounded retry. Non-split turns keep their existing local completion inference.

This keeps the quality guard fail-closed, preserves the bounded verbatim suffix, and avoids treating user text as prompt authority. No config, schema, protocol, or default changes are introduced.

The first exact-head CI run also exposed an unrelated flaky UI test. Product code was unaffected: the test hit Vitest's 1-second wait timeout while the attention panel awaited a lazy import. The test now joins that import and then awaits Lit's update before asserting the same top-layer menu ancestry. No timeout was increased and no assertion was weakened.

User Impact

Sessions whose latest user turn is preserved behind a long tool chain—or split across the retention cut—can compact instead of cancelling or reviving completed work. Accepted checkpoints cannot mark a successfully completed latest turn as pending.

Evidence

Live Gateway proof

  • Exact committed head: 8e62635fd626e69da80179777a0b1de4e9cf0356
  • Direct AWS Crabbox run: https://crabbox.openclaw.ai/portal/runs/run_24a23cff22e0
  • Environment: built OpenClaw Gateway and CLI from the exact head, isolated state, deterministic local OpenAI-compatible provider.
  • The first compaction response deliberately placed the completed split-turn request under ## Pending user asks.
  • Observed three provider requests: completed user turn, rejected bad compaction, corrective compaction.
  • Persisted result: all three generated pending sections were None.; the completed request and /tmp/pr130620/live/marker remained under non-pending context.
  • The one-shot lease cbx_3381f0b0b953 was destroyed after artifact collection.

Regression proof

  • The split-turn regression reproduces the live failure: empty history body, long request prefix, terminal completion in the retained suffix, bad first summary, corrective retry.
  • Agent Core coverage proves completion is bound to the turn intersecting the cut, not a newer retained turn with different terminal state.
  • The completed-turn regression first returns a summary that places the completed request under ## Pending user asks; the repaired owner rejects it and accepts only the corrected checkpoint.
  • The all-preserved regression proves the producer sees both the latest request and its terminal assistant completion.
  • The retention regression proves a completed request survives final artifact budgeting outside the pending section.

Local verification

  • node scripts/run-vitest.mjs packages/agent-core/src/harness/compaction/compaction.test.ts src/agents/agent-hooks/compaction-safeguard.test.ts — 45/45 core and 142/142 safeguard passed
  • node scripts/run-vitest.mjs ui/src/components/sidebar-attention.test.ts — 33/33 passed on the prior exact head; the UI file is unchanged by the split-turn repair
  • Focused attention-panel test — 10/10 repeated runs passed
  • node scripts/check-changed.mjs — formatting, core/core-test typecheck, lint, dead-code, architecture, import-cycle, guard, and UI i18n lanes passed
  • Final project-local structured autoreview — clean; no P0/P1 actionable findings (0.93 confidence)

CI diagnosis

Initial run 33034247213 failed only checks-node-compact-large-11 in ui/src/components/sidebar-attention.test.ts; the assertion timed out at 1009 ms while awaiting the lazy panel module. All compaction checks and the focused ClawSweeper proof passed on that head. Run 33038123439 completed green on the prior repaired head. Exact-head CI for 8e62635fd626e69da80179777a0b1de4e9cf0356 is tracked separately before merge.

Scope

  • Production: +100 / -9 (net +91)
  • Tests: +270 / -24 (net +246)
  • Total: 6 files, +370 / -33

The production growth carries one cut-scoped completion fact through the existing Agent Core preparation contract and adds the missing generated-section audit. There is no parallel compaction path or compatibility surface.

What was not tested

No replay of the reporter's private ~255k-token gateway transcript was performed. The live proof uses the real Gateway/session/CLI/persistence path with deterministic provider responses so the bad-first-summary/corrective-retry boundary is reproducible; it is not external-provider proof.

Worked on by

The safeguard reads the latest user ask from the pre-partition window but
only feeds the summarizer the partitioned messages. When recentTurnsPreserve
keeps the ask verbatim and the preserved suffix is head-truncated, the
producer can never reflect it, so every attempt fails
latest_user_ask_not_reflected and compaction cancels, leaving the session
stuck at the context limit.

Hand the bounded ask to the summarizer as untrusted data on every attempt so
the guard only demands what the producer was shown.
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@VACInc
VACInc marked this pull request as ready for review August 27, 2026 02:45
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 27, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 12:07 AM ET / 04:07 UTC.

ClawSweeper review

What this changes

The PR carries terminal completion state into compaction summary retention and validation so completed latest requests are not retained as pending work, and makes a lazy Control UI panel test await its render.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal merge review. The requested completion-state fix is present at the compaction quality boundary and the prior P1 scenario is covered; no new blocking correctness defect was found.

Priority: P1
Reviewed head: 0093a7f6fc196cd100cfe15791d3d3fdd62aa31a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The current source resolves the prior completion-state blocker with focused owner-boundary coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-associated PR is exempt from the external-contributor real-behavior-proof gate; its supplied focused test evidence remains supplemental.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-associated PR is exempt from the external-contributor real-behavior-proof gate; its supplied focused test evidence remains supplemental.
Evidence reviewed 8 items Completion-state retention: Completed latest-turn context is retained in Decisions rather than Pending user asks when final budgeting rebuilds the summary.
Completion-state audit: The quality audit rejects a completed latest ask when it overlaps the pending-asks section.
Producer and audit wiring: The handler derives the latest turn before preservation, carries its completion flag through finalization, and passes it to final validation.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/agent-hooks/compaction-safeguard.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/agents/agent-hooks/compaction-safeguard.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/agents/agent-hooks/compaction-safeguard.test.ts"

[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130620-JWHMKD/target

 ✓  agents-support  src/agents/agent-hooks/compaction-safeguard.test.ts (141 tests) 1798ms
     ✓ surfaces a total provider failure and leaves the safeguard transcript unchanged  1582ms

 Test Files  1 passed (1)
      Tests  141 passed (141)
   Start at  04:08:53
   Duration  15.45s (transform 10.82s, setup 949ms, import 12.34s, tests 1.80s, environment 0ms)

[test] passed 1 Vitest shard in 22.13s

Assertions:

  • FAIL expect_output: passed

How this fits together

Compaction turns older agent conversation into a structured checkpoint that later turns consume. The safeguard partitions context, generates or retains a summary, audits its required facts, and writes the resulting session context.

flowchart LR
  A[Conversation history] --> B[Context partitioning]
  B --> C[Compaction summary]
  C --> D[Quality audit]
  D --> E[Retained checkpoint]
  E --> F[Later agent turn]
Loading

Before merge

  • Resolve merge risk (P1) - Production changes are +50/-9 lines; the added completion fact must cross the existing producer, retention, and audit boundary, and source review found no smaller owner-boundary refactor that preserves that invariant.
  • Complete next step (P2) - No repair lane is needed; the remaining work is ordinary exact-head CI and merge review.
Agent review details

Security

None.

PR surface

Source +41, Tests +167. Total +208 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 50 9 +41
Tests 2 191 24 +167
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 241 33 +208

Review metrics

Metric Value Why it matters
Production versus test delta production +50/-9; tests +191/-24 The production growth carries one completion fact through summary retention and validation, while the larger test change protects the completed-versus-pending regression.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep completion state on the existing compaction-quality boundary and merge after the exact-head checks complete.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep completion state on the existing compaction-quality boundary and merge after the exact-head checks complete.

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

No live current-main replay was performed in this read-only review, but the focused handler-level regression provides a high-confidence source reproduction of the completed request being treated as pending.

Is this the best way to solve the issue?

Yes. The completion fact is captured with the latest turn and consumed by the existing retention and audit owner rather than inferred from summary prose downstream.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • 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 maintainer-associated PR is exempt from the external-contributor real-behavior-proof gate; its supplied focused test evidence remains supplemental.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Incorrect compaction state can revive completed user work in the next agent turn.
  • 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 maintainer-associated PR is exempt from the external-contributor real-behavior-proof gate; its supplied focused test evidence remains supplemental.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: History attributes the consolidation of compaction and context-engine ownership to this area. (role: major compaction refactor contributor; confidence: high; commits: bde1602e6e86, 475ea69f2c35; files: src/agents/agent-hooks/compaction-safeguard.ts)
  • Vito Cappello: Recent history records the prepared-window and audited-identifier repair on the same safeguard path. (role: recent compaction contributor; confidence: high; commits: 6124d47e046a; files: src/agents/agent-hooks/compaction-safeguard.ts, src/agents/agent-hooks/compaction-safeguard-quality.ts)
  • RoboClaw: Recent history includes the audited-facts retention repair that owns the related summary-budget boundary. (role: recent summary-retention contributor; confidence: medium; commits: 97cd06b946fe; files: src/agents/agent-hooks/compaction-safeguard-quality.ts)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-27T02:51:48.687Z sha 6a6dcd7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T03:37:35.485Z sha 0a545b7e0e5efaa3a57f5e9086bc80a54d3a92a1 :: found issues before merge. :: [P1] Keep completed asks out of accepted pending work

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 27, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 27, 2026
@roboclaw-bot
roboclaw-bot force-pushed the fix/compaction-latest-ask-visible-to-summarizer branch from 0a545b7 to 0093a7f Compare August 27, 2026 04:01
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

The P1 completion-state finding is addressed on 0093a7f6fc196cd100cfe15791d3d3fdd62aa31a:

  • terminal assistant completion is carried into the quality audit;
  • a completed latest request overlapping ## Pending user asks is rejected and corrected;
  • final artifact retention keeps completed request context outside the pending section;
  • the regression first produces the previously accepted bad checkpoint, then proves only the corrected checkpoint is accepted.

Local proof: compaction safeguard 141/141, sidebar attention 33/33, full changed-file gate clean, and structured autoreview clean.

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@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. labels Aug 27, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Live Gateway proof and the split-turn repair are now on exact head 8e62635fd626e69da80179777a0b1de4e9cf0356.

  • Direct AWS Crabbox run: https://crabbox.openclaw.ai/portal/runs/run_24a23cff22e0
  • Built real Gateway + CLI from the exact committed head; isolated state; deterministic local OpenAI-compatible provider.
  • The first compaction response deliberately revived the completed split-turn request under ## Pending user asks.
  • The quality owner rejected it, issued a corrective request, and persisted only the corrected checkpoint: three provider requests total, every generated pending section None., completed ask and exact identifier retained elsewhere.
  • Lease cbx_3381f0b0b953 was destroyed after artifact collection.

Local proof: Agent Core 45/45, compaction safeguard 142/142, complete check:changed, and final isolated autoreview clean at P0/P1 (0.93). Exact-head CI is running.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot
roboclaw-bot merged commit 4b5341c into main Aug 27, 2026
205 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

@roboclaw-bot
roboclaw-bot deleted the fix/compaction-latest-ask-visible-to-summarizer branch August 27, 2026 07:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…#130620)

* fix(compaction): show the summarizer the audited latest ask

The safeguard reads the latest user ask from the pre-partition window but
only feeds the summarizer the partitioned messages. When recentTurnsPreserve
keeps the ask verbatim and the preserved suffix is head-truncated, the
producer can never reflect it, so every attempt fails
latest_user_ask_not_reflected and compaction cancels, leaving the session
stuck at the context limit.

Hand the bounded ask to the summarizer as untrusted data on every attempt so
the guard only demands what the producer was shown.

* fix(compaction): preserve latest turn context

Worked on by:
- @VACInc

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

* test(ui): await lazy attention panel render

Worked on by:
- @VACInc

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

* fix(compaction): audit completed split turns

Worked on by:
- @VACInc

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

---------

Co-authored-by: VACInc <[email protected]>
Co-authored-by: roboclaw-bot <[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 app: web-ui App: web-ui 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: 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.

2 participants