WIP: contacts import v2 S1; finish flat resident memory #817

Draft
kayg wants to merge 2 commits from feat/contacts-import-v2-s1 into dev
Owner

Device latency plan at 41bece8b

The original 1,000-card path made a durable child job, file flush, state-card copy, SQLite outcome commit and parent progress save for each card. At 12535aad, dev-01 added 8,233 fsync/fdatasync calls per 1,000 cards (8.233/card), and the full import took 77.382 s. The 1 MiB/1,024-card group at 858ce2bf reduced dev-01 flushes to 163 added calls per 1,000 cards when syncfs is included (0.163/card), but the 100 ms preparation cap still formed four batches on dev-01. The Mac 1,000-card run took 990.052 ms against the 500 ms gate.

Chosen follow-up

Keep the 1 MiB payload, 1,024-card count, 100 ms staging cap and all final durability barriers. Cards::put_many reaches a serial fsio::replace_many loop; write large unique-path batches on at most four scoped workers, fall back to serial for repeated paths, then keep one final volume sync. Create all staging SQLite tables and the source digest inside one synchronous=FULL transaction. The source file, staging-root, child journal, Home files, state copies, outcomes and final done record remain durable before success. File work stays O(N), prepared payload stays O(1 MiB) plus one oversized card, and worker count is capped at four.

Failure Effect Detection Recovery Gate
Parallel copy write fails Some cache entries may be old or new File write returns an error before volume sync Retry the complete unwritten page from Home companions Copy recovery and exact-card tests
Repeated destination in a batch Parallel completion could change last-writer order Detect duplicate paths before starting workers Preserve serial replacement order Repeated-destination regression
Stage schema transaction fails No import parent has been published SQLite rollback or error Retry preflight from the durable source Stage atomicity and source-boundary tests
Final flush fails Import must not report completion Child/outcome/done save returns an error Resume or undo from the last durable batch Final-flush retry and undo tests

Gates

  • Run the mid-batch kill/recovery test and every crash, recovery, final-flush, retry and undo test.
  • Measure dev-01 with Nix strace -c -f -e trace=fsync,fdatasync,syncfs at 1,000 and 20,000 cards, including stage time per card and batch count.
  • Measure the Mac 1,000-card import under the Mac lock; it must finish below 0.5 s before the 20,000-card SSD run, which must finish below 2 s.
  • Rerun the capped 25% and 100% HTTP memory gates and preserve exact outcomes, companion bytes and the <=1.10x flatness rule.

The current Mac run accidentally included --import-big 20000, which started a separate 20,000-card phase after the 1,000-card run failed. Its 29.570 s result is diagnostic only and does not satisfy the conditional 20,000-card gate.


Metadata-cache finding: the saved paired heaptrack stack attributes 1.89 MB positive growth to MetaDb::apply. Incremental single-card refreshes keep the default 2 MiB SQLite writer cache; the existing larger-batch guard does not bound that steady cache more tightly. Test a 512 KiB steady metadata writer cache, keeping the existing 8 MiB temporary bulk budget and the independent list-reader budget. Restore 512 KiB after bulk/fresh fills. O(512 KiB steady writer pages) independent of card count, no schema/file-format change. Failure -> effect -> detection -> recovery -> test: wrong/reset budget -> retained cache growth -> pragma assertion and RSS pair -> derived metadata remains rebuildable -> initial/fresh-fill resource regression, full notes/actions/server suite, then fresh capped gates if diagnostics pass. Extra I/O is a tradeoff to measure, not a functional timing assertion. Original 4eeb8cb1 capped pair continues as the control.

Current final diagnostic hypothesis: known-count reservation missed (40,168/44,880 KiB, 1.1173x) and is dropped. Combine the already-tested compact index pages with existing allocator reclamation at 128 durable outcomes and after source cards >=256 KiB. Neither alone cleared RSS: the hypothesis is that both page pinning and continuous-import retention must be addressed. Text pages 64 KiB, records 256/page, O(live UTF-8 + 24 bytes/note + bounded page slack); reclaim dead text amortized after dead > live and 64 KiB. No disk format change, no allocator override. Validate combined 25/100 diagnostics first. Retain only if measured gate clears; then full suite and fresh capped matrix. Failure/recovery remains the prior paged-index table: file/log remain authoritative, reused slots and compaction preserve identity/path lookup, existing recovery and storage-bound tests verify this.

Current bounded-capacity experiment: the staged plan already knows how many remaining cards create notes. Reserve exactly that many slot records and the two compact lookup tables before execution, reusing vacant slots. This removes geometric slot-vector growth and old/new-buffer overlap during per-card publication. O(existing notes + remaining creates) metadata; no payload reservation, no padding to the maximum import size, no disk-format change. Updates/refusals reserve no new slots. Recovery repeats the reservation for remaining creates only.

Failure -> effect -> detection -> recovery -> test: incorrect count -> capacity growth or spare metadata only -> RSS and existing identity/recovery checks -> ordinary vector growth still works -> index/action/server suite and fresh 25/100 diagnostics. Crash -> volatile reservation lost -> durable child/outcome cursor -> repeat count from disk -> existing crash/replay suite. Gate: uncapped diagnostics first, then full expanded suite and capped disk-backed matrix if the hypothesis clears flatness. Existing 4eeb8cb1 acceptance matrix is still running; no result is claimed yet.

S1 remains draft. The full action/server suite and the 20k-card HTTP workload with eight large notes now pass. Flat RSS still misses on both VMs; work continues on runtime memory churn. Current evidence and exact commands: docs/plans/0064-s1-compatibility-stop.md.

Current allocation plan

The index-page experiment is reverted because it passed its owned-byte bound but failed RSS (1.1282x). Keep the simpler existing index. Seed preparation already runs on a blocking worker; batches <=64 occupy one chunk but currently start an extra scoped OS thread. Use prepare_part directly for that chunk, preserving larger parallel batches. No disk format or result changes; same O(N) preparation, no extra per-card worker stack or worker lifetime.

Failure Effect Detection Recovery Gate
Seed encoding differs Incompatible history Exact Yjs bytes and UTF-16 edit tests Retain canonical plan text Existing seed tests
Small/large batch order differs Incorrect card history Outcome/order and crash tests Existing durable cursor replay Full action/server/notes suite
Runtime memory still grows RSS flatness miss Paired 25/100% and stage samples Keep draft, investigate actual retention <=1.10x under 256 MiB, swap 0
Large payload copies remain Resource limit failure Eight large notes at 20k scale Existing per-card recovery <=192 MiB RSS under 256 MiB

First run quick uncapped diagnostics on tmpfs; those are not acceptance. Then rerun the full suite and disk-backed capped HTTP gates. Durable plan copies, SQLite pages, verification identities and sweeping identities remain bounded as described below.

Implemented behavior

HTTP decoding and disk planning process one card at a time. Execution uses stable per-card history children and contiguous durable outcomes for recovery and exact replay. Note planning releases parsed/serialized copies before commit and execution. Yjs seed allocation reserves the final terminator. Staging SQLite is capped at 1 MiB. Verification pages 128 identities and contact cache sweeping pages 256 identities/removals.

Remaining gates

Flat RSS <=1.10x; strict corpus/skip thresholds and the 900-case same-UID rerun; deep-history recovery/undo and staged lifecycle faults; reservation, cleanup, capacity, slow consumers and device latency; refusal paging and formal legacy-history bounds. Never merge this draft on the current evidence.

## Device latency plan at `41bece8b` The original 1,000-card path made a durable child job, file flush, state-card copy, SQLite outcome commit and parent progress save for each card. At `12535aad`, dev-01 added 8,233 `fsync`/`fdatasync` calls per 1,000 cards (8.233/card), and the full import took 77.382 s. The 1 MiB/1,024-card group at `858ce2bf` reduced dev-01 flushes to 163 added calls per 1,000 cards when `syncfs` is included (0.163/card), but the 100 ms preparation cap still formed four batches on dev-01. The Mac 1,000-card run took 990.052 ms against the 500 ms gate. ### Chosen follow-up Keep the 1 MiB payload, 1,024-card count, 100 ms staging cap and all final durability barriers. `Cards::put_many` reaches a serial `fsio::replace_many` loop; write large unique-path batches on at most four scoped workers, fall back to serial for repeated paths, then keep one final volume sync. Create all staging SQLite tables and the source digest inside one `synchronous=FULL` transaction. The source file, staging-root, child journal, Home files, state copies, outcomes and final `done` record remain durable before success. File work stays O(N), prepared payload stays O(1 MiB) plus one oversized card, and worker count is capped at four. | Failure | Effect | Detection | Recovery | Gate | |---|---|---|---|---| | Parallel copy write fails | Some cache entries may be old or new | File write returns an error before volume sync | Retry the complete unwritten page from Home companions | Copy recovery and exact-card tests | | Repeated destination in a batch | Parallel completion could change last-writer order | Detect duplicate paths before starting workers | Preserve serial replacement order | Repeated-destination regression | | Stage schema transaction fails | No import parent has been published | SQLite rollback or error | Retry preflight from the durable source | Stage atomicity and source-boundary tests | | Final flush fails | Import must not report completion | Child/outcome/`done` save returns an error | Resume or undo from the last durable batch | Final-flush retry and undo tests | ### Gates - Run the mid-batch kill/recovery test and every crash, recovery, final-flush, retry and undo test. - Measure dev-01 with Nix `strace -c -f -e trace=fsync,fdatasync,syncfs` at 1,000 and 20,000 cards, including stage time per card and batch count. - Measure the Mac 1,000-card import under the Mac lock; it must finish below 0.5 s before the 20,000-card SSD run, which must finish below 2 s. - Rerun the capped 25% and 100% HTTP memory gates and preserve exact outcomes, companion bytes and the <=1.10x flatness rule. The current Mac run accidentally included `--import-big 20000`, which started a separate 20,000-card phase after the 1,000-card run failed. Its 29.570 s result is diagnostic only and does not satisfy the conditional 20,000-card gate. --- Metadata-cache finding: the saved paired heaptrack stack attributes 1.89 MB positive growth to MetaDb::apply. Incremental single-card refreshes keep the default 2 MiB SQLite writer cache; the existing larger-batch guard does not bound that steady cache more tightly. Test a 512 KiB steady metadata writer cache, keeping the existing 8 MiB temporary bulk budget and the independent list-reader budget. Restore 512 KiB after bulk/fresh fills. O(512 KiB steady writer pages) independent of card count, no schema/file-format change. Failure -> effect -> detection -> recovery -> test: wrong/reset budget -> retained cache growth -> pragma assertion and RSS pair -> derived metadata remains rebuildable -> initial/fresh-fill resource regression, full notes/actions/server suite, then fresh capped gates if diagnostics pass. Extra I/O is a tradeoff to measure, not a functional timing assertion. Original 4eeb8cb1 capped pair continues as the control. Current final diagnostic hypothesis: known-count reservation missed (40,168/44,880 KiB, 1.1173x) and is dropped. Combine the already-tested compact index pages with existing allocator reclamation at 128 durable outcomes and after source cards >=256 KiB. Neither alone cleared RSS: the hypothesis is that both page pinning and continuous-import retention must be addressed. Text pages 64 KiB, records 256/page, O(live UTF-8 + 24 bytes/note + bounded page slack); reclaim dead text amortized after dead > live and 64 KiB. No disk format change, no allocator override. Validate combined 25/100 diagnostics first. Retain only if measured gate clears; then full suite and fresh capped matrix. Failure/recovery remains the prior paged-index table: file/log remain authoritative, reused slots and compaction preserve identity/path lookup, existing recovery and storage-bound tests verify this. Current bounded-capacity experiment: the staged plan already knows how many remaining cards create notes. Reserve exactly that many slot records and the two compact lookup tables before execution, reusing vacant slots. This removes geometric slot-vector growth and old/new-buffer overlap during per-card publication. O(existing notes + remaining creates) metadata; no payload reservation, no padding to the maximum import size, no disk-format change. Updates/refusals reserve no new slots. Recovery repeats the reservation for remaining creates only. Failure -> effect -> detection -> recovery -> test: incorrect count -> capacity growth or spare metadata only -> RSS and existing identity/recovery checks -> ordinary vector growth still works -> index/action/server suite and fresh 25/100 diagnostics. Crash -> volatile reservation lost -> durable child/outcome cursor -> repeat count from disk -> existing crash/replay suite. Gate: uncapped diagnostics first, then full expanded suite and capped disk-backed matrix if the hypothesis clears flatness. Existing 4eeb8cb1 acceptance matrix is still running; no result is claimed yet. S1 remains draft. The full action/server suite and the 20k-card HTTP workload with eight large notes now pass. Flat RSS still misses on both VMs; work continues on runtime memory churn. Current evidence and exact commands: `docs/plans/0064-s1-compatibility-stop.md`. ## Current allocation plan The index-page experiment is reverted because it passed its owned-byte bound but failed RSS (1.1282x). Keep the simpler existing index. Seed preparation already runs on a blocking worker; batches <=64 occupy one chunk but currently start an extra scoped OS thread. Use `prepare_part` directly for that chunk, preserving larger parallel batches. No disk format or result changes; same O(N) preparation, no extra per-card worker stack or worker lifetime. | Failure | Effect | Detection | Recovery | Gate | |---|---|---|---|---| | Seed encoding differs | Incompatible history | Exact Yjs bytes and UTF-16 edit tests | Retain canonical plan text | Existing seed tests | | Small/large batch order differs | Incorrect card history | Outcome/order and crash tests | Existing durable cursor replay | Full action/server/notes suite | | Runtime memory still grows | RSS flatness miss | Paired 25/100% and stage samples | Keep draft, investigate actual retention | <=1.10x under 256 MiB, swap 0 | | Large payload copies remain | Resource limit failure | Eight large notes at 20k scale | Existing per-card recovery | <=192 MiB RSS under 256 MiB | First run quick uncapped diagnostics on tmpfs; those are not acceptance. Then rerun the full suite and disk-backed capped HTTP gates. Durable plan copies, SQLite pages, verification identities and sweeping identities remain bounded as described below. ## Implemented behavior HTTP decoding and disk planning process one card at a time. Execution uses stable per-card history children and contiguous durable outcomes for recovery and exact replay. Note planning releases parsed/serialized copies before commit and execution. Yjs seed allocation reserves the final terminator. Staging SQLite is capped at 1 MiB. Verification pages 128 identities and contact cache sweeping pages 256 identities/removals. ## Remaining gates Flat RSS <=1.10x; strict corpus/skip thresholds and the 900-case same-UID rerun; deep-history recovery/undo and staged lifecycle faults; reservation, cleanup, capacity, slow consumers and device latency; refusal paging and formal legacy-history bounds. Never merge this draft on the current evidence.
docs(contacts): record S1 compatibility stop and reproduction
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
d68e0a666f
kayg changed title from WIP: contacts import v2 S1 compatibility stop to WIP: contacts import v2 S1 photo HTTP compatibility stop 2026-10-31 21:36:59 +00:00
Author
Owner

