Skip to content

fix(export): keep junction dumps FK-consistent with soft-deleted memories - #1253

Merged
ajianaz merged 2 commits into
developfrom
fix/structural-export-soft-delete
Sep 15, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/structural-export-soft-delete

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

What

Structural export (export_full) now keeps every memory-referencing section consistent with the live-memory filter the memories section already used:

  • room_memories, memory_edges, and timeline_events dumps join against memories and drop rows referencing a soft-deleted (deprecated = 1) memory (for memory_edges, both endpoints must be live).
  • graph_nodes rows survive, but a memory_id pointing at a soft-deleted memory is exported as NULL (import-side effect matches the schema's ON DELETE SET NULL for hard deletes).
  • Manifest section counts use the same filtered queries, so manifest counts now equal the rows actually exported (previously COUNT(*) over the raw tables even when the dump filtered them — already inconsistent for memories today).

STRUCTURAL_EXPORT_VERSION stays 1: import unchanged, old exports still import fine.

Why

Any real production store accrues soft-deleted memories (contradiction resolution, forget flows). With one present, the export contained junction rows referencing memories absent from the dump, so FK-enforced import into a fresh store aborted the atomic import (or silently dangled with FK off). Found by the v0.18.0 pre-release cora scan. Closes #1243.

Testing

  • New regression test test_structural_export_drops_soft_deleted_memory_references: seeds live + soft-deleted memories with room membership, a memory edge, a timeline event, and graph-node links; asserts filtered sections, nulled node link, no dead content in the dump, manifest counts, and a clean FK-enforced import into a fresh store. Verified red before the fix (export carried 2 memories / 1 room link) and green after.
  • Full cargo test -p uteke-core --lib: 561 passed / 0 failed (33 ignored).
  • cargo fmt --check and cargo clippy -p uteke-core --lib -- -D warnings clean.

…ries

Structural export filtered memories to live rows but dumped room_memories,
memory_edges, and timeline_events in full, so any store holding soft-deleted
memories produced an export whose junction rows reference memories absent
from the dump - failing FK-enforced import into a fresh store (or silently
dangling with FK off). graph_nodes.memory_id pointing at a dead memory was
exported verbatim for the same reason.

Filter every memory-referencing section by the same liveness predicate at
export time, null graph-node links to dead memories (mirroring the schema's
ON DELETE SET NULL), and count manifest sections with the same filtered
queries so manifest counts match the rows actually exported.

Closes #1243
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(export): structural export drops deprecated memories but keeps their junction rows — round-trip breaks on FK

1 participant