Skip to content

fix: preserve conversation after memory flush exhaustion - #132010

Merged
steipete merged 1 commit into
mainfrom
steipete/compaction-logic-review-625078
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/compaction-logic-review-625078

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #131957

What Problem This Solves

Fixes an issue where conversations lost older, unsummarized context after optional pre-compaction memory maintenance exhausted its retries, even when the conversation was small and preflight compaction correctly had nothing to do. Required compaction failures could also be hidden by an automatic reset instead of giving the user the existing recovery guidance.

Why This Change Was Made

Memory maintenance failure is not evidence that conversation history should be discarded. The reply coordinator now leaves compaction decisions and failure reporting with the compaction owner, removing the exhaustion-triggered reset and its special overflow-error swallow. The now-unused reset callback/type plumbing is removed; the separate role-ordering recovery path is unchanged.

This changes no configuration, schema, dependency, retry budget, credential routing, or compaction threshold. It preserves the optional degraded notice and ordinary replies when preflight is unnecessary or succeeds. AI-assisted audit and repair.

User Impact

Older asks and decisions stay available after exhausted memory flushing. When compaction really is required but fails, users receive the existing explicit failure/recovery reply and keep their conversation, rather than silently starting over. The behavior is documented at https://docs.openclaw.ai/concepts/compaction#memory-flush.

Release-note context: preserve conversation continuity after optional memory-maintenance exhaustion; do not mask required compaction failures with a reset.

Evidence

Production LOC: +29/-85 (net -56). Tests: +152/-147 (net +5). Docs: +3/-1.

The regression uses real memory-flush preparation, preflight decisions, the reset implementation, and SQLite-backed transcript reconstruction. A regular file blocks the isolated workspace's memory directory while token usage remains low. The test verifies that older context reaches the next agent turn and that session lifecycle, usage, and compaction counters are preserved. Required overflow and auth-shaped compaction failures remain visible and never reset the session.

Before the production change, the updated boundary suite failed in the two intended cases (context continuity and required-overflow failure) and passed the other 15. After the fix, all 17 pass. Another 173 memory/preflight/reset/queued-followup tests and 31 CLI-compaction sibling tests pass.

Commands executed:

node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-direct-runtime-config.test.ts
node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts src/auto-reply/reply/agent-runner-memory.preflight-stale-tokens.test.ts src/auto-reply/reply/agent-runner-session-reset.test.ts src/auto-reply/reply/agent-runner-execution-conversation-failures.test.ts src/auto-reply/reply/followup-turn-admission.test.ts src/auto-reply/reply/followup-turn-execution.test.ts src/agents/command/cli-compaction.test.ts

The sibling invocation was interrupted after its 173-test auto-reply shard passed; the remaining 31-test CLI shard was rerun explicitly and passed:

node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts
node scripts/check-changed.mjs -- docs/concepts/compaction.md src/auto-reply/reply/agent-runner-direct-runtime-config.test.ts src/auto-reply/reply/agent-runner-execute.ts src/auto-reply/reply/agent-runner-run.ts

The resumed changed-file gate passed core/test typechecks, targeted formatting/lint, dead exports, import cycles, and the selected guards. Its earlier attempt was interrupted, not counted as a pass.

Real Gateway behavior

Provider: blacksmith-testbox. Lease: tbx_01m14qh81rwetqqcs75k3kg9an. Testbox run.

The isolated proof built private QA with OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build, then ran a temporary driver through the existing Gateway-child, mock-openai, and qa-channel harnesses. No reply-coordinator mock, monkey patch, or production test seam was used. It created an actual channel session, seeded twenty short historical messages, blocked memory-file preparation, and sent three normal inbound channel turns. Failure counts advanced 1, 2, then exhausted; all three replies arrived, and the oldest marker remained in every actual outbound provider request.

{
  "verdict": "PASS",
  "gateway": "ephemeral-child",
  "runtime": "openclaw",
  "provider": "mock-openai",
  "channel": "qa-channel",
  "ordinaryRepliesDelivered": true,
  "finalProviderRequestRetainsOldMarker": true,
  "allProviderRequestsRetainOldMarker": true,
  "exactlyThreeOrdinaryProviderRequests": true,
  "filesystemPreparationFailedThreeTimes": true,
  "exhaustionObserved": true,
  "cycleSkipPersisted": true,
  "noCompaction": true,
  "noResetBoundary": true,
  "sameSessionLifecycle": true,
  "terminalHealthy": true,
  "lowReportedUsage": true,
  "ownedServicesStopped": true
}

Testbox committed the synchronized candidate as temporary snapshot 71f679a136fffc02e89c18f1731d345f6d113cf5, parent 787e602e228edb9fd1b4a88111de2608f6444b4a; hashes of both repaired production files match the local candidate exactly. The snapshot therefore has an empty working diff, not missing changes. Command exit 0; build plus proof took approximately seven minutes.

