Skip to content

fix(compaction): stop a failed summary audit from leaving a session permanently uncompactable - #130393

Merged
steipete merged 19 commits into
openclaw:mainfrom
amittell:fix/compaction-degrade-instead-of-cancel
Oct 11, 2026
Merged

steipete merged 19 commits into
openclaw:mainfrom
amittell:fix/compaction-degrade-instead-of-cancel

Conversation

@amittell

@amittell amittell commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #120162
Related: #138416

What Problem This Solves

Fixes long sessions becoming permanently uncompactable when a small model repeatedly fails the safeguard summary audit or required facts cannot fit the summary budget.

User Impact

OpenClaw commits the best available bounded summary and continues the session. It marks the compaction record as degraded, keeps a degradation warning in /status for that history, and always displays a notice—even with notifyUser: false—that older details, exact identifiers, or pending requests may be missing. The notice suggests resending important context, /new, or a larger model.

Maintainer decision (Peter Steinberger, 2026-10-10): accept marked lossy fallback for exhausted quality audits and infeasible retention, including manual compaction. Preservation is best-effort on this path. Complete messages remain in the stored transcript, but facts omitted from active context are not automatically recovered by later summaries. This introduces no configuration switch or database schema migration. Existing installations use the same behavior after updating; older versions ignore the additive quality metadata.

Why This Change Was Made

Cancelling a failed audit leaves the context at the same size, so every later compaction can fail again. The safeguard now keeps the generated candidate with the fewest audit failures, reuses it if a corrective generation fails, and preserves as much request, identifier, and split-turn context as the existing budget permits. An incomplete structured summary is normalized without discarding its generated facts. Caller cancellation remains terminal; missing models, credentials, and an initial generation failure keep their existing error paths.

The transcript writer projects only committed degraded boundaries into session metadata, so stale bookkeeping cannot erase the warning. A fresh session lifecycle clears it. Completion events and recovery receipts carry the same committed details through manual commands, automatic compaction, and notifications. Imported histories conservatively retain the warning if they contain a degraded boundary.

This preserves @amittell's original contribution and commits, merges current main instead of rebasing, and reconciles the merged CJK fitting fix. The two documentation findings are resolved: request retention is best-effort under constrained budgets, and caller abort signals are distinguished from provider-local timeouts.

Evidence

Native Ollama llama3.2:latest, an 8,192-token context, 48-token model output cap, two quality attempts, and isolated synthetic history through the public sessions compact CLI and Gateway:

  • Main 5c7004136d9c: both attempts returned ok: false, compacted: false, and Compaction safeguard finalized summary failed quality checks. The log reports missing sections/identifiers; after repeating the command the original ten messages remain with zero compaction records. CLI wall time: 9.14 s, then 5.01 s.
  • Main regression: the candidate's summary-budget test fails both lossy-recovery cases with { cancel: true }; the affordable CJK case passes. Cold wrapper wall time: 74.55 s.

Candidate 6def8754a71a merges main 76a282c7a1c6 to include the upstream typecheck and mock-isolation repairs. The compaction owner is unchanged by that second merge.

  • Exact candidate 6def8754a71ae44bd09f2982661573b62e1f6ab1: the same failed audit commits a degraded boundary, reduces active history from 296 to 250 estimated tokens / ten to five messages, prints the warning with notifyUser: false, and shows Compactions: 1 · degraded history through real /status. The same native Ollama session then answers “A ripe banana is typically yellow.” Both durable markers remain after continuation. Compaction: 8.40 s CLI / 2.857 s runtime; correct continuation: 5.24 s CLI / 1.386 s runtime. Its first continuation completed but produced tool-shaped text; one explicit no-tools follow-up answered correctly without changing model or configuration. This is a response-quality limitation, not an audit-cancellation loop.
  • 305 tests passed across 14 focused files (323.38 s total wrapper wall time, individual commands below); all 17 persistence/direct-notice/CJK cases were rechecked on the final merged head (85.35 s). The three CJK/budget cases pass on the candidate; main failed the two recovery cases. This includes SQLite reopen, warmed metadata reads, stale bookkeeping, same-ID/new-lifecycle reset, caller abort, provider-local timeout, direct callers without dispatchers, and command/event notices.
  • Full pnpm build passed on the exact final head (4m 59.8s). It emits the same non-gating UI startup-size warning seen in the main control build; this PR changes no UI bundle source.
  • Core typecheck and the agents-other, agents-sessions, messaging, commands, and other test graphs passed. Targeted type-aware lint passed. Max-lines, line-cap, assertion-safety, timeout-race, mock-export, config-doc, and plugin-inventory guards passed.
  • Codex autoreview: scoped-clean at P2 on 6def8754a71a. The first review caught an obsolete fallback fixture; it now asserts retained generated facts instead of discarded template text.
  • Prompt snapshots regenerated with no diff: static prompt token delta 0. Docs listing, MDX/format checks, and git diff --check passed.

