Skip to content

fix: compaction keeps stale decisions after corrections - #167757

Merged
roboclaw-bot merged 2 commits into
mainfrom
openclaw/compaction-correction-eval
Oct 9, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
openclaw/compaction-correction-eval

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: compaction can leave superseded dates and pending verification status in its main Decisions section when later corrections are retained as recent-turn or split-turn context.

User Impact

The compacted handoff updates current decisions and task status instead of presenting contradictory old and corrected facts. Unaffected facts and explicitly historical verbatim excerpts remain available. No configuration change or migration is required.

Tradeoff: the reproduced split-turn case now makes two summary requests (main summary plus prefix) rather than one prefix-only request; larger preserved windows can require additional chunks.

Why This Change Was Made

Recent-turn preservation could remove every main-summary target. OpenClaw then copied the stale previous summary through a deterministic fallback, while a separate prefix request merely appended the correction. Strengthening the main prompt alone did not fix a prompt that was never invoked.

The main summary now reconciles the prepared, post-pruning history together with preserved turns and split-turn progress. Instructions require corrections and observed results to update the main sections, distinguish completed failed checks from pending work, and label superseded history. Existing window, pruning, pairing, budget, quality-check, cancellation, and persistence boundaries remain intact. Shared test fixtures were extracted so the regressions do not grow already-oversized files.

Evidence

  • Replayed the supplied correction fixture through real OpenClaw SDK AgentSession.compact() using openai/gpt-6-astra; disposed/reopened SQLite and inspected the persisted summary. Assessed the saved state against the supplied YAML criteria, not just an assistant reply.
  • Baseline and prompt-only runs both retained October 8 / verification pending in Decisions. The prompt plus input-routing fix passed 3/3 exact-candidate runs, and a further compaction retained the corrected facts: Maya remains owner; confirmed launch date October 15; verification ran and failed because approval is missing; preparation unfinished; no pending date-edit task.
  • The regression suite passes 85 tests across four files. The three correction-routing cases failed against unchanged routing. The new cases prove model-input routing; mocked output is not presented as semantic-model proof.
  • Scoped formatting/lint, core production and test typechecks, line-cap/max-lines/assertion guards, and git diff --check pass.
  • Canonical AutoReview completed on the final six-file candidate at P0–P3 with no actionable findings. This is independent AI source review, not a human GitHub approval.

Limits: this is an available-OpenAI-model SDK replay, not the original Nvidia-model/external-judge run or a Gateway/CLI end-to-end test. It does not establish broad cross-model or long-history reliability. Raw request traces, fixture databases, and private attachments are not included in this PR. Full build/full runtime suite were not run; hosted CI status remains separate from the local proof.

Focused validation commands and cost
pnpm test src/agents/agent-hooks/compaction-safeguard.test.ts src/agents/agent-hooks/compaction-safeguard-corrections.test.ts src/agents/agent-hooks/compaction-safeguard-quality.test.ts src/agents/compaction.summary-format.test.ts --maxWorkers=1
pnpm tsgo:core

The four-file test command took 38.93 seconds including compiled-worker preparation. Standalone pnpm test <file> --maxWorkers=1 wall times: correction regressions 40.83 seconds (cold compiled-worker preparation dominates; three cases run in milliseconds), existing safeguard suite 13.09 seconds. These exercise the real safeguard hook input routing; there are no new sleeps or per-case Gateway boots. Test typechecks used the repository changed-path graph selector. CI seconds are not yet available.

Worked on by

  • @jacobtomlinson — supplied the failing eval, identified the contradictory durable state, and directed the fix and verification.

Work sessions


View the OpenClaw team session

roboclaw-bot and others added 2 commits October 8, 2026 18:38
Worked on by:
- @jacobtomlinson

Co-authored-by: jacobtomlinson <[email protected]>
OpenClaw-Publication: 2603ad3e-1e48-4d17-80f5-1f6277b42d53
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 9, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Independent review completed for head de479846797b60a516e00617ebd90a1109fbdcfd (tree 251f194a8dd9c9d34ae49e5b91962c285bd5563a).

Canonical AutoReview, P0–P3: scoped-clean; no actionable findings. The review covered the full six-file change and surrounding owners: correction input routing, previous-summary re-distillation, preserved/split-turn context, budgets, quality checks, cancellation, persistence, and fixture extraction.