Updated through ba2e14edd796a1ae30398f64cae608d70241b3c9. Growth wording is recorded on #815 at 2cc70e0b and comment 71756. Revised local-text preflight passes 300/300. The next required realistic stratum fails: 100/100 valid 2 MiB photo cards receive HTTP 413 before action execution; converter/executor accept all 100 with exact companion/photo checks. Same-generator 32 KiB control passes all paths. Ordinary contacts/actions/server suites (283 tests), fmt and combined all-target clippy pass. Per the requested stop condition, no full-scale RSS or new staged-phase crash gates were run after this non-wording failure. Draft retained; no merge or settings changes. Exact commands, fixture hashes and logs are in docs/plans/0064-s1-compatibility-stop.md.

Updated through `ba2e14edd796a1ae30398f64cae608d70241b3c9`. Growth wording is recorded on #815 at `2cc70e0b` and comment 71756. Revised local-text preflight passes 300/300. The next required realistic stratum fails: 100/100 valid 2 MiB photo cards receive HTTP 413 before action execution; converter/executor accept all 100 with exact companion/photo checks. Same-generator 32 KiB control passes all paths. Ordinary contacts/actions/server suites (283 tests), fmt and combined all-target clippy pass. Per the requested stop condition, no full-scale RSS or new staged-phase crash gates were run after this non-wording failure. Draft retained; no merge or settings changes. Exact commands, fixture hashes and logs are in `docs/plans/0064-s1-compatibility-stop.md`.
kayg changed title from WIP: contacts import v2 S1 photo HTTP compatibility stop to WIP: contacts import v2 S1 retained-update compatibility stop 2026-10-31 21:49:10 +00:00
Author
Owner

Updated through cdcb71dd. The import-only limit fix resolves the original photo gate: 100/100 Apple 2 MiB photos plus 100/100 folded 300 KiB Apple and Google photos pass converter/action/HTTP. Shared limits and an emission-time canonical note writer are in place; the oversized-card neighbor, 100 MiB source rejection and unchanged unrelated-route limit regressions pass. Ordinary contacts/actions/server suites: 289 passing; fmt and all-target clippy pass.

Stopped on the next measured required corpus failure: all nine retained-local update strata (900 total, Apple/Google/Outlook with 4 KiB/64 KiB/1 MiB local prose) have 100% skips through contacts.import action and HTTP. The existing known-UID deduplication leaves the old phone/companion unchanged; the pure merge probe passes. Draft retained. Full corpus/resource/new staged-phase crash gates were not reached; no <192 MiB claim. Exact commands and hashes are in the updated report. No merge or settings changes.

Updated through `cdcb71dd`. The import-only limit fix resolves the original photo gate: 100/100 Apple 2 MiB photos plus 100/100 folded 300 KiB Apple and Google photos pass converter/action/HTTP. Shared limits and an emission-time canonical note writer are in place; the oversized-card neighbor, 100 MiB source rejection and unchanged unrelated-route limit regressions pass. Ordinary contacts/actions/server suites: 289 passing; fmt and all-target clippy pass. Stopped on the next measured required corpus failure: all nine retained-local update strata (900 total, Apple/Google/Outlook with 4 KiB/64 KiB/1 MiB local prose) have 100% skips through contacts.import action and HTTP. The existing known-UID deduplication leaves the old phone/companion unchanged; the pure merge probe passes. Draft retained. Full corpus/resource/new staged-phase crash gates were not reached; no <192 MiB claim. Exact commands and hashes are in the updated report. No merge or settings changes.
Author
Owner

Resuming the measured same-UID failure. Classification fix: look up the current contact identity, compare exact saved source before merge, report updated/unchanged separately, and stage changed note/card edits in the same bulk action job with inverse companions. Create-only imports retain their prepared fast path; mixed/update jobs use the existing edit-capable path. Existing incoming limits and prior-pair 8 MiB admission remain. Local prose is excluded from positive growth charging; the legacy merger still materializes snapshots, so this does not claim the planned range-writer or <192 MiB gate.

Failure checks: identical source → unchanged/no contact revision; changed source → guarded edit and companion in one job; merge conflict → incoming kind with prior local text retained by inverse/history; ambiguous/missing original or excessive prior pair → refuse without changing target; crash → existing bulk replay/undo. Tests cover updated, unchanged, repeat file, independent/local conflicting fields, and undo. Next: retained-local action/HTTP gate, remaining compatibility/resource checks on dev-02; stop only at a measured required-gate failure. No merge or settings changes.

Resuming the measured same-UID failure. Classification fix: look up the current contact identity, compare exact saved source before merge, report updated/unchanged separately, and stage changed note/card edits in the same bulk action job with inverse companions. Create-only imports retain their prepared fast path; mixed/update jobs use the existing edit-capable path. Existing incoming limits and prior-pair 8 MiB admission remain. Local prose is excluded from positive growth charging; the legacy merger still materializes snapshots, so this does not claim the planned range-writer or <192 MiB gate. Failure checks: identical source → unchanged/no contact revision; changed source → guarded edit and companion in one job; merge conflict → incoming kind with prior local text retained by inverse/history; ambiguous/missing original or excessive prior pair → refuse without changing target; crash → existing bulk replay/undo. Tests cover updated, unchanged, repeat file, independent/local conflicting fields, and undo. Next: retained-local action/HTTP gate, remaining compatibility/resource checks on dev-02; stop only at a measured required-gate failure. No merge or settings changes.
kayg changed title from WIP: contacts import v2 S1 retained-update compatibility stop to WIP: contacts import v2 S1 same-UID updates; HTTP memory gate stop 2026-10-31 22:07:44 +00:00
Author
Owner

Memory investigation in progress. Nix heaptrack on dev-02 at 7b46c7d2: 25% and 50% HTTP imports complete with 486576/811672 KiB process peak including profiler overhead. Full size reaches 1239168 KiB and returns HTTP 429 before commit. Exact cause is being captured. Heaptrace shows whole-body JSON, job-sized converted pairs/seeds and whole-plan serialization, so allocator tuning cannot establish the bound. No acceptance result is claimed.

First correction: spool HTTP frames to an unlinked temporary file with a 64 KiB write window, explicit wire counter/idle timeout, 2 global and 1 per-owner active receives; validate request keys before polling. Parse from a buffered file reader to remove whole-wire retention. Keep existing decoded limits. Cap the history import cache at 8 MiB independent of count. This first correction still retains decoded input and job-sized planning payloads; the next full-size gate will decide progression, never an RSS-limit increase.

Failure checks: invalid key/auth or receive saturation -> no body polling; interrupted/over-wire body -> drop spool, no action; malformed JSON -> no action; cancellation -> file handle cleanup; parse/action failure -> no claimed import success. Test admission and split-frame/size/error cleanup, rerun contacts/action/server suites and clippy, then remeasure scale and real 256 MiB gate. Keep draft unless all required gates pass. No merge or settings changes.

Memory investigation in progress. Nix heaptrack on dev-02 at 7b46c7d2: 25% and 50% HTTP imports complete with 486576/811672 KiB process peak including profiler overhead. Full size reaches 1239168 KiB and returns HTTP 429 before commit. Exact cause is being captured. Heaptrace shows whole-body JSON, job-sized converted pairs/seeds and whole-plan serialization, so allocator tuning cannot establish the bound. No acceptance result is claimed. First correction: spool HTTP frames to an unlinked temporary file with a 64 KiB write window, explicit wire counter/idle timeout, 2 global and 1 per-owner active receives; validate request keys before polling. Parse from a buffered file reader to remove whole-wire retention. Keep existing decoded limits. Cap the history import cache at 8 MiB independent of count. This first correction still retains decoded input and job-sized planning payloads; the next full-size gate will decide progression, never an RSS-limit increase. Failure checks: invalid key/auth or receive saturation -> no body polling; interrupted/over-wire body -> drop spool, no action; malformed JSON -> no action; cancellation -> file handle cleanup; parse/action failure -> no claimed import success. Test admission and split-frame/size/error cleanup, rerun contacts/action/server suites and clippy, then remeasure scale and real 256 MiB gate. Keep draft unless all required gates pass. No merge or settings changes.
kayg changed title from WIP: contacts import v2 S1 same-UID updates; HTTP memory gate stop to WIP: contacts import v2 S1; profiled memory gate remains failing 2026-10-31 22:25:19 +00:00
Author
Owner

Resuming with bounded per-card execution, as requested. The previous whole-job importer will be replaced rather than wrapped in another accumulating layer.

Sizes and complexity: one decoded card (8 MiB maximum), one conversion/update and one child history plan at a time; 64 KiB source I/O; fixed SQLite cache <=8 MiB, mmap disabled. Source ranges, identity/deduplication, naming and outcomes live in an import staging SQLite database. Planning metadata is scanned in bounded records; note/card payloads never accumulate. Source bytes <=100 MiB, records <=20,000, existing output limits unchanged. Work is linear in payload bytes plus indexed disk lookups. Each card commits through the existing notes pipeline under a stable child job id. A small parent job refers to the group; undo visits children newest first.

Failure table:

  • Incomplete or invalid upload -> no action or publication -> receiver/stream decoder error -> discard private spool -> fragmented/trailing/limit tests.
  • Stop before a child plan -> card remains pending -> durable offset -> re-read source -> source/prepared boundary tests.
  • Stop after a child plan or publication, before cursor advance -> same child id found -> finish/replay child, then record outcome -> every history boundary plus restart/retry checks.
  • Stop while recording outcome/summary -> committed cursor and outcome remain transactional; summary rebuilt from bounded rows -> restart -> exact counts/no duplicate checks.
  • Undo interruption -> stable child undo jobs -> continue descending child cursor -> resume/whole-import undo tests.

Gates: 25/50/100% measured memory slope; full 20,000-card/100 MiB HTTP and worker under 256 MiB, peak <192 MiB; crash/restart; 900 same-UID updates; remaining corpus strata; contacts/actions/server suites; fmt and clippy -D warnings. Keep draft until gates pass; never merge. No repository settings changes.

Resuming with bounded per-card execution, as requested. The previous whole-job importer will be replaced rather than wrapped in another accumulating layer. Sizes and complexity: one decoded card (8 MiB maximum), one conversion/update and one child history plan at a time; 64 KiB source I/O; fixed SQLite cache <=8 MiB, mmap disabled. Source ranges, identity/deduplication, naming and outcomes live in an import staging SQLite database. Planning metadata is scanned in bounded records; note/card payloads never accumulate. Source bytes <=100 MiB, records <=20,000, existing output limits unchanged. Work is linear in payload bytes plus indexed disk lookups. Each card commits through the existing notes pipeline under a stable child job id. A small parent job refers to the group; undo visits children newest first. Failure table: - Incomplete or invalid upload -> no action or publication -> receiver/stream decoder error -> discard private spool -> fragmented/trailing/limit tests. - Stop before a child plan -> card remains pending -> durable offset -> re-read source -> source/prepared boundary tests. - Stop after a child plan or publication, before cursor advance -> same child id found -> finish/replay child, then record outcome -> every history boundary plus restart/retry checks. - Stop while recording outcome/summary -> committed cursor and outcome remain transactional; summary rebuilt from bounded rows -> restart -> exact counts/no duplicate checks. - Undo interruption -> stable child undo jobs -> continue descending child cursor -> resume/whole-import undo tests. Gates: 25/50/100% measured memory slope; full 20,000-card/100 MiB HTTP and worker under 256 MiB, peak <192 MiB; crash/restart; 900 same-UID updates; remaining corpus strata; contacts/actions/server suites; fmt and clippy -D warnings. Keep draft until gates pass; never merge. No repository settings changes.
kayg changed title from WIP: contacts import v2 S1; profiled memory gate remains failing to WIP: contacts import v2 S1; per-card worker recovery gate failing 2026-10-31 22:54:32 +00:00
Author
Owner

