contacts: pure Home companion module (FO1, step D1) #778

Closed
kayg wants to merge 4 commits from feat/contacts-companion-pure into dev
Owner

Plan (foundational; read this first)

Step D1 of the contacts plan: the pure half of FO1 (ADR 0063/0064, 2026-10-28). New module calternal_contacts::companion in crates/contacts. No I/O. D2 (journaled Home writes, recovery, migration) is not in this PR.

Round 1 plan update (before code)

  • Keep path identity supplied by the caller: plan_write(..., intent: WriteIntent, path_equal: PathEquality) receives the Home filesystem's equality function, including its case rule and Unicode normalization (macOS NFD).
  • Add WriteIntent::{Create, Update, VerifiedRecovery}. A missing companion during Update returns RepairMissing; only explicit creation or verified recovery can plan a fresh companion.
  • Represent writes as ordered WriteStep::{WriteNew, Verify, DeleteOld}. A delete follows verification and is omitted whenever path_equal says it aliases any path written.
  • Add shared plan vectors for case-only folder renames, NFC/NFD names and lexical aliases, exercised under both case-sensitive and case-insensitive equality functions. Cover missing-after-write and state-loss repair.
  • Scope: one small planner/API update plus focused vectors and tests. plan_write stays O(card bytes + path bytes) for hashing, byte comparison and path equality; output uses at most three steps.

What it decides

  • companion_name(id), parse_name, companion_id(path, folder), companion_id_anywhere, is_companion, companion_path(note_path, id): names and role detection by the exact pattern, never by extension.
  • note_id(note): reads calternal-id from front matter only (needs format: calternal-contact).
  • associate(notes, paths, folders): pairs notes with companions by id. Results: Paired{beside}, MissingCompanion, Orphan, Ambiguous, UnnamableId.
  • classify(found, last_applied): Identical, OutsideEdited, Untracked, Missing, Ambiguous. Byte-exact compare (same_bytes), BLAKE3 CardHash.
  • plan_write(note_path, id, card, found, last_applied, intent: WriteIntent, path_equal: PathEquality): ordered Write{steps}, Unchanged, RepairMissing, Conflict, Ambiguous.

