Skip to content

fix: re-key hallways/tunnels on wing-name migration so the graph follows renamed wings - #1939

Open
ggettert wants to merge 1 commit into
MemPalace:developfrom
ggettert:fix/migrate-rekey-graph-1938
Open

fix: re-key hallways/tunnels on wing-name migration so the graph follows renamed wings#1939
ggettert wants to merge 1 commit into
MemPalace:developfrom
ggettert:fix/migrate-rekey-graph-1938

Conversation

@ggettert

@ggettert ggettert commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1938. migrate_wing_names re-keyed drawer/closet/topics_by_wing metadata but never touched the associative graph, so hallways.json and tunnels.json kept pointing at the pre-normalization wing.

What changed

  • hallways.rekey_hallway_wings(rename_map) — rewrites hallway wing + regenerates ids; merges records that collapse onto the same (wing, entity-pair).
  • palace_graph.rekey_tunnel_wings(rename_map) — rewrites tunnel endpoint wings + regenerates canonical ids; drops tunnels whose endpoints coincide after the rename; merges id collisions. Covers entity and topic tunnels (shared store).
  • migrate_wing_names calls both after the metadata re-key, using the same rename map, and reports counts.
  • Extracted _hallway_label so freshly-computed and re-keyed/merged records format identically (no behavior change).

Why re-key, not recompute

A wing-name migration is a pure rename — drawer membership and entity co-occurrence are unchanged. Re-keying is sufficient and preserves the #1578 dynamics fields (strength/stability/last_activated/access_count); a recompute from drawers would reset them. Collision merges keep the stronger/more-recent dynamics.

Tests

  • Unit: rename regenerates ids + preserves dynamics; collision merges counts/rooms/dynamics; untouched wings/tunnels left alone; self-referential tunnels dropped.
  • Integration: seed _alpha+beta drawers, build hallways/tunnels, run migration → graph moves to alpha; two-wings-into-one merges to a single hallway with summed count.

Known limitations

  • The re-key runs after the drawer/closet/topics_by_wing re-key without a shared transaction across the four stores. If the graph step fails mid-way, the drawer re-key is intentionally not rolled back (a successful data migration shouldn't be undone because a derived index failed); the failure is surfaced as a warning and the operation is re-runnable — a subsequent migrate re-keys any orphaned graph records. Full cross-store atomicity is out of scope for this fix.

Fixes #1938.

…ows renamed wings

Fixes MemPalace#1938. migrate_wing_names re-keyed drawer/closet/topics_by_wing metadata but never touched the associative graph, so hallways.json and tunnels.json kept pointing at the pre-normalization wing.

- hallways.rekey_hallway_wings: rewrite wing + regenerate ids; merge records that collapse onto the same (wing, entity-pair).
- palace_graph.rekey_tunnel_wings: rewrite endpoint wings + regenerate canonical ids; drop self-referential tunnels; merge id collisions.
- migrate_wing_names calls both after the metadata re-key.
- Extracted _hallway_label so fresh and re-keyed records format identically.

Re-key (not recompute) preserves the MemPalace#1578 dynamics fields.
@ggettert
ggettert force-pushed the fix/migrate-rekey-graph-1938 branch from d5bd9a1 to 31b02cf Compare July 21, 2026 19:31
@ggettert

Copy link
Copy Markdown
Contributor Author

Rebased this onto current develop after v3.6.0 and updated the graph re-key path to pass the explicit MempalaceConfig(palace_path=...) through to hallway/tunnel side-files. Local focused tests and full GitHub CI are green.

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: wing-name migration re-keys drawers but leaves hallways/tunnels on the old wing

1 participant