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
pull from: feat/contacts-import-v2-s1
merge into: kayg:dev
kayg:main
kayg:port/tasks-float-2
kayg:fix/train-1116-2
kayg:fix/train-1116-3
kayg:fix/train-1116-1
kayg:fix/flake-1134
kayg:fix/server-1182
kayg:dev
kayg:port/notes-float-3c
kayg:docs/auto-update-ig
kayg:feat/dav-transport
kayg:port/tasks-float-1
kayg:wip/mail1011-sv-order-1116
kayg:fix/flake-1179
kayg:fix/flake-1178
kayg:fix/guards-1153-fsio-split
kayg:fix/guards-1153-notes-split-we
kayg:fix/guards-1153-notes-lib
kayg:fix/guards-1153-notes-home
kayg:fix/guards-1153-ui-primitives
kayg:fix/guards-1153-primitives-e2e
kayg:fix/guards-1153-visibility-doc
kayg:feat/paper-grey-1116
kayg:fix/flake-1165
kayg:fix/flake-1119
kayg:docs/imap-766-plan-v2
kayg:fix/e2e-unique-ports
kayg:t3/paged-search-reconcile-final
kayg:wip/mail1011-final-1115
kayg:docs/tasks-float-port
kayg:perf/editor-first-paint-1c
kayg:feat/imap-notes-fetch
kayg:feat/imap-notes-projection
kayg:feat/imap-notes-readonly
kayg:feat/imap-notes-auth
kayg:feat/imap-notes-server-foundation
kayg:wip/mail1011-txn-ownvocab-1115
kayg:wip/mail1011-txn-novocab-1115
kayg:perf/p1117-final-harness
kayg:perf/single-shot-repeats
kayg:port/tasks-matrix
kayg:wip/mail1011-txn-1115
kayg:fix/static-gates-1155
kayg:feat/files-s1-identity-r7
kayg:fix/files-r7-idle-loop
kayg:fix/daily-train-1152
kayg:port/notes-float
kayg:fix/editor-tables-test-types
kayg:port/notes-float-listscript
kayg:feat/tasks-actions
kayg:port/notes-float-phone-preload
kayg:perf/sound-comparator
kayg:port/notes-float-listscroll
kayg:port/notes-float-budgets
kayg:port/notes-float-suite-fix-b
kayg:port/notes-float-sidebar-fix
kayg:port/notes-float-trim
kayg:port/notes-float-3-lists
kayg:fix/attachments-meta-capability
kayg:docs/carddav-writes-v2-plan
kayg:feat/contacts-companion-pure
kayg:issue/carddav-read-perf-fix-r2
kayg:issue/carddav-read-r2
kayg:port/notes-float-devsync2
kayg:review/calendar-2
kayg:review/switcher-a-pills
kayg:port/notes-float-switcher-a
kayg:port/port-tables-2
kayg:review/switcher-ends
kayg:wip/whiteboard-s1-1114
kayg:port/port-tables
kayg:wip/mail1011-perfneutral
kayg:review/photo-tint
kayg:port/notes-float-shell
kayg:wip/local/collections-db
kayg:wip/local/mail-p1
kayg:wip/local/cold-growth-on-tiering
kayg:wip/local/tiering-v3-s1
kayg:wip/local/wal1051-cap
kayg:wip/local/tiering-v3-s1-resume
kayg:wip/local/index-position-startup-scan
kayg:port/notes-float-flat
kayg:port/notes-float-promote
kayg:wip/handover/mail1011-candidate
kayg:wip/handover/files-s1-candidate
kayg:port/notes-float-shell-only
kayg:port/notes-float-perf
kayg:feat/whiteboard-s1
kayg:feat/tiering-v5
kayg:fix/app-switch-hitch
kayg:wip/local/files-s1-dev-v4-final
kayg:feat/files-s1-dev-v4
kayg:fix/c2-glass-shared
kayg:feat/flat-lists
kayg:wip/handover/whiteboard-s1-resume
kayg:wip/att-lazy-861
kayg:feat/switcher-browse
kayg:wip/att-lazy-860
kayg:feat/tasks-float
kayg:recovered/flat-backup-candidate
kayg:perf/stalls-1054-kc
kayg:land/ai-toolbar
kayg:feat/collections-db
kayg:feat/collections-db-fixes
kayg:codex/mail-1011-redesign-20261111
kayg:fix/ai-toolbar
kayg:backup/macos-vm/st3-head
kayg:perf/trim-candidate-phonestack
kayg:feat/switcher-three
kayg:fix/1051-index-idle-checkpoint
kayg:perf/stalls-1054-kb
kayg:perf/stalls-1054-k
kayg:perf/stalls-1054-r3
kayg:fix/c2-contrast-tail
kayg:perf/stalls-1054-r3-preview
kayg:feat/collections-before
kayg:feat/tiering-v4
kayg:fix/timelog-caret
kayg:wip/local/tasks-actions
kayg:docs/tasks-writes-v2-plan
kayg:st3-r3
kayg:feat/pass8
kayg:review/calendar-2-before-1111
kayg:wip/tiering-v3-cold4
kayg:perf/stalls-1054-r2
kayg:fix/suite-A4
kayg:fix/suite-A5-probe
kayg:fix/suite-A6
kayg:fix/suite-A3
kayg:fix/suite-A2
kayg:fix/suite-A5
kayg:fix/suite-A1
kayg:wip/local/attachments-861-fix
kayg:feat/contrast
kayg:wip/local/ports-861
kayg:storage/wal-checkpoint-off-save-1051
kayg:wip/local/mail-1011-reconcile-20261110
kayg:feat/style-sheet-fixes
kayg:feat/money-round
kayg:perf/stalls-1054
kayg:wip/tiering-v3-cold5
kayg:t3/mail-1011-liveness
kayg:feat/iphone-fixes
kayg:feat/notes-approve
kayg:wip/local/shrow-work
kayg:feat/files-s1-identity
kayg:feat/quickfix
kayg:wip/tiering-v3-cold
kayg:wip/local/shared-row-swipes
kayg:backup/macos-vm/pfx-B
kayg:backup/macos-vm/pfx-C
kayg:backup/macos-vm/pfx-D
kayg:feat/contrast-r1
kayg:feat/tiering-v3-s2-tags
kayg:feat/folder-drop
kayg:t3/photos-s1
kayg:feat/tiering-v3-s1-namespace
kayg:wip/local/photos-s1
kayg:t3/photos-plan-slice-one
kayg:recovered/backup/p1b-61505
kayg:t3/paged-search-reconcile
kayg:t3/smooth-pane-transitions
kayg:t3/index-position-startup-scan
kayg:fix/private-staging-759b-r2
kayg:backup/macos-vm/hk/hk1009/pr877
kayg:backup/macos-vm/hk/hk1009/pr878
kayg:docs/undo-block-ids-plan
kayg:fix/undo-768
kayg:backup/macos-vm/hk/hk1009/pr875
kayg:backup/macos-vm/hk/hk1009/pr904
kayg:proto/block-identity-v7d
kayg:backup/macos-vm/hk/hk1009/pr846
kayg:backup/macos-vm/hk/hk1009/pr860
kayg:backup/macos-vm/hk/hk1009/pr861
kayg:backup/macos-vm/hk/hk1009/pr849
kayg:backup/macos-vm/hk/hk1009/pr848
kayg:backup/macos-vm/hk/hk1009/pr853
kayg:backup/macos-vm/hk/hk1009/pr957
kayg:backup/macos-vm/hk/hk1009/pr893
kayg:backup/macos-vm/hk/hk1009/pr889
kayg:backup/macos-vm/hk/hk1009/pr902
kayg:docs/imap-notes-plan
kayg:docs/quota-plan-2
kayg:fix/parallel-test-flakes
kayg:docs/calendar-backend-v2-plan
kayg:feat/calendar-ical-converter
kayg:backup/macos-vm/hk/hk1009/pr808
kayg:docs/contacts-import-v2-plan
kayg:issue/610-pm-midnight
kayg:feat/calendar-v2-s1-containment
kayg:backup/macos-vm/hk/hk1009/pr854
kayg:backup/macos-vm/hk/hk1009/pr845
kayg:backup/macos-vm/hk/hk1009/pr917
kayg:docs/dav-recorder-v2-plan
kayg:plan/previews-865
kayg:plan/save-log-durable-entry
kayg:backup/macos-vm/hk/hk1009/pr934
kayg:fix/e2e-data-on-ram
kayg:backup/macos-vm/hk/hk1009/pr888
kayg:feat/appwindow3
kayg:feat/appwindow2
kayg:feat/appwindow
kayg:feat/money-p1
kayg:feat/keys-sheet
kayg:review/calendar-2-themes
kayg:feat/smooth-cursor
kayg:fix/float-style
kayg:review/calendar-2-float
kayg:release/2026-11-06-hotfix
kayg:archive/port/rows-drop-code
kayg:archive/port/rows-actions
kayg:archive/port/rows
kayg:scratch/tasks-894-ui-gates
kayg:review/calendar-2-night-wip
kayg:recovered/flaky/toast-reduced
kayg:release/2026-11-05
kayg:archive/flaky/rows-drop-fixed
kayg:archive/flaky/rows-actions
kayg:archive/flaky/rows
kayg:sim/bm15-final
kayg:sim/bm15-bis-932
kayg:sim/bm15-bis-909
kayg:sim/bm15
kayg:sim/bm15-bis-887
kayg:perf/tiering-option-b
kayg:fix/sw-lazy-precache
kayg:archive/plan/save-log-durable-entry
kayg:mock/money-fix2
kayg:archive/fix/e2e-data-on-ram
kayg:mock/appearance-all
kayg:mock/pill-press
kayg:mock/pill-press-mac
kayg:backup/macos-vm/appearance-after
kayg:mock/auto-swipes
kayg:mock/mail-actions
kayg:backup/macos-vm/mock/mail-actions
kayg:mock/money-static
kayg:archive/review/standards-917
kayg:perf/tiering-761-fix
kayg:mock/type-audit
kayg:mock/third-pane
kayg:perf/executor-hot-path
kayg:archive/port/hidden-blocks
kayg:archive/port/devices
kayg:scratch/executor-on-894
kayg:scratch/executor-spans2
kayg:scratch/executor-spans
kayg:archive/port/rows-drop
kayg:feat/tiering-761-d-scale
kayg:feat/tiering-761-c-index
kayg:feat/tiering-761-b-reader
kayg:archive/review/sharing-pr3-review-9fec3d1f
kayg:perf/ports-lazy-budgets
kayg:feat/tiering-761-a-migration
kayg:archive/review/sharing-pr3-review
kayg:archive/review/sharing-pr3-review-code
kayg:archive/plan/previews-865
kayg:archive/port/port-attachments-3
kayg:archive/port/contacts-merge
kayg:fix/motion-audit-859
kayg:fix/motion-audit-859-mac
kayg:archive/port/port-pickers
kayg:archive/port/port-tables-2
kayg:archive/port/port-tables
kayg:recovered/local/sharing-s1-pr2-room-snapshot-candidate
kayg:archive/fix/parallel-test-flakes-code-minipc01
kayg:docs/imap-766-readonly-slice
kayg:feat/dav-recorder-v3
kayg:research/788-diagnosis
kayg:archive/fix/parallel-test-flakes
kayg:archive/perf/pr792-cold-index-edit
kayg:docs/sharing-slice-1
kayg:recovered/feat/dav-recorder-v2
kayg:recovered/feat/dav-recorder-v2-edd7bbb
kayg:spike/imap-766-s0-cases
kayg:archive/fix/undo-768
kayg:recovered/feat/dav-recorder
kayg:recovered/feat/dav-recorder-901acd4
kayg:feat/contacts-import
kayg:perf/cold-growth-on-764
kayg:perf/cold-growth-on-tiering
kayg:recovered/feat/tasks-set-status
kayg:feat/tasks-move-reorder
kayg:feat/tasks-delete-promote-duplicate
kayg:feat/carddav-writes
kayg:perf/quota-on-tiering
kayg:perf/quota-simple
kayg:perf/cold-growth-on-quota-stack
kayg:recovered/perf/cold-growth-on-tiering
kayg:feat/calendar-identity
kayg:feat/calendar-event-parser
kayg:feat/calendar-props-maps
kayg:port/glass-when-ring
kayg:recovered/feat/tiering-761-s1-wip-8132a84
kayg:recovered/feat/tiering-761-s1-wip-9da4094
kayg:recovered/feat/tiering-761-s1-wip-724512c
kayg:recovered/feat/tiering-761-s1-wip-66e667e
kayg:recovered/feat/tiering-761-s1
kayg:wip/6by32-01-tier-761-s1-pause-20261030
kayg:spike/imap-766-s0
kayg:wip/6by32-02-calternal-pause-20261030
kayg:wip/8by64-01-review-688-pause-20261030
kayg:wip/6by32-01-verify-744-pause-20261030
kayg:wip/6by32-01-verify-742-pause-20261030
kayg:fix/private-staging-759b
kayg:wip/6by32-01-review-748-pause-20261030
kayg:wip/6by32-01-review-733c-pause-20261030
kayg:wip/6by32-01-review-733b-pause-20261030
kayg:review/calendar-month
kayg:wip/local/bm15-trash
kayg:plan/759b-staging
kayg:review/767b-tests
kayg:review/preview-2026-10-29
kayg:docs/tiering-731-plan
kayg:wip/c6b02-review-733d
kayg:wip/c6b02-bm1-full-a
kayg:docs/deploy-plan
kayg:fix/storage-owner-liveness-642
kayg:fix/storage-fix-7
kayg:feat/tiering-731
kayg:wip/tiering-731-first-attempt
kayg:perf/idle-honest-2
kayg:fix/storage-private-tmp-642-dev
kayg:fix/storage-exact-file-quarantine-642
kayg:perf/one-flush-save
kayg:review/calendar-static
kayg:review/indexing-ring
kayg:review/when-field-2
kayg:proto/block-identity-2-review
kayg:proto/block-identity-review
kayg:review/when-field
kayg:issue/tasks-create-ids
kayg:issue/tasks-create
kayg:review/combined
kayg:review/task-polish
kayg:review/top-buttons
kayg:review/q1-q5
kayg:archive/integ325-293
kayg:archive/integ325-ci
kayg:issue/calendar-adr
kayg:archive/old/train/2026-10-23bk2
kayg:archive/old/train/2026-10-23bk
kayg:issue/469-mockup-9a
kayg:issue/smart-tasks-mockup
kayg:issue/469-menus
kayg:issue/652-signout-flake
kayg:issue/652-history-fix7
kayg:issue/652-history-fix6
kayg:archive/old/issue/spring-check-perf
kayg:issue/spring-check-perf
kayg:issue/659-rename-fast
kayg:archive/old/train/2026-10-21ar
kayg:issue/search-hardening-3
kayg:issue/652-history-fix5
kayg:issue/660-port-sheets-glass
kayg:issue/652-history-fix4
kayg:issue/652-history-fix3
kayg:issue/652-history-fix2
kayg:issue/652-history-flake
kayg:train/2026-10-21an
kayg:issue/settings-admin-port
kayg:issue/search-port
kayg:train/2026-10-20am
kayg:issue/storage-split-fix2
kayg:issue/storage-split
kayg:archive/old/issue/folder-ids-fix
kayg:train/2026-10-20al
kayg:archive/old/issue/folder-ids
kayg:train/2026-10-20ak
kayg:issue/tables-mockup
kayg:train/2026-10-19aj
kayg:train/2026-10-19ai
kayg:issue/469-merge-fixes
kayg:issue/sidebar-band
kayg:archive/old/issue/608-settings-spec
kayg:train/2026-10-19ah
kayg:issue/swipe-offscreen
kayg:train/2026-10-19ag
kayg:archive/old/issue/590-nlp-adr
kayg:archive/old/issue/587-event-after-write-2
kayg:train/2026-10-19af
kayg:archive/old/issue/587-event-after-write
kayg:issue/469-pill-room-c
kayg:issue/469-pill-room
kayg:train/2026-10-19ae
kayg:issue/469-narrow-handle
kayg:issue/397-ios-swipe-2
kayg:issue/469-desk-fixes
kayg:archive/old/issue/auto-update-adr
kayg:issue/469-filter-gap
kayg:issue/469-port-1b
kayg:issue/442-opacity-flake
kayg:issue/327-web-fast-3
kayg:archive/old/issue/469-port-1
kayg:issue/469-port-1
kayg:issue/327-web-fast-2
kayg:archive/old/issue/327-web-fast
kayg:archive/old/issue/425-stt-bench-vq1
kayg:archive/old/issue/445-no-bleed
kayg:archive/old/issue/400-swipe-mockup-2
kayg:issue/426-client-review
kayg:issue/426-client-2
kayg:issue/426-client
kayg:archive/old/issue/476-safe-area-lab
kayg:archive/old/issue/445-top-light
kayg:issue/471-blocks-mockup
kayg:archive/old/issue/448-links-app-2
kayg:archive/old/issue/448-links-app
kayg:archive/old/issue/398-cold-links
kayg:issue/434-442-small-2
kayg:issue/434-442-small
kayg:archive/old/issue/398-unload
kayg:archive/old/issue/445-bottom-band
kayg:issue/445-bottom-band
kayg:issue/351-rem-3
kayg:issue/351-rem-2
kayg:issue/351-rem
kayg:archive/old/issue/327-first-note
kayg:issue/395-width-phone
kayg:archive/old/issue/327-typing
kayg:issue/396-ios-edges
kayg:issue/397-ios-swipe
kayg:archive/old/issue/327-notes-index
kayg:issue/345-347-contrast-empty-2
kayg:archive/old/issue/44-arenas
kayg:issue/44-arenas
kayg:archive/integ325
kayg:archive/old/issue/327-perf-harness
kayg:archive/old/issue/44-thp
kayg:issue/44-thp
kayg:archive/old/issue/285-sticky-pills
kayg:archive/old/issue/44-trim-3
kayg:issue/44-trim-3
kayg:archive/old/issue/165-cards
kayg:archive/old/issue/165-picker-2
kayg:archive/old/issue/212-multi-select
No reviewers
Labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
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
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/contacts-import-v2-s1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Device latency plan at
41bece8bThe 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,233fsync/fdatasynccalls per 1,000 cards (8.233/card), and the full import took 77.382 s. The 1 MiB/1,024-card group at858ce2bfreduced dev-01 flushes to 163 added calls per 1,000 cards whensyncfsis 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_manyreaches a serialfsio::replace_manyloop; 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 onesynchronous=FULLtransaction. The source file, staging-root, child journal, Home files, state copies, outcomes and finaldonerecord 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.donesave returns an errorGates
strace -c -f -e trace=fsync,fdatasync,syncfsat 1,000 and 20,000 cards, including stage time per card and batch count.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
4eeb8cb1capped 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
4eeb8cb1acceptance 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_partdirectly 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.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.
WIP: contacts import v2 S1 compatibility stopto WIP: contacts import v2 S1 photo HTTP compatibility stopUpdated through
ba2e14edd796a1ae30398f64cae608d70241b3c9. Growth wording is recorded on #815 at2cc70e0band 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 indocs/plans/0064-s1-compatibility-stop.md.WIP: contacts import v2 S1 photo HTTP compatibility stopto WIP: contacts import v2 S1 retained-update compatibility stopUpdated 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.
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.
WIP: contacts import v2 S1 retained-update compatibility stopto WIP: contacts import v2 S1 same-UID updates; HTTP memory gate stopMemory 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.
WIP: contacts import v2 S1 same-UID updates; HTTP memory gate stopto WIP: contacts import v2 S1; profiled memory gate remains failingResuming 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:
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.
WIP: contacts import v2 S1; profiled memory gate remains failingto WIP: contacts import v2 S1; per-card worker recovery gate failingS1 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.
WIP: contacts import v2 S1; per-card worker recovery gate failingto WIP: contacts import v2 S1; finish bounded index memoryWIP: contacts import v2 S1; finish bounded index memoryto WIP: contacts import v2 S1; finish flat resident memoryResumed final measurements complete. Report head:
0c3ee080b4; measured code head:0a52bf0057(subsequent commits only update the report).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
0a52bf00has 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.
S1 gate update
PR #817 remains a draft at
12535aad.Passed
Failed
Pending
The gate table, evidence, and exact commands are in
docs/plans/0064-s1-compatibility-stop.md. No merge was made.S1 follow-up at
c71812d8Group 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
doneis saved only after the final durable batch.fsync+fdatasync: 8.233 to 0.104); harness time 77.382 s to 2.744 s.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 device-latency follow-up at
544457b3Resumed 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 ata4040a88before 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 withsynchronous=FULLand 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. Testscanning_known_cards_commits_a_fixed_number_of_timesreads 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-backedTMPDIR.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_keys114.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):fdatasyncfsyncsyncfsBefore: about 4.2
fdatasyncper 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 scriptRelease build at
46603546. Fresh import, then the same cards again, new process per row.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_import414 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_npFULLSYNC|WAIT), outcome commit 3 ms, parent progress 8 ms, summary 3 ms.Repeat of 1,000 on the Mac:
whole_import21 ms, 0 volume syncs, but 0.5–0.7 s end to end. The timeline showsplan_importat 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:520unnecessary cast,tests/import.rs:392disallowedstd::fs::write) were fixed in544457b3.cargo test --locked -p calternal-contacts-actionsat46603546: 143 passed, 0 failed, includingimport_killed_mid_batch_recovers_each_card_once_and_undoesand the other fiveimport_killed_*cases. The summary-rebuild test, the new scan test and the mid-batch kill test also pass at544457b3.Risks for the durability review
companion_key_page(...).awaitcalls. An error drops the stage and rolls back; a kill leaves a hot journal that SQLite rolls back on reopen.knownis 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.donestate is written earlier than before.No merge.
S1 device-latency follow-up at
b8c7416dCommits since
544457b3:b74b5f8a(profile points),3ea7d960(benchCONTACT_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_importstarts after planning, so it never counted it. For every known card,import_updateread the contact note file (contact_note_in_home) before comparing the stored original with the incoming bytes. Profile, 1,000 repeat:note_read_ms503 and 597 (two runs),companion_read_ms33–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_ms0,companion_read_ms23–27,plan_import36–41 ms.2. History/publication swing (250 ms → 1.6 s) — storage latency, not work per card
Same code, same cards, profiled runs (ms):
fsync_volume_npFULLSYNC)Probe on the Mac VM (3 passes):
write+fsync4 KB median 1.8–2.1 ms;F_FULLFSYNCmedian 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_msoverlapschild_plan_journal_ms), anddonemust 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_benchrelease (seconds; median [min–max])Fresh code is identical before and after, so its differences are host noise. Only "again" changed.
544457b330d1e3d3(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 oncontact_import_releases_excess_history_page_cache(process-wide SQLite memory under parallel load); alone it passes 3/3 on both this head and544457b3, and the second full run was green.cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points crash: pass.cargo clippy -p calternal-notes -- -D warningson that crate alone fails on three feature-gated lines (meta.rs:1397,creates.rs:499,creates.rs:627) that exist at544457b3.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.IM1 plan: pack each import batch's state copies (kayg 11-03)
Base:
b8c7416d. Overlap check: no other open PR touchescrates/contacts-actionscards/copy/import (searched open PRs 11-04). I build on #817's branch.What the code does today (so the change stays small)
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.Contacts::read(the export calternaldav serves, built byContact::from_note(note, OriginalCard)) all read the companion from history. None of them reads a file.contacts/raw/<id>.vcfis 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
.vcffiles. 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))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).finish_with_deferred_files): no extra durable wait, and 1 file create instead of N.<id>.vcfwins (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).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
30d1e3d3)Again), notes removed; copies sweptunwrittenin history →copy_nowrewrites copies (loose)Failure table
unwrittenunwrittencopy_nowwrites loose copiesCopiedcopy_nowrewritescopy_nowdoneGates
fmt; clippy
-D warningsoncalternal-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 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 incontacts/raw/packs/; format and failure table as in the plan. Two notes beyond the plan:copy_nowrepairs 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.Files per import (state folder, from the runs below)
(the base ~20 files are the stage SQLite, journals, history; 1 pack per 1,024-card batch)
Mac VM (
macos-01-std), releasecontacts_bench, old =b8c7416d, new =f97cec7e, ABAB-interleaved, lock held with an EXIT trapIdle control before:
F_FULLFSYNC4 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]:
1,000 cards again, two more A/B sets (8 and 10 rounds, the second with
sync; sleep 4before 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_sync39 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)state_copy_ms)volume_sync_ms(1 call)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 gates at
e07d4dca(code unchanged since44b0a091; later commits are tests and fmt)dev-01, all through
~/bin/slot, in the Nix dev shell:cargo fmt --check -p calternal-contacts-actionscargo clippy --locked -p calternal-contacts-actions --all-targets -j4 -- -D warningscargo test --locked -p calternal-contacts-actions -j4cargo test --locked -p calternal-notes -p calternal-contacts-actions --features crash-points -j4 crashcargo test --locked -p calternal-notes -j4New 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, andtests::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::checkverifies 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.
Independent review: IM1 card packs at
e07d4dcaScope:
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) andimport_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::readis reached only throughcopy_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 deletedassertion 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)bulk::undo/ resume; rows not copiedcreates.rs:628-636, pack + notes in onesync_deferred), before historydonedone, beforemark_job_written_soon(commit.rs:300-302)unwrittencopy_nowwrites loose copies with the same bytes, and loose winssync_related_filesturns it into a job failure → batch undone (jobs.rs:124)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 newpacks/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_updateresolves the targetidfrom 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 staysincoming.to_vec()(:731). An identical re-import returnsOk(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-17says "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_nowrewrites"). Butcopy_now(copy.rs:40-46) only reads history rows still markedunwritten, andmark_job_written_soonalready marked this batch written. Nothing notices a bad pack or resets those rows.Scenario: a bit flip or torn sector in
packs/<tag>.pack→Scanandreadskip it with a warning (cards.rs:70,:102) → up to 1,024 live contacts permanently have no file copy. That breaks the invariantEnv::checkasserts 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, socopy_nowrewrites them as loose copies (pack ids are unknown, so do it perjobfrom 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_packsskips a pack that failsopen(cards.rs:220-222), andScannever 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.p.all()?(cards.rs:226) fails →remove_manyfails →sweepreturns 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
temp_pathnames the temp file.calternal-tmp-<unique>-<tag>.pack(fsio/src/lib.rstemp_path). The.packextension passespack_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 sweepsTEMP_PREFIXundercontacts/raw). A fully written temp file that was never renamed is a second valid pack, so its ids are scanned twice. Skip names starting withTEMP_PREFIXinpack_pathsand delete them in the sweep.buildaccepts duplicate ids thatparsethen refuses (pack.rs:55vs: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 makebuildreturn an error so it fails at write time.remove_manywith 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, insideperson.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 legacyreadfallback 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.import.rs:679-699vswrite.rs:592). A UID-matched note whoseformat: contactthe person removed used to be refused ("not a contact"). It now reports "unchanged". No write and no loss, only a different report. Keep theformatcheck before the early return, or note the change..vcfper 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::readreturns 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
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 newunwrittenrows, socopy_nowwrites a loose copy again. That race already existed for loose files.commit.rs:191,:213-220). Updates, merges and undo copies go loose throughcopy_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).copy_batchclone + 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.
Fixes for the data-safety review (comment 77388)
Commits on
feat/contacts-import-v2-s1(aftere07d4dca):9696a046,9f53c99e,61922c2f,493ed851,a11a232d, then style/clippy fixes, and071db53f(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.rsandcards.rssay 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_manyreturns 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) andone_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:buildrefuses duplicate ids (test). 3: the scan now returns the pack each id is in, andremove_manyopens 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 (testan_import_replay_of_a_note_that_is_no_longer_a_contact_is_refused); this gives back the note read that30d1e3d3had 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: okcargo clippy --workspace --all-targets -- -D warnings: cleancargo 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.kayg referenced this pull request2026-11-05 23:21:11 +00:00
Housekeeping #1009 status: audited head
071db53f6ea20e9c9f16a271160568ac7c2311f3against devcd7f84432feb.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.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.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.