Proof limits: this is a real Gateway with a synthetic channel/provider, not live Telegram or a live model. There was no separate pre-fix built Gateway artifact; the pre-fix failure is the captured boundary regression. Required-compaction failure propagation is covered by that regression, not this channel scenario. Independent live OpenAI/Anthropic compact-and-replay and pinned Codex compact/replay/restart probes passed during the wider audit, but are not substitutes for this changed-path Gateway proof.

The isolated Codex autoreview completed successfully with no actionable findings at its requested P0-only threshold. This is not a claim of an all-severity independent review. Exact-head CI completed successfully for 4a5703c73ebd55fc63e7a4d6082ea67064802fe6, including openclaw/ci-gate. The fresh ClawSweeper review reports no actionable findings, sufficient changed-path Gateway proof, and no before-merge work or Rank-up moves.

Provenance and solution choice

The exhaustion reset originated in the memory-flush reply recovery change, authored and merged by @steipete on 2026-07-06. The subsequent preflight ordering change, authored by @TurboTheTurtle and merged by @steipete that day, retained the reset behind the no-compaction condition; later extraction carried it forward.

The best fix is deleting the optional-maintenance reset inference at the reply coordinator. Restricting resets to a different error string would still discard unsummarized context, and adding another retry or configuration switch would retain the wrong ownership relationship. The existing compaction failure outcome already tells the user how to recover without losing the active conversation.

Optional memory maintenance must not reset unsummarized conversation history. Preserve ordinary replies after exhausted flush retries and surface required compaction failures through the existing recovery outcome.

Fixes #131957
@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 18:20
@clawsweeper clawsweeper Bot added 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 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 2:53 PM ET / 18:53 UTC.

ClawSweeper review

What this changes

The PR stops optional memory-flush exhaustion from resetting an active conversation, while retaining explicit recovery for required preflight-compaction failures.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking findings. This active maintainer-authored PR removes a source-proven session reset that current main still performs after optional memory-flush exhaustion, and it has focused boundary plus Gateway-path proof.

Priority: P1
Reviewed head: 4a5703c73ebd55fc63e7a4d6082ea67064802fe6

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused net-negative repair has strong boundary coverage and source-mapped Gateway-path proof, with no concrete correctness or security finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed production owner is the reply coordinator; supplied after-fix live output drives it through an ephemeral Gateway child with real session persistence, a QA channel, and a mock OpenAI transport. It observes three delivered replies, preserved historical context, exhaustion, and no reset; the synthetic transport is appropriate for this internal session-reliability path.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed production owner is the reply coordinator; supplied after-fix live output drives it through an ephemeral Gateway child with real session persistence, a QA channel, and a mock OpenAI transport. It observes three delivered replies, preserved historical context, exhaustion, and no reset; the synthetic transport is appropriate for this internal session-reliability path.
Evidence reviewed 8 items Current-main defect: Current main retains the exhaustion-plus-no-compaction reset: a no-op preflight leaves the applied count unchanged and the coordinator invokes the reset path.
Owner-boundary repair: The branch always lets preflight compaction return or throw its own outcome, then emits the existing degraded notice without resetting the active session.
Compaction owner contract: The compaction owner independently decides whether compaction is needed and throws an explicit required-compaction failure rather than returning a reset instruction.
Findings None None.
Security None None.

How this fits together

A channel turn enters the reply coordinator, which runs optional memory maintenance and preflight compaction before the main agent turn. These phases update the active session and then either continue the reply or return an explicit recovery message.

flowchart LR
A[Inbound channel turn] --> B[Reply coordinator]
B --> C[Optional memory flush]
C --> D[Preflight compaction]
D --> E[Main agent turn]
E --> F[Channel reply]
D --> G[Explicit recovery reply]
Loading

Before merge

  • Resolve merge risk (P1) - Two captured PR comments were filtered from the supplied review context; their content should be checked for any later maintainer direction before merge.
Agent review details

Security

None.

PR surface

Source -56, Tests +5, Docs +2. Total -49 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 29 85 -56
Tests 1 152 147 +5
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 184 233 -49

Review metrics

Metric Value Why it matters
Production versus test LOC production +29/-85 (net -56); tests +152/-147 (net +5); docs +3/-1 The repair reduces production branching while adding boundary coverage for retained session continuity and required-compaction failure delivery.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #131957
Summary: This PR is the explicit candidate fix for the reported optional-memory-maintenance reset behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the coordinator free of memory-flush reset inference: preserve the active session after optional maintenance failure, and let the compaction owner return either successful compaction or its explicit recovery outcome.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the coordinator free of memory-flush reset inference: preserve the active session after optional maintenance failure, and let the compaction owner return either successful compaction or its explicit recovery outcome.

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