S1 status at e23a1aa65d. Recovery now resumes from contiguous durable outcomes and accepts only exact replays; kill-9 recovery verifies all 1,000 unique cards exactly once, with outcomes matching a clean run. The full action/server sequence, clippy and formatting pass.

Base HTTP peaks at 25/50/100% were 44,804 / 50,452 / 57,580–60,580 KiB. They remain under 192 MiB, but rise with input size, so flat memory is not established. Full 20k-card base HTTP passed 3/3 and the 20k worker run passed. The 20k-card eight-large-note HTTP run under MemoryMax=256M and no swap was OOM-killed at 256,616 KiB; S1 full-scale acceptance remains incomplete.

Open: strict corpus skip thresholds and the 900 same-UID rerun; deep-history recovery/undo and staged lifecycle faults; disk reservation/cleanup/capacity/slow-consumer and device-latency gates; refusal paging and formal legacy history-path bounds. The status report is updated; PR remains draft.

S1 status at e23a1aa65da76e0de57af5ce29b5126c6551ca9a. Recovery now resumes from contiguous durable outcomes and accepts only exact replays; kill-9 recovery verifies all 1,000 unique cards exactly once, with outcomes matching a clean run. The full action/server sequence, clippy and formatting pass. Base HTTP peaks at 25/50/100% were 44,804 / 50,452 / 57,580–60,580 KiB. They remain under 192 MiB, but rise with input size, so flat memory is not established. Full 20k-card base HTTP passed 3/3 and the 20k worker run passed. The 20k-card eight-large-note HTTP run under MemoryMax=256M and no swap was OOM-killed at 256,616 KiB; S1 full-scale acceptance remains incomplete. Open: strict corpus skip thresholds and the 900 same-UID rerun; deep-history recovery/undo and staged lifecycle faults; disk reservation/cleanup/capacity/slow-consumer and device-latency gates; refusal paging and formal legacy history-path bounds. The status report is updated; PR remains draft.
kayg changed title from WIP: contacts import v2 S1; per-card worker recovery gate failing to WIP: contacts import v2 S1; finish bounded index memory 2026-11-01 17:42:00 +00:00
kayg changed title from WIP: contacts import v2 S1; finish bounded index memory to WIP: contacts import v2 S1; finish flat resident memory 2026-11-01 18:37:31 +00:00
Author
Owner

Resumed final measurements complete. Report head: 0c3ee080b4; measured code head: 0a52bf0057 (subsequent commits only update the report).

HTTP workload VM Peak RSS KiB Seconds Result
25%, 5,000 cards dev-01 37,580 944.770 PASS
50%, 10,000 cards dev-02 37,376 2,551.804 PASS
100%, 20,000 cards dev-01 40,368 3,207.503 PASS
100%, eight large notes dev-01 143,904 3,208.574 PASS

All ran through VM slots under MemoryMax=256M, MemorySwapMax=0 with disk-backed TMPDIR, no allocator override, exit 0 and zero OOM/OOM-kill events. Peak is child wait4.ru_maxrss. Paired dev-01 full/25% ratio is 1.0742x, below 1.10x. Both full workloads verified 20,000 durable outcomes and exactly 104,857,600 companion bytes. The large-note peak is 140.53 MiB, below 192 MiB.

The saved full expanded suite at 0a52bf00 has suite_exit=0: fmt; all-target clippy -D warnings for core/engine/contacts/actions/server/notes; core/engine/contacts/actions/server tests; notes bulk; fsio usage; full notes suite; standalone memory harness build. Exact Nix/slot commands and reproduction are in docs/plans/0064-s1-compatibility-stop.md. This continuation checked the completed logs and durable summaries, without repeating the finished runs.

The retained per-card state is shared note-index identity/path/lookup metadata, still O(published notes). Import payloads/outcomes remain disk-backed. Heaptrack identified the metadata publication writer cache; the final code bounds its steady cache at 512 KiB and restores that budget after bulk/fresh fills. Earlier fixes release serialized planning copies, reserve complete initial seeds, prepare one seed chunk on the existing worker, and page cache sweeping/verification. The measured RSS gate now passes; this is not a constant-space claim for arbitrarily large Homes.

Compact results/manifests, binary hashes and profile summaries remain in ~/contacts-s1-evidence on the VMs. Completed final scratch data and build targets were removed; no jobs remain running. No merge.

PR remains draft: strict corpus skip thresholds/900 same-UID rerun; deep-history recovery/undo and lifecycle faults; disk reservation/cleanup/capacity/slow-consumer/device-latency gates; refusal paging and formal legacy history-path bounds remain open.

Resumed final measurements complete. Report head: 0c3ee080b43696a0d436cada7270b36a68794f72; measured code head: 0a52bf005799ceeaaff6303af415e5b62dc42084 (subsequent commits only update the report). | HTTP workload | VM | Peak RSS KiB | Seconds | Result | |---|---|---:|---:|---| | 25%, 5,000 cards | dev-01 | 37,580 | 944.770 | PASS | | 50%, 10,000 cards | dev-02 | 37,376 | 2,551.804 | PASS | | 100%, 20,000 cards | dev-01 | 40,368 | 3,207.503 | PASS | | 100%, eight large notes | dev-01 | 143,904 | 3,208.574 | PASS | All ran through VM slots under MemoryMax=256M, MemorySwapMax=0 with disk-backed TMPDIR, no allocator override, exit 0 and zero OOM/OOM-kill events. Peak is child wait4.ru_maxrss. Paired dev-01 full/25% ratio is 1.0742x, below 1.10x. Both full workloads verified 20,000 durable outcomes and exactly 104,857,600 companion bytes. The large-note peak is 140.53 MiB, below 192 MiB. The saved full expanded suite at 0a52bf00 has suite_exit=0: fmt; all-target clippy -D warnings for core/engine/contacts/actions/server/notes; core/engine/contacts/actions/server tests; notes bulk; fsio usage; full notes suite; standalone memory harness build. Exact Nix/slot commands and reproduction are in docs/plans/0064-s1-compatibility-stop.md. This continuation checked the completed logs and durable summaries, without repeating the finished runs. The retained per-card state is shared note-index identity/path/lookup metadata, still O(published notes). Import payloads/outcomes remain disk-backed. Heaptrack identified the metadata publication writer cache; the final code bounds its steady cache at 512 KiB and restores that budget after bulk/fresh fills. Earlier fixes release serialized planning copies, reserve complete initial seeds, prepare one seed chunk on the existing worker, and page cache sweeping/verification. The measured RSS gate now passes; this is not a constant-space claim for arbitrarily large Homes. Compact results/manifests, binary hashes and profile summaries remain in ~/contacts-s1-evidence on the VMs. Completed final scratch data and build targets were removed; no jobs remain running. No merge. PR remains draft: strict corpus skip thresholds/900 same-UID rerun; deep-history recovery/undo and lifecycle faults; disk reservation/cleanup/capacity/slow-consumer/device-latency gates; refusal paging and formal legacy history-path bounds remain open.
Author
Owner

S1 gate update

PR #817 remains a draft at 12535aad.