Production +477/-219 (net +258); tests/support +1060/-473 (net +587); docs +40/-19. Production growth is needed for committed degradation/status state and complete mandatory-notice delivery across manual, automatic, preflight, and direct-return paths. Existing presentation owners are reused; discarded fallback scaffolding and duplicated exact-artifact fixtures were removed. The stored flag is additive session metadata in the existing SQLite owner; no schema/version/configuration change.

Focused test cost

Commands: TMPDIR=<isolated-temp> node scripts/run-vitest.mjs <file> --maxWorkers=1.

File Passed Wall time

| compaction-safeguard.degraded-fallback.test.ts | 5 | 39.89 s |
| compaction-safeguard.summary-budget.test.ts | 3 | 10.62 s |
| compaction-safeguard.test.ts | 62 | 21.62 s |
| compaction-safeguard-quality.test.ts | 4 | 2.98 s |
| compaction-safeguard-tool-failures.test.ts | 3 | 2.26 s |
| compact.hooks.test.ts | 82 | 50.36 s |
| agent-session-compaction.degraded-reload.test.ts | 2 | 15.71 s |
| agent-session-compaction.provider-boundary.test.ts | 5 | 13.00 s |
| agent-session-compaction.test.ts | 17 | 17.78 s |
| agent-runner-execution-compaction.test.ts | 9 | 33.04 s |
| agent-runner.misc.runreplyagent.test.ts | 66 | 67.01 s |
| agent-runner.direct-replies.test.ts | 12 | 26.02 s |
| sessions-compact.test.ts | 9 | 3.66 s |
| status-message.test.ts | 26 | 19.43 s |

Wall time includes cold compilation/imports. The persisted-reload cases exercise the actual SQLite writer and reopen path; most pure safeguard test bodies take milliseconds. Existing hook and reply suites retain their established coverage and setup. Exact-head CI completed with 62 successful jobs; the three failing jobs took 148 s, 352 s, and 503 s. They fail inherited native-binding tests, as detailed below; these are whole-job wall times, not incremental test cost.

Review and inherited CI

Codex autoreview is scoped-clean at P2 on this exact head. ClawSweeper's exact-head review has Findings: None and acknowledges the approved product decision and both documentation fixes.

Maintainer-approved proof limitation: additional Telegram Test Server, latest-stable upgrade, and data-compatibility runs are deferred; exact-head native Ollama/Gateway behavior and real SQLite reopen/stale-write/reset coverage are supplied above.

Exact-head CI run 38098684939 finished failure, including openclaw/ci-gate. Build, production/test types, lint, and baseline-ratchet jobs passed. Each failed test family was then reproduced without this PR's changes in a clean detached main checkout at 76a282c7a1c6ca958517ce15f13e17371c14be11:

  • test/canonical-descendant.integration.test.ts: the full file in original order fails the same 70 initialization/rollback binding cases; 4 pass. Main control wall time 107.53 s. Errors include Codex session binding changed during initialization and Codex initialization binding owner changed before rollback.
  • src/config/sessions/session-native-binding.reclamation.test.ts: both CI cases, successor false and true, reproduce the same 120,000 ms timeout on main. The remainder was stopped after the bounded attribution attempt rather than replaying more timeouts.
  • src/config/sessions/session-agent-purge.test.ts: the targeted settles the purge's typed native binding when the agent commit is refused: false case reproduces the same 120,000 ms timeout on main (1 failed, 7 skipped; 172.56 s wall).

These are inherited failures, not a green CI result. No workflow reruns or extra pushes were used to seek green. The lead must use the native inherited-failure exception or wait for the baseline repairs; this worker has not landed the PR.