Yes, source reproducibly identifies the exhausted optional flush plus successful no-op preflight condition on current main; the supplied boundary and Gateway evidence exercise that scenario after the repair.

Is this the best way to solve the issue?

Yes. Removing the coordinator's reset inference is the clean owner-boundary repair because the compaction owner already decides whether compaction is required and surfaces its own failure outcome.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The branch repairs loss of model-visible conversation continuity on an existing reply path.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owner is the reply coordinator; supplied after-fix live output drives it through an ephemeral Gateway child with real session persistence, a QA channel, and a mock OpenAI transport. It observes three delivered replies, preserved historical context, exhaustion, and no reset; the synthetic transport is appropriate for this internal session-reliability path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the reply coordinator; supplied after-fix live output drives it through an ephemeral Gateway child with real session persistence, a QA channel, and a mock OpenAI transport. It observes three delivered replies, preserved historical context, exhaustion, and no reset; the synthetic transport is appropriate for this internal session-reliability path.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the prior merged memory-flush recovery commit and the current coordinator repair. (role: prior reply-recovery author and recent area contributor; confidence: high; commits: dd972b8bf775, 4a5703c73ebd; files: src/auto-reply/reply/agent-runner-execute.ts, src/auto-reply/reply/agent-runner-run.ts)
  • TurboTheTurtle: Authored the prior merged preflight ordering change that established this maintenance ordering. (role: preflight-ordering contributor; confidence: medium; commits: e24d4426fe8c; files: src/auto-reply/reply/agent-runner-memory.ts, src/auto-reply/reply/agent-runner-execute.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 (1 earlier review cycle)
  • reviewed 2026-08-28T18:25:45.063Z sha 4a5703c :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Pre-merge verification for 4a5703c73ebd55fc63e7a4d6082ea67064802fe6: the optional-maintenance reset inference is removed at the reply coordinator, required compaction failures retain their visible recovery path, and role-ordering recovery is unchanged. Production net −56 lines; no new config, schema, dependency, or credential behavior.

The boundary regression failed in the two intended cases before the fix, then passed all 17. Memory/preflight/reset/execution/followup siblings passed 173, and the resumed CLI-compaction shard passed 31: 221 focused/sibling tests passed. The changed-file gate passed. Exact-head hosted CI is successful, including openclaw/ci-gate.

The Blacksmith Testbox proof (tbx_01m14qh81rwetqqcs75k3kg9an) built private QA and exercised an actual isolated Gateway with qa-channel/mock-openai. Three real memory-file preparation failures exhausted maintenance, but all three ordinary replies arrived and every outbound provider request retained the oldest marker. No reset boundary or lifecycle change occurred. Exact production-file hashes match this candidate; the owned services and lease are stopped.

The isolated Codex autoreview passed at its P0-only threshold. The fresh ClawSweeper review has no findings, no before-merge work, and no Rank-up moves. Native review, PR-head guards, and review artifacts are validated. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 132010 completed successfully on retry, verified hosted gates, and retained the exact reviewed head without another push.

Exact local commands and proof limits
node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-direct-runtime-config.test.ts
node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts src/auto-reply/reply/agent-runner-memory.preflight-stale-tokens.test.ts src/auto-reply/reply/agent-runner-session-reset.test.ts src/auto-reply/reply/agent-runner-execution-conversation-failures.test.ts src/auto-reply/reply/followup-turn-admission.test.ts src/auto-reply/reply/followup-turn-execution.test.ts src/agents/command/cli-compaction.test.ts

The auto-reply shard completed before interruption; the remaining CLI shard was explicitly resumed:

node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts
node scripts/check-changed.mjs -- docs/concepts/compaction.md src/auto-reply/reply/agent-runner-direct-runtime-config.test.ts src/auto-reply/reply/agent-runner-execute.ts src/auto-reply/reply/agent-runner-run.ts

Gateway proof uses a synthetic provider/channel, not live Telegram. The pre-fix failure and required-compaction failure branch are regression evidence, not separate live Gateway scenarios. Earlier interrupted check/review attempts are not counted as passes. Native prepare encountered a GitHub HTTPS fetch HTTP 429; its exact retained lock was recovered only after verifying the owned child processes had exited. No landing gate was bypassed.

@steipete
steipete merged commit 75a3e75 into main Aug 28, 2026
326 checks passed
@steipete
steipete deleted the steipete/compaction-logic-review-625078 branch August 28, 2026 19:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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]: Exhausted memory maintenance resets conversations that do not need compaction

1 participant