Commit f74a5e6
fix: workspace-scoped entity identity — share/federate copy instead of clobbering (#339)
remember()'s identity was (category, key): a cross-workspace write with a
colliding key took the UPDATE path and overwrote the other workspace's row
in place. mimir_share's "clone into target workspace" was therefore a
destructive MOVE of the source entity (source workspace lost it, the fresh
mem-* id was discarded, retrieval stats clobbered), and mimir_federate's
vault_import had the same failure mode for every remapped entity.
Changes:
- Identity is now (category, key, workspace_hash): remember()'s existence
lookup includes workspace_hash, and the schema's unique index becomes
idx_entities_category_key_ws (SCHEMA_VERSION 4). The index is created in
the gated migration block after the workspace_hash ALTER — on a legacy DB
the ungated DDL runs before that column exists. Create-then-drop so
uniqueness is never unenforced; safe on populated DBs because the old
constraint was strictly tighter.
- get_entity(category, key) picks deterministically when the same key now
exists in several workspaces (global '' first, then lexicographic) instead
of whichever row SQLite visited.
- forget()'s FTS cleanup uses IN, not a scalar subquery — it archives every
workspace's row for (category, key), so it must clean FTS for all of them.
Single-workspace vaults (workspace_hash = '' everywhere) behave identically.
Tests: remember_identity_is_workspace_scoped_so_share_copies_instead_of_moving,
migrates_unique_index_to_workspace_scoped_identity.
Suite: 161 passed / 0 failed.
Fixes #339
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent f132a13 commit f74a5e6
2 files changed
Lines changed: 147 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
1498 | 1504 | | |
1499 | 1505 | | |
1500 | | - | |
1501 | | - | |
| 1506 | + | |
| 1507 | + | |
1502 | 1508 | | |
1503 | 1509 | | |
1504 | 1510 | | |
| |||
2420 | 2426 | | |
2421 | 2427 | | |
2422 | 2428 | | |
2423 | | - | |
| 2429 | + | |
| 2430 | + | |
2424 | 2431 | | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
2425 | 2437 | | |
2426 | 2438 | | |
2427 | 2439 | | |
| |||
2450 | 2462 | | |
2451 | 2463 | | |
2452 | 2464 | | |
2453 | | - | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
2454 | 2469 | | |
2455 | 2470 | | |
2456 | | - | |
| 2471 | + | |
2457 | 2472 | | |
2458 | 2473 | | |
2459 | 2474 | | |
| |||
6966 | 6981 | | |
6967 | 6982 | | |
6968 | 6983 | | |
| 6984 | + | |
| 6985 | + | |
| 6986 | + | |
| 6987 | + | |
| 6988 | + | |
| 6989 | + | |
| 6990 | + | |
| 6991 | + | |
| 6992 | + | |
| 6993 | + | |
| 6994 | + | |
| 6995 | + | |
| 6996 | + | |
| 6997 | + | |
| 6998 | + | |
| 6999 | + | |
| 7000 | + | |
| 7001 | + | |
| 7002 | + | |
| 7003 | + | |
| 7004 | + | |
| 7005 | + | |
| 7006 | + | |
| 7007 | + | |
| 7008 | + | |
| 7009 | + | |
| 7010 | + | |
| 7011 | + | |
| 7012 | + | |
| 7013 | + | |
| 7014 | + | |
| 7015 | + | |
| 7016 | + | |
| 7017 | + | |
| 7018 | + | |
| 7019 | + | |
| 7020 | + | |
| 7021 | + | |
| 7022 | + | |
| 7023 | + | |
| 7024 | + | |
| 7025 | + | |
| 7026 | + | |
| 7027 | + | |
| 7028 | + | |
| 7029 | + | |
6969 | 7030 | | |
6970 | 7031 | | |
6971 | 7032 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| |||
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
140 | | - | |
| 143 | + | |
141 | 144 | | |
142 | 145 | | |
143 | 146 | | |
| |||
262 | 265 | | |
263 | 266 | | |
264 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
265 | 282 | | |
266 | 283 | | |
267 | 284 | | |
| |||
604 | 621 | | |
605 | 622 | | |
606 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
607 | 683 | | |
608 | 684 | | |
609 | 685 | | |
| |||
0 commit comments