@clawsweeper

clawsweeper Bot commented Aug 26, 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 agents Agent runtime and tooling size: XS labels Aug 26, 2026
@amittell
amittell marked this pull request as ready for review August 26, 2026 20:38
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR commits a bounded degraded summary after exhausted quality checks and preserves visible warnings about lost context.

Example: Native Ollama llama3.2 with an 8,192-token context, a 48-token output cap, and notifyUser false.

  • Before: Repeated CLI compaction fails its audit and leaves ten messages without a compaction boundary.
  • After: The candidate commits a marked degraded boundary, reduces active history to five messages, displays a warning, and answers a subsequent question.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, owner-approved recovery with substantial production-path evidence and no definite finding; required channel and released-state coverage remain incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A session repeatedly fails summary validation without shrinking, eventually preventing further useful replies.
Reason: The native control supports the failure, current main retains it, and the area owner adopted marked lossy recovery with visible warnings.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR retains useful, owner-approved recovery work that current main does not provide; no definite introduced bug was found.

Priority: P1
Reviewed head: 6def8754a71ae44bd09f2982661573b62e1f6ab1

Before merge

  • Add real behavior proof - Exact-head native Ollama through the public CLI/Gateway demonstrates degraded recovery, warning output with notifyUser false, status, and continuation. Required Telegram Test Server delivery remains unproven. The v2026.9.9 upgrade ran on an earlier head before final metadata changes; supply a v2026.10.1 upgrade preserving settings and transcript, degradation after reopen, and successful continuation. Redacted terminal output, logs, or recordings are acceptable; remove IPs, keys, phone numbers, and non-public endpoints. The recorded deferral does not satisfy the enforced compatibility gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply Telegram Test Server warning/status evidence and a latest-stable upgrade through the final metadata changes; the supplied regression controls demonstrate base failures and candidate recovery.
Agent review details

How this fits together

The safeguard receives prepared conversation history and model summaries, fits and audits them, and passes committed boundaries through SQLite storage, session events, replies, and status.

flowchart TD
  A[Prepared conversation history] --> B[Safeguard summarization]
  B --> C[Budget and quality audit]
  C --> D[Accepted or degraded summary]
  D --> E[SQLite transcript owner]
  E --> F[Session continuation]
  E --> G[Completion notices and status]
Loading

Technical review

Best possible solution:

Land the approved recovery at the existing safeguard and transcript owners once its required behavior and upgrade evidence is complete.

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

Current-main source still cancels exhausted audits, and the supplied native-model control demonstrates repeated cancellation without shrinking history; no new reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The approved bounded fallback fixes the recovery decision at its existing owner, retains generated facts where possible, and records losses without adding a configuration switch.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +258, Tests +587, Docs +21, Other 0. Total +866 across 44 files. Added test files: 5.

View PR surface stats
Area Files Added Removed Net
Source 24 477 219 +258
Tests 16 1060 473 +587
Docs 3 40 19 +21
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 44 1578 712 +866

Review metrics

Metric Value Why it matters
Production versus tests Production +477/-219; tests/support +1060/-473 Growth supports durable degradation tracking and warning delivery; moved provider and direct-reply coverage accounts for part of the test additions.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Repeated safeguard rejection can block continuation of a real long-running session.
  • merge-risk: 🚨 session-state: Recovery deliberately permits omitted active-context facts; the area owner accepted that tradeoff with durable marking and warnings.
  • merge-risk: 🚨 compatibility: The default recovery behavior and persisted session metadata change, requiring released-state compatibility evidence before merge.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Telegram can observe the mandatory degraded-summary warning with notifyUser false and the persisted degradation indicator in /status.