The published tree is byte-identical to the reviewed implementation commit a44ebf2350b1c54b023736f2fb599881ab7adb71; the publisher added only its attribution/marker commit. Existing local proof remains applicable: 85 focused tests and 3/3 final-source model-backed replays plus repeated compaction passed.

This is completed independent AI source review, not a human GitHub approval. The reviewer did not independently execute tests; the live replay limitations remain documented in the PR body. Hosted CI and ClawSweeper’s separate review are not represented as complete or green.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Compaction, which condenses conversation history, includes retained corrections in the main summary request so current decisions and task status replace stale facts.

Example: The user corrects the launch date and verification returns a failed result.

  • Before: The main Decisions section can retain October 8 and verification pending while appended context records October 15 and missing approval.
  • After: The main summarizer receives both states and instructions to record October 15 and the completed failed verification.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and source-supported, with limited entry-point proof and redundant canned-output assertions.
Proof confidence 🦐 gold shrimp (3/6) This bot-authored PR is outside the external-contributor proof gate. Its reported real-model AgentSession.compact() replay exercises the safeguard and reopened SQLite summary, but does not demonstrate the prior Gateway/CLI rank-up scenario. The persisted entry contract is unchanged and requires no migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After a correction, the conversation handoff can still present the old date and verification status as current decisions.
Reason: The source and supplied replay establish a bounded defect in existing compaction behavior. The repair stays at the current producer and preserves existing settings and storage contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR repairs a source-confirmed compaction gap that remains on current main. No blocking correctness or security defect was found.

Priority: P2
Reviewed head: de479846797b60a516e00617ebd90a1109fbdcfd

Before merge

None.

Findings

None.

Tests

  • Low-value test src/agents/agent-hooks/compaction-safeguard-corrections.test.ts: reconciles $name in the main summary request: Remove the canned Decisions assertions at lines 73–77: the mock returns corrected facts regardless of its input, so those assertions do not prove semantic reconciliation; retain the meaningful input-routing regression.
  • Missing end-to-end proof: The prior rank-up scenario remains unshown: run the correction fixture through Gateway or CLI compaction and inspect the persisted main Decisions section.
Agent review details

How this fits together

OpenClaw compaction turns older conversation into a persisted summary that later agent turns consume. The safeguard prepares model input, retains recent excerpts, and applies existing summary budgets and quality checks before persistence.

flowchart LR
 A[Prepared conversation] --> C[Compaction safeguard]
 B[Previous summary] --> C
 C --> D[Main summary with corrections]
 C --> E[Retained recent and split-turn context]
 D --> F[Budget and quality checks]
 E --> F
 F --> G[Persisted session summary]
Loading

Technical review

Best possible solution:

Reconcile corrected facts at the existing safeguard summary producer while retaining bounded historical excerpts.

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

Yes, by source: a previous summary plus an all-preserved correction or split-turn correction can skip the main summarizer on current main. The supplied SDK before/after replay corroborates this path; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes. Routing the already-prepared correction context to the existing summary producer addresses why stronger instructions alone failed, without adding a competing state owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0907600c0e76.