Decisions

  1. A valid id is a canonical lowercase hyphenated UUID (what contact_id makes). Hand-made ids such as example-ravi (ADR examples, test fixtures) cannot name a companion: companion_name errors and associate reports UnnamableId. D2 decides what to do with them. This keeps the name strict and stops path tricks through the id.
  2. Role needs both the exact name and a folder. associate takes a list of folders (the contact folder and its Trash twin; the Trash layout is D2's to supply). A look-alike elsewhere, or with a bad id, is a normal file.
  3. Untracked (companion exists, nothing recorded, state lost) is never overwritten with different bytes: the Home is the authority, so it is a Conflict. Identical bytes are Unchanged.
  4. A companion left in the wrong folder (half-done move, Trash, restore) is Paired{beside:false}; plan_write carries it to the note's folder with Write → Verify → Delete, unless the injected path equality says the paths alias. An outside-edited one is a Conflict, not moved.
  5. Added blake3 (already in the workspace) to calternal-contacts. Doc comments in lib.rs and OriginalCard now name the Home companion instead of state/contacts/raw.

Sizes and big-O

  • About 330 lines of code in 4 small files, 300 lines of tests, one shared JSON vector file (tests/corpus/companion-vectors.json: 19 name vectors, 13 pairing vectors for rename, move, half move, Trash, restore, orphan, missing, two companions, copied note) for D2 and any other consumer.
  • Name, parse, classify: O(id length). Hash and compare: O(card bytes). associate: O((n + m) log n) for n notes, m listed paths; allocation O(n + m) (20k contacts is a few ms, no per-card parse). note_id: at most 32 lines.

Failure table

Failure Effect Detection Recovery Test
User file named like a companion Hidden file exact name + UUID + folder normal file name_vectors, pairing_vectors (look-alikes)
Id with /, .., upper case, wrong length Path escape or wrong name is_valid_id error, no name names_roundtrip_and_reject_bad_ids, a_path_cannot_be_smuggled_through_the_id
Two companions for one id Ambiguous original Ambiguous / Plan::Ambiguous report, keep both, write nothing two companions..., ambiguous_writes_nothing_and_lists_both
Two notes with one id (copied note) Wrong pairing Ambiguous report, keep all copied note vector
Companion missing during update or state loss Lossy export replaces the original MissingCompanion, classify Missing, and typed intent RepairMissing; only explicit create or verified recovery writes missing_original_vectors
Orphan companion Hidden data Orphan keep for rebuild orphan vector
Outside editor changes companion Silent loss hash vs last applied Conflict, never overwritten outside_edit_is_never_overwritten
State lost, stale cache vs Home card Home card overwritten Untracked and bytes differ Conflict untracked_and_different...
Half-done move/Trash/restore or aliased paths Pair in two folders or old-path deletion removes new bytes beside:false and injected path equality write, verify, then delete only a distinct old path write_plan_vectors, companion_left_behind..., trash_and_restore...
Not a contact note / bad front matter Wrong id strict note_id None note_id_reads_front_matter_only
Hand-made id No companion possible UnnamableId D2 decides hand-made id vector

Gate tests: cargo test -p calternal-contacts (all 21 new tests, existing suites unchanged), clippy -D warnings, fmt check.

Gate results on current head 3de5f011 (cua@calternal-dev-02-std, aarch64, Nix dev shell)

Command Result
cargo test -j4 -p calternal-contacts PASS; 152 tests passed, including 23 companion tests
cargo clippy -j4 -p calternal-contacts --all-targets -- -D warnings PASS
cargo fmt -p calternal-contacts -- --check PASS
git diff --check PASS

Nix evaluation printed deprecation warnings for stdenv.isLinux and stdenv.isDarwin; the Rust gates succeeded. The full workspace was not run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xi6YxsuZ7m2ESGC7aS91AN

## Plan (foundational; read this first) Step D1 of the contacts plan: the pure half of FO1 (ADR 0063/0064, 2026-10-28). New module `calternal_contacts::companion` in `crates/contacts`. No I/O. D2 (journaled Home writes, recovery, migration) is not in this PR. ### Round 1 plan update (before code) - Keep path identity supplied by the caller: `plan_write(..., intent: WriteIntent, path_equal: PathEquality)` receives the Home filesystem's equality function, including its case rule and Unicode normalization (macOS NFD). - Add `WriteIntent::{Create, Update, VerifiedRecovery}`. A missing companion during `Update` returns `RepairMissing`; only explicit creation or verified recovery can plan a fresh companion. - Represent writes as ordered `WriteStep::{WriteNew, Verify, DeleteOld}`. A delete follows verification and is omitted whenever `path_equal` says it aliases any path written. - Add shared plan vectors for case-only folder renames, NFC/NFD names and lexical aliases, exercised under both case-sensitive and case-insensitive equality functions. Cover missing-after-write and state-loss repair. - Scope: one small planner/API update plus focused vectors and tests. `plan_write` stays O(card bytes + path bytes) for hashing, byte comparison and path equality; output uses at most three steps. ### What it decides - `companion_name(id)`, `parse_name`, `companion_id(path, folder)`, `companion_id_anywhere`, `is_companion`, `companion_path(note_path, id)`: names and role detection by the exact pattern, never by extension. - `note_id(note)`: reads `calternal-id` from front matter only (needs `format: calternal-contact`). - `associate(notes, paths, folders)`: pairs notes with companions by id. Results: `Paired{beside}`, `MissingCompanion`, `Orphan`, `Ambiguous`, `UnnamableId`. - `classify(found, last_applied)`: `Identical`, `OutsideEdited`, `Untracked`, `Missing`, `Ambiguous`. Byte-exact compare (`same_bytes`), BLAKE3 `CardHash`. - `plan_write(note_path, id, card, found, last_applied, intent: WriteIntent, path_equal: PathEquality)`: ordered `Write{steps}`, `Unchanged`, `RepairMissing`, `Conflict`, `Ambiguous`. ### Decisions 1. A valid id is a canonical lowercase hyphenated UUID (what `contact_id` makes). Hand-made ids such as `example-ravi` (ADR examples, test fixtures) cannot name a companion: `companion_name` errors and `associate` reports `UnnamableId`. D2 decides what to do with them. This keeps the name strict and stops path tricks through the id. 2. Role needs both the exact name and a folder. `associate` takes a list of folders (the contact folder and its Trash twin; the Trash layout is D2's to supply). A look-alike elsewhere, or with a bad id, is a normal file. 3. `Untracked` (companion exists, nothing recorded, state lost) is never overwritten with different bytes: the Home is the authority, so it is a `Conflict`. Identical bytes are `Unchanged`. 4. A companion left in the wrong folder (half-done move, Trash, restore) is `Paired{beside:false}`; `plan_write` carries it to the note's folder with `Write → Verify → Delete`, unless the injected path equality says the paths alias. An outside-edited one is a `Conflict`, not moved. 5. Added `blake3` (already in the workspace) to `calternal-contacts`. Doc comments in `lib.rs` and `OriginalCard` now name the Home companion instead of `state/contacts/raw`. ### Sizes and big-O - About 330 lines of code in 4 small files, 300 lines of tests, one shared JSON vector file (`tests/corpus/companion-vectors.json`: 19 name vectors, 13 pairing vectors for rename, move, half move, Trash, restore, orphan, missing, two companions, copied note) for D2 and any other consumer. - Name, parse, classify: O(id length). Hash and compare: O(card bytes). `associate`: O((n + m) log n) for n notes, m listed paths; allocation O(n + m) (20k contacts is a few ms, no per-card parse). `note_id`: at most 32 lines. ### Failure table | Failure | Effect | Detection | Recovery | Test | |---|---|---|---|---| | User file named like a companion | Hidden file | exact name + UUID + folder | normal file | `name_vectors`, `pairing_vectors` (look-alikes) | | Id with `/`, `..`, upper case, wrong length | Path escape or wrong name | `is_valid_id` | error, no name | `names_roundtrip_and_reject_bad_ids`, `a_path_cannot_be_smuggled_through_the_id` | | Two companions for one id | Ambiguous original | `Ambiguous` / `Plan::Ambiguous` | report, keep both, write nothing | `two companions...`, `ambiguous_writes_nothing_and_lists_both` | | Two notes with one id (copied note) | Wrong pairing | `Ambiguous` | report, keep all | `copied note` vector | | Companion missing during update or state loss | Lossy export replaces the original | `MissingCompanion`, `classify` Missing, and typed intent | `RepairMissing`; only explicit create or verified recovery writes | `missing_original_vectors` | | Orphan companion | Hidden data | `Orphan` | keep for rebuild | `orphan` vector | | Outside editor changes companion | Silent loss | hash vs last applied | `Conflict`, never overwritten | `outside_edit_is_never_overwritten` | | State lost, stale cache vs Home card | Home card overwritten | `Untracked` and bytes differ | `Conflict` | `untracked_and_different...` | | Half-done move/Trash/restore or aliased paths | Pair in two folders or old-path deletion removes new bytes | `beside:false` and injected path equality | write, verify, then delete only a distinct old path | `write_plan_vectors`, `companion_left_behind...`, `trash_and_restore...` | | Not a contact note / bad front matter | Wrong id | strict `note_id` | None | `note_id_reads_front_matter_only` | | Hand-made id | No companion possible | `UnnamableId` | D2 decides | `hand-made id` vector | Gate tests: `cargo test -p calternal-contacts` (all 21 new tests, existing suites unchanged), clippy `-D warnings`, fmt check. ## Gate results on current head `3de5f011` (cua@calternal-dev-02-std, aarch64, Nix dev shell) | Command | Result | |---|---| | `cargo test -j4 -p calternal-contacts` | PASS; 152 tests passed, including 23 companion tests | | `cargo clippy -j4 -p calternal-contacts --all-targets -- -D warnings` | PASS | | `cargo fmt -p calternal-contacts -- --check` | PASS | | `git diff --check` | PASS | Nix evaluation printed deprecation warnings for `stdenv.isLinux` and `stdenv.isDarwin`; the Rust gates succeeded. The full workspace was not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Xi6YxsuZ7m2ESGC7aS91AN
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xi6YxsuZ7m2ESGC7aS91AN
contacts: lock file for blake3 dependency
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
9455271c4f
Author
Owner

Independent review, round 1

Reviewed head 9455271c4f83d45738e6ad1e59fffbb8ea742a8e, ADRs 0063/0064, the PR body, all four companion modules and the companion tests/vectors. This review concerns the pure decisions; D2 I/O is not assumed to exist.

Findings

  • P1: a case-only path difference can plan removal of the newly written companion. crates/contacts/src/companion/plan.rs:106 uses exact string equality for in_place, then :110 puts the old spelling in remove. Legal example: note contacts/Priya.md, found Contacts/.calternal-contact-11111111-1111-4111-8111-111111111111.vcf, and matching old bytes/hash. companion_id explicitly accepts the folder case-insensitively (name.rs:63), but the plan is Write { path: "contacts/.calternal-contact-…vcf", remove: Some("Contacts/.calternal-contact-…vcf"), … }. On a case-insensitive filesystem those paths identify the same file. A consumer following the documented write-then-remove sequence deletes the newly installed original. Fix: give the planner an explicit path-identity/case policy or require canonical Home paths and validate that precondition; never emit removal when source and target can alias. Do not blindly lowercase paths on case-sensitive Homes. Cover case-only folder changes in pure vectors and verify eventual placement/removal on a case-insensitive filesystem in D2.
  • P2: missing an existing original is indistinguishable from creating a fresh pair. crates/contacts/src/companion/plan.rs:94 returns Write for every missing companion, including last_applied = Some(old_hash), and accepts any supplied bytes. Thus a lost Home original plus a lossy note export gets a successful replacement plan rather than the missing-companion repair result required by ADR 0063. The PR's claim that a fresh write is allowed only from a real card is not represented in this API. Fix: make missing-existing a report/repair outcome and distinguish explicit new creation or verified recovery from ordinary updates. Supply provenance/intent as a typed input or use a separate creation/recovery API. Add tests for missing-after-an-existing-write and state loss; neither should silently authorize a note-only regeneration.

Checks and limits

The byte/hash comparisons correctly reject a different untracked or outside-edited card. associate preserves duplicate notes/companions as ambiguous and retains orphans; the ordinary conflict and ambiguous branches write nothing. Strict UUID naming prevents ID-based path traversal. The findings above concern the plan returned from valid inputs, not an observed filesystem mutation in this pure module.

Static review only. No build/test/install ran on the control host. git diff --check d83e54db 9455271c -- crates/contacts Cargo.lock passed. Existing reported VM tests were read, not independently rerun.

Verdict: fix first. No P0 finding; fix the P1 path-alias deletion plan and represent missing-original repair explicitly before D2 consumes this API.

## Independent review, round 1 Reviewed head `9455271c4f83d45738e6ad1e59fffbb8ea742a8e`, ADRs 0063/0064, the PR body, all four companion modules and the companion tests/vectors. This review concerns the pure decisions; D2 I/O is not assumed to exist. ### Findings - **P1: a case-only path difference can plan removal of the newly written companion.** `crates/contacts/src/companion/plan.rs:106` uses exact string equality for `in_place`, then `:110` puts the old spelling in `remove`. Legal example: note `contacts/Priya.md`, found `Contacts/.calternal-contact-11111111-1111-4111-8111-111111111111.vcf`, and matching old bytes/hash. `companion_id` explicitly accepts the folder case-insensitively (`name.rs:63`), but the plan is `Write { path: "contacts/.calternal-contact-…vcf", remove: Some("Contacts/.calternal-contact-…vcf"), … }`. On a case-insensitive filesystem those paths identify the same file. A consumer following the documented write-then-remove sequence deletes the newly installed original. **Fix:** give the planner an explicit path-identity/case policy or require canonical Home paths and validate that precondition; never emit removal when source and target can alias. Do not blindly lowercase paths on case-sensitive Homes. Cover case-only folder changes in pure vectors and verify eventual placement/removal on a case-insensitive filesystem in D2. - **P2: missing an existing original is indistinguishable from creating a fresh pair.** `crates/contacts/src/companion/plan.rs:94` returns `Write` for every missing companion, including `last_applied = Some(old_hash)`, and accepts any supplied bytes. Thus a lost Home original plus a lossy note export gets a successful replacement plan rather than the missing-companion repair result required by ADR 0063. The PR's claim that a fresh write is allowed only from a real card is not represented in this API. **Fix:** make missing-existing a report/repair outcome and distinguish explicit new creation or verified recovery from ordinary updates. Supply provenance/intent as a typed input or use a separate creation/recovery API. Add tests for missing-after-an-existing-write and state loss; neither should silently authorize a note-only regeneration. ### Checks and limits The byte/hash comparisons correctly reject a different untracked or outside-edited card. `associate` preserves duplicate notes/companions as ambiguous and retains orphans; the ordinary conflict and ambiguous branches write nothing. Strict UUID naming prevents ID-based path traversal. The findings above concern the plan returned from valid inputs, not an observed filesystem mutation in this pure module. Static review only. No build/test/install ran on the control host. `git diff --check d83e54db 9455271c -- crates/contacts Cargo.lock` passed. Existing reported VM tests were read, not independently rerun. **Verdict: fix first.** No P0 finding; fix the P1 path-alias deletion plan and represent missing-original repair explicitly before D2 consumes this API.
Author
Owner

Round 1 status (3de5f011)

Review item Status Resolution
P1 path alias deletion Fixed plan_write receives PathEquality and never schedules DeleteOld for a path equal to any path it writes.
P2 missing original Fixed WriteIntent::Update returns RepairMissing, including after state loss. Only explicit Create or VerifiedRecovery can plan a new write.
Operation order Fixed Plans use WriteNew → Verify → DeleteOld; deletion is included only after verification and only for a distinct path.
Shared vectors Added Case-only rename, NFC/NFD and dot-segment alias vectors run under case-sensitive and case-insensitive equality.

Gates on dev-02

Command Result
cargo test -j4 -p calternal-contacts PASS; 152 passed, 0 failed (23 companion tests)
cargo clippy -j4 -p calternal-contacts --all-targets -- -D warnings PASS
cargo fmt -p calternal-contacts -- --check PASS

The Nix evaluation emitted deprecation warnings for stdenv.isLinux and stdenv.isDarwin; the Rust gates succeeded.

## Round 1 status (`3de5f011`) | Review item | Status | Resolution | |---|---|---| | P1 path alias deletion | Fixed | `plan_write` receives `PathEquality` and never schedules `DeleteOld` for a path equal to any path it writes. | | P2 missing original | Fixed | `WriteIntent::Update` returns `RepairMissing`, including after state loss. Only explicit `Create` or `VerifiedRecovery` can plan a new write. | | Operation order | Fixed | Plans use `WriteNew → Verify → DeleteOld`; deletion is included only after verification and only for a distinct path. | | Shared vectors | Added | Case-only rename, NFC/NFD and dot-segment alias vectors run under case-sensitive and case-insensitive equality. | ### Gates on dev-02 | Command | Result | |---|---| | `cargo test -j4 -p calternal-contacts` | PASS; 152 passed, 0 failed (23 companion tests) | | `cargo clippy -j4 -p calternal-contacts --all-targets -- -D warnings` | PASS | | `cargo fmt -p calternal-contacts -- --check` | PASS | The Nix evaluation emitted deprecation warnings for `stdenv.isLinux` and `stdenv.isDarwin`; the Rust gates succeeded.
Author
Owner

Independent review, round 2

Reviewed PR head 3de5f011f448f522ae5f1b9618bd1403976aa985 and the planner, pairing code, tests, shared vectors, and ADRs 0063/0064. Static review; no build or tests run on the read-only control host.

Round 1 findings

Finding Status Does the test prove it?
P1 case-only path alias can delete the newly written companion Verified fixed Yes, for the supplied equality callback: the case-only vector checks both modes and omits DeleteOld when the callback reports an alias. It does not prove the callback matches a real volume.
P2 missing original can be regenerated from a lossy export Verified fixed Yes: update vectors with and without last_applied expect RepairMissing.
Write/verify/delete ordering Verified fixed Yes: plan vectors assert WriteNew → Verify → DeleteOld when deleting a distinct old path.
Shared case-only, NFC/NFD, and dot-segment vectors Verified added Yes: the same vector file is exercised under both test callbacks. These test callback behavior, not actual filesystem semantics.

New findings

  • P1 — A wrong equality callback can still schedule destructive deletion. plan_write trusts the caller’s function. If a case-insensitive volume is given case-sensitive equality, the case-only vector produces WriteNew → Verify → DeleteOld for two spellings of the same file. There is no conservative fallback or validation, so the round-1 data-loss bug returns when a caller gets volume semantics wrong. Make deletion require proven distinct identity (or bind the callback to a validated volume policy) and cover the real consumer’s policy.
  • P2 — Path identity is not used for every path comparison. pair.rs::associate deduplicates companion paths by exact string, and beside compares folder strings with ==; neither receives PathEquality. On a case-insensitive volume, Contacts/P.md paired with contacts/.calternal-contact-….vcf reports beside: false; duplicate aliases can be reported as ambiguous. Apply the same identity policy or require canonical paths, with pairing vectors for aliases.
  • P2 — Replanning after a partial write cannot finish the plan. After WriteNew and Verify, but before DeleteOld, a fresh listing contains both the new target and old companion. Re-running plan_write classifies two companions as Ambiguous, so it cannot finish cleanup. This is safe if recovery durably replays the original plan; otherwise it strands the pair. Document and test the replay contract or make this partial state recoverable.
  • P3 — Unicode equality coverage is narrow. The vectors cover canonical NFC/NFD, and the test callback uses default Unicode case folding, but there are no dotted/dotless Turkish I or ß/ SS cases. Since production equality belongs to the caller, these vectors do not establish how a supported filesystem treats those names.

Verdict: fix first. No P0 finding.

## Independent review, round 2 Reviewed PR head `3de5f011f448f522ae5f1b9618bd1403976aa985` and the planner, pairing code, tests, shared vectors, and ADRs 0063/0064. Static review; no build or tests run on the read-only control host. ### Round 1 findings | Finding | Status | Does the test prove it? | |---|---|---| | P1 case-only path alias can delete the newly written companion | **Verified fixed** | Yes, for the supplied equality callback: the case-only vector checks both modes and omits `DeleteOld` when the callback reports an alias. It does not prove the callback matches a real volume. | | P2 missing original can be regenerated from a lossy export | **Verified fixed** | Yes: update vectors with and without `last_applied` expect `RepairMissing`. | | Write/verify/delete ordering | **Verified fixed** | Yes: plan vectors assert `WriteNew → Verify → DeleteOld` when deleting a distinct old path. | | Shared case-only, NFC/NFD, and dot-segment vectors | **Verified added** | Yes: the same vector file is exercised under both test callbacks. These test callback behavior, not actual filesystem semantics. | ### New findings - **P1 — A wrong equality callback can still schedule destructive deletion.** `plan_write` trusts the caller’s function. If a case-insensitive volume is given case-sensitive equality, the case-only vector produces `WriteNew → Verify → DeleteOld` for two spellings of the same file. There is no conservative fallback or validation, so the round-1 data-loss bug returns when a caller gets volume semantics wrong. Make deletion require proven distinct identity (or bind the callback to a validated volume policy) and cover the real consumer’s policy. - **P2 — Path identity is not used for every path comparison.** `pair.rs::associate` deduplicates companion paths by exact string, and `beside` compares folder strings with `==`; neither receives `PathEquality`. On a case-insensitive volume, `Contacts/P.md` paired with `contacts/.calternal-contact-….vcf` reports `beside: false`; duplicate aliases can be reported as ambiguous. Apply the same identity policy or require canonical paths, with pairing vectors for aliases. - **P2 — Replanning after a partial write cannot finish the plan.** After `WriteNew` and `Verify`, but before `DeleteOld`, a fresh listing contains both the new target and old companion. Re-running `plan_write` classifies two companions as `Ambiguous`, so it cannot finish cleanup. This is safe if recovery durably replays the original plan; otherwise it strands the pair. Document and test the replay contract or make this partial state recoverable. - **P3 — Unicode equality coverage is narrow.** The vectors cover canonical NFC/NFD, and the test callback uses default Unicode case folding, but there are no dotted/dotless Turkish I or `ß`/ `SS` cases. Since production equality belongs to the caller, these vectors do not establish how a supported filesystem treats those names. **Verdict: fix first.** No P0 finding.
Author
Owner

Round 2 P1 follow-up

The planner now checks path identity independently of the caller callback. Different spellings with the same NFC plus full Unicode case-fold key return Ambiguous; the callback can suppress additional deletes but cannot authorize one for these aliases.

Check Status Evidence
Wrong path-equality callback Fixed The case-only alias vector fails before the change when the callback is case-sensitive, then passes without DeleteOld.
Unicode alias vectors PASS Case-only, NFC/NFD, Turkish I/İ/ı, ß/SS, and canonically reordered combining marks run under both callback modes.
Contacts crate tests PASS cargo test -j4 -p calternal-contacts --locked (152 tests)
Clippy PASS cargo clippy -j4 -p calternal-contacts --all-targets --locked -- -D warnings
Formatting PASS cargo fmt --check -p calternal-contacts
Head PASS 23d479b1
## Round 2 P1 follow-up The planner now checks path identity independently of the caller callback. Different spellings with the same NFC plus full Unicode case-fold key return `Ambiguous`; the callback can suppress additional deletes but cannot authorize one for these aliases. | Check | Status | Evidence | |---|---|---| | Wrong path-equality callback | Fixed | The case-only alias vector fails before the change when the callback is case-sensitive, then passes without `DeleteOld`. | | Unicode alias vectors | PASS | Case-only, NFC/NFD, Turkish `I`/`İ`/`ı`, `ß`/`SS`, and canonically reordered combining marks run under both callback modes. | | Contacts crate tests | PASS | `cargo test -j4 -p calternal-contacts --locked` (152 tests) | | Clippy | PASS | `cargo clippy -j4 -p calternal-contacts --all-targets --locked -- -D warnings` | | Formatting | PASS | `cargo fmt --check -p calternal-contacts` | | Head | PASS | `23d479b1` |
Author
Owner

Independent review, round 3 (final)

Reviewed head 23d479b16d2e6f9c5776a3dab0b0d082ad222b34.

Status

Check Status Evidence
Round 1/2 alias-delete finding Fixed The planner uses NFC + full Unicode case folding independently of the callback. An alternate spelling with the same key returns Ambiguous; write_plan also blocks DeleteOld for that key.
Required Unicode vectors Pass Case-only, NFC/NFD, Turkish I, ß/SS, and combining-mark vectors pass in both callback modes.
Missing original and operation order Verified Update returns RepairMissing; only Create or VerifiedRecovery can write when missing; deletes follow write and verify.
Ambiguous and other deletion paths Safe in this PR Plan::Ambiguous has no steps, and this module has no production caller yet. The only planned Home-companion deletion is DeleteOld. The existing raw-card cleanup removes state cache files, not Home companions.
Re-run / recovery Safe with the journal contract Replanning identical inputs is deterministic. After write/verify but before delete, a fresh listing yields Ambiguous; recovery must replay the durable original plan as ADR 0063/0064 specify. This PR has no executor to verify that integration.
Exact-head crate tests Pass On dev-01: cargo test -j4 -p calternal-contacts --locked — 152 passed, 0 failed, including 23 companion tests.

Findings (P0–P3)

  • P0: None.
  • P1: None.
  • P2: plan.rs:143 still uses the caller callback to decide in_place, not only to suppress deletion. A false-positive callback can make a same-byte companion in a different folder return Unchanged, skipping the required move. Use exact spelling / the conservative key for the no-op decision; reserve the callback for deletion suppression, and treat callback-only aliases conservatively.
  • P2 (round 2 item still open): pair.rs:81 compares parent folders with exact string equality. Case-only or NFC/NFD-equivalent folder spellings can report beside: false even when the planner’s conservative key says they may be the same folder. Apply a shared identity policy or require canonical paths, and add pairing vectors.
  • P3: None. Ambiguous files are deliberately preserved; no automatic cleanup path was found.

Verdict: small fix (P2-or-lower only).

## Independent review, round 3 (final) Reviewed head `23d479b16d2e6f9c5776a3dab0b0d082ad222b34`. ### Status | Check | Status | Evidence | |---|---|---| | Round 1/2 alias-delete finding | Fixed | The planner uses NFC + full Unicode case folding independently of the callback. An alternate spelling with the same key returns `Ambiguous`; `write_plan` also blocks `DeleteOld` for that key. | | Required Unicode vectors | Pass | Case-only, NFC/NFD, Turkish I, ß/SS, and combining-mark vectors pass in both callback modes. | | Missing original and operation order | Verified | `Update` returns `RepairMissing`; only `Create` or `VerifiedRecovery` can write when missing; deletes follow write and verify. | | `Ambiguous` and other deletion paths | Safe in this PR | `Plan::Ambiguous` has no steps, and this module has no production caller yet. The only planned Home-companion deletion is `DeleteOld`. The existing raw-card cleanup removes state cache files, not Home companions. | | Re-run / recovery | Safe with the journal contract | Replanning identical inputs is deterministic. After write/verify but before delete, a fresh listing yields `Ambiguous`; recovery must replay the durable original plan as ADR 0063/0064 specify. This PR has no executor to verify that integration. | | Exact-head crate tests | Pass | On dev-01: `cargo test -j4 -p calternal-contacts --locked` — 152 passed, 0 failed, including 23 companion tests. | ### Findings (P0–P3) - **P0:** None. - **P1:** None. - **P2:** `plan.rs:143` still uses the caller callback to decide `in_place`, not only to suppress deletion. A false-positive callback can make a same-byte companion in a different folder return `Unchanged`, skipping the required move. Use exact spelling / the conservative key for the no-op decision; reserve the callback for deletion suppression, and treat callback-only aliases conservatively. - **P2 (round 2 item still open):** `pair.rs:81` compares parent folders with exact string equality. Case-only or NFC/NFD-equivalent folder spellings can report `beside: false` even when the planner’s conservative key says they may be the same folder. Apply a shared identity policy or require canonical paths, and add pairing vectors. - **P3:** None. Ambiguous files are deliberately preserved; no automatic cleanup path was found. **Verdict: small fix (P2-or-lower only).**
Author
Owner

Round 3 follow-up

Fixed the P2: plan_write now requires an exact folder match before returning Unchanged. A folder that only matches after NFC normalization and full case folding returns Ambiguous, independently of the caller equality callback. Added vectors for a different-folder false-positive callback and a case-folded folder alias with that callback.

Gates on dev-02

  • cargo test -j4 -p calternal-contacts --locked — PASS (152 passed)
  • cargo clippy -j4 -p calternal-contacts --all-targets --locked -- -D warnings — PASS
  • cargo fmt --check -p calternal-contacts — PASS
## Round 3 follow-up Fixed the P2: `plan_write` now requires an exact folder match before returning `Unchanged`. A folder that only matches after NFC normalization and full case folding returns `Ambiguous`, independently of the caller equality callback. Added vectors for a different-folder false-positive callback and a case-folded folder alias with that callback. ### Gates on dev-02 - `cargo test -j4 -p calternal-contacts --locked` — PASS (152 passed) - `cargo clippy -j4 -p calternal-contacts --all-targets --locked -- -D warnings` — PASS - `cargo fmt --check -p calternal-contacts` — PASS
Author
Owner

housekeeping #1009: rebased+green, left open for review.

rebased pure contacts companion; kept current dev fields and documented the Home companion.

head: ea60c6dfa208d8c2b0c8f117e143e8f91e888771. rebased onto dev cd7f84432febfc63b788fbb9b9f9950452982d74 and pushed with the original exact force-with-lease.

Mac VM validation through Nix and the shared Mac lock/slot passed: root bun install --frozen-lockfile; bun run check, bun run lint, bun run build, bun run test in apps/web; bundle-only perf gate; cargo fmt -p calternal-contacts -- --check; cargo check -j4 --locked -p calternal-contacts --all-targets; cargo clippy -j4 --locked -p calternal-contacts --all-targets -- -D warnings; cargo test -j4 --locked -p calternal-contacts. Rust commands and logs; frontend logs. no UI browser changes in this backend companion slice.

original-head patch inventory, file pr-778.md.

housekeeping #1009: rebased+green, left open for review. rebased pure contacts companion; kept current dev fields and documented the Home companion. head: `ea60c6dfa208d8c2b0c8f117e143e8f91e888771`. rebased onto dev `cd7f84432febfc63b788fbb9b9f9950452982d74` and pushed with the original exact force-with-lease. Mac VM validation through Nix and the shared Mac lock/slot passed: root `bun install --frozen-lockfile`; `bun run check`, `bun run lint`, `bun run build`, `bun run test` in `apps/web`; bundle-only perf gate; `cargo fmt -p calternal-contacts -- --check`; `cargo check -j4 --locked -p calternal-contacts --all-targets`; `cargo clippy -j4 --locked -p calternal-contacts --all-targets -- -D warnings`; `cargo test -j4 --locked -p calternal-contacts`. [Rust commands and logs](https://git.kayg.org/attachments/9151b9b7-7ef6-424e-941f-01d37d84f7c9); [frontend logs](https://git.kayg.org/attachments/64244177-fd81-4992-860e-4d5d22ca01cd). no UI browser changes in this backend companion slice. [original-head patch inventory](https://git.kayg.org/attachments/fe3c09dc-dea3-47a0-92e2-b44a777083e5), file `pr-778.md`.
Author
Owner

Gate comment: merged origin/dev 8b00393b0, green

Head 867f946ee (merge commit, clean, no conflicts; pushed as a fast-forward). On dev-01 via ~/bin/slot, Nix shell:

exit command
0 cargo fmt --all -- --check
0 cargo clippy -j4 --locked -p calternal-contacts --all-targets -- -D warnings
0 cargo test -j4 --locked -p calternal-contacts (all suites ok)

No web, storage or Notes files changed (10 files, all in crates/contacts plus docs). git merge-tree with the #776 head is clean, so either merge order works. Not merged. Lane dav1114, 14 Nov.

## Gate comment: merged origin/dev `8b00393b0`, green Head `867f946ee` (merge commit, clean, no conflicts; pushed as a fast-forward). On dev-01 via `~/bin/slot`, Nix shell: | exit | command | |---|---| | 0 | `cargo fmt --all -- --check` | | 0 | `cargo clippy -j4 --locked -p calternal-contacts --all-targets -- -D warnings` | | 0 | `cargo test -j4 --locked -p calternal-contacts` (all suites ok) | No web, storage or Notes files changed (10 files, all in `crates/contacts` plus docs). `git merge-tree` with the #776 head is clean, so either merge order works. Not merged. Lane `dav1114`, 14 Nov.
Author
Owner

Final forward-merge of origin/dev 44fc0b7c4 (web-only since the gated tree: ADR renumbering and the tables port; git diff HEAD~1 HEAD -- crates Cargo.toml Cargo.lock is empty) pushed as a fast-forward, head 5b61d370a. Rust gates above stay valid. Not merged. Lane dav1114.

Final forward-merge of origin/dev `44fc0b7c4` (web-only since the gated tree: ADR renumbering and the tables port; `git diff HEAD~1 HEAD -- crates Cargo.toml Cargo.lock` is empty) pushed as a fast-forward, head `5b61d370a`. Rust gates above stay valid. Not merged. Lane `dav1114`.
Author
Owner

Merged into dev with --no-ff at 6c50dd99c by the orchestrator (gates in the lane comments; the daily train re-runs the full suite on dev). Closing.

Merged into `dev` with `--no-ff` at `6c50dd99c` by the orchestrator (gates in the lane comments; the daily train re-runs the full suite on dev). Closing.
kayg closed this pull request 2026-11-14 19:40:43 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!778
No description provided.