Train BI: contacts piece 2 (#657) #680

Closed
kayg wants to merge 0 commits from train/2026-10-23bi into dev
Owner

Train BI ran the full suite (run bi2, dev 9485ccf + issue/contacts-actions c18cc26): fmt, clippy, workspace tests, build, svelte-check, every Playwright project. Rust all green. Browser: cr1440 331, cr390 267+214, wk1440 139+191, wk390 157+193+131, small 19, admin 41; failures re-run: missing-links:227 (webkit-390) 4/4 passed; admin-contrast with setup 5/5 passed.

Contents (#657, contacts piece 2): contact actions (import with undo, links and renames, Me card), card copies tracked and joined by shutdown, exact quota on failed placement, crash-safe delete+purge (intent journal), acknowledged edits survive undo. Merged with Tasks (#674) and the full-disk shutdown work (#677) - both sides' guarantees kept; a combined task+contact rename test added.

Independent reviews: several rounds; four correctness fixes (024daa0), gate fixes (ee14c78), merge-resolution check: merge (0ca2f30 + test 517d3fd), re-merge with #677 (c18cc26) - all gates incl. notes crash 20/20 and shutdown settlement 10/10.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk

Train BI ran the full suite (run bi2, dev 9485ccf + issue/contacts-actions c18cc26): fmt, clippy, workspace tests, build, svelte-check, every Playwright project. Rust all green. Browser: cr1440 331, cr390 267+214, wk1440 139+191, wk390 157+193+131, small 19, admin 41; failures re-run: missing-links:227 (webkit-390) 4/4 passed; admin-contrast with setup 5/5 passed. Contents (#657, contacts piece 2): contact actions (import with undo, links and renames, Me card), card copies tracked and joined by shutdown, exact quota on failed placement, crash-safe delete+purge (intent journal), acknowledged edits survive undo. Merged with Tasks (#674) and the full-disk shutdown work (#677) - both sides' guarantees kept; a combined task+contact rename test added. Independent reviews: several rounds; four correctness fixes (024daa0), gate fixes (ee14c78), merge-resolution check: merge (0ca2f30 + test 517d3fd), re-merge with #677 (c18cc26) - all gates incl. notes crash 20/20 and shutdown settlement 10/10. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
kayg added 38 commits 2026-10-23 09:19:58 +00:00
Piece 2 of ADR 0064. A new plugin, calternal-contacts-actions, with
contacts.create, contacts.update, contacts.read, contacts.delete and
contacts.restore. Every write is one notes bulk-edit job, so history,
journal, live updates and crash recovery are the notes pipeline's own.
The original card is staged in the state root before the job's plan is
stored (the commit point) and promoted after, so a crash leaves the note
and its card both old or both new.

File names: Contacts/<Full name>.md, then company, city, nickname, email
domain, a number; NFC, no unsafe characters, byte limits, never empty.
Renames repoint every link; link words change only when they were the
old name. Deletes go to the Trash.

Notes: link_steps, edit_step and disk_names are public for plugins that
name their own notes; a note with a format: property is never renamed
after its title; a crash-points feature lets other crates' kill-9 tests
pause a job; health::dangling_links finds links that lead nowhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A free name is now checked with one lookup per name tried instead of a
listing of the whole Contacts folder, so making a contact costs the same
at 20 or 20,000 contacts. An update whose card bytes stay the same stages
nothing. The promote rename is no longer flushed on its own: a crash
leaves the card staged and recovery promotes it again, oldest job first.
The bench prints each disk's flush cost and plain-notes baselines. Two
tests no longer match "111" inside a random id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Reading the just-planned job back from history waited for the previous
job's last progress write to reach the disk: one extra flush on every
contact write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The card now lives in the note's history as its companion, stored in the
same history transaction as the note change: one flush for both, and no
staged files or promotion step. A copy of each card is still written to
contacts/raw/<id>.vcf afterwards (file, then folder flushed, then history
told), and caught up at start.

- create: a held note (text and card to history; identity to the id
  index at the same time; the file follows like typing). History without
  identity comes back at start from its notes.path companion.
- update: one patch with its card through the room. A new name is a job
  whose card is staged with the plan; notes.undo puts the card back.
- contacts.import: many cards, one job, plan and all cards in one flush,
  creates written together (one syncfs, one history transaction, one
  index flush); the same file twice changes nothing.
- the contacts naming rule runs for H1 edits in the app and for restores
  from the Trash (notes naming hook); sweeps of copies run after the
  Trash's sweep, deleting forever and undo (notes sweepers).
- retries after a failure plan a fresh attempt; nothing is written twice.
- notes: undo uses the inverse worked out on the real text, and undoes the
  steps a failed batch had already made; edit forks the live note when
  nothing is in flight; history readers are pooled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The copier gathers a burst of writes for a moment and writes their card
copies with one syncfs (fsio::replace_many) instead of two flushes per
card. Marking copies, and a held note's identity, as done now rides on the
next history flush (History::mark_written_soon): a crash before it only
repeats the copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A held note's identity now goes to the id index at once and is flushed in
the background: its notes.path companion, written with its text, brings
it back if a crash loses the index line, and is marked done only after
the line is durable. The deleted-for-good check reads history directly
instead of queueing behind its writer, an import reads every deleted id
once, and the new note's room opens in the background. Debug timings for
the create and update phases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A note in the Trash keeps its history, so a new note without history is
not there; the Trash folder lives on the slow disk. The contacts create
timing also reports the name lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Store actual edit results with history and order companions by application. Preserve link identities across Trash, restore and concurrent contact changes. Prepare imports before one history transaction and place files as one durable batch, with indexing in the background. Share unchanged photo bytes and document the proposed keep policy. Cover the review cases and crash boundaries with permanent tests.
Keep attribution and deletion age visible with the recovered note. Finish metadata-only interrupted placements, and recheck outside deletions under the lifecycle lock before forgetting an identity. Cover first-read metadata and interrupted placement with permanent regressions.
Place complete files with one final watcher event and no per-file flush. Preserve destination inheritance policies and occupied paths, with a safe local fallback. Encode initial Yjs updates directly and verify exact compatibility with yrs. Report exact latency budgets and start independent import samples after a quiet window.
Trash removals use calternal_fsio::remove_file from dev. Bulk note
writes, published import folders and card copies now report their
files to the disk-usage counter, so a 20k import is counted at once
instead of after the next recount.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The converter no longer builds a file name for a related person: its own
escaping ('/'->'_', ':'->'%3A', trailing dots kept) never matched the
namer's, so "John Smith Jr.", "AC/DC" and "Re: Zero" linked to files that
don't exist. Now the caller says where each related person lives
(Contact::link_related) and anything it can't vouch for stays plain text.

crates/contacts-actions/src/related.rs decides who a name is: a contact
written in the same import first (at the path the import chose, so a
second "Gopal Krishna" links to its own file), else the one contact in the
book with that name, checked by its title. Two candidates: plain text.
Import, create and update all use it; links already in a note keep their
targets, so a rename still moves them.

A plain name that would read back as a link is marked with a backslash
and read back exactly. New tests: tests::related (the review's repros plus
a property test over Unicode, punctuation, dots, bidi controls and device
names: every link reaches the person it shows; a unique name in an import
is always linked).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Storage (review P1): imports, new contacts and updates that grow a card are
admitted through the server's UploadPolicy before anything is written,
like an upload; nothing new to store needs no room. The quota counter now
counts each person's files on the state root too (Usage::with_roots), so
note history and contact cards with photos count the same on one disk or
two; contact writes refresh the history database's size at once.

Duplicates (review P2, P3): every companion row gets a small key when it
is stored (history migration 10, key_companions; older rows are keyed on
first use). An import checks the book by these keys instead of reading
every card with its photos, and every version counts, so a UID-less card
the phone edited is still a duplicate of the file imported before.

Also: a card file starting with a byte order mark is read (the mark is
dropped); bidi controls (U+202E and friends) never reach a file name,
joiners stay; a held contact whose identity a crash lost comes back under
the contacts naming order (company, city, ...) if its planned path was
taken, not "Name 2" (the notes.path marker now carries the names).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
contacts.create is measured against notes.create and contacts.update
against notes.patch, in a seeded shuffled order with background work
settled before each action, and every p95 is shown against the measured
flush floor. A book of 224 KB photo cards times the duplicate check of a
one-card import, which must not grow with the book's photo bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Counting the whole state root broke dev's quota contract: a person's
indexes and history databases ate their limit, so an upload of exactly
the limit was refused (the calternal isolation quota tests). The counter
now counts each person's Home plus only `contacts` on the state root
(Usage::with_app_data): the card copies, photos included, which is what a
person stores there. Contact writes are admitted for the note plus the
card, and announce the copies' sizes as they commit, so the limit sees
them before the background copier writes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Review round 4 (P2): a same-size photo swap passed as "no growth" while
history kept every version, and an undo put a large card back unadmitted.

What a person's limit counts for contacts is now what the history
retains: every card version's own bytes, each shared part (a photo kept
across versions) once, until the contact is deleted for good. History
keeps that sum per owner in the same transaction as every change
(migration 11, companion_usage; recounted on purge), and the contacts
plugin reports it to the storage counter for a separate state root
(usage::provide, Usage::with_state; a cached read-only connection per
person). Writes are admitted for exactly what they add
(History::companion_growth: a new photo in full, an unchanged one free),
and notes.undo is admitted for what putting older cards back adds. The
card copies are a cache and no longer count.

P3: a phone sending back exactly the stored card changes nothing and adds
no version; only links in the card's `related` group are related-person
links (not ones under ## Notes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Contacts writes go through Notes::enter (now public for plugins): create,
update, import, delete, recovery and the card copier hold a Drain Work and
are refused once shutdown begins. The write paths this branch added check
Home::writable (now public) before writing: bulk import placement and its
private folder image, Trash link sidecars, and the card copies. Held
creates enter like every other notes write. The storage_startup test takes
dev's version (its in-process rollback and 100x repeat).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Review round 5 (P2): undoing an import (or any create) deleted the notes
but kept their history, so the storage count never went down, and rows a
failed job staged for notes it never made stayed too.

The undo's delete step now purges the history of a note the undone job
made (it never existed before), so nothing it kept counts; a step a crash
interrupted after the file went finishes the purge on replay. Links to it
read as never made, as before. A finished undo also deletes the rows the
undone job staged and never applied (History::drop_unapplied). Purge now
takes exactly what it releases off the count instead of recounting the
whole book (no O(n^2) on a 20k undo).

ADR 0064: the count only goes down when a contact is deleted forever or
the import/create that made it is undone; history isn't pruned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Keep contact companions and durable undo receipts in the bounded history retry lane. Preserve dev's Saved checks and bounded shutdown behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Run creation undo's final version check and deletion in one room turn. Journal deletion before unlinking and recover it before scanning or replaying jobs, preserving files changed while the server was down.

Track card copy writes and their completion bookkeeping with the Home shutdown join. Roll back every prepared import seed, including cards whose file placement failed, without releasing shared quota still used by surviving contacts.

Add exact-boundary regressions and independent quota recounts for all four cases. Complete the history API integration with dev's retry and shutdown changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Use dev's membership nonce when joining and framing the contact live tests. The earlier fixtures omitted it, so the server correctly refused their joins before either contact scenario began.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Gate the manual trash sweep to its available caller and wait for the survivor note save before measuring quota.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Bring in Tasks backend PR #674 at 5111711917.

Resolve plugins.rs by registering Contacts and Tasks before any Home opens.
Resolve notes/Cargo.toml by retaining the Contacts notify 9.0.0-rc.5 pin
and adding dev's memchr and pulldown-cmark dependencies for CommonMark links.
Resolve notes/lib.rs by keeping Contacts deletion, namers, sweepers and quota
alongside Tasks describers, properties and list-store access. Task rows still
commit in the describe pass's note-list transaction.
Resolve rename.rs by keeping plugin-specific naming and the full-title check
before stripping a collision suffix; this includes dev's numbered-title fix.
Resolve room/edit.rs by applying typed Props through the durable receipt and
companion-aware edit path. Preserve the actual version and inverse for undo,
replay and acknowledged edits; keep dev's whole-key outside-edit resolution
and property writes during file I/O. Update the merged admission test fixture
to include the companion field.
Resolve tests/renames.rs by retaining both sides' regression cases, including
Contacts format names, cancelled prepared imports and numbered titles.

Keep the automatically merged CommonMark link boundaries and typed property
writer. Preserve Contacts undo checks, joined card-copy shutdown, exact quota
rollback and crash-safe deletion recovery. Add shipping-registry coverage for
a contact and a task in one Home: each belongs only to its own plugin, and
ordinary Notes lists hide the task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Added by the independent merge review (#657).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Merge dev 3671dc4fc8 without rebasing
contacts head 517d3fd. Preserve the full-disk shutdown work from #664/#677
and the contacts actions guarantees.

Resolve the save.rs conflict by moving the contacts deleting guard into
save_settled. Both ordinary saves and the closing actor use this guard,
so an intended deletion cannot recreate a note. Drop the obsolete early
dirty/time-zone check from save: history settles before file work, and
save_settled finishes any placed snapshot's promotion before checking dirt.
Keep dev's single closing settlement, terminal failure state, consumed
receipt handling and bounded concurrent room closes. A failed settlement
cannot retry through save or acknowledge unjournaled typing.

Keep the automatically merged contacts companion and API receipt fields
in each retained history entry and replay batch. Keep actor-owned creation
undo/deletion, exact companion quota accounting, durable deletion intents
and tracked card-copy work joined before history shuts down.

Fix shutdown test assertions exposed by standalone repetition: pooled
read-only history connections can keep history.db open after its writer
was joined, including reads made by the test after shutdown. Inspect the
exact writer's closed queue and joined handle under its locks instead of
using all database descriptors as a proxy. Keep shutdown time allowances,
Saved durability, history-before-files, twice-replayed recovery, storage
lock and idle-thread checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Merge commit 'c18cc260e6' into train/2026-10-23bi
Some checks failed
CI / web (pull_request) Failing after 1m8s
CI / server (pull_request) Successful in 2m1s
CI / rust (pull_request) Failing after 7m53s
7007841e07
Author
Owner

Closing: this PR's head commit is already in dev (checked 26 Oct, against dev a779a46). The train landed it by merging directly into dev.

Closing: this PR's head commit is already in `dev` (checked 26 Oct, against dev `a779a46`). The train landed it by merging directly into dev.
kayg closed this pull request 2026-10-26 11:18:01 +00:00
Some checks failed
CI / web (pull_request) Failing after 1m8s
CI / server (pull_request) Successful in 2m1s
CI / rust (pull_request) Failing after 7m53s

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!680
No description provided.