Provenance checked

  • src/agents/agent-hooks/compaction-safeguard.ts: recent-turn exclusion and fallback changes intended behavior with a stated reason (Compaction/Safeguard: preserve recent turns verbatim #25554: Preserve exact wording from the freshest conversation turns by excluding them from summarization and appending them verbatim.)
  • src/agents/agent-hooks/compaction-safeguard.ts: includePreservedContext changes intended behavior with a stated reason (fix(compaction): show the summarizer the audited latest ask #130620: Show generating summaries the preserved completion context while keeping eligible all-preserved windows model-free.)
  • src/agents/agent-hooks/compaction-safeguard-quality.ts: previous-summary instructions keeps the original intent (7920f8d: The commit adds instructions to re-distill previous summaries with new messages and remove stale duplicate detail.)
  • src/agents/agent-hooks/compaction-safeguard.test.ts and compaction-safeguard.test-support.ts keeps the original intent (test(runtime): remove low-value tests (batch d097) #161101: Consolidate repeated setup and assertions while retaining meaningful compaction behavior coverage.)
  • src/agents/agent-hooks/compaction-safeguard.ts: split-prefix generation keeps the original intent (fix(compaction): recover split-turn summaries without duplicate sections #132618: Use the dedicated prefix format and nested headings so split context cannot create a second canonical summary document.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction and current-main necessity: The introduced delta changes the safeguard routing and instructions; the fetched main has no changes to these two production files relative to the merge base, so the stale-summary fallback remains there. (src/agents/agent-hooks/compaction-safeguard.ts:1167, 0907600c0e76)
  • Repair stays with the summary producer: The main request now receives the post-pruning prepared window, including preserved messages and split-turn progress. Existing chunk planning, prefix formatting, final budgeting, cancellation, and quality auditing remain in place. (src/agents/agent-hooks/compaction-safeguard.ts:1197, de479846797b)
  • Original preservation contract: Compaction/Safeguard: preserve recent turns verbatim #25554 preserved recent wording by excluding it from summarization and appending it verbatim. This PR retains those excerpts but explains why they also need to reach the main summary when updating durable decisions. (src/agents/agent-hooks/compaction-safeguard.ts:1151, c8b45a4c5c04)
  • Prior producer-context repair: fix(compaction): show the summarizer the audited latest ask #130620 already established that a generating summarizer needs preserved completion context, while allowing all-preserved windows to remain model-free when the audited ask survives. This PR explains the narrower exception needed when a previous summary contains stale decisions. (src/agents/agent-hooks/compaction-safeguard.ts:1158, 4b5341ce4353)
  • Reported model-backed replay and its limits: The complete supplied body and live discussion describe three exact-candidate AgentSession.compact() runs with a real model, SQLite close/reopen inspection, and a further compaction retaining corrected facts. They explicitly disclose that this was an SDK replay rather than Gateway/CLI proof and provide no raw traces. The implementation and publication commits have identical trees; this review did not execute tests or another reviewer. (de479846797b)
  • No stored-format migration: The patch changes generated summary content and model input, not the compaction entry shape, identity, retained cut point, or append contract. Existing previous summaries still enter through the same normalization and re-distillation path. (src/agents/sessions/agent-session-compaction.ts:471, de479846797b)

Likely related people:

  • Vito Cappello: Raw commit 4b5341c adds src/agents/agent-hooks/compaction-safeguard.ts:1260 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4b5341ce4353; files: src/agents/agent-hooks/compaction-safeguard.ts)
  • itayzit: Raw commit cbbaa0d adds src/agents/agent-hooks/compaction-safeguard-quality.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cbbaa0d3ada1; files: src/agents/agent-hooks/compaction-safeguard-quality.ts)

PR surface

Source +3, Tests +112, Docs +2. Total +117 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 20 17 +3
Tests 3 352 240 +112
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 374 257 +117

Review metrics

Metric Value Why it matters
Production versus test LOC production +20/-17; tests and support +352/-240 The small production growth repairs the existing owner; most test movement extracts shared fixtures.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Contradictory compaction decisions can misdirect later agent work, with no established outage or urgent release impact.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Demonstrate the correction fixture through Gateway or CLI compaction and inspect the persisted main Decisions section.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-09T09:52:02.205Z sha de47984 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T09:59:10.357Z sha de47984 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 6:13 AM ET / 10:13 UTC (Revision 3).

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 9, 2026 10:07
@roboclaw-bot
roboclaw-bot merged commit 0cf5e29 into main Oct 9, 2026
201 of 203 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/compaction-correction-eval branch October 9, 2026 10:24
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

amittell added a commit to amittell/openclaw that referenced this pull request Oct 9, 2026
Main moved again under this branch: 50dd07c (openclaw#167640) added the
summary-timeout exception to the qualityGuard and safeguard reference
lines this branch rewrites, which conflicted in both docs pages. Both
keep the degraded-fallback text and take main's exception sentences.

0cf5e29 (openclaw#167757) merged cleanly: the terminal audit branch now
keys on reconciliationMessages, and the shared safeguard test harness
moved into compaction-safeguard.test-support.ts. The degraded-fallback
suite drops its local harness for that shared one.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
)

Reconcile corrected facts and completed verification results in the main compaction summary instead of copying stale decisions alongside newer turn context. Preserve historical excerpts, prepared-window boundaries, chunking, budgets, cancellation, and persistence ownership.

Validated with 85 focused tests and real model-backed SDK compaction replays with SQLite reopen checks. Gateway/CLI and original Nvidia/judge execution remain outside that proof.

Original discussion: https://team.openclaw.ai/chat/roboclaw/dashboard/71e26bee-aa04-4ca2-ae2d-9c8a3c55879e
Implementation and verification: https://team.openclaw.ai/chat/roboclaw/dashboard/4c5954fa-378d-4e55-afc7-79b718c8cbde

Co-authored-by: jacobtomlinson <[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 docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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