Repository navigation
fix(memory): preserve inline notes during MEMORY.md compaction - #164089
Conversation
Require a promotion marker to end at its first comment closing delimiter. Preserve mixed lines instead of pruning their enclosing section when the file exceeds its budget. Related: openclaw#163900
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR preserves promotion sections containing inline handwritten comments during MEMORY.md budget compaction. Example: A promotion marker in the 2026-04-01 section is followed by <!-- HANDWRITTEN_KEEP café 中文 -->.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a current-main data-loss bug with a focused patch and credible shipped-CLI proof; no actionable code defects remain. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core's promotion writer passes existing MEMORY.md content, a new promotion section, and budget limits to the compactor, then publishes the complete result only if it fits. flowchart TD
A[Memory promotion CLI or dreaming] --> B[Promotion writer]
C[Existing MEMORY.md] --> B
B --> D[Budget compactor]
D --> E[Preserve mixed sections]
D --> F[Reclaim clean generated sections]
E --> G[Final budget check and publication]
F --> G
Technical reviewBest possible solution: Land the focused deletion-eligibility repair after required checks pass, preserving existing section boundaries and loss limits. Do we have a high-confidence way to reproduce the issue? The greedy marker check and its publication caller establish the failure path, corroborated by supplied paired CLI output; this read-only review ran no target code. Is this the best way to solve the issue? This is the smallest complete repair: tighten only deletion eligibility while retaining the existing boundary predicate, preventing the previously identified prefix-deletion regression. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d20f161513f7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests 0, Docs +2. Total +7 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed November 1, 2026, 9:24 AM ET / 14:24 UTC (Revision 5). |
|
@clawsweeper re-review The PR body now includes paired, synthetic before/after evidence through the real promotion writer for both inline-note cases and an all-clean control, actual published-file diffs, exact parameters (including the explicit fixture loss limit), a reproducible harness, focused-test wall times, and available CI timing. The head remains |
|
🦞👀 Re-review progress:
|
|
Thanks @GoldArowana for fixing the inline-comment data-loss case and providing the writer evidence. While checking that compaction only becomes more conservative, I found two safety issues in
Suggested repair shape: retain the original I have not pushed changes or run the full Gateway/live-provider acceptance flow; this is a data-safety handoff, not landing approval. Leaving the PR open for the follow-up. |
|
Thanks for the detailed reproduction. Both regressions are addressed in
Added seven regressions for CR, U+2028, U+2029, both promotion subsection forms, and both Setext underline forms. The original two inline-note regressions remain in place. I also exercised the production promotion writer with synthetic files and the default Validation: 168 focused tests passed (including seven temporary writer-proof cases), the committed budget suite passes 38/38 in 8.786s process wall time, and all 28 selected check components passed. The PR body now contains the updated evidence and the reproducible writer fixture. |
…on (openclaw#163900) A marker line qualified a consolidation block for deletion when it merely started with a generated marker: the greedy .*--> in the lineage and promotion marker regexes accepted '<!-- openclaw-memory-lineage:key --> <!-- user note -->' as one generated comment, so budget compaction could drop a block holding a handwritten inline note. Deletion qualification now requires each marker line to be exactly one HTML comment, using the same single-comment predicate as openclaw#164089; boundary detection and entry counting keep the existing matcher. Proof: built CLI memory promote --apply on an isolated workspace. The reviewed head dropped the annotated oldest consolidation section and its note; this commit keeps that section byte for byte and drops the next plain generated section instead.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This SolvesRelated: #163900. Under MEMORY.md budget pressure, a promotion marker followed by a handwritten HTML comment can be mistaken for a completely generated block. The greedy marker regex consumes through the second closing delimiter, making that handwritten content eligible for deletion. This keeps the existing permissive marker recognition for section boundaries, but uses a first-comment-bounded marker check when deciding whether the entire section is safe to delete. The two checks intentionally have different responsibilities: tightening section-boundary recognition would allow deletion of a generated prefix from a mixed section. The accepted line domain remains unchanged. Contributor Credit and OwnershipOriginal contributor commits Current main was integrated before proof because it had changed the owning module. No changes from the held PR were adopted. EvidenceReal shipped CLI proof in secretless Linux Docker on Node 24.22.1:
20 real apply runs, two per case on each ref:
The primary data-loss cases are successful writes, not no-op preservation: both refs report Actual MEMORY.md diff excerpts: Main removes the annotated section: -## Promoted From Short-Term Memory (2026-04-01)
-<!-- openclaw-memory-promotion:fixture-0 --> <!-- HANDWRITTEN_KEEP café café 中文 🦞 -->Candidate instead removes a clean generated section, leaving that annotation intact: -## Promoted From Short-Term Memory (2026-04-02)
-<!-- openclaw-memory-promotion:fixture-1 -->Both diffs append the newly promoted sourced preference. Full before/after MEMORY.md files and unified diffs are retained with the proof. The primary fixture starts at 7,349 UTF-8 bytes: main ends at 6,448 bytes without the note, candidate at 6,499 bytes with it. Focused regression: the existing mixed-block case now uses an annotated marker and verifies that the whole mixed section survives while the clean neighboring section is removed. Same final file on main: 1 intended failure / 12 passes (wrong section dropped); candidate: 13 passes. Existing heading, project grouping, budget/loss-bound and marker-only cases remain. Focused formatting passed. Simplification retains the two necessary marker responsibilities and no additional parser or state. Whole-PR production +6/−1 (net +5; seven changed lines), tests 0 net, docs +2. The added duplicate unit setup is replaced by the strengthened existing case plus the shipped-CLI controls. No SDK, schema, config, loss limit or compaction policy expansion. Compatibility and Merge DangerTwo-way door for the code: reverting restores prior classification without a migration. Deletions already made by an older build are not automatically restored. Blast radius is append-compaction eligibility for MEMORY.md promotion sections; generated-only reclamation stays available, while handwritten annotations make the entire section non-deletable. |
|
Landed in 49600b5. Thanks @GoldArowana. memory promote no longer deletes handwritten notes in MEMORY.md. |
…law#164089) fix(memory): keep handwritten notes attached to promotion blocks in MEMORY.md Fixes openclaw#163900. When `openclaw memory promote --apply` had to make room in MEMORY.md, a greedy marker match treated a generated promotion block followed by a handwritten HTML comment as one generated block and deleted both, so the user's note was lost. Generated blocks with a handwritten annotation are now kept whole, and clean generated blocks are still reclaimed. Boundary recognition and deletion eligibility are now separate checks. CRLF and Unicode line-separator content is unchanged. Evidence: built `memory promote --apply` on Node 24.22.1, 20 runs. On main, two runs deleted the handwritten comment; with this change, two runs kept the whole annotated section, reclaimed a clean generated section and appended the new promotion. Unannotated blocks stayed reclaimable. CRLF and Unicode separator controls were byte-identical. Details and MEMORY.md diffs: openclaw#164089 (comment). Thanks @GoldArowana. Co-authored-by: Ayaan Zaidi <[email protected]>
fix(memory): keep handwritten notes attached to promotion blocks in MEMORY.md Fixes #163900. When `openclaw memory promote --apply` had to make room in MEMORY.md, a greedy marker match treated a generated promotion block followed by a handwritten HTML comment as one generated block and deleted both, so the user's note was lost. Generated blocks with a handwritten annotation are now kept whole, and clean generated blocks are still reclaimed. Boundary recognition and deletion eligibility are now separate checks. CRLF and Unicode line-separator content is unchanged. Evidence: built `memory promote --apply` on Node 24.22.1, 20 runs. On main, two runs deleted the handwritten comment; with this change, two runs kept the whole annotated section, reclaimed a clean generated section and appended the new promotion. Unannotated blocks stayed reclaimable. CRLF and Unicode separator controls were byte-identical. Details and MEMORY.md diffs: #164089 (comment). Thanks @GoldArowana. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 49600b5) Release adaptation: Apply strict generated-block deletion eligibility to the release memory-budget owner; retain existing handwritten-prose coverage alongside inline-comment regression. Co-authored-by: RomneyDa <[email protected]>
Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: 0a171b4 — Leizhen Zhang — fix(auto-reply): long punctuation runs stall abort-trigger detection (#184433) Backport-of: 49600b5 — Long Jin — fix(memory): preserve inline notes during MEMORY.md compaction (#164089) Backport-of: 982f3b1 — RoboClaw — fix(imessage): report Automation failures after Gateway updates (#186117) Backport-of: 3f7ee38 — art22s — fix: require approval for dynamic shell predicates (#187884) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]>
Backport #164089. Keep annotated promotion sections intact while reclaiming clean generated sections. Proof: 3 red regressions and 19 passing controls; 193 focused/sibling tests pass with one existing platform skip; all 10 static/type gates pass. Real built CLI qualification remains blocked before domain execution by runtime-publication service inspection; no bypass or release qualification is claimed. Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]>
* fix(gateway): publish node reapproval with committed pairing facts Adapt main commit 94f180d to the extended-stable worker dispatcher, retaining cleanup admission and stale-session fencing. Co-authored-by: RomneyDa <[email protected]> * test(gateway): clarify CLI announcement tool-only phase Keep exact token, barrier, and completion ordering assertions intact while explicitly excluding narration before the barrier. Co-authored-by: RomneyDa <[email protected]> * style(gateway): format node reapproval regression Reflow the spy chain reported by hosted CI; no behavioral changes. Co-authored-by: RomneyDa <[email protected]> * test(secrets): decouple Telegram fixture from plugin discovery Import the real public Telegram secret collector directly so collection does not depend on Gateway discovery environment. Exercise collection with bundled plugins disabled while retaining existing token assertions. Gateway timeout attribution remains unresolved; no production behavior or timeout changes. Co-authored-by: RomneyDa <[email protected]> * test(secrets): load Telegram fixture through public resolver Replace the static extension import rejected by core type and boundary checks with the existing test public-artifact resolver. Keep the real collector in the Vitest module graph and preserve the disabled-discovery regression. Independent source review accepted; local test, typecheck, build, install, and performance execution remain excluded by operator instruction. Hosted CI must validate the correction. Co-authored-by: RomneyDa <[email protected]> * style(secrets): format Telegram fixture import Co-authored-by: RomneyDa <[email protected]> * fix(ui): honor recovery holds before initial chat history Keep drafting available while the existing send owner holds recovery or a retained initial turn. Restore Send when that hold clears without waiting for initial history or submitting the draft automatically. Add renderer regressions for both holds and clarify the pre-history outbox contract. Controlled real-Gateway red/green evidence: 42523861169 / 42526889715. Diagnostic branch is not merged. Co-authored-by: RomneyDa <[email protected]> * fix(ui): preserve startup status presentation while holding send Restore the existing connected startup/history status suppression without reopening Send admission. Extend both durable hold regressions to reject the duplicate composer status band. Existing cloud E2E assertions remain unchanged. Co-authored-by: RomneyDa <[email protected]> * fix(release): backport installer, service, path and telemetry repairs Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: eb5d0cb — Javier MV — fix(install): keep the installed runtime private under umask 0002 (#186782) Backport-of: b079019 — Sukhdeep — fix(daemon): Gateway repair stops the Gateway and fails when macOS denies the Trash (#189321) Backport-of: 558e2f3 — YangManBOBO — fix(cli): compare gateway state dirs case-insensitively on Windows (#185917) Backport-of: b7ce1c3 — Peter Steinberger — test(windows): keep ordinary CLI coverage in one partition Backport-of: ba75cf7 — Juan Buhagiar Duijst — fix(diagnostics-otel): gateway stalls after model calls on large sessions with content capture on (#186666) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): preserve notes and harden messaging and exec approval Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: 0a171b4 — Leizhen Zhang — fix(auto-reply): long punctuation runs stall abort-trigger detection (#184433) Backport-of: 49600b5 — Long Jin — fix(memory): preserve inline notes during MEMORY.md compaction (#164089) Backport-of: 982f3b1 — RoboClaw — fix(imessage): report Automation failures after Gateway updates (#186117) Backport-of: 3f7ee38 — art22s — fix: require approval for dynamic shell predicates (#187884) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): retain sandbox, recovery lease and Matrix boundaries Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: a19f1bf — Agustin Rivera — fix(agents): fail closed when sandboxed spawned children resolve CLI-backed models (#178742) Backport-of: c9f3f82 — Peter Steinberger — fix(agents): release restart-recovery fences for killed runs (#181992) Backport-of: dfb6454 — Leizhen Zhang — fix(matrix): crafted formatted_body stalls the Gateway in the mention check (#184432) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(config): preserve last-good state through writes and rollback Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: 99418fc — weiqinl — fix(config): keep last-known-good when the observer flags the config as truncated (#152565) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(sessions): preserve history when relocating relative stores Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: a64daf7 — Peter Steinberger — fix(sessions): resolve relative session stores against the state dir, not the working directory (#182444) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): repair September backport type contracts Split terminal recovery actions into distinct discriminants without changing behavior. Use the branch-native Doctor import signature, checking held maintenance authority before and after the awaited import. Validation: independent exact-diff source review, formatter and git diff --check passed. Local tests, typechecks and builds not run per operator restriction; fresh exact-head remote qualification required. Repairs CI 42643973970 attempt 1. Co-authored-by: RomneyDa <[email protected]> * fix(release): align backport regressions with September contracts Preserve uncertain config-write outcomes while correcting branch-native fixture APIs and lint errors found by hosted CI. Co-authored-by: RomneyDa <[email protected]> * test(ci): separate Windows capacity from growing inventory Keep package coverage and the five-job limit independent of a historical timing snapshot. Preserve the rounded capacity boundary and exercise the documented bounded-growth fallback with fixed estimates. Co-authored-by: RomneyDa <[email protected]> * test(node-host): keep launcher cleanup with its invoke owner Wait for a positive launcher PID before probing liveness, and cancel through the existing invocation owner on every exit path. Never send SIGKILL to file-derived PID zero. Co-authored-by: RomneyDa <[email protected]> * test(release): observe owned Gateway reservation cleanup Verify the real reservation closes before relaunch instead of rebinding an already-released port that another socket can acquire. Preserve all seven packaged startup recovery scenarios. Co-authored-by: RomneyDa <[email protected]> * test(release): capture native compiler busy-executable evidence Preserve real API execution and errors while recording failure-only executable inode and writable descriptor metadata. Add a Linux kernel-path diagnostic regression; no retry or copy change. Co-authored-by: RomneyDa <[email protected]> * test(release): repair stability regression fixtures Register CLI admission metadata through the runtime registry, observe the rollback health baseline, and preserve exact SQLite byte expectations. Co-authored-by: RomneyDa <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]>
…law#164089) fix(memory): keep handwritten notes attached to promotion blocks in MEMORY.md Fixes openclaw#163900. When `openclaw memory promote --apply` had to make room in MEMORY.md, a greedy marker match treated a generated promotion block followed by a handwritten HTML comment as one generated block and deleted both, so the user's note was lost. Generated blocks with a handwritten annotation are now kept whole, and clean generated blocks are still reclaimed. Boundary recognition and deletion eligibility are now separate checks. CRLF and Unicode line-separator content is unchanged. Evidence: built `memory promote --apply` on Node 24.22.1, 20 runs. On main, two runs deleted the handwritten comment; with this change, two runs kept the whole annotated section, reclaimed a clean generated section and appended the new promotion. Unannotated blocks stayed reclaimable. CRLF and Unicode separator controls were byte-identical. Details and MEMORY.md diffs: openclaw#164089 (comment). Thanks @GoldArowana. Co-authored-by: Ayaan Zaidi <[email protected]> Release adaptation: Scoped deletion-eligibility regex and focused memory compaction regression. Later 22135bd only extracts promotion budget configuration; not required for marker recognition. Existing block boundaries and generated compaction retained. (cherry picked from commit 49600b5) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a98dbc01e5fb40463eeb273363d27126f476a8e9) (cherry picked from commit b5fcf6104e402f16587372756587cbfb45c27fd7)
What Problem This Solves
Related: #163900. Under MEMORY.md budget pressure, a promotion marker followed by a handwritten HTML comment can be mistaken for a completely generated block. The greedy marker regex consumes through the second closing delimiter, making that handwritten content eligible for deletion.
This keeps the existing permissive marker recognition for section boundaries, but uses a first-comment-bounded marker check when deciding whether the entire section is safe to delete. The two checks intentionally have different responsibilities: tightening section-boundary recognition would allow deletion of a generated prefix from a mixed section. The accepted line domain remains unchanged.
Contributor Credit and Ownership
Original contributor commits
2ac8d3ac3484andf00cf7211efa, plus the contributor's main-merge commit0cad931b130b, are preserved. Authorship maps to @GoldArowana; the merge uses GitHub's normal web-flow committer. No original maintainer repair commits or assignees were found. Linked #165245 concerns compaction observability, not this deletion bug. Held #164051 was left untouched.Current main was integrated before proof because it had changed the owning module. No changes from the held PR were adopted.
Evidence
Real shipped CLI proof in secretless Linux Docker on Node 24.22.1:
87ba257f66d04d65772ce1e160c4cc9e872a21cd.775a05671e3c381f850e86eededf0e87cea0bd16(current main integrated).6b431a5ce43f759ca8774f019ca7d7ed99783a41; later changes only consolidate tests and document the behavior.memory rem-backfill --path <daily-note> --stage-short-term; no helper mocked the promotion store. Embeddings were disabled through the documentedmemory.search.provider: "none"FTS-only setting. No model credentials were used.20 real apply runs, two per case on each ref:
The primary data-loss cases are successful writes, not no-op preservation: both refs report
apply.applied: 1, append the new preference, and reclaim an existing generated section under the unchanged default prior-entry-loss bound. Candidate keepsHANDWRITTEN_KEEP café café 中文 🦞exactly. The CRLF/separator controls execute the same apply command under budget pressure and report budget refusal rather than deleting protected bytes; their original buffers compare exactly equal afterward.Actual MEMORY.md diff excerpts:
Main removes the annotated section:
Candidate instead removes a clean generated section, leaving that annotation intact:
Both diffs append the newly promoted sourced preference. Full before/after MEMORY.md files and unified diffs are retained with the proof. The primary fixture starts at 7,349 UTF-8 bytes: main ends at 6,448 bytes without the note, candidate at 6,499 bytes with it.
Focused regression: the existing mixed-block case now uses an annotated marker and verifies that the whole mixed section survives while the clean neighboring section is removed. Same final file on main: 1 intended failure / 12 passes (wrong section dropped); candidate: 13 passes. Existing heading, project grouping, budget/loss-bound and marker-only cases remain. Focused formatting passed.
Simplification retains the two necessary marker responsibilities and no additional parser or state. Whole-PR production +6/−1 (net +5; seven changed lines), tests 0 net, docs +2. The added duplicate unit setup is replaced by the strengthened existing case plus the shipped-CLI controls. No SDK, schema, config, loss limit or compaction policy expansion.
Compatibility and Merge Danger
Two-way door for the code: reverting restores prior classification without a migration. Deletions already made by an older build are not automatically restored. Blast radius is append-compaction eligibility for MEMORY.md promotion sections; generated-only reclamation stays available, while handwritten annotations make the entire section non-deletable.