Passed

  • Memory: flatness 1.0742×; large-note peak 143,904 KiB (140.53 MiB), below 192 MiB (#issuecomment-73725).
  • Retained-local same-UID: 900 cases across nine strata, with zero converter, action, or HTTP skips.
  • Photo compatibility: 100 Apple 2 MiB cards, zero skips on all paths, exact companion and image checks.
  • Staged lifecycle: seven import placement/history fault cases and recovery/undo across all nine durable checkpoints.
  • Refusal preview: capped at 64 rows with no paging field; formatting check passed.

Failed

  • Mac device latency: the 1,000-card import remained in I/O wait for more than two minutes against the 0.5 s target. The 20,000-card case was not reached.

Pending

  • Full 30,000-card corpus: at least 10,000 cards per family and strictly below 0.1% skips overall and per family/stratum.
  • Deep-history recovery and undo at 10,000 revisions and at least 256 MiB of prior history.
  • Physical disk reservation/capacity and restart during cleanup; slow-consumer backpressure; formal legacy history-path bounds.

The gate table, evidence, and exact commands are in docs/plans/0064-s1-compatibility-stop.md. No merge was made.

## S1 gate update PR #817 remains a draft at `12535aad`. **Passed** - Memory: flatness 1.0742×; large-note peak 143,904 KiB (140.53 MiB), below 192 MiB (#issuecomment-73725). - Retained-local same-UID: 900 cases across nine strata, with zero converter, action, or HTTP skips. - Photo compatibility: 100 Apple 2 MiB cards, zero skips on all paths, exact companion and image checks. - Staged lifecycle: seven import placement/history fault cases and recovery/undo across all nine durable checkpoints. - Refusal preview: capped at 64 rows with no paging field; formatting check passed. **Failed** - Mac device latency: the 1,000-card import remained in I/O wait for more than two minutes against the 0.5 s target. The 20,000-card case was not reached. **Pending** - Full 30,000-card corpus: at least 10,000 cards per family and strictly below 0.1% skips overall and per family/stratum. - Deep-history recovery and undo at 10,000 revisions and at least 256 MiB of prior history. - Physical disk reservation/capacity and restart during cleanup; slow-consumer backpressure; formal legacy history-path bounds. The gate table, evidence, and exact commands are in `docs/plans/0064-s1-compatibility-stop.md`. No merge was made.
Author
Owner

S1 follow-up at c71812d8

Group commit replaced per-card durable commits. At 1,000 cards, five batch child commits, five outcome transactions and five parent progress saves cover all cards; at 20,000 cards there are 95 of each. Per-card idempotent outcomes remain durable, and done is saved only after the final durable batch.

  • Dev-01 at 1,000 cards: 8.233 to 0.111 flush calls/card (fsync + fdatasync: 8.233 to 0.104); harness time 77.382 s to 2.744 s.
  • Dev-01 at 20,000 cards: 0.0574 flush calls/card; harness time 67.461 s.
  • Mac 1,000-card device gate: more than 120 s before, 1.604 s after; the 0.5 s target still fails. Mac 20,000 was not run because 1,000 missed.
  • HTTP memory rerun under 256 MiB with no swap: 25% peak 53,340 KiB; 100% peak 60,980 KiB; flatness 1.1436x, above the 1.10 limit. Both passed exact outcome/companion checks, stayed below 192 MiB, and had no OOM events.

Dev-01 checks passed: contacts-actions 141/141, fsio 46/46, notes bulk 5/5. The updated gate table and stage timings are in docs/plans/0064-s1-compatibility-stop.md. The PR remains draft; device latency and memory flatness still fail, and the other pending S1 gates remain open. No merge.

## S1 follow-up at `c71812d8` Group commit replaced per-card durable commits. At 1,000 cards, five batch child commits, five outcome transactions and five parent progress saves cover all cards; at 20,000 cards there are 95 of each. Per-card idempotent outcomes remain durable, and `done` is saved only after the final durable batch. - Dev-01 at 1,000 cards: 8.233 to 0.111 flush calls/card (`fsync` + `fdatasync`: 8.233 to 0.104); harness time 77.382 s to 2.744 s. - Dev-01 at 20,000 cards: 0.0574 flush calls/card; harness time 67.461 s. - Mac 1,000-card device gate: more than 120 s before, 1.604 s after; the 0.5 s target still fails. Mac 20,000 was not run because 1,000 missed. - HTTP memory rerun under 256 MiB with no swap: 25% peak 53,340 KiB; 100% peak 60,980 KiB; flatness 1.1436x, above the 1.10 limit. Both passed exact outcome/companion checks, stayed below 192 MiB, and had no OOM events. Dev-01 checks passed: contacts-actions 141/141, fsio 46/46, notes bulk 5/5. The updated gate table and stage timings are in `docs/plans/0064-s1-compatibility-stop.md`. The PR remains draft; device latency and memory flatness still fail, and the other pending S1 gates remain open. No merge.
Author
Owner

S1 device-latency follow-up at 544457b3

Resumed from the stopped Codex run. Group commit (c71812d8, batches of up to 1,024 cards / 1 MiB / 100 ms) was already on the branch. I re-measured at a4040a88 before changing anything.

Cause found

The per-card durable commit that remained was in the known-card scan (index_book, crates/contacts-actions/src/import/planning.rs). It inserted each known companion key into the staging file as its own statement. The staging file runs with synchronous=FULL and a DELETE journal, so each insert was a flushed commit. Importing the same cards again therefore paid one flushed commit per card already in the book.

Fixed in 8434d883: the whole scan commits once. Test scanning_known_cards_commits_a_fixed_number_of_times reads SQLite's file-change counter and fails when commits grow with the number of known cards. Red without the fix (62 commits for 60 known cards), green with it (at most 4).

dev-01 (12 cores, load average 9–20 during these runs, so absolute times are noisy)

Release contacts_bench, one fresh import then the same cards again (--pairs 0), disk-backed TMPDIR.

Cards Fresh before → after Same cards again before → after Peak RSS before → after
100 0.64 s → 1.28 s (noise, see below) 8.8 s → 1.04 s 17.4 → 17.8 MiB
1,000 2.14 s → 0.72 s 66.6 s → 1.27 s 31.2 → 29.2 MiB
10,000 6.82 s → 6.02 s 910.9 s → 11.3 s 62.4 → 63.8 MiB

The fresh path is not touched by this change; its differences are load noise. Before the fix, the repeat cost about 90 ms per card (index_companion_keys 114.9 s for 1,000 rows in the profiled run).

strace -c -f, 1,000 cards (fresh + repeat in one process), against a zero-import control (--import 0):

Syscall Control Before After
fdatasync 58 4,234 239
fsync 223 231 231
syncfs 2 13 10

Before: about 4.2 fdatasync per card, all in the repeat. After: 0.18 per card.

Mac VM (calternal-macos-01-std, VirtualMac2,1), lock held with an EXIT trap in the running script

Release build at 46603546. Fresh import, then the same cards again, new process per row.

Cards Fresh Same cards again Peak RSS
100 0.232 s 0.127 s 20.4 MiB
1,000 (5 runs) 0.98, 1.17, 1.36, 0.52, 2.10 s 0.67, 0.69, 0.53, 0.72 s 36.0 MiB
10,000 7.13 s 6.15 s 63.1 MiB

The 0.5 s target for 1,000 cards is not met. The median is 1.17 s; the best run is 0.52 s. 20,000 was not run because 1,000 missed. The spread is large: in the 2.10 s run the history/publication step took 1.60 s, against 0.25 s in the 0.52 s run.

Stage costs, profiled 1,000-card fresh run (0.52 s end to end, whole_import 414 ms): stage create 32 ms, index book 5 ms, choose paths 13 ms, plan commit 5 ms, batch prepare 8 ms, child commit 365 ms (history/publication 250 ms, finish 115 ms), card-copy image 255 ms (overlaps), one volume sync 112 ms (fsync_volume_np FULLSYNC|WAIT), outcome commit 3 ms, parent progress 8 ms, summary 3 ms.

Repeat of 1,000 on the Mac: whole_import 21 ms, 0 volume syncs, but 0.5–0.7 s end to end. The timeline shows plan_import at about 323 ms in the repeat versus 16 ms in the fresh run. I have not attributed it yet.

Gates (dev-01, 544457b3)

  • cargo fmt --check -p calternal-contacts-actions: pass.
  • cargo clippy --locked -p calternal-contacts-actions --all-targets -- -D warnings: pass. Two errors from earlier commits (import_stage.rs:520 unnecessary cast, tests/import.rs:392 disallowed std::fs::write) were fixed in 544457b3.
  • cargo test --locked -p calternal-contacts-actions at 46603546: 143 passed, 0 failed, including import_killed_mid_batch_recovers_each_card_once_and_undoes and the other five import_killed_* cases. The summary-rebuild test, the new scan test and the mid-batch kill test also pass at 544457b3.
  • Not rerun: the HTTP memory gates (25% / 100%). The change only batches the known-key scan, which is empty on a first import.

Risks for the durability review

  • The scan now holds one open staging transaction across companion_key_page(...).await calls. An error drops the stage and rolls back; a kill leaves a hot journal that SQLite rolls back on reopen. known is derived data, rebuilt by every run, and nothing acknowledged depends on it. The kill-9 tests pass, but none kills during the key scan itself.
  • Group-commit durability is unchanged: no outcome or done state is written earlier than before.
  • Latency target still open (see Mac table). The remaining cost is file publication plus the history transaction and one full volume sync; further gains need either fewer small-file creates or an agreed relaxed target on a virtual disk.

No merge.

## S1 device-latency follow-up at `544457b3` Resumed from the stopped Codex run. Group commit (`c71812d8`, batches of up to 1,024 cards / 1 MiB / 100 ms) was already on the branch. I re-measured at `a4040a88` before changing anything. ### Cause found The per-card durable commit that remained was in the **known-card scan** (`index_book`, `crates/contacts-actions/src/import/planning.rs`). It inserted each known companion key into the staging file as its own statement. The staging file runs with `synchronous=FULL` and a DELETE journal, so each insert was a flushed commit. Importing the same cards again therefore paid one flushed commit per card already in the book. Fixed in `8434d883`: the whole scan commits once. Test `scanning_known_cards_commits_a_fixed_number_of_times` reads SQLite's file-change counter and fails when commits grow with the number of known cards. Red without the fix (62 commits for 60 known cards), green with it (at most 4). ### dev-01 (12 cores, load average 9–20 during these runs, so absolute times are noisy) Release `contacts_bench`, one fresh import then the same cards again (`--pairs 0`), disk-backed `TMPDIR`. | Cards | Fresh before → after | Same cards again before → after | Peak RSS before → after | |---:|---:|---:|---:| | 100 | 0.64 s → 1.28 s (noise, see below) | 8.8 s → 1.04 s | 17.4 → 17.8 MiB | | 1,000 | 2.14 s → 0.72 s | **66.6 s → 1.27 s** | 31.2 → 29.2 MiB | | 10,000 | 6.82 s → 6.02 s | **910.9 s → 11.3 s** | 62.4 → 63.8 MiB | The fresh path is not touched by this change; its differences are load noise. Before the fix, the repeat cost about 90 ms per card (`index_companion_keys` 114.9 s for 1,000 rows in the profiled run). `strace -c -f`, 1,000 cards (fresh + repeat in one process), against a zero-import control (`--import 0`): | Syscall | Control | Before | After | |---|---:|---:|---:| | `fdatasync` | 58 | 4,234 | 239 | | `fsync` | 223 | 231 | 231 | | `syncfs` | 2 | 13 | 10 | Before: about 4.2 `fdatasync` per card, all in the repeat. After: 0.18 per card. ### Mac VM (`calternal-macos-01-std`, VirtualMac2,1), lock held with an EXIT trap in the running script Release build at `46603546`. Fresh import, then the same cards again, new process per row. | Cards | Fresh | Same cards again | Peak RSS | |---:|---:|---:|---:| | 100 | 0.232 s | 0.127 s | 20.4 MiB | | 1,000 (5 runs) | 0.98, 1.17, 1.36, 0.52, 2.10 s | 0.67, 0.69, 0.53, 0.72 s | 36.0 MiB | | 10,000 | 7.13 s | 6.15 s | 63.1 MiB | **The 0.5 s target for 1,000 cards is not met.** The median is 1.17 s; the best run is 0.52 s. 20,000 was not run because 1,000 missed. The spread is large: in the 2.10 s run the history/publication step took 1.60 s, against 0.25 s in the 0.52 s run. Stage costs, profiled 1,000-card fresh run (0.52 s end to end, `whole_import` 414 ms): stage create 32 ms, index book 5 ms, choose paths 13 ms, plan commit 5 ms, batch prepare 8 ms, child commit 365 ms (history/publication 250 ms, finish 115 ms), card-copy image 255 ms (overlaps), one volume sync 112 ms (`fsync_volume_np` FULLSYNC|WAIT), outcome commit 3 ms, parent progress 8 ms, summary 3 ms. Repeat of 1,000 on the Mac: `whole_import` 21 ms, 0 volume syncs, but 0.5–0.7 s end to end. The timeline shows `plan_import` at about 323 ms in the repeat versus 16 ms in the fresh run. I have not attributed it yet. ### Gates (dev-01, `544457b3`) - `cargo fmt --check -p calternal-contacts-actions`: pass. - `cargo clippy --locked -p calternal-contacts-actions --all-targets -- -D warnings`: pass. Two errors from earlier commits (`import_stage.rs:520` unnecessary cast, `tests/import.rs:392` disallowed `std::fs::write`) were fixed in `544457b3`. - `cargo test --locked -p calternal-contacts-actions` at `46603546`: 143 passed, 0 failed, including `import_killed_mid_batch_recovers_each_card_once_and_undoes` and the other five `import_killed_*` cases. The summary-rebuild test, the new scan test and the mid-batch kill test also pass at `544457b3`. - Not rerun: the HTTP memory gates (25% / 100%). The change only batches the known-key scan, which is empty on a first import. ### Risks for the durability review - The scan now holds one open staging transaction across `companion_key_page(...).await` calls. An error drops the stage and rolls back; a kill leaves a hot journal that SQLite rolls back on reopen. `known` is derived data, rebuilt by every run, and nothing acknowledged depends on it. The kill-9 tests pass, but none kills during the key scan itself. - Group-commit durability is unchanged: no outcome or `done` state is written earlier than before. - Latency target still open (see Mac table). The remaining cost is file publication plus the history transaction and one full volume sync; further gains need either fewer small-file creates or an agreed relaxed target on a virtual disk. No merge.
Author
Owner

S1 device-latency follow-up at b8c7416d

Commits since 544457b3: b74b5f8a (profile points), 3ea7d960 (bench CONTACT_BENCH_SETTLE), 30d1e3d3 (the fix), b8c7416d (fmt). Code change is one commit: 30d1e3d3. The 0.5 s fresh target is still not met; I changed no plan text and no durability step.

1. Re-import planning gap (323 ms vs 21 ms) — found and fixed

whole_import starts after planning, so it never counted it. For every known card, import_update read the contact note file (contact_note_in_home) before comparing the stored original with the incoming bytes. Profile, 1,000 repeat: note_read_ms 503 and 597 (two runs), companion_read_ms 33–36. An exact replay needs only the stored card, so the compare now runs first and the note is read only when the card changed (a cheap live-index check stays). After: note_read_ms 0, companion_read_ms 23–27, plan_import 36–41 ms.

2. History/publication swing (250 ms → 1.6 s) — storage latency, not work per card

Same code, same cards, profiled runs (ms):

Part Good run Slow run
history txn, statements run 8.8 98
history txn, commit 35 54–103
note image wait (1,000 file creates) 194 130–644
card-copy image (1,000 file creates) 262 292–757
volume sync (fsync_volume_np FULLSYNC) 139 157–300
outcome commit (stage SQLite) 3 109–192

Probe on the Mac VM (3 passes): write+fsync 4 KB median 1.8–2.1 ms; F_FULLFSYNC median 69–110 ms, p90 154–207 ms, max 5.5 s; creating 100 small files single-threaded median 163–181 ms (≈1.7 ms per file). The fresh path has ~8 sequential full-sync waits (source spool, stage flush, history start, volume sync, history finish, outcome, parent progress, done) plus 2,000 file creates. Each wait or create burst swings 2–5× between runs, so the sum swings the same. Other VMs share the Studio's disk; the same fresh code measured 0.88–1.66 s here and 0.52–2.10 s earlier.

Batched history entry: the import already writes one job row per 1,024-card batch. The per-card rows are each note's own first version, seed and card original; undo, recovery and per-note history read them, so one "Imported 1,000 contacts" record cannot replace them without dropping per-note history. Their cost is the 9–98 ms statement run, not the swing. No plan change proposed.

Card-copy images: already built in parallel with the history transaction (state_copy_ms overlaps child_plan_journal_ms), and done must wait for them to be durable. Writing them after the cards are visible does not shorten the import. A real saving would need fewer files (for example one packed state file), which changes the plan; not done.

Mac VM, 5 runs each, interleaved, contacts_bench release (seconds; median [min–max])

Fresh code is identical before and after, so its differences are host noise. Only "again" changed.

Cards Fresh before 544457b3 Fresh after 30d1e3d3 Again before Again after
100 0.31 [0.23–1.94] 0.22 [0.21–0.26] 0.18 [0.12–0.52] 0.10 [0.09–0.11]
1,000 0.86 [0.80–1.66] 1.23 [0.88–3.98] 0.60 [0.57–0.95] 0.21 [0.18–0.57]
10,000 24.2 [12.6–44.5] 14.1 [9.1–17.9] 10.9 [6.3–47.6] 0.91 [0.86–1.16]

(The Mac was slower than on 11-02 for the whole window; the 10,000 fresh run was 7.1 s then.)

Gates, dev-01 (b8c7416d)

  • cargo fmt --check -p calternal-contacts-actions -p calternal-notes: pass.
  • cargo clippy --locked -p calternal-contacts-actions --all-targets -j4 -- -D warnings: pass.
  • cargo test --locked -p calternal-contacts-actions: 143 passed, 0 failed (includes kill9 and recovery tests).
  • cargo test --locked -p calternal-notes: 462 passed. The first full run failed once on contact_import_releases_excess_history_page_cache (process-wide SQLite memory under parallel load); alone it passes 3/3 on both this head and 544457b3, and the second full run was green.
  • cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points crash: pass.
  • Not mine: cargo clippy -p calternal-notes -- -D warnings on that crate alone fails on three feature-gated lines (meta.rs:1397, creates.rs:499, creates.rs:627) that exist at 544457b3.

What would still be needed for 0.5 s fresh

At the best run the path is ~100 ms pre-batch + 262 ms images + 144 ms finish + ~115 ms request/spool. Candidates, each ≤ 50 ms and below the noise: start the card image before the stage flush, overlap the source fsync with stage creation, fold the last parent-progress save into done. None reaches 0.5 s alone. Meeting it on this disk needs fewer files or fewer full syncs; that is a plan decision for kayg. No merge; PR stays draft.

## S1 device-latency follow-up at `b8c7416d` Commits since `544457b3`: `b74b5f8a` (profile points), `3ea7d960` (bench `CONTACT_BENCH_SETTLE`), `30d1e3d3` (the fix), `b8c7416d` (fmt). Code change is one commit: `30d1e3d3`. **The 0.5 s fresh target is still not met; I changed no plan text and no durability step.** ### 1. Re-import planning gap (323 ms vs 21 ms) — found and fixed `whole_import` starts after planning, so it never counted it. For every known card, `import_update` read the contact **note file** (`contact_note_in_home`) before comparing the stored original with the incoming bytes. Profile, 1,000 repeat: `note_read_ms` 503 and 597 (two runs), `companion_read_ms` 33–36. An exact replay needs only the stored card, so the compare now runs first and the note is read only when the card changed (a cheap live-index check stays). After: `note_read_ms` 0, `companion_read_ms` 23–27, `plan_import` 36–41 ms. ### 2. History/publication swing (250 ms → 1.6 s) — storage latency, not work per card Same code, same cards, profiled runs (ms): | Part | Good run | Slow run | |---|---:|---:| | history txn, statements run | 8.8 | 98 | | history txn, commit | 35 | 54–103 | | note image wait (1,000 file creates) | 194 | 130–644 | | card-copy image (1,000 file creates) | 262 | 292–757 | | volume sync (`fsync_volume_np` FULLSYNC) | 139 | 157–300 | | outcome commit (stage SQLite) | 3 | 109–192 | Probe on the Mac VM (3 passes): `write+fsync` 4 KB median 1.8–2.1 ms; **`F_FULLFSYNC` median 69–110 ms, p90 154–207 ms, max 5.5 s**; creating 100 small files single-threaded median 163–181 ms (≈1.7 ms per file). The fresh path has ~8 sequential full-sync waits (source spool, stage flush, history start, volume sync, history finish, outcome, parent progress, done) plus 2,000 file creates. Each wait or create burst swings 2–5× between runs, so the sum swings the same. Other VMs share the Studio's disk; the same fresh code measured 0.88–1.66 s here and 0.52–2.10 s earlier. Batched history entry: the import already writes one job row per 1,024-card batch. The per-card rows are each note's own first version, seed and card original; undo, recovery and per-note history read them, so one "Imported 1,000 contacts" record cannot replace them without dropping per-note history. Their cost is the 9–98 ms statement run, not the swing. No plan change proposed. Card-copy images: already built in parallel with the history transaction (`state_copy_ms` overlaps `child_plan_journal_ms`), and `done` must wait for them to be durable. Writing them after the cards are visible does not shorten the import. A real saving would need fewer files (for example one packed state file), which changes the plan; not done. ### Mac VM, 5 runs each, interleaved, `contacts_bench` release (seconds; median [min–max]) Fresh code is identical before and after, so its differences are host noise. Only "again" changed. | Cards | Fresh before `544457b3` | Fresh after `30d1e3d3` | Again before | Again after | |---:|---|---|---|---| | 100 | 0.31 [0.23–1.94] | 0.22 [0.21–0.26] | 0.18 [0.12–0.52] | **0.10 [0.09–0.11]** | | 1,000 | 0.86 [0.80–1.66] | 1.23 [0.88–3.98] | 0.60 [0.57–0.95] | **0.21 [0.18–0.57]** | | 10,000 | 24.2 [12.6–44.5] | 14.1 [9.1–17.9] | 10.9 [6.3–47.6] | **0.91 [0.86–1.16]** | (The Mac was slower than on 11-02 for the whole window; the 10,000 fresh run was 7.1 s then.) ### Gates, dev-01 (`b8c7416d`) - `cargo fmt --check -p calternal-contacts-actions -p calternal-notes`: pass. - `cargo clippy --locked -p calternal-contacts-actions --all-targets -j4 -- -D warnings`: pass. - `cargo test --locked -p calternal-contacts-actions`: 143 passed, 0 failed (includes kill9 and recovery tests). - `cargo test --locked -p calternal-notes`: 462 passed. The first full run failed once on `contact_import_releases_excess_history_page_cache` (process-wide SQLite memory under parallel load); alone it passes 3/3 on both this head and `544457b3`, and the second full run was green. - `cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points crash`: pass. - Not mine: `cargo clippy -p calternal-notes -- -D warnings` on that crate alone fails on three feature-gated lines (`meta.rs:1397`, `creates.rs:499`, `creates.rs:627`) that exist at `544457b3`. ### What would still be needed for 0.5 s fresh At the best run the path is ~100 ms pre-batch + 262 ms images + 144 ms finish + ~115 ms request/spool. Candidates, each ≤ 50 ms and below the noise: start the card image before the stage flush, overlap the source fsync with stage creation, fold the last parent-progress save into `done`. None reaches 0.5 s alone. Meeting it on this disk needs fewer files or fewer full syncs; that is a plan decision for kayg. No merge; PR stays draft.
Author
Owner

IM1 plan: pack each import batch's state copies (kayg 11-03)

Base: b8c7416d. Overlap check: no other open PR touches crates/contacts-actions cards/copy/import (searched open PRs 11-04). I build on #817's branch.

What the code does today (so the change stays small)

  • The authoritative original card of a contact is its history companion (calternal_notes::history::Companion), staged by the import plan and applied in the note's own history transaction: already one transaction per 1,024-card batch, no per-card file.
  • Re-import, dedupe, undo and Contacts::read (the export calternaldav serves, built by Contact::from_note(note, OriginalCard)) all read the companion from history. None of them reads a file.
  • The per-contact file contacts/raw/<id>.vcf is a derived copy "for tools and for rebuilding caches". Imports create 1 note file + 1 of these copies per contact: the 2,000 creates.

So IM1 is: the import writes its copies as one pack per batch instead of N .vcf files. Notes stay one markdown file each. History stays the merge base (the incoming card, exact bytes), so identical re-imports still never touch local edits. No change to what calternaldav serves (generated from the note + original), and the packed bytes are what keeps X- fields and odd labels, as the companion does today.

Pack format (contacts/raw/packs/<batch-tag>.pack, tag = blake3(child job id))

"CALPACK1\n"                                   magic + version (9 B)
record*   = id_len u8 | id | len u32 LE | card bytes | blake3[..8] of (id|bytes)
index     = count u32 | (id_len u8 | id | offset u64 | len u32)* sorted by id
trailer   = index_offset u64 | blake3[..16] of index | "CALPACKE"   (32 B)
  • Written once into a temp file and renamed (existing fsio::replace_many_deferred), so a pack is never visible half-written. A sealed pack is never modified (append-only across batches: every batch adds a new pack).
  • One fsync for the pack, folded into the batch's existing deferred sync with the Home notes (finish_with_deferred_files): no extra durable wait, and 1 file create instead of N.
  • Lookup: loose <id>.vcf wins (newer, written by the copier after an edit); else scan pack trailers → binary search the index → read one record → verify its checksum. O(P pack opens + log N). Only a fallback/tool path, history is the normal read.
  • scan/sweep: ids from loose files and from each pack's index, one pack in memory at a time (index ≈ 60 B × ≤1,024).
  • Sweep of gone contacts: a pack with dead ids is rewritten without them (temp+rename+dir sync); an all-dead pack is deleted.

Sizes

Batch ≤ 1,024 cards / 1 MiB payload (+ one oversized card): pack build is O(batch bytes), index ≤ ~64 KiB per pack. Files per 1,000-card import: 1 pack instead of 1,000. Peak extra memory: one batch of card bytes (already held).

Finding a card's original

Caller Source Change
Export / calternaldav read history companion, then loose, then pack pack added last
Re-import / dedupe (known UID) history companion keys + companion bytes none; compare runs before the note read (30d1e3d3)
Undo history rows (Again), notes removed; copies swept pack entries swept like loose files
Recovery after crash rows still unwritten in history → copy_now rewrites copies (loose) none

Failure table

Failure Effect Detection Recovery Test
Crash before the pack is renamed No pack; rows still unwritten history unwritten copy_now writes loose copies kill-9 mid-batch (existing kill9 test, extended)
Crash after rename, before dir sync Pack present or absent trailer checks present: reads fine; absent: as above crash-point test at Copied
Torn/corrupt pack on disk (bad trailer or record sum) That pack ignored; record read errors magic, trailer sum, record sum fall back to history companion; copy_now rewrites corrupt-byte tests (each section)
Retry of the same batch Same tag, same bytes, pack replaced n/a idempotent retry test
Contact edited after import Loose copy newer than pack loose-first rule n/a edit-then-read test
Undo / delete forever Dead entries in a pack sweep compaction / delete sweep tests
Trash conflict in batch No pack written existing check whole batch on copy_now existing
Disk full while writing pack Import batch errors before done write error resume/undo from last durable batch existing final-flush tests

Gates

fmt; clippy -D warnings on calternal-contacts-actions; cargo test -p calternal-contacts-actions; notes crash tests (-p calternal-notes -p calternal-contacts-actions --features crash-points crash); new: pack unit tests, kill-mid-batch, round trip (import → edit in app → export → re-import: nothing lost, edit kept). Mac VM (idle control first, lock with EXIT trap): 100 / 1,000 / 10,000 fresh and re-import, peak RSS, 5 runs at 1,000, target ≤ 0.5 s median fresh. If the target is still missed I report the remaining waits; no durability step is dropped.

## IM1 plan: pack each import batch's state copies (kayg 11-03) Base: `b8c7416d`. Overlap check: no other open PR touches `crates/contacts-actions` cards/copy/import (searched open PRs 11-04). I build on #817's branch. ### What the code does today (so the change stays small) - The authoritative original card of a contact is its **history companion** (`calternal_notes::history::Companion`), staged by the import plan and applied in the note's own history transaction: already one transaction per 1,024-card batch, no per-card file. - Re-import, dedupe, undo and `Contacts::read` (the export calternaldav serves, built by `Contact::from_note(note, OriginalCard)`) all read the companion from history. None of them reads a file. - The per-contact file `contacts/raw/<id>.vcf` is a derived copy "for tools and for rebuilding caches". Imports create 1 note file + 1 of these copies per contact: the 2,000 creates. So IM1 is: **the import writes its copies as one pack per batch instead of N `.vcf` files.** Notes stay one markdown file each. History stays the merge base (the incoming card, exact bytes), so identical re-imports still never touch local edits. No change to what calternaldav serves (generated from the note + original), and the packed bytes are what keeps X- fields and odd labels, as the companion does today. ### Pack format (`contacts/raw/packs/<batch-tag>.pack`, tag = blake3(child job id)) ``` "CALPACK1\n" magic + version (9 B) record* = id_len u8 | id | len u32 LE | card bytes | blake3[..8] of (id|bytes) index = count u32 | (id_len u8 | id | offset u64 | len u32)* sorted by id trailer = index_offset u64 | blake3[..16] of index | "CALPACKE" (32 B) ``` - Written once into a temp file and renamed (existing `fsio::replace_many_deferred`), so a pack is **never visible half-written**. A sealed pack is never modified (append-only across batches: every batch adds a new pack). - One fsync for the pack, folded into the batch's existing deferred sync with the Home notes (`finish_with_deferred_files`): **no extra durable wait**, and 1 file create instead of N. - Lookup: loose `<id>.vcf` wins (newer, written by the copier after an edit); else scan pack trailers → binary search the index → read one record → verify its checksum. O(P pack opens + log N). Only a fallback/tool path, history is the normal read. - `scan`/sweep: ids from loose files and from each pack's index, one pack in memory at a time (index ≈ 60 B × ≤1,024). - Sweep of gone contacts: a pack with dead ids is rewritten without them (temp+rename+dir sync); an all-dead pack is deleted. ### Sizes Batch ≤ 1,024 cards / 1 MiB payload (+ one oversized card): pack build is O(batch bytes), index ≤ ~64 KiB per pack. Files per 1,000-card import: 1 pack instead of 1,000. Peak extra memory: one batch of card bytes (already held). ### Finding a card's original | Caller | Source | Change | |---|---|---| | Export / calternaldav read | history companion, then loose, then pack | pack added last | | Re-import / dedupe (known UID) | history companion keys + companion bytes | none; compare runs before the note read (30d1e3d3) | | Undo | history rows (`Again`), notes removed; copies swept | pack entries swept like loose files | | Recovery after crash | rows still `unwritten` in history → `copy_now` rewrites copies (loose) | none | ### Failure table | Failure | Effect | Detection | Recovery | Test | |---|---|---|---|---| | Crash before the pack is renamed | No pack; rows still `unwritten` | history `unwritten` | `copy_now` writes loose copies | kill-9 mid-batch (existing kill9 test, extended) | | Crash after rename, before dir sync | Pack present or absent | trailer checks | present: reads fine; absent: as above | crash-point test at `Copied` | | Torn/corrupt pack on disk (bad trailer or record sum) | That pack ignored; record read errors | magic, trailer sum, record sum | fall back to history companion; `copy_now` rewrites | corrupt-byte tests (each section) | | Retry of the same batch | Same tag, same bytes, pack replaced | n/a | idempotent | retry test | | Contact edited after import | Loose copy newer than pack | loose-first rule | n/a | edit-then-read test | | Undo / delete forever | Dead entries in a pack | sweep | compaction / delete | sweep tests | | Trash conflict in batch | No pack written | existing check | whole batch on `copy_now` | existing | | Disk full while writing pack | Import batch errors before `done` | write error | resume/undo from last durable batch | existing final-flush tests | ### Gates fmt; clippy `-D warnings` on `calternal-contacts-actions`; `cargo test -p calternal-contacts-actions`; notes crash tests (`-p calternal-notes -p calternal-contacts-actions --features crash-points crash`); new: pack unit tests, kill-mid-batch, round trip (import → edit in app → export → re-import: nothing lost, edit kept). Mac VM (idle control first, lock with EXIT trap): 100 / 1,000 / 10,000 fresh and re-import, peak RSS, 5 runs at 1,000, target ≤ 0.5 s median fresh. If the target is still missed I report the remaining waits; no durability step is dropped.
Author
Owner

IM1 interim: packed card copies at f97cec7e (gates pending)

Commits on this branch: 44b0a091 (pack), 604c0fa2 (fmt), f97cec7e (tests). Plan: #issuecomment-77312. A pack is one file per import batch in contacts/raw/packs/; format and failure table as in the plan. Two notes beyond the plan:

  • A corrupt pack at rest is ignored (history serves the card); copy_now repairs only copies history still marks unwritten, so there is no auto-rewrite of a corrupted, already-marked pack. It is a derived copy, so nothing user-visible depends on it.
  • Re-import and dedupe never read these files (they use history companions), so the identical-re-import rule is unchanged.

Files per import (state folder, from the runs below)

Cards Before After
100 121 22
1,000 1,021 22
10,000 10,021 31

(the base ~20 files are the stage SQLite, journals, history; 1 pack per 1,024-card batch)

Mac VM (macos-01-std), release contacts_bench, old = b8c7416d, new = f97cec7e, ABAB-interleaved, lock held with an EXIT trap

Idle control before: F_FULLFSYNC 4 KiB median 66 ms, p90 105 ms, max 389 ms (after: 41 / 157 / 482 ms). The host disk was heavily contended for the whole window (old 10,000 fresh took 10–60 s against 7–14 s on 11-02), so absolute times are far above the 11-03 report; compare old to new only.

Seconds, median [min–max]:

Cards Fresh old Fresh new Again old Again new Peak RSS old → new
100 (4 rounds) 0.86 [0.23–1.49] 0.79 [0.19–1.56] 0.21 [0.12–0.29] 0.36 [0.10–0.66] 20.6 → 20.8 MiB
1,000 (6 rounds) 4.14 [2.13–5.88] 2.82 [2.15–3.12] 0.28 [0.15–1.40] 0.43 [0.38–0.71] 35.5 → 35.5 MiB
10,000 (3 rounds) 59.7 [10.3–60.0] 26.8 [12.5–26.9] 3.13 [1.82–7.03] 1.81 [1.52–2.23] 60.2 → 59.6 MiB

1,000 cards again, two more A/B sets (8 and 10 rounds, the second with sync; sleep 4 before each run): old 0.26 [0.20–1.00] / 0.76 [0.19–1.73], new 0.41 [0.19–0.93] / 0.59 [0.22–1.23]. The re-import code path is byte-for-byte the same in both (it never reads card copies); the profile of matching runs shows the same stages and the gap is fsync swings (source_stage_file_sync 39 vs 142 ms in runs of the same code). I see no regression, but I will repeat it on a quiet disk before calling it flat.
1,000 fresh, those two sets: old 3.14 [0.88–41.1] / 5.7 [0.75–14.6], new 1.06 [0.45–3.59] / 2.35 [0.51–5.49].

Where the time went (CONTACTS_IMPORT_PROFILE, 1,000 fresh)

Part old (typical) new
card copies (state_copy_ms) 309–583 ms 2.9–5.6 ms
batch total 759–1,140 ms 323–400 ms (best), 1,158 ms in a slow-disk run
volume_sync_ms (1 call) 136–194 ms 114–152 ms (492 ms when the disk stalled)

The best new run took 0.454 s end to end (batch 323 ms); the 0.5 s target is met on a quiet moment, not as a median over 5 runs on this disk today (the remaining time is ~6 durable waits whose individual cost swings 30 → 490 ms: source sync, stage flush, history commits, volume sync, outcome, parent). I changed no durability step. Next candidates are the ones named in the previous report (overlap source fsync with stage creation, fold the last parent save into done); each is below the noise here, so I want a quiet-disk window before spending more code on them.

Gates (fmt/clippy/tests on dev-01) are queued behind train BM14d, which has held every slot for hours; results follow here.

## IM1 interim: packed card copies at `f97cec7e` (gates pending) Commits on this branch: `44b0a091` (pack), `604c0fa2` (fmt), `f97cec7e` (tests). Plan: #issuecomment-77312. A pack is one file per import batch in `contacts/raw/packs/`; format and failure table as in the plan. Two notes beyond the plan: - A corrupt pack at rest is ignored (history serves the card); `copy_now` repairs only copies history still marks unwritten, so there is no auto-rewrite of a corrupted, already-marked pack. It is a derived copy, so nothing user-visible depends on it. - Re-import and dedupe never read these files (they use history companions), so the identical-re-import rule is unchanged. ### Files per import (state folder, from the runs below) | Cards | Before | After | |---:|---:|---:| | 100 | 121 | 22 | | 1,000 | 1,021 | 22 | | 10,000 | 10,021 | 31 | (the base ~20 files are the stage SQLite, journals, history; 1 pack per 1,024-card batch) ### Mac VM (`macos-01-std`), release `contacts_bench`, old = `b8c7416d`, new = `f97cec7e`, ABAB-interleaved, lock held with an EXIT trap Idle control before: `F_FULLFSYNC` 4 KiB median 66 ms, p90 105 ms, max 389 ms (after: 41 / 157 / 482 ms). The host disk was **heavily contended for the whole window** (old 10,000 fresh took 10–60 s against 7–14 s on 11-02), so absolute times are far above the 11-03 report; compare old to new only. Seconds, median [min–max]: | Cards | Fresh old | Fresh new | Again old | Again new | Peak RSS old → new | |---:|---|---|---|---|---| | 100 (4 rounds) | 0.86 [0.23–1.49] | 0.79 [0.19–1.56] | 0.21 [0.12–0.29] | 0.36 [0.10–0.66] | 20.6 → 20.8 MiB | | 1,000 (6 rounds) | 4.14 [2.13–5.88] | **2.82 [2.15–3.12]** | 0.28 [0.15–1.40] | 0.43 [0.38–0.71] | 35.5 → 35.5 MiB | | 10,000 (3 rounds) | 59.7 [10.3–60.0] | **26.8 [12.5–26.9]** | 3.13 [1.82–7.03] | 1.81 [1.52–2.23] | 60.2 → 59.6 MiB | 1,000 cards again, two more A/B sets (8 and 10 rounds, the second with `sync; sleep 4` before each run): old 0.26 [0.20–1.00] / 0.76 [0.19–1.73], new 0.41 [0.19–0.93] / 0.59 [0.22–1.23]. The re-import code path is byte-for-byte the same in both (it never reads card copies); the profile of matching runs shows the same stages and the gap is fsync swings (`source_stage_file_sync` 39 vs 142 ms in runs of the same code). I see no regression, but I will repeat it on a quiet disk before calling it flat. 1,000 fresh, those two sets: old 3.14 [0.88–41.1] / 5.7 [0.75–14.6], new **1.06 [0.45–3.59]** / 2.35 [0.51–5.49]. ### Where the time went (`CONTACTS_IMPORT_PROFILE`, 1,000 fresh) | Part | old (typical) | new | |---|---:|---:| | card copies (`state_copy_ms`) | 309–583 ms | **2.9–5.6 ms** | | batch total | 759–1,140 ms | 323–400 ms (best), 1,158 ms in a slow-disk run | | `volume_sync_ms` (1 call) | 136–194 ms | 114–152 ms (492 ms when the disk stalled) | The best new run took **0.454 s** end to end (batch 323 ms); the 0.5 s target is met on a quiet moment, **not** as a median over 5 runs on this disk today (the remaining time is ~6 durable waits whose individual cost swings 30 → 490 ms: source sync, stage flush, history commits, volume sync, outcome, parent). I changed no durability step. Next candidates are the ones named in the previous report (overlap source fsync with stage creation, fold the last parent save into `done`); each is below the noise here, so I want a quiet-disk window before spending more code on them. Gates (fmt/clippy/tests on dev-01) are queued behind train BM14d, which has held every slot for hours; results follow here.
Author
Owner

IM1 gates at e07d4dca (code unchanged since 44b0a091; later commits are tests and fmt)

dev-01, all through ~/bin/slot, in the Nix dev shell:

Gate Command Result
fmt cargo fmt --check -p calternal-contacts-actions pass
clippy cargo clippy --locked -p calternal-contacts-actions --all-targets -j4 -- -D warnings pass
contacts-actions cargo test --locked -p calternal-contacts-actions -j4 153 passed, 0 failed
crash tests cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points -j4 crash 3 + 12 passed
notes cargo test --locked -p calternal-notes -j4 462 passed, 6 ignored (as before)

New tests: pack::tests (round trip, empty cards, every single-byte flip caught, torn pack refused), cards::tests (one file per batch, loose beats pack, retry is idempotent, compaction and deletion on sweep, corrupt pack reads as absent), tests::pack::an_import_keeps_its_copies_in_one_pack, and tests::pack::import_edit_export_import_again_loses_nothing_and_keeps_the_edit (import with an X- field and an odd label, edit the phone in the app, export, identical re-import: 120 unchanged, version and text of the edited note identical, the export still has 999 and both unshown fields, and the export is the same with every pack deleted).
Kill/recovery/undo coverage, all green with packs in the path: kill9::import_killed_mid_batch_recovers_each_card_once_and_undoes, import_killed_copying, import_killed_committed, import_killed_mid_import, import_killed_planned/prepared, mixed_import_resumes_and_undoes_after_each_contact_boundary; Env::check verifies on every step that each live contact's copy (loose or packed) equals its history card.

Finding while writing the round trip: after an app edit, the note gets a title: line added about 0.4 s later by its own background work (version +1). It is not the import (a no-import control shows it); the test waits for the note to settle first.

Mac numbers are in the interim comment (#issuecomment-77345). Summary: state files per import 1,021 → 22 (1,000 cards); card copy step 309–583 ms → 3–6 ms; 1,000 fresh median 4.1 s → 2.8 s (6 rounds) and 3.1 s → 1.1 s / 5.7 s → 2.4 s (two more sets) on a heavily contended disk; best run 0.454 s. The "≤ 0.5 s median over 5 runs" target is NOT met on this disk today: the rest is ~6 durable waits that each swing 30–490 ms. Re-import and 10,000-card numbers are flat-or-better, RSS flat (35.5 → 35.5 MiB at 1,000; 60.2 → 59.6 MiB at 10,000). Needs a quiet-disk window to confirm; no durability step was removed.

No merge.

## IM1 gates at `e07d4dca` (code unchanged since `44b0a091`; later commits are tests and fmt) dev-01, all through `~/bin/slot`, in the Nix dev shell: | Gate | Command | Result | |---|---|---| | fmt | `cargo fmt --check -p calternal-contacts-actions` | pass | | clippy | `cargo clippy --locked -p calternal-contacts-actions --all-targets -j4 -- -D warnings` | pass | | contacts-actions | `cargo test --locked -p calternal-contacts-actions -j4` | 153 passed, 0 failed | | crash tests | `cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points -j4 crash` | 3 + 12 passed | | notes | `cargo test --locked -p calternal-notes -j4` | 462 passed, 6 ignored (as before) | New tests: `pack::tests` (round trip, empty cards, every single-byte flip caught, torn pack refused), `cards::tests` (one file per batch, loose beats pack, retry is idempotent, compaction and deletion on sweep, corrupt pack reads as absent), `tests::pack::an_import_keeps_its_copies_in_one_pack`, and `tests::pack::import_edit_export_import_again_loses_nothing_and_keeps_the_edit` (import with an X- field and an odd label, edit the phone in the app, export, identical re-import: 120 unchanged, version and text of the edited note identical, the export still has 999 and both unshown fields, and the export is the same with every pack deleted). Kill/recovery/undo coverage, all green with packs in the path: `kill9::import_killed_mid_batch_recovers_each_card_once_and_undoes`, `import_killed_copying`, `import_killed_committed`, `import_killed_mid_import`, `import_killed_planned/prepared`, `mixed_import_resumes_and_undoes_after_each_contact_boundary`; `Env::check` verifies on every step that each live contact's copy (loose or packed) equals its history card. Finding while writing the round trip: after an app edit, the note gets a `title:` line added about 0.4 s later by its own background work (version +1). It is not the import (a no-import control shows it); the test waits for the note to settle first. Mac numbers are in the interim comment (#issuecomment-77345). Summary: state files per import 1,021 → 22 (1,000 cards); card copy step 309–583 ms → 3–6 ms; 1,000 fresh median 4.1 s → 2.8 s (6 rounds) and 3.1 s → 1.1 s / 5.7 s → 2.4 s (two more sets) on a heavily contended disk; best run **0.454 s**. **The "≤ 0.5 s median over 5 runs" target is NOT met on this disk today**: the rest is ~6 durable waits that each swing 30–490 ms. Re-import and 10,000-card numbers are flat-or-better, RSS flat (35.5 → 35.5 MiB at 1,000; 60.2 → 59.6 MiB at 10,000). Needs a quiet-disk window to confirm; no durability step was removed. No merge.
Author
Owner

Independent review: IM1 card packs at e07d4dca

Scope: 44b0a091 (pack write) + 30d1e3d3 (exact-replay compare moved before the note read) + the pack tests. Read only. I built and ran nothing.

Bottom line: I found no path where a contact's note or its history card (the companion) is lost, corrupted or wrongly overwritten. The reason is that packs aren't on any read path that matters. Contacts::read (write.rs:524-527) and import_update (import.rs:686-699) both read the history companion. Companion rows stay until the contact is deleted forever (notes/src/history/companions.rs:17-18). Cards::read is reached only through copy_or_empty (write.rs:542-546), and only when there is no companion: legacy contacts, never an imported one. calternaldav export and undo therefore can't lose X- fields because of a pack. The …export is the same with every pack deleted assertion in the round-trip test shows this. The findings below are about the copies themselves: the guarantee as written, deleting data, and cost.

Crash at every point (create-only batch, import/commit.rs:241-302)

Point On disk Recovery OK?
before pack rename temp file only job not done → bulk::undo / resume; rows not copied yes (temp file: see P3-1)
after rename, before volume sync pack may or may not exist job not done → undone or resumed with the same tag and bytes; an extra pack holds undone ids until the sweep yes
after sync (creates.rs:628-636, pack + notes in one sync_deferred), before history done both durable same as above yes
after done, before mark_job_written_soon (commit.rs:300-302) pack durable, rows still unwritten copy_now writes loose copies with the same bytes, and loose wins yes
pack write/sync error — sync_related_files turns it into a job failure → batch undone (jobs.rs:124) yes (same as before IM1)

Pack and notes are never durable one without the other at done: there is one volume sync for both, and the history commit comes after it. The new packs/ folder relies on that volume sync (syncfs / full flush) to make its directory entry durable. That's fine on Linux and macOS.

Re-import rule: correct

import_update resolves the target id from the known UID first. It then checks the stored companion's identity (import.rs:691) and compares the exact bytes against that companion (:697) before it reads the note. The merge base stays incoming.to_vec() (:731). An identical re-import returns Ok(None) and never touches the note or history, so local edits survive. One side effect of the reorder is P3-4.

P2

P2-1. The failure table and module doc promise a recovery that doesn't exist. pack.rs:16-17 says "A pack that fails a check is treated as absent; the copier then rewrites the copies from history". The plan's table says the same ("fall back to history companion; copy_now rewrites"). But copy_now (copy.rs:40-46) only reads history rows still marked unwritten, and mark_job_written_soon already marked this batch written. Nothing notices a bad pack or resets those rows.
Scenario: a bit flip or torn sector in packs/<tag>.pack → Scan and read skip it with a warning (cards.rs:70, :102) → up to 1,024 live contacts permanently have no file copy. That breaks the invariant Env::check asserts in tests ("every live contact's copy equals its history card"), and in production nobody would notice. The contact data is safe (history), but the "for tools / rebuilding caches" copy the ADR promises is gone without a trace.
Fix: either (a) when the scan or sweep finds an unreadable pack, re-mark the companion rows of its contacts unwritten, so copy_now rewrites them as loose copies (pack ids are unknown, so do it per job from the tag, or keep a tag→job mapping), or (b) fix the doc and the failure table to say that the copy is lost and only history holds the card. Either way, add a test: corrupt the pack → contact still exports → copy state is whatever the doc claims.

P2-2. An unreadable pack keeps deleted contacts' cards forever, and one bad record stops the whole sweep.

  • drop_from_packs skips a pack that fails open (cards.rs:220-222), and Scan never lists its ids. Cards of contacts that were deleted forever stay on disk in it. That breaks "delete forever" for personal data (names, phones, X- fields), and nothing ever removes the file.
  • If the index is valid but one record is bad, p.all()? (cards.rs:226) fails → remove_many fails → sweep returns an error (copy.rs:117) at that batch on every hourly run. Later batches never run. Their loose files are already unlinked, but the folder sync and every later pack's compaction are skipped.
    Fix: compact while skipping bad records (keep the records that check out, drop the rest), and delete a pack that can't be opened once its job's contacts are all gone or have been re-copied (ties to P2-1). Add tests: one bad record, then a sweep that also has gone ids in another pack.

P3

  1. Leftover temp packs show up as packs. temp_path names the temp file .calternal-tmp-<unique>-<tag>.pack (fsio/src/lib.rs temp_path). The .pack extension passes pack_paths (cards.rs:165). After a crash mid-write, a torn temp file gets a warning on every scan or read fallback and is never removed (nothing sweeps TEMP_PREFIX under contacts/raw). A fully written temp file that was never renamed is a second valid pack, so its ids are scanned twice. Skip names starting with TEMP_PREFIX in pack_paths and delete them in the sweep.
  2. build accepts duplicate ids that parse then refuses (pack.rs:55 vs :176, >=). If a create-only batch ever stages one id twice, the write succeeds, the rows are marked written, and the whole pack can't be read (P2-1 then applies). I don't see a way to get duplicates today, but make build return an error so it fails at write time.
  3. Cost of the sweep and of many packs. Every remove_many with gone ids opens and hashes every pack (cards.rs:218), so a sweep costs O(sweep batches × packs). Each pack holding one gone id is rewritten (~1 MiB) with its own volume sync, inside person.writing, so imports and edits wait for it. Packs are never merged: many small imports (1 card each) leave one tiny pack each, and the legacy read fallback opens all of them. Not a correctness bug. It's worth a gate in the perf run: delete forever 1 contact in a book of 20 packs, plus 200 one-card imports.
  4. The exact-replay check now runs before the "is this still a contact" check (import.rs:679-699 vs write.rs:592). A UID-matched note whose format: contact the person removed used to be refused ("not a contact"). It now reports "unchanged". No write and no loss, only a different report. Keep the format check before the early return, or note the change.
  5. Several docs still say one .vcf per contact: contacts/src/lib.rs:3, contacts/src/note_io.rs:10, notes/src/history/companions.rs:19-20, cards.rs:6-8. Also, Cards::read returns the first pack in tag-hash order when two packs hold the same id (cards.rs:98), not the newest. That only matters for the legacy path, but the doc should say "any".

Other questions from the brief

  • Sweep vs a running import: the two can't overlap. Both hold person.writing (import.rs:129, copy.rs:87) for the whole import, and the pack task is awaited before the batch returns (commit.rs:282-286). Notes-level undo/redo doesn't take that lock. It can race the sweep (compact out an id that a redo brings back), but redo's companion rows are new unwritten rows, so copy_now writes a loose copy again. That race already existed for loose files.
  • Dedupe / undo across packs: packs are written only for create-only batches (commit.rs:191, :213-220). Updates, merges and undo copies go loose through copy_now, and loose wins. A contact therefore never has a newer card in a pack than in its loose copy. Undone or merged-away contacts stay in the pack until purged from the Trash, then the sweep removes them (subject to P2-2).
  • 10k+ imports: each batch holds ≤ 1,024 cards / 1 MiB (+1 oversized card). Peak memory during the pack write is staged bytes + the copy_batch clone + the built pack, about 3× batch bytes, bounded and independent of import size. A 20k import makes ≤ 20 packs. The index is capped at 16 MiB. The 10k RSS numbers in #issuecomment-77386 (60.2 → 59.6 MiB) are consistent with this.

Verdict

No P1. Contacts and their original cards are safe in every crash, sync, re-import, dedupe and undo case I traced. Request changes before merge: 2 × P2 (fix P2-1, either the recovery or the doc and failure table, and P2-2, so a bad pack can't keep deleted cards or stop the sweep), plus 5 × P3 (P3-1 and P3-2 are small and worth doing in the same pass). Separately, the PR's own "≤ 0.5 s median" gate is still unmet according to the gates comment. No merge.

## Independent review: IM1 card packs at `e07d4dca` Scope: `44b0a091` (pack write) + `30d1e3d3` (exact-replay compare moved before the note read) + the pack tests. Read only. I built and ran nothing. **Bottom line: I found no path where a contact's note or its history card (the companion) is lost, corrupted or wrongly overwritten.** The reason is that packs aren't on any read path that matters. `Contacts::read` (`write.rs:524-527`) and `import_update` (`import.rs:686-699`) both read the history companion. Companion rows stay until the contact is deleted forever (`notes/src/history/companions.rs:17-18`). `Cards::read` is reached only through `copy_or_empty` (`write.rs:542-546`), and only when there is **no** companion: legacy contacts, never an imported one. calternaldav export and undo therefore can't lose X- fields because of a pack. The `…export is the same with every pack deleted` assertion in the round-trip test shows this. The findings below are about the copies themselves: the guarantee as written, deleting data, and cost. ### Crash at every point (create-only batch, `import/commit.rs:241-302`) | Point | On disk | Recovery | OK? | |---|---|---|---| | before pack rename | temp file only | job not done → `bulk::undo` / resume; rows not copied | yes (temp file: see P3-1) | | after rename, before volume sync | pack may or may not exist | job not done → undone or resumed with the same tag and bytes; an extra pack holds undone ids until the sweep | yes | | after sync (`creates.rs:628-636`, pack + notes in one `sync_deferred`), before history `done` | both durable | same as above | yes | | after `done`, before `mark_job_written_soon` (`commit.rs:300-302`) | pack durable, rows still `unwritten` | `copy_now` writes loose copies with the same bytes, and loose wins | yes | | pack write/sync error | — | `sync_related_files` turns it into a job failure → batch undone (`jobs.rs:124`) | yes (same as before IM1) | Pack and notes are never durable one without the other at `done`: there is one volume sync for both, and the history commit comes after it. The new `packs/` folder relies on that volume sync (syncfs / full flush) to make its directory entry durable. That's fine on Linux and macOS. ### Re-import rule: correct `import_update` resolves the target `id` from the known UID first. It then checks the stored companion's identity (`import.rs:691`) and compares the exact bytes against **that** companion (`:697`) before it reads the note. The merge base stays `incoming.to_vec()` (`:731`). An identical re-import returns `Ok(None)` and never touches the note or history, so local edits survive. One side effect of the reorder is P3-4. ### P2 **P2-1. The failure table and module doc promise a recovery that doesn't exist.** `pack.rs:16-17` says "A pack that fails a check is treated as absent; the copier then rewrites the copies from history". The plan's table says the same ("fall back to history companion; `copy_now` rewrites"). But `copy_now` (`copy.rs:40-46`) only reads history rows still marked `unwritten`, and `mark_job_written_soon` already marked this batch written. Nothing notices a bad pack or resets those rows. *Scenario:* a bit flip or torn sector in `packs/<tag>.pack` → `Scan` and `read` skip it with a warning (`cards.rs:70`, `:102`) → up to 1,024 live contacts permanently have no file copy. That breaks the invariant `Env::check` asserts in tests ("every live contact's copy equals its history card"), and in production nobody would notice. The contact data is safe (history), but the "for tools / rebuilding caches" copy the ADR promises is gone without a trace. *Fix:* either (a) when the scan or sweep finds an unreadable pack, re-mark the companion rows of its contacts `unwritten`, so `copy_now` rewrites them as loose copies (pack ids are unknown, so do it per `job` from the tag, or keep a tag→job mapping), or (b) fix the doc and the failure table to say that the copy is lost and only history holds the card. Either way, add a test: corrupt the pack → contact still exports → copy state is whatever the doc claims. **P2-2. An unreadable pack keeps deleted contacts' cards forever, and one bad record stops the whole sweep.** - `drop_from_packs` skips a pack that fails `open` (`cards.rs:220-222`), and `Scan` never lists its ids. Cards of contacts that were deleted forever stay on disk in it. That breaks "delete forever" for personal data (names, phones, X- fields), and nothing ever removes the file. - If the index is valid but one record is bad, `p.all()?` (`cards.rs:226`) fails → `remove_many` fails → `sweep` returns an error (`copy.rs:117`) at that batch on **every** hourly run. Later batches never run. Their loose files are already unlinked, but the folder sync and every later pack's compaction are skipped. *Fix:* compact while skipping bad records (keep the records that check out, drop the rest), and delete a pack that can't be opened once its job's contacts are all gone or have been re-copied (ties to P2-1). Add tests: one bad record, then a sweep that also has gone ids in another pack. ### P3 1. **Leftover temp packs show up as packs.** `temp_path` names the temp file `.calternal-tmp-<unique>-<tag>.pack` (`fsio/src/lib.rs` `temp_path`). The `.pack` extension passes `pack_paths` (`cards.rs:165`). After a crash mid-write, a torn temp file gets a warning on every scan or read fallback and is never removed (nothing sweeps `TEMP_PREFIX` under `contacts/raw`). A fully written temp file that was never renamed is a second valid pack, so its ids are scanned twice. Skip names starting with `TEMP_PREFIX` in `pack_paths` and delete them in the sweep. 2. **`build` accepts duplicate ids that `parse` then refuses** (`pack.rs:55` vs `:176`, `>=`). If a create-only batch ever stages one id twice, the write succeeds, the rows are marked written, and the whole pack can't be read (P2-1 then applies). I don't see a way to get duplicates today, but make `build` return an error so it fails at write time. 3. **Cost of the sweep and of many packs.** Every `remove_many` with gone ids opens and hashes **every** pack (`cards.rs:218`), so a sweep costs O(sweep batches × packs). Each pack holding one gone id is rewritten (~1 MiB) with its own volume sync, inside `person.writing`, so imports and edits wait for it. Packs are never merged: many small imports (1 card each) leave one tiny pack each, and the legacy `read` fallback opens all of them. Not a correctness bug. It's worth a gate in the perf run: delete forever 1 contact in a book of 20 packs, plus 200 one-card imports. 4. **The exact-replay check now runs before the "is this still a contact" check** (`import.rs:679-699` vs `write.rs:592`). A UID-matched note whose `format: contact` the person removed used to be refused ("not a contact"). It now reports "unchanged". No write and no loss, only a different report. Keep the `format` check before the early return, or note the change. 5. **Several docs still say one `.vcf` per contact:** `contacts/src/lib.rs:3`, `contacts/src/note_io.rs:10`, `notes/src/history/companions.rs:19-20`, `cards.rs:6-8`. Also, `Cards::read` returns the first pack in **tag-hash** order when two packs hold the same id (`cards.rs:98`), not the newest. That only matters for the legacy path, but the doc should say "any". ### Other questions from the brief - **Sweep vs a running import:** the two can't overlap. Both hold `person.writing` (`import.rs:129`, `copy.rs:87`) for the whole import, and the pack task is awaited before the batch returns (`commit.rs:282-286`). Notes-level undo/redo doesn't take that lock. It can race the sweep (compact out an id that a redo brings back), but redo's companion rows are new `unwritten` rows, so `copy_now` writes a loose copy again. That race already existed for loose files. - **Dedupe / undo across packs:** packs are written only for create-only batches (`commit.rs:191`, `:213-220`). Updates, merges and undo copies go loose through `copy_now`, and loose wins. A contact therefore never has a newer card in a pack than in its loose copy. Undone or merged-away contacts stay in the pack until purged from the Trash, then the sweep removes them (subject to P2-2). - **10k+ imports:** each batch holds ≤ 1,024 cards / 1 MiB (+1 oversized card). Peak memory during the pack write is staged bytes + the `copy_batch` clone + the built pack, about 3× batch bytes, bounded and independent of import size. A 20k import makes ≤ 20 packs. The index is capped at 16 MiB. The 10k RSS numbers in #issuecomment-77386 (60.2 → 59.6 MiB) are consistent with this. ### Verdict **No P1. Contacts and their original cards are safe in every crash, sync, re-import, dedupe and undo case I traced.** Request changes before merge: **2 × P2** (fix P2-1, either the recovery or the doc and failure table, and P2-2, so a bad pack can't keep deleted cards or stop the sweep), plus **5 × P3** (P3-1 and P3-2 are small and worth doing in the same pass). Separately, the PR's own "≤ 0.5 s median" gate is still unmet according to the gates comment. No merge.
Author
Owner

Fixes for the data-safety review (comment 77388)

Commits on feat/contacts-import-v2-s1 (after e07d4dca): 9696a046, 9f53c99e, 61922c2f, 493ed851, a11a232d, then style/clippy fixes, and 071db53f (docs).

P2-1 corrupt pack. The sweep now checks every pack whole (index and every record). For a pack that fails, history marks its import job's companions "not copied" (durably, first), then the pack is deleted, then the copier writes the cards as loose copies. The pack's file name is the job name in hex, so a damaged pack is traced back to its job even when its index is unreadable. Test a_corrupt_pack_is_copied_again_from_history: corrupt a record in one pack and the end mark of another, sweep, copy: all 80 copies byte-equal to history.

Failure table row now: pack fails a check → warning at read (treated as absent; history still answers) → the next sweep (hourly) marks its job unwritten, deletes the pack, copier rewrites loose copies → test above. Module docs in pack.rs and cards.rs say the same.

P2-2 sweep. An unreadable pack is rebuilt/deleted as above, so cards of contacts deleted forever do not stay (their rows are only marked, never written). A bad record inside a pack no longer fails the sweep: remove_many returns the damaged packs, logs, and carries on with the other packs; the sweep then rebuilds those. Tests: an_unreadable_pack_does_not_keep_forgotten_cards (index-damaged and record-damaged packs plus a forgotten contact; no file holds its card afterwards) and one_bad_record_does_not_stop_the_other_packs.

P3. 1: pack discovery only accepts hex-named <tag>.pack; leftover .calternal-tmp-* files are never packs and the sweep removes them (test). Note: I kept fsio's temp naming (it ends in .pack) and filter by name instead of changing the shared helper. 2: build refuses duplicate ids (test). 3: the scan now returns the pack each id is in, and remove_many opens only those packs (test: 10,000 cards in 10 packs, one delete rewrites exactly one pack). 4: the "is this still a contact" read is back before the exact-replay shortcut (test an_import_replay_of_a_note_that_is_no_longer_a_contact_is_refused); this gives back the note read that 30d1e3d3 had saved. 5: docs updated (contacts/src/lib.rs, note_io.rs, history/companions.rs, cards.rs, ADR 0063, 0064).

Also fixed three clippy errors that were already on the branch (creates.rs test module position, fsio tests useless vec) because the gate is -D warnings.

Gates (dev-01)

  • cargo fmt --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test -p calternal-contacts-actions: 162 passed, 0 failed (includes the kill9 and crash-point tests and the new tests)
  • cargo test -p calternal-notes: 462 passed. First run had 1 failure, history::tests::contact_import_releases_excess_history_page_cache (memory-retention check); passes alone 3/3 and in a full rerun. It looks load-sensitive in a parallel run; I did not touch that code.

Delete forever, 10,000 cards in 10 packs, one card deleted (release build, dev-01, ABAB x5, NOT a perf VM)

Scan of 10 packs about 2.0 ms both. Delete: before (opens all packs) 1.98 to 3.17 ms, after 2.85 to 3.11 ms. Indistinguishable at 10 packs because the one rewritten pack (about 1000 cards) dominates; the saving is the per-pack open and hash, which grows with pack count. Perf VMs were blocked by other holders of the shared lock (fcd-hold, fh-hold sleep 20000), so the perf-VM run is still to do; I did not wait for it.

## Fixes for the data-safety review (comment 77388) Commits on `feat/contacts-import-v2-s1` (after e07d4dca): 9696a046, 9f53c99e, 61922c2f, 493ed851, a11a232d, then style/clippy fixes, and 071db53f (docs). **P2-1 corrupt pack.** The sweep now checks every pack whole (index and every record). For a pack that fails, history marks its import job's companions "not copied" (durably, first), then the pack is deleted, then the copier writes the cards as loose copies. The pack's file name is the job name in hex, so a damaged pack is traced back to its job even when its index is unreadable. Test `a_corrupt_pack_is_copied_again_from_history`: corrupt a record in one pack and the end mark of another, sweep, copy: all 80 copies byte-equal to history. Failure table row now: pack fails a check → warning at read (treated as absent; history still answers) → the next sweep (hourly) marks its job unwritten, deletes the pack, copier rewrites loose copies → test above. Module docs in `pack.rs` and `cards.rs` say the same. **P2-2 sweep.** An unreadable pack is rebuilt/deleted as above, so cards of contacts deleted forever do not stay (their rows are only marked, never written). A bad record inside a pack no longer fails the sweep: `remove_many` returns the damaged packs, logs, and carries on with the other packs; the sweep then rebuilds those. Tests: `an_unreadable_pack_does_not_keep_forgotten_cards` (index-damaged and record-damaged packs plus a forgotten contact; no file holds its card afterwards) and `one_bad_record_does_not_stop_the_other_packs`. **P3.** 1: pack discovery only accepts hex-named `<tag>.pack`; leftover `.calternal-tmp-*` files are never packs and the sweep removes them (test). Note: I kept fsio's temp naming (it ends in `.pack`) and filter by name instead of changing the shared helper. 2: `build` refuses duplicate ids (test). 3: the scan now returns the pack each id is in, and `remove_many` opens only those packs (test: 10,000 cards in 10 packs, one delete rewrites exactly one pack). 4: the "is this still a contact" read is back before the exact-replay shortcut (test `an_import_replay_of_a_note_that_is_no_longer_a_contact_is_refused`); this gives back the note read that 30d1e3d3 had saved. 5: docs updated (`contacts/src/lib.rs`, `note_io.rs`, `history/companions.rs`, `cards.rs`, ADR 0063, 0064). Also fixed three clippy errors that were already on the branch (creates.rs test module position, fsio tests useless vec) because the gate is `-D warnings`. ### Gates (dev-01) - `cargo fmt --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: clean - `cargo test -p calternal-contacts-actions`: 162 passed, 0 failed (includes the kill9 and crash-point tests and the new tests) - `cargo test -p calternal-notes`: 462 passed. First run had 1 failure, `history::tests::contact_import_releases_excess_history_page_cache` (memory-retention check); passes alone 3/3 and in a full rerun. It looks load-sensitive in a parallel run; I did not touch that code. ### Delete forever, 10,000 cards in 10 packs, one card deleted (release build, dev-01, ABAB x5, NOT a perf VM) Scan of 10 packs about 2.0 ms both. Delete: before (opens all packs) 1.98 to 3.17 ms, after 2.85 to 3.11 ms. Indistinguishable at 10 packs because the one rewritten pack (about 1000 cards) dominates; the saving is the per-pack open and hash, which grows with pack count. Perf VMs were blocked by other holders of the shared lock (fcd-hold, fh-hold `sleep 20000`), so the perf-VM run is still to do; I did not wait for it.
Author
Owner

Housekeeping #1009 status: audited head 071db53f6ea20e9c9f16a271160568ac7c2311f3 against dev cd7f84432feb. git cherry origin/dev <head> reports 246 unmatched commits and 0 equivalent patches. Separate stable patch-id indexing and key-file checks do not establish full landing. Absent from dev: crates/contacts-actions/proptest-regressions/tests/related.txt, crates/contacts-actions/src/import/commit.rs, crates/contacts-actions/src/import/planning.rs. Left unchanged as WIP, per kayg’s instruction; no rebase, close, tests, or merge. The #1009 audit records the unmatched commit list.

Housekeeping #1009 status: audited head `071db53f6ea20e9c9f16a271160568ac7c2311f3` against dev `cd7f84432feb`. `git cherry origin/dev <head>` reports 246 unmatched commits and 0 equivalent patches. Separate stable patch-id indexing and key-file checks do not establish full landing. Absent from dev: `crates/contacts-actions/proptest-regressions/tests/related.txt`, `crates/contacts-actions/src/import/commit.rs`, `crates/contacts-actions/src/import/planning.rs`. Left unchanged as WIP, per kayg’s instruction; no rebase, close, tests, or merge. The #1009 audit records the unmatched commit list.
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
This pull request has changes conflicting with the target branch.
  • crates/contacts-actions/src/cards.rs
  • crates/contacts-actions/src/import.rs
  • crates/contacts-actions/src/lib.rs
  • crates/contacts/src/lib.rs
  • crates/contacts/src/note_io.rs
  • crates/fsio/src/lib.rs
  • crates/fsio/src/tests.rs
  • crates/notes/src/history.rs
  • crates/notes/src/lib.rs
  • crates/notes/src/meta.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'feat/contacts-import-v2-s1:feat/contacts-import-v2-s1'
git switch 'feat/contacts-import-v2-s1'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'dev'
git merge --no-ff 'feat/contacts-import-v2-s1'
git switch 'feat/contacts-import-v2-s1'
git rebase 'dev'
git switch 'dev'
git merge --ff-only 'feat/contacts-import-v2-s1'
git switch 'feat/contacts-import-v2-s1'
git rebase 'dev'
git switch 'dev'
git merge --no-ff 'feat/contacts-import-v2-s1'
git switch 'dev'
git merge --squash 'feat/contacts-import-v2-s1'
git switch 'dev'
git merge --ff-only 'feat/contacts-import-v2-s1'
git switch 'dev'
git merge 'feat/contacts-import-v2-s1'
git push origin 'dev'
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!817
No description provided.