Rank-up moves

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

  • Complete the missing Telegram and latest-stable upgrade evidence already identified in the prior review.

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 (26 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-24T15:36:31.635Z sha 7805358 :: blocked before merge. :: none
  • reviewed 2026-10-09T01:54:53.827Z sha 7805358 :: blocked before merge. :: none
  • reviewed 2026-10-09T18:59:26.851Z sha 08f5268 :: blocked before merge. :: none
  • reviewed 2026-10-09T22:30:39.948Z sha 08f5268 :: blocked before merge. :: none
  • reviewed 2026-10-09T23:35:30.635Z sha 3474e67 :: blocked before merge. :: none
  • reviewed 2026-10-10T04:03:06.295Z sha 3474e67 :: blocked before merge. :: none
  • reviewed 2026-10-10T04:37:42.901Z sha 3474e67 :: blocked before merge. :: [P3] Describe request retention as best-effort under constrained budgets | [P3] Distinguish caller cancellation from provider-local timeouts
  • reviewed 2026-10-11T00:43:12.961Z sha 6def875 :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 9:19 PM ET / October 11, 2026, 01:19 UTC (Revision 27).

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 26, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S and removed size: XS labels Aug 27, 2026
@amittell

Copy link
Copy Markdown
Contributor Author

Pushed 0f0c783528c58f3f60ce43730775805889ee0bfa. All three P1s are addressed, plus the "one canonical degradation path" note from merge risk.

Cover retention-infeasible quality failures. Correct and the more serious of the three: qualityRetentionInfeasible returned { cancel: true } at compaction-safeguard.ts:1452, before auditSummaryQuality ran at all, so the fallback this PR added never covered that branch. With the preflight caller throwing on cancel, an unsatisfiable required-fact budget stranded the session exactly the way the PR exists to prevent. It now returns through the same degraded route.

Retain generated split-turn context in the fallback. Also correct. Normal finalization passes both generatedSplitTurnSection and preservedTurnsSection (:1427-1431); the fallback passed only the second, so a final audit failure during split-turn compaction committed without the separately summarized turn prefix. Both are passed now.

One canonical path. Both terminal cases call a single degradeToFallbackSummary instead of repeating the finalizeSummaryText call. Net production change against the reviewed head is +22/-15 in one function, not a second terminal branch.

Update the quality-guard default contract. Three files stated the old contract and all three were wrong after this PR:

  • docs/concepts/compaction.md - "compaction stops before writing a transcript entry, keeps the original history"
  • docs/reference/session-management-compaction.md:254 - "exhaustion or a corrective generation failure cancels before append and leaves the original transcript authoritative"
  • docs/gateway/config-agents.md:635 - "OpenClaw preserves the original history and returns a compaction failure instead of storing known-invalid context"

Each now describes the bounded degraded artifact, names reasonCode=quality_guard_degraded_fallback, and names the paths that still cancel and keep history: provider throw, missing model, missing credentials. setCompactionSafeguardCancelReason still has 6 call sites, so those paths are intact.

On the decision needed. My read is option 1 as written, and the docs now carry the tradeoff explicitly rather than leaving it implicit in code. The asymmetry that decides it: a lossy summary loses some fidelity once, while a cancel loses the session permanently, because nothing shrinks and every later turn fails the same preflight. Happy to reverse to option 3 if maintainers would rather keep the abort, but then the retention-infeasible branch still needs covering, since today it strands sessions on a path no config can turn off.

Evidence

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

before   Tests  138 passed (138)
after    Tests  139 passed (139)    exit 0

Mutation-checked in both directions, each restored byte-identical (sha256 45f7fc5ebe00ba75):

mutation result named failure
drop generatedSplitTurnSection from the degraded path 1 failed / 138 passed, exit 1 retains the generated split-turn section in the degraded fallback
route qualityRetentionInfeasible back to { cancel: true } 1 failed / 138 passed, exit 1 degrades when audit-required tail sections cannot fit the artifact cap
restored 139 passed, exit 0 -

The retention test is the one this PR previously left uncovered. It was fails closed when audit-required tail sections cannot fit the artifact cap and asserted the cancel reason directly, which is why the gap was invisible: the test encoded the stranding as intended behavior.

Honest limit on my side: I could not run the full tsc --noEmit -p tsconfig.json here, it OOMs at ~4GB heap and aborts with 134 on this machine. A standalone check of the changed source reports 0 errors in compaction-safeguard.ts (the only diagnostic is TS5112, about passing files on the command line alongside a tsconfig). So treat repo-wide typecheck as unverified by me and let CI carry it.

Claude assisted with the patch and this comment. The submitter owns the conclusions and final review.

@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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 27, 2026
@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. labels Aug 27, 2026
@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. labels 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.
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 9, 2026
@amittell

amittell commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the conflicts against main and pushed 08f52683e21. Main moved twice under the branch, so there are two merges: 1a44c410f6a (main 27e3afbd8fc, six files) and 08f52683e21 (main 4db022470af, the two docs lines #167640 rewrote).

Resolutions, all at main's owners:

  • compaction-safeguard.ts: main's cancelCompaction helper, auth typing, CompactionSuffix-only suffix helpers and fix: compaction keeps stale decisions after corrections #167757's reconciliationMessages stay. The tool-failure extraction, the reserved split-turn suffix and the degraded fallback apply on top, and main's two terminal cancelCompaction calls (infeasible retention, final audit failure) become degradeToFallbackSummary. Generation failures, a missing model and missing credentials still cancel.
  • agent-core compaction.ts: main's latestUserText, formatRequiredAskContext and the no-summary reduction from fix(compaction): commit a deterministic reduction after a summary timeout #164246 stay in compaction.ts. Only the stored details contract moves to compaction-details.ts, with qualityDegraded and MAX_LATEST_USER_REQUEST_CHARS.
  • Tests: main's tool-failure tests are now one table, and its safeguard harness now lives in compaction-safeguard.test-support.ts. The table moved to compaction-safeguard-tool-failures.test.ts with the module. With the degraded cases inside the grandfathered compaction-safeguard.test.ts the line-cap ratchet counted 2178 -> 2193, so they live in compaction-safeguard.degraded-fallback.test.ts on the shared harness and replace main's fail-closed case. The reasonCode assertion from @Hansen1018's terminal-helper test folded into the retained-facts case: same input, same terminal path.
  • compact.hooks.test.ts: main's corrective-408 row stays a cancellation; the quality rejection row expects degrade.
  • Docs: both reference lines keep the degraded-fallback text and take docs: safeguard references omit the summary-timeout exception #167640's summary-timeout sentences.
  • assertion-safety-baseline.txt: compaction-safeguard.ts 12 -> 10, the two casts that moved to the tool-failures module with SAFETY notes.

Validation on the refreshed head (M4 Pro, Node 26.10.0, pnpm 12.7.0): 13 compaction test files, 261 passed, 0 failed, including the four degraded-fallback cases, both SQLite reload cases and compact.hooks.test.ts (81). tsgo:core and the agents-other and agents-sessions test graphs are clean; line-cap, max-lines and assertion-safety ratchets OK against 4db022470af; oxfmt and oxlint clean on the changed files. With main's compaction-safeguard.ts swapped into the same tree, the degraded-fallback file fails 4 of 4 on { cancel: true }, the reload file 2 of 2 on "Compaction cancelled", and the quality rejection row in compact.hooks.test.ts fails while the other 80 pass. Per-file counts and pnpm test <file> --maxWorkers=1 wall times for the four new test files are in the body.

The red checks on 7805358201f were outside this diff: server-runtime-services.delivery-recovery.test.ts, check-max-lines-ratchet.test.ts ("context canceled") and full-release-artifact-contract.test.ts ("GitHub token is required").

Owner decision, still open. The review notes that #164246's timeout exception excludes quality failures, and #167640 says so in the docs. This PR asks for that same trade, a usable session over full retention, for a summary that was generated and then failed the audit, and it also covers manual /compact, which is where the production reproduction came from. If maintainers want one owner for "commit without an audited summary", the alternative is to route terminal quality failure through #164246's host-side compactWithoutSummary path instead of the safeguard's structured fallback, at the cost of the retention plan and the qualityDegraded marker. Happy to rework it that way.

Also added Related: #120162 to the body, per @Hansen1018's note. On this branch a corrective attempt that throws still cancels (corrective_generation_failed); only a summary that came back and failed the audit degrades, so a retry cut short by the shared timeoutSeconds budget does not log quality_guard_degraded_fallback.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 9, 2026
Main's 1d09a03 (openclaw#167916) reworked the safeguard under this branch
and conflicted in four files:

- compaction-safeguard.ts: main's imports stay, minus the two the
  tool-failure helpers took with them to their own module.
- compaction-safeguard.test-support.ts: main's
  setSummarizeCompactionHistoryForTest seam stays; the two tool-failure
  entries are gone with the helpers.
- compaction-safeguard.test.ts: main's fail-closed case stays replaced
  by the degraded-fallback suite.
- assertion-safety-baseline.txt: compaction-safeguard.ts 11 -> 9, the
  same two casts that moved with the tool-failure helpers.

Two changes the textual merge could not see: openclaw#167916 dropped
effectivePreviousSummary with history pruning, so the degraded fallback
builds from previousSummary, and the degraded-fallback suite uses the
renamed summarizeCompactionHistory seam.
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 9, 2026
@amittell

amittell commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Main conflicted with the branch again, so it is merged once more: 3474e67196f (main 286fff87a2a). #167916 reworked the safeguard and conflicted in four files (compaction-safeguard.ts, its test and test-support files, and the assertion-safety baseline, now 11 -> 9 for the two casts that moved with the tool-failure helpers). Beyond the conflicts, #167916 dropped effectivePreviousSummary along with history pruning, so the degraded fallback now builds from previousSummary, and the degraded-fallback suite uses the renamed summarizeCompactionHistory seam.

On the merged head (M4 Pro, Node 26.10.0): 13 compaction test files, 260 passed, 0 failed (degraded-fallback 4, degraded-reload 2, tool-failures 3, provider-boundary 5, compact.hooks.test.ts 81, compaction-safeguard.test.ts 69, the rest unchanged); tsgo:core and the agents-other and agents-sessions test graphs are clean; the max-lines, line-cap, assertion-safety, database-worker, test-timeout-race and test-mock-exports ratchets pass against 286fff87a2a; oxfmt and oxlint are clean on the changed files.

Cost note, corrected 2026-10-10: an earlier version of this comment said the degraded-reload file got slower on this head and put that down to main's SQLite session path. It was load on the shared M4. Interleaved on the same machine, three rounds each, the file took 3.7, 5.1 and 8.3 s of test time on 3474e67196f and 8.6, 13.3 and 10.7 s on the previous head 08f52683e21. Main's own agent-session-compaction.admission.test.ts took 3.4 to 4.2 s on 4db022470af (median 4.1 s) and 3.8 to 5.9 s on 286fff87a2a (median 3.8 s). Load averages were 18 to 33 throughout; neither this branch nor main is consistently slower.

Ran the upgrade from the released v2026.9.9: a session written by the published [email protected] package migrates, compacts through the degraded fallback, reloads with qualityDegraded: true, and answers the next turn. Main at the merge base cancels on the same state, and the session stays stuck.

  • Phase 1: npm install [email protected] (OpenClaw 2026.9.9 (bcfc888)), six openclaw agent --local turns of about 12,000 chars into one isolated state directory, all exit 0. Agent database schema v24, 22 transcript events.
  • Phase 2 on 3474e67196f, same path: openclaw doctor --fix --non-interactive upgrades the agent database v24 -> v25 and exits 0. The provider is a mock on loopback that rejects agent requests over 79,750 chars and never returns the required summary headings. Turn 7 overflows (85,742 chars), the guard logs final quality attempt failed ... reasonCode=quality_guard_degraded_fallback, compaction goes 36,343 -> 21,390 tokens, and the retry answers (exit 0). Turn 8 is a new process: it reopens the session, sends 16,324 chars with the summary and the request context in it, and answers (exit 0). The stored boundary reads back qualityDegraded: true with the request context and 2 of 3 seeded identifiers, the two the safeguard audits.
  • Control on 286fff87a2a with the same snapshot: Doctor migrates the same way, then turn 7 logs finalized summary failed quality checks and livenessState=blocked, replies "Context overflow: prompt too large for the model", exits 1, and stores no boundary. Turn 8 fails the same way.

Full commands and output are in the body under "Upgrade from the released v2026.9.9". Not run: a rollback to v2026.9.9 after the database is at v25, and a live model.

@clawsweeper clawsweeper Bot added proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
steipete and others added 5 commits October 10, 2026 15:59
Merge main and reconcile CJK summary fitting. Recover the best generated summary after audit exhaustion, preserve committed degradation through status and notices, and clarify best-effort retention.

Co-authored-by: Alex Mittell <[email protected]>
Reuse the notice presentation owner for completion and status formatting. Keep warnings in returned replies when no streaming dispatcher exists, preserve abort fencing, and assert retained summary facts instead of a discarded fallback template.
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 11, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants