Skip to content

fix(memory-core): MEMORY.md compaction deletes user notes written under a promotion-style heading - #116180

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
yetval:fix/memory-budget-marker-ownership
Jul 30, 2026
Merged

vincentkoc merged 3 commits into
openclaw:mainfrom
yetval:fix/memory-budget-marker-ownership

Conversation

@yetval

@yetval yetval commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #116057

What Problem This Solves

Budget compaction could silently delete durable operator notes from MEMORY.md when a top-level heading resembled generated promotion history. The original patch correctly rejected heading-only ownership, but one marker still claimed the entire accumulated block, including unheaded user prose after a generated entry.

This is a shipped P1 data-integrity bug in v2026.7.2-beta.5 and remained present on main.

Best Fix

Compaction now treats a promotion-shaped block as OpenClaw-owned only when its complete nonblank body matches the grammar emitted by buildPromotionSection:

  • optional marker-backed ### Global / ### Project: headings;
  • an <!-- openclaw-memory-promotion:... --> marker;
  • the immediately following single-line - entry.

Marker-free, marker-only, malformed, or mixed blocks are preserved whole. A marker authenticates its generated entry, not arbitrary trailing operator text. Genuine generated blocks remain eligible for oldest-first compaction.

User Impact

Durable notes survive budget pressure even when they use a promotion-style heading or sit unheaded after generated entries. No config, migration, schema, or operator action changes.

Evidence

Exact repaired head: c976279982759d9ba7825c1f62f0541ad71c72c3.

  • memory-budget.test.ts: 30 tests passed.
  • short-term-promotion.test.ts: 85 tests passed.
  • Blacksmith Testbox tbx_01kyryz9gy6xe62pw7d91pk5dn: 143 focused tests passed, including the cold citation startup regression.
  • Current merge-result proof: 115/115 compaction and promotion tests passed on c9762799827 merged into live main cc570a74532e in Testbox tbx_01kys1qtmatt5nw3skv32m96z0.
  • Real filesystem + SQLite-backed recall/ranking/apply/write regression proves a mixed block sentinel survives while a clean generated neighbor is compacted.
  • pnpm check:changed passed on the same Testbox lease, including extension production/test typechecks, lint, format, ownership guards, deadcode, database-first, and import-cycle checks.
  • Fresh autoreview: clean, no accepted/actionable findings, 0.99 confidence.

Hosted exact-head CI run 30524117587 is green, including checks-node-changed-3 and openclaw/ci-gate. Latest ClawSweeper review found no code defect; its current-merge-result rank-up move is satisfied by the proof above.

Attribution

Original diagnosis and marker-ownership direction by @yetval. Maintainer repair preserves contributor ancestry and co-author credit.

… user sections

Budget compaction decided that a MEMORY.md section belonged to OpenClaw purely
from its heading text, so a user-authored section under a heading that looks
generated, such as "## Promoted From Short-Term Memory (2026-04-10)", was
eligible for deletion once the file plus the new promotion exceeded
memoryFileMaxChars. The rewrite succeeded silently and the atomic replace made
the loss durable.

A matching heading is now provisional: the block is classified as a promotion
only when it structurally contains at least one
"<!-- openclaw-memory-promotion:... -->" marker, which buildPromotionSection
emits for every promoted candidate. Marker-free sections are preserved.
Generated sections, including the multi-project shape whose markers sit under
"### Global" and "### Project:" subsections, are still dropped oldest-first, so
the size bound from openclaw#73691 is unchanged.

Extends openclaw#116057, which made only subsection handling marker-aware and left the
top-level heading classifier trusting presentation text.
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 3:47 AM ET / 07:47 UTC.

ClawSweeper review

What this changes

The branch restricts MEMORY.md budget compaction to fully generated promotion blocks, adds unit and production-path regressions for mixed user content, and increases one cold-start citation test timeout.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: it addresses a real durable-memory data-loss path left after the earlier heading-boundary repair. The patch makes deletion ownership depend on the complete generated marker-and-bullet structure rather than a promotion-like heading or marker alone; no concrete correctness or security defect is evident in the proposed change, but its persisted-memory behavior should be revalidated on the current merge result before landing.

Priority: P1
Reviewed head: c976279982759d9ba7825c1f62f0541ad71c72c3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, conservative repair with strong behavior evidence; only current-merge-result validation remains material before merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR supplies after-fix real filesystem and SQLite-backed promotion evidence showing a mixed user-text sentinel survives while a clean generated neighbor is compacted; redact private workspace content if any follow-up artifact is posted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR supplies after-fix real filesystem and SQLite-backed promotion evidence showing a mixed user-text sentinel survives while a clean generated neighbor is compacted; redact private workspace content if any follow-up artifact is posted.
Evidence reviewed 5 items Current behavior and changed boundary: The current compaction design classifies promotion-shaped MEMORY.md sections for oldest-first removal; this PR changes that classification so a block is removable only when its full nonblank body matches the generated promotion marker-and-single-bullet grammar, preserving ambiguous or mixed operator content.
Regression coverage: The branch adds focused parser cases plus a production-path promotion-write regression that seeds a real workspace and SQLite-backed recall state, then verifies mixed user text survives while an adjacent clean generated promotion is compacted.
Earlier repair relationship: Merged predecessor #116057 repaired heading boundaries, while this PR covers the distinct remaining case where unheaded user prose follows an otherwise marker-backed generated entry.
Findings None None.
Security None None.

How this fits together

Memory Core promotes recalled short-term notes into a workspace’s durable MEMORY.md file and compacts older generated entries when that file reaches its size budget. This change sits at the ownership boundary that decides which stored sections may be deleted before the promotion writer rewrites the file.

flowchart LR
  A[Short-term recall candidates] --> B[Promotion writer]
  B --> C[Existing MEMORY.md]
  C --> D[Compaction ownership check]
  D --> E[Preserve user or mixed blocks]
  D --> F[Drop oldest generated blocks]
  E --> G[Updated durable memory]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The PR changes eligibility for deleting persisted MEMORY.md sections and is behind current main; before merge, validate the focused compaction and real promotion-write regressions on the actual merge result so current-base behavior cannot reintroduce note loss or prevent valid generated cleanup.
Agent review details

Security

None.

PR surface

Source +34, Tests +163. Total +197 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 40 6 +34
Tests 3 171 8 +163
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 211 14 +197

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: extensions/memory-core/src/short-term-promotion.test.ts, unknown-data-model-change: extensions/memory-core/src/memory-budget.test.ts, unknown-data-model-change: extensions/memory-core/src/memory-budget.ts, unknown-data-model-change: extensions/memory-core/src/short-term-promotion.test.ts, vector/embedding metadata: extensions/memory-core/src/memory-budget.test.ts, vector/embedding metadata: extensions/memory-core/src/memory-budget.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #116180
Summary: This PR is the canonical remaining repair for marker-backed promotion blocks containing unheaded user content; the earlier merged repair addressed only heading-derived block boundaries.

Members:

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

Merge-risk options

Maintainer options:

  1. Validate the merge result first (recommended)
    Run the focused memory-budget and production promotion-write regressions against the current merge result, then merge if mixed blocks are preserved and clean generated sections still compact.
  2. Pause if merge-result proof differs
    Hold the PR for a narrow update if current-main integration changes either deletion eligibility or budget-compaction behavior.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Validate the focused memory-compaction regressions against the current merge result and confirm mixed user text remains while a clean generated neighbor is compacted.

Technical review

Best possible solution:

Land the conservative grammar-based ownership rule after current-merge-result validation confirms mixed operator text survives and clean generated blocks remain compactable oldest-first.

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

Yes, from source and the supplied production-path regression: seed an over-budget MEMORY.md containing a marker-backed generated entry followed by unheaded user prose, then execute the real recall, ranking, promotion, and write path. The reported before/after evidence shows the prior ownership rule could remove that user prose.

Is this the best way to solve the issue?

Yes. Requiring the complete writer-emitted grammar is the narrowest maintainable ownership rule: it preserves any block that could contain user text while retaining oldest-first compaction for clearly generated entries.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: Without this repair, normal budget compaction can silently delete durable user-authored memory during an existing promotion workflow.
  • merge-risk: 🚨 session-state: The patch changes which persisted MEMORY.md blocks may be deleted during compaction, so an integration mistake could lose or retain durable agent state incorrectly.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR supplies after-fix real filesystem and SQLite-backed promotion evidence showing a mixed user-text sentinel survives while a clean generated neighbor is compacted; redact private workspace content if any follow-up artifact is posted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies after-fix real filesystem and SQLite-backed promotion evidence showing a mixed user-text sentinel survives while a clean generated neighbor is compacted; redact private workspace content if any follow-up artifact is posted.

Evidence

What I checked:

  • Current behavior and changed boundary: The current compaction design classifies promotion-shaped MEMORY.md sections for oldest-first removal; this PR changes that classification so a block is removable only when its full nonblank body matches the generated promotion marker-and-single-bullet grammar, preserving ambiguous or mixed operator content. (extensions/memory-core/src/memory-budget.ts, c97627998275)
  • Regression coverage: The branch adds focused parser cases plus a production-path promotion-write regression that seeds a real workspace and SQLite-backed recall state, then verifies mixed user text survives while an adjacent clean generated promotion is compacted. (extensions/memory-core/src/short-term-promotion.test.ts, c97627998275)
  • Earlier repair relationship: Merged predecessor fix(memory-core): stop MEMORY.md compaction from deleting user headings #116057 repaired heading boundaries, while this PR covers the distinct remaining case where unheaded user prose follows an otherwise marker-backed generated entry. (extensions/memory-core/src/memory-budget.ts, 772235cc5597)
  • Review continuity: The prior ClawSweeper cycle found no patch defect and identified one remaining rank-up move: validate the focused compaction regressions against the current merge result because the branch is behind main. (e3b435d61fc1)
  • Proof supplied: The PR body reports 115 focused tests and an after-fix real filesystem plus SQLite-backed promotion run that preserves a mixed-block sentinel while removing a clean generated neighbor; the later head commit only changes a test timeout. (extensions/memory-core/src/memory-budget.test.ts, c97627998275)

Likely related people:

  • vincentkoc: Authored the marker-ownership repair in this PR, is assigned to its review, and authored the follow-up commit that tightened the generated-block boundary. (role: recent area contributor and repair author; confidence: high; commits: e3b435d61fc1, c97627998275; files: extensions/memory-core/src/memory-budget.ts, extensions/memory-core/src/short-term-promotion.test.ts)
  • yetval: Authored the preceding merged memory-compaction repair and the initial diagnosis/implementation direction for the current ownership case. (role: prior merged feature contributor; confidence: high; commits: 8a3521becee5, a5496372ca3f; files: extensions/memory-core/src/memory-budget.ts, extensions/memory-core/src/memory-budget.test.ts)

Rank-up moves

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

  • Run the focused compaction and real promotion-write regressions on the current merge result, then attach the redacted result to the PR body or review context.

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 (3 earlier review cycles)
  • reviewed 2026-07-30T02:31:55.933Z sha 8a3521b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T02:42:16.506Z sha 8a3521b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T04:50:00.174Z sha e3b435d :: needs maintainer review before merge. :: none

@yetval
yetval marked this pull request as ready for review July 30, 2026 02:37
@vincentkoc vincentkoc self-assigned this Jul 30, 2026
Validate the complete marker-and-entry grammar before treating a promotion-shaped block as writer-owned. Preserve marker-only and mixed blocks so unheaded operator notes cannot be deleted during budget compaction.

Co-authored-by: yetval <[email protected]>
@vincentkoc
vincentkoc merged commit d952566 into openclaw:main Jul 30, 2026
94 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 30, 2026
…n-dedupe

* origin/main: (25 commits)
  fix(qqbot): use Gateway timezone for reminders (#116294)
  test(openai): cover out-of-order named mark acks
  docs(openai): clarify cumulative playback marks
  test(openai): cover sustained unnamed mark acknowledgements
  fix(openai): preserve playback acknowledgement order
  test(openai): verify bounded playback acknowledgements
  fix(openai): bound realtime playback marks
  test(agents): mock incremental registry persistence (#116307)
  fix(memory-core): MEMORY.md compaction deletes user notes written under a promotion-style heading (#116180)
  feat(reply): annotate recent history images (#100866)
  chore(ios): refresh native i18n inventory
  fix(ios): isolate capability router handlers
  docs(ios): cut 2026.7.22 release notes
  docs(hooks): document validation responses
  test(qa): assert hook account rejection reasons
  fix(gateway): validate hook delivery accounts
  perf(gateway): bound prepared runtime startup work (#116261)
  fix(agents): prevent registry stalls during large fan-outs (#116286)
  fix(sqlite): preserve replaced snapshot targets on Windows (#116284)
  fix(ci): load frozen shard runner without repository fetch (#116273)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
…er a promotion-style heading (openclaw#116180)

* fix(memory-core): stop MEMORY.md compaction from deleting marker-free user sections

Budget compaction decided that a MEMORY.md section belonged to OpenClaw purely
from its heading text, so a user-authored section under a heading that looks
generated, such as "## Promoted From Short-Term Memory (2026-04-10)", was
eligible for deletion once the file plus the new promotion exceeded
memoryFileMaxChars. The rewrite succeeded silently and the atomic replace made
the loss durable.

A matching heading is now provisional: the block is classified as a promotion
only when it structurally contains at least one
"<!-- openclaw-memory-promotion:... -->" marker, which buildPromotionSection
emits for every promoted candidate. Marker-free sections are preserved.
Generated sections, including the multi-project shape whose markers sit under
"### Global" and "### Project:" subsections, are still dropped oldest-first, so
the size bound from openclaw#73691 is unchanged.

Extends openclaw#116057, which made only subsection handling marker-aware and left the
top-level heading classifier trusting presentation text.

* fix(memory-core): preserve mixed promotion blocks

Validate the complete marker-and-entry grammar before treating a promotion-shaped block as writer-owned. Preserve marker-only and mixed blocks so unheaded operator notes cannot be deleted during budget compaction.

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

* test(memory-core): allow cold citation startup

---------

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
…n-dedupe

* origin/main: (25 commits)
  fix(qqbot): use Gateway timezone for reminders (openclaw#116294)
  test(openai): cover out-of-order named mark acks
  docs(openai): clarify cumulative playback marks
  test(openai): cover sustained unnamed mark acknowledgements
  fix(openai): preserve playback acknowledgement order
  test(openai): verify bounded playback acknowledgements
  fix(openai): bound realtime playback marks
  test(agents): mock incremental registry persistence (openclaw#116307)
  fix(memory-core): MEMORY.md compaction deletes user notes written under a promotion-style heading (openclaw#116180)
  feat(reply): annotate recent history images (openclaw#100866)
  chore(ios): refresh native i18n inventory
  fix(ios): isolate capability router handlers
  docs(ios): cut 2026.7.22 release notes
  docs(hooks): document validation responses
  test(qa): assert hook account rejection reasons
  fix(gateway): validate hook delivery accounts
  perf(gateway): bound prepared runtime startup work (openclaw#116261)
  fix(agents): prevent registry stalls during large fan-outs (openclaw#116286)
  fix(sqlite): preserve replaced snapshot targets on Windows (openclaw#116284)
  fix(ci): load frozen shard runner without repository fetch (openclaw#116273)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core 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. 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