Skip to content

fix(memory-wiki): preserve handwritten notes when markers are damaged - #117104

Merged
steipete merged 1 commit into
mainfrom
codex/memory-wiki-malformed-notes-guard
Jul 31, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/memory-wiki-malformed-notes-guard

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #102230 and follow-up to #102294.

What Problem This Solves

Fixes an issue where Memory Wiki users permanently lost handwritten Notes when an imported source was pruned, updated, or re-ingested after either human-owned Notes marker was accidentally damaged. A real Gateway stress run reproduced silent loss on current main: the source page was deleted, its SQLite tracking row disappeared, and the annotation was not recovered.

Why This Change Was Made

The shared Notes parser previously treated unmatched markers exactly like absent Notes. Distinguish genuinely absent/empty Notes from damaged marker pairs at the canonical Markdown owner, report the exact marker the operator must restore, and let malformed-Notes failures escape the prune owner's filesystem-read suppression boundary. Bridge and unsafe-local refreshes plus ordinary ingestion inherit the same protection without separate fallback paths.

User Impact

Handwritten wiki annotations and their persisted source tracking remain intact when a Notes marker is missing. Gateway and CLI operations show an actionable repair error instead of silently deleting or overwriting user-authored content; normal empty Notes, fenced-source marker spoofing, nested copied markers, oversized generated pages, and repeated collision-safe recovery retain their existing behavior.

Evidence

AI-assisted; independently reviewed and verified on Blacksmith Testbox tbx_01kyx5bh8kprjwq0f4kj0tw7mm.

Before, against a real isolated Gateway:

  • {"phase":"unterminated-human-notes-adversarial","removedCount":1,"pageSurvived":false,"notesRecovered":false,"persistedRows":0}

After, against the same real packaged Gateway and CLI:

  • {"phase":"gateway-rejects-malformed-note-update","pageSurvived":true,"persistedRows":1,"actionableError":true}
  • {"phase":"unterminated-human-notes-retained","pageSurvived":true,"persistedRows":1,"actionableError":true}
  • {"phase":"missing-opening-human-notes-retained","pageSurvived":true,"persistedRows":1,"actionableError":true}
  • {"phase":"ordinary-ingest-retains-malformed-notes","pageSurvived":true,"actionableError":true}
  • {"phase":"live-stress-passed","initialSources":48,"oversizedSourceMiB":17,"recoveredNotes":38,"focusedAssertions":800}

The isolated live run covered actual Gateway RPC, standalone CLI, 48 real source files, unavailable source roots, 17 MiB existing pages, four simultaneous import processes, Gateway restart with direct SQLite-row verification, collision-safe repeated Notes recovery, spoofed/blank Notes, both damaged-marker directions, and recovery after the operator repairs each marker.

  • corepack pnpm test extensions/memory-wiki: 399 tests passed across 41 files.
  • Focused changed-owner/sibling run: 179 tests passed across 11 files.
  • Baseline stress loop: 100 assertions passed in each of 8 consecutive runs.
  • corepack pnpm build: passed, including bundled plugin packaging, Plugin SDK exports, and built Control UI.
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed: passed, including production/test typechecks, oxfmt, oxlint, boundary checks, database-first guard, and import-cycle guard.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted: clean; no accepted/actionable findings.
  • Production delta: +1 net line; no config, schema, protocol, dependency, or public API changes.

@steipete
steipete marked this pull request as ready for review July 31, 2026 23:19
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready maintainer verification for head 2c800ac7979d184afdab7cb94cde7e48a8f6f305.

Root cause: the shared Memory Wiki Markdown owner treated an unmatched handwritten Notes marker as absent Notes; pruning silently deleted the page and SQLite row, and source updates/re-ingest could overwrite the same annotation.

Before live Gateway proof: {"removedCount":1,"pageSurvived":false,"notesRecovered":false,"persistedRows":0}.

After live Gateway proof: both missing-marker directions retain the page and SQLite row with an actionable repair error; repairing the marker recovers the notes normally. The packaged Gateway/CLI stress run covered 48 real sources, a 17 MiB existing page, unavailable roots, Gateway restart, four concurrent processes, and 38 recovered note versions.

Validation on Blacksmith Testbox tbx_01kyx5bh8kprjwq0f4kj0tw7mm:

  • corepack pnpm test extensions/memory-wiki — 399 passed / 41 files.
  • Focused changed-owner/sibling suite — 179 passed / 11 files.
  • Eight baseline stress iterations — 800 passing assertions.
  • corepack pnpm build — passed.
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed — passed, including production/test typechecks, format, lint, plugin boundaries, database-first guard, and import cycles.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — clean, zero accepted/actionable findings.
  • scripts/pr review-validate-artifacts 117104 — READY FOR /prepare-pr, zero findings.

Production delta: +1 net line. No known proof gaps.

@steipete
steipete merged commit 6d8f0a1 into main Jul 31, 2026
146 of 153 checks passed
@steipete
steipete deleted the codex/memory-wiki-malformed-notes-guard branch July 31, 2026 23:26
@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant