Skip to content

fix: preserve Memory relations in backups - #499

Merged
possiblyneal merged 6 commits into
mainfrom
fix/443-relations
Nov 21, 2026
Merged

possiblyneal merged 6 commits into
mainfrom
fix/443-relations

Conversation

@possiblyneal

@possiblyneal possiblyneal commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Intent

Closes #443

Preserve Memory relations across full export/import and snapshot create/restore, including relations stored under legacy generated keys.

Read first

  • src/functions/export-import.ts — durable store, validation, and replacement using actual storage keys.
  • src/functions/snapshot.ts — relation replacement and stale-key pruning.
  • src/engine/inproc/state.ts — exact SQLite key decoding for paged readers.

Decisions

  • A backup that captured an empty Relation scope replaces it with empty; an older backup that omitted the scope leaves destination relations alone.
  • Keep storage keys rather than reconstructing them: a legacy generated key need not match the current composite key.
  • Preserve custom string types and legacy mesh endpoints without coercing endpoint values. Normalize non-string types to related and omit malformed confidence in backup data without changing source rows.
  • Reject invalid or duplicate relation entries before replace import or snapshot restore can mutate any scope.

Out of scope

Verified

  • Full local gate passed on 27f42d59: clean install, build, generated hooks, skills, typecheck, npm test (3,286 passed, one skipped), npm run eval:gate, and npm run eval:gate:rules.
  • Export, snapshot, and SQLite tests cover legacy storage keys, replacement, older backups, and embedded NULs. EXPLAIN QUERY PLAN confirmed index ordering without a temporary sort.

Not verified

  • No live store or production restore was used.

Merge danger

Door: One-way for a replace or restore that prunes destination-only relations; reverting code does not undo a restore.

Blast radius: Full export/import and snapshot restoration of Memory relations.

Generated-By: gpt-6.1-terra
Generated-By: gpt-6.1-terra
Generated-By: gpt-6.1-terra
Sort by the stored TEXT column rather than the projected BLOB alias.
SQLite can then use the key index for ordering while returning all key
bytes, including embedded NULs.

Refs: #443
Generated-By: gpt-6.2-sol
@possiblyneal

Copy link
Copy Markdown
Owner Author

Code review: standard scan, clean.

Axes: Standards+Spec, Correctness/Logic

Reviewed-Head: 27f42d5

@possiblyneal
possiblyneal merged commit 1f56745 into main Nov 21, 2026
3 checks passed
@possiblyneal
possiblyneal deleted the fix/443-relations branch November 21, 2026 21:09
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.

Export and snapshot drop Memory relations

1 participant