contacts: stream vCard imports with duplicate suggestions #800
Closed
kayg
wants to merge 1 commit from
feat/contacts-import into dev
pull from: feat/contacts-import
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:feat/contacts-import-v2-s1
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: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!800
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/contacts-import"
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?
Plan (foundational; read this first)
Contacts D12: vCard import plan
Goal
Add an authenticated, streaming
.vcfupload to the existing contacts importjob. Return durable per-card outcomes, preserve the existing all-at-once notes
job and crash recovery, and suggest possible duplicates without merging them.
The current limits remain 20,000 cards and 100 MiB.
Scope and decisions
POST /api/v1/contacts/import, authenticated through the existingSignedextractor. It accepts rawtext/vcardand legacytext/x-vcardrequest bodies, not JSON or multipart. The file name is not trusted or used.
Bodyframes directly. Reject a declared or observed body over 100 MiB;count
BEGIN:VCARDrecords as bytes arrive and reject record 20,001 beforecollecting the complete request. Split cards while retaining the physical
line containing each
BEGIN:VCARD.and malformed cards become failed per-card results when card boundaries are
recoverable; valid neighboring cards still import.
per-card failure with an explicit unsupported-version reason. The contacts
converter deliberately excludes 2.1, whose quoted-printable and charset
rules differ from 3.0. Do not relabel 2.1 as 3.0 or risk corrupting bytes.
bytes. A retry or upload of the same file replays the original durable job.
The existing UID and byte identity checks continue to suppress repeated
cards when callers use a different key.
imported,updated,skipped, andfailed. Every card result has its 1-based source line, status, and contactID or reason. Same UID with changed card data updates that contact using the
contacts merge rules inside the import bulk job; an unchanged card is
skipped. A different UID with matching contact facts remains a separate
imported contact and gets a suggestion.
or full name after case and punctuation normalization. Local phone numbers
never gain a guessed country code. Fuzzy name matching is deferred.
card and 10,000 suggestions per import. Keys over 1 KiB are not indexed.
duplicate_suggestions_limitedreports that an output budget was reached;results are samples, not a complete enumeration. Suggestions never merge.
ImportLimitschecker runs before streaming card buffers grow andbefore direct action callers reach identity extraction or either parser.
Caps: 2 MiB/unfolded line, 4,096 physical lines including blanks/folds (also
bounds properties), 8 MiB/card, 4 MiB/total encoded PHOTO content-line bytes.
A discarded card has a durable
skippedresult with atoo largereason.Its neighbors continue; accepted original bytes remain unchanged.
crash recovery return the same summary. Keep original vCard bytes, including
inline photos, in the existing contact history companion.
example.testaddresses, andreserved
555-01xxnumbers.Size and complexity
Estimated size: 5 to 7 small Rust files changed or added, about 450 to 700
implementation lines and 300 to 500 test lines. No new parser or phone-number
dependency is planned.
Let
Bbe uploaded bytes,Iincoming cards,Kthe total bytes in existingand incoming matching keys, and
Sretained suggestions. Framing, budget checksand conversion scan
O(B)bytes. Exact hash indexing and lookup take expectedO(K + I + S)work: each key retains at most 9 IDs and each incoming cardreturns at most 8 matches.
S <= 10,000; identical-name/email groups nevermaterialize pairs. There are no deletion signatures or edit-distance checks.
The checker uses constant space and each streaming card buffer is bounded by
8 MiB, then freed immediately on overflow. Accepted upload bytes total at most
100 MiB. Index space is linear in key bytes and contact IDs; large existing
name fields never expand into per-character allocations. Existing path selection
remains
O(I log I)and is independent of suggestion matching.Failure table
Content-Lengthor streamed byte count exceeds 100 MiB; return 413 before accepting more bytes; no job starts.vcfContent-LengthBEGIN:VCARDis seen while streaming; return 413 before full buffering; no job startsGates
Run on
cua@calternal-dev-02-stdinside the Nix dev shell and through~/bin/slot:cargo fmt --all -- --checkcargo clippy -j4 -p calternal-contacts -p calternal-contacts-actions -p calternal-server --all-targets -- -D warningscargo test -j4 -p calternal-contactscargo test -j4 -p calternal-contacts-actionscargo test -j4 -p calternal-serverSources and format notes
vCard 2.1 quoted-printable and in-card
CHARSET; 3.0 requiresTYPE=onparameters and supports folded inline binary values.
UTF-8, CRLF lines, and continuation folding that must not split a UTF-8
character.
say 3.0 is the default and 2.1 has a separate encoding choice.
confirms exports default to 3.0 and can be re-exported as 2.1 with encoding
adjusted.
offers CSV or vCard but does not promise a vCard version.
documents
.vcfsharing, while its duplicate promptlets a person choose update or create-new. Microsoft's pages do not promise a
vCard version, so this plan follows the Calternal converter's 3.0/4.0
contract instead of guessing.
Implementation tasks
Task 1: Durable import summary, updates, and duplicate suggestions
Interfaces: extend
contacts.importwithout breaking existing{cards}callers;the server route will pass source line numbers and recoverable parser failures.
Keep each result and every suggestion in the bulk job summary.
Steps:
failed results, same-UID updates, exact-key replay, and duplicate suggestions
by email, E.164 phone, and exact name.
because the result contract and suggestion matching are missing.
in the existing resumable bulk job. Preserve same-UID update merge semantics
and never merge suggested contacts.
Expected: new tests fail before implementation, then pass; prior contacts-actions
tests remain green.
Task 2: Authenticated streaming vCard upload route
Interfaces:
POST /api/v1/contacts/importacceptstext/vcardandtext/x-vcard; it authenticates before reading and invokescontacts.importwith a BLAKE3 key over exact request bytes.
Steps:
rejection, declared and streamed size limits, the 20,001st card, physical
source lines, and exact-file replay.
collecting the full request, and forwards card lines and parse failures to
the durable import action.
Expected: route tests fail before implementation, then pass; request bodies over
either limit never dispatch an import action.
Task 3: Full gates and branch review
Interfaces: the route, action result, and converter must agree on 3.0/4.0 input,
per-card failures, and line numbers. No UI changes.
Steps:
contacts-actions, and server test suites on dev-02 through
~/bin/slot.failing test first, and update the PR with exact gate results.
Expected: every listed gate passes; the branch remains unmerged and the PR
continues to target
dev.Round 1 implementation status
Head:
ae2cbf27fa31e43a3ce6dfd2b90bf439427c94cf. All steps committed and pushed; no merge. Ready for the next independent review (round 1 fixes, maximum 3 review rounds).duplicate_suggestions_limitedreports omitted possibilities.ImportLimits/ImportBudget, enforced before streaming buffers grow and before direct-action identity/parsing: 2 MiB unfolded line, 4,096 physical lines including blanks/folds (also bounds properties), 8 MiB card, 4 MiB total encoded PHOTO content lines. Oversized cards are discarded and durably reported asskippedwithtoo large; neighbors continue.Final gates on
cua@calternal-dev-02-std, in the Nix dev shell, under~/bin/slot:cargo fmt --all -- --checkcargo clippy -j4 -p calternal-contacts -p calternal-contacts-actions -p calternal-server --all-targets --locked -- -D warningscargo test -j4 -p calternal-contacts --lockedcargo test -j4 -p calternal-contacts-actions --lockedcargo test -j4 -p calternal-server --lockedResource checks ran the compiled regression test executables under the same Nix/slot wrapper, using Python
os.wait4peak RSS and wall-clock measurements with hard assertions of <128 MiB / <10 s for the 20,000-fact matcher and <256 MiB / <10 s for the hostile streaming-card test. These measure those isolated components, not peak RSS for a full disk import. Regression tests also assert the scanner's constant state, bounded per-card buffer, fixed bucket sizes and at most 10,000 serialized suggestions (<2 MiB).Decisions/limits: suggestions are bounded samples and fuzzy matching is deferred; very large cards/photos or unusually folded/property-heavy cards are skipped by the explicit limits above. Accepted original vCard bytes, unknown fields and photos remain intact. No independent re-review has been performed by this implementation agent.
Final-head resource measurements: matcher peak RSS 28,668 KiB, 0.184 s; hostile-card stream peak RSS 28,896 KiB, 0.109 s. Both hard memory/time assertions passed. Final gate log:
~/pr800-r1-locked.logon dev-02; it records the head SHA and ends withRESOURCE_GATES_PASSEDandALL_GATES_PASSED.Independent review, round 1
Reviewed
60d990ddf452a933f4f009fff409b4a29233d8fc, the PR plan/failure table, ADRs 0063/0064, and the contacts decisions memory.Verdict: fix first.
P1: bound duplicate work and output before materializing matches
crates/contacts-actions/src/import.rs:883–951collects every candidate, returns every matching pair, and appends every suggestion without a per-card or per-job budget. An empty address book plus 20,000 cards with distinct UIDs and the same email produces20,000 * 19,999 / 2 = 199,990,000suggestion rows. This requires only a few MiB of upload and does not require hash collisions. Each row owns a contact ID and reason strings; the result is then sorted, converted to JSON, and persisted in the job summary. It can exhaust process memory before the durable job starts, and matching/sorting also consumes quadratic CPU. An existing book can amplify this further. Bound candidate visits and retained suggestions, or represent large groups compactly with an explicit truncation/continuation contract. Apply the budget inside matching, before collecting an exhaustive Vec. Regression: the maximum-card same-email file must finish within a documented memory/work budget and retain separate contacts.P1: bound name indexing independently of upload bytes
crates/contacts-actions/src/import.rs:784–814, 833–840, 895–899builds chars, prefixes, and a hash set sized to the full normalized FN, then creates a separate map entry and owned contact-ID set for each distinct deletion signature. FN has no maximum matching length. A single accepted card with a tens-of-MiB pseudorandom alphabetic FN therefore creates millions of map entries and small allocations, using many GiB despite remaining below 100 MiB and one card. The 4,096-character linear-storage test checks only signature values, not the much larger MatchIndex or a practical maximum. Skip fuzzy matching above a documented length/work budget (preserving the original field), or use another bounded representation; cover both incoming names and existing names when constructing the index. Regression: huge ordinary and folded FN values must not expand into an unbounded matching index.P1: enforce structural parsing budgets before allocating per-line objects
crates/contacts-actions/src/import.rs:706–710callsCard::parseto detect 2.1 and then parses again inContact::from_vcard. The new streaming route caps only raw bytes and BEGIN records, so a single otherwise valid card can contain millions of tiny properties or empty physical lines.crates/contacts/src/card.rs:38–55allocates a Vec and a Line for each non-folded physical line, plus property objects for parsed properties. For example, a card containing about 90 MiB of blank LF lines passes the upload limits but attempts about 94 million Line records during the preliminary version check alone. This can kill the server before any per-card failure or job is recorded. Add a physical/logical-line or property-count/allocation budget while streaming, or use a bounded parser representation; do not fully parse merely to inspect VERSION before enforcing that budget. Preserve accepted unknown fields and large-photo bytes. Regression: a one-card many-lines/many-properties upload must fail safely or parse within a documented bound, without exhausting the process.P0: none found. P2/P3: no additional findings.
Auth is extracted before body polling; the observed-byte check precedes parser buffering for each frame, and BEGIN counting stops at 20,001. User-scoped engine runtimes/job IDs and the stored bulk plan support isolation and replay. The suggestion path itself only reads facts and builds results; it does not merge contacts. Original-card persistence retains unmodeled fields. Those observations do not remove the resource blockers above.
Validation: source review and exact pair-count analysis, not runtime/RSS measurements. No builds or tests were run on the read-only control host; the passing gates listed in the PR are author-reported. Existing kill/recovery tests cover create-only imports; add update/mixed create+update crash/replay coverage for the new import path. Also close the author-recorded missing-END recovery and mixed 2.1/3.0/4.0 route cases. No code changed or pushed.
Round 1 implementation plan
Replace fuzzy signatures with exact normalized email/E.164/full-name hash maps. Retain at most 9 representatives per key, visit at most 8 returned candidates per incoming card, and retain at most 10,000 suggestions per job. Matching keys above 1 KiB are ignored without changing stored fields. Fuzzy matching is a follow-up. Work is O(input/indexed key bytes + bounded suggestions), including identical-name/email groups; no exhaustive pair materialization.
Use one shared limits struct in the pure contacts crate and an allocation-free incremental budget checker used before buffering/parsing: 2 MiB unfolded line, 4,096 physical lines (also bounds properties), 8 MiB/card, 4 MiB total encoded PHOTO property bytes/card. Keep 100 MiB/upload and 20,000 cards. Oversized cards are discarded while streaming until the next boundary, then reported as
skippedwithtoo largeand the source line; accepted neighboring cards and original bytes remain intact. Direct action callers receive the same checks before identity/parser allocations.Commit/push after each meaningful implementation step. Run fmt, clippy -D warnings and contacts, contacts-actions, server tests on dev-02 via Nix and slot. Never merge.
Round 1 implementation status
Head:
ae2cbf27fa31e43a3ce6dfd2b90bf439427c94cf. All steps committed and pushed; no merge. Ready for the next independent review (round 1 fixes, maximum 3 review rounds).duplicate_suggestions_limitedreports omitted possibilities.ImportLimits/ImportBudget, enforced before streaming buffers grow and before direct-action identity/parsing: 2 MiB unfolded line, 4,096 physical lines including blanks/folds (also bounds properties), 8 MiB card, 4 MiB total encoded PHOTO content lines. Oversized cards are discarded and durably reported asskippedwithtoo large; neighbors continue.Final gates on
cua@calternal-dev-02-std, in the Nix dev shell, under~/bin/slot:cargo fmt --all -- --checkcargo clippy -j4 -p calternal-contacts -p calternal-contacts-actions -p calternal-server --all-targets --locked -- -D warningscargo test -j4 -p calternal-contacts --lockedcargo test -j4 -p calternal-contacts-actions --lockedcargo test -j4 -p calternal-server --lockedResource checks ran the compiled regression test executables under the same Nix/slot wrapper, using Python
os.wait4peak RSS and wall-clock measurements with hard assertions of <128 MiB / <10 s for the 20,000-fact matcher and <256 MiB / <10 s for the hostile streaming-card test. These measure those isolated components, not peak RSS for a full disk import. Regression tests also assert the scanner's constant state, bounded per-card buffer, fixed bucket sizes and at most 10,000 serialized suggestions (<2 MiB).Decisions/limits: suggestions are bounded samples and fuzzy matching is deferred; very large cards/photos or unusually folded/property-heavy cards are skipped by the explicit limits above. Accepted original vCard bytes, unknown fields and photos remain intact. No independent re-review has been performed by this implementation agent.
Final-head resource measurements: matcher peak RSS 28,668 KiB, 0.184 s; hostile-card stream peak RSS 28,896 KiB, 0.109 s. Both hard memory/time assertions passed. Final gate log:
~/pr800-r1-locked.logon dev-02; it records the head SHA and ends withRESOURCE_GATES_PASSEDandALL_GATES_PASSED.Independent review, round 2
Reviewed
ae2cbf27fa31e43a3ce6dfd2b90bf439427c94cf, round 1 (#issuecomment-71487), fixes (#issuecomment-71529), and the relevant plan/ADRs. Verdict: fix first.Full supported-scale RSS gate: not demonstrated. The ~28 MiB results measure the 20,000-fact matcher and a smaller scanner-only input separately. Neither measures an end-to-end import combining 20,000 cards and 100 MiB. No round-1 item was found regressed.
P1: parameter-value floods bypass the new structural budget and still consume GiB
crates/contacts/src/import_limits.rs:65,114counts physical lines and unfolded bytes, but never parameter/value objects.crates/contacts/src/card.rs:116–134allocates a String entry for every comma-separated parameter value and a Parameter for every semicolon-separated parameter.crates/contacts/src/field.rs:67then clones parameters into the converted field, while the original parsed card is retained (note.rs:72–91). These allocations occur after the budget accepts the card. A single line below 2 MiB can therefore allocate over two million value entries despite having only five ordinary physical lines plus a UID.Independent reproduction on dev-02, using the final-head compiled contacts crate, Nix and
~/bin/slot:All 49 distinct-UID contacts convert successfully; total wire size 102,761,418 bytes, below 100 MiB; 102,757,361 parameter-value objects in the fields alone, plus their original-card counterparts. Python
resource.getrusage(RUSAGE_CHILDREN).ru_maxrssaround this single executable measured 4,932,284 KiB peak RSS, 10.563 s. A parser-only probe at the same scale measured 2,515,608 KiB. These are component measurements, not a claim of measured full-route peak RSS. The import conversion path retains converted contacts across the upload and clones these same structures, so the new limits still admit a multi-GiB allocation before durable preparation. Unique UIDs prevent identity deduplication from eliminating the attack.Bound parser substructure allocations before constructing vectors/strings, including parameter counts, comma-separated parameter values, and typed list/component entries. Enforce a practical aggregate object/work budget as well as byte/line limits, preserving accepted original bytes. Add an approximately 100 MiB, distinct-UID regression that runs the actual conversion path under a documented peak-RSS budget; scanner-only measurements cannot catch this.
Replay, recovery, summary, and route-gap checks
too largereasons and count toward the 20,000-card cap. Accepted neighboring cards retain physical source lines.failures[].reason; that field is only checked for nonempty text and is excluded fromMAX_BYTES, so there is no universal action-level summary-byte bound. No additional P0/P1 finding from that path in this review.P0: none. New P1: parameter/value allocation bypass above. Additional P2/P3 findings: none.
Independent validation on
cua@calternal-dev-02-std, final head, Nix dev shell, through~/bin/slot:cargo test -j4 -p calternal-contacts-actions --locked import -- --nocapture: 44 passed, including the new seven update/mixed kill/recovery cases and oversized-summary replay.cargo test -j4 -p calternal-server --locked contacts_import: 1 unit + 11 route tests passed.rustc --edition=2024 ... -L dependency=target/debug/deps --extern calternal_contacts=..., measured by Pythonresource.getrusagearound each executable. Probe sources remain under/tmp/pr800-review2.*on dev-02 for reproduction.No repository code changed or pushed; no builds/tests ran on the control host. This is round 2 of at most 3.
Recheck at the same head: confirmed the existing round-2 finding against the budget, parser, field conversion, matcher and streaming source, and confirmed the recorded author resource-gate log and retained probe artifacts on dev-02. This recheck did not rerun the earlier runtime probes or test suites. Updated this existing round-2 comment to avoid duplicating the review.
Round 2 implementation plan
Reserve one conservative per-card allocation envelope before the allocating parser or converter runs. Charge raw byte copies (names, parameter names/values, unfolded/unescaped text, rendering and decoded photos) and object/vector storage, including empty parameter values and typed list/component items. The reservation is bounded by 16 times raw card bytes plus a small fixed allowance, with an absolute ceiling. Counting every delimiter, even quoted/escaped ones, deliberately overestimates storage. Exceeded reservations produce durable
skipped: too largeoutcomes. Keep original bytes of accepted cards unchanged.Remove parallel batch conversion and consume each converted contact immediately. Retain only the bulk plan data and matching/naming facts needed for the existing atomic import; reparse related contacts individually when paths are known. Complexity remains O(input bytes + bounded matching output); allocation checking is constant-space O(card bytes).
Steps: (1) budget plus regressions, commit/push; (2) sequential conversion and full-scale memory gate, commit/push; (3) VM fmt, clippy -D warnings, contacts/contacts-actions/server suites and measured status table, commit/push documentation. Never merge.
round 2 implementation complete, ready for FINAL review. head
7b932eb9627b364ddc55bb370eb7f597e1762f2d. no merge performed.skipped: too largecapacity decision: for raw bytes B, LF count L and comma/semicolon count D, reserve
16B + 1024L + 256D + 1024, required to fitmin(32B + 64 KiB, 64 MiB). separators inside quoted/escaped text also count. this conservative reservation includes object/capacity overhead before allocation; unusually dense otherwise valid cards can be skipped. the import-specific checked converter uses a single parse; general editing conversion retains its existing contract. accepted original wire bytes remain intact.full-scale fixtures each contain 20,000 × 5,242-byte cards: 18,000 imported, 2,000 unsupported 2.1. both wait for companion copies, history copy marks and background index/journal publication.
scripts/contacts-import-memory.pyverifies named ignored tests exist, runs each in a fresh process, and asserts absolute Linuxos.wait4peak RSS, including fixture generation and completed publication. compilation is outside measurement.exact gates, each through
~/bin/slotinside the dev-02 Nix shell:functional gates passed at
adfd25df3249194605f91df6ab6647fceab41a44, log~/pr800-r2-final-gates.logendsALL_GATES_PASSED. the following commitca779da171dadb6ef1935436f01f05b418a8edbfstrengthened ignored resource tests to drain publication and updated documentation. fmt and the same clippy gate passed again there, followed by~/bin/slot python3 scripts/contacts-import-memory.py. log~/pr800-r2-complete.logendsIMPORT_MEMORY_GATES_PASSEDandFINAL_RESOURCE_GATES_PASSED. final head adds only the recorded measurements.allocation contract, methodology and results.
limits: measurements cover one import into an empty Home on dev-02, not a universal process-memory cap with existing book state, concurrent requests or live editor documents. anonymous spooling adds temporary disk I/O; preparation errors leave no job or roll back the transaction, and committed recovery remains in history. no builds/tests ran on the control host.
Independent review, round 3 (final)
Reviewed
7b932eb9627b364ddc55bb370eb7f597e1762f2d, round 1, round 2, and fix status. Verdict: stop and simplify. A new P1 remains in round 3, triggering kayg's three-round rule. No code changed or pushed.New P1: shared group labels bypass the allocation reservation during rendering
crates/contacts/src/import_limits.rs:40charges wire bytes and delimiter/line counts. However,crates/contacts/src/note_io/fields.rs:118,222associates oneX-ABLabelwith every property in its group.write_lineat line 489 prints the entire label for each property, andcrates/contacts/src/note_io.rs:144accumulates the result in an unrestricted String. The import callsto_note()before quota admission and retains that result inFresh; bulk-plan creation subsequently copies/serializes it. The reservation's claim to cover rendering output is therefore false.Independent bounded reproduction on dev-02, linked to the branch's compiled contacts crate:
Measured: 288,844 wire bytes → 268,457,034 rendered-note bytes, capacity 268,515,328; 267,672 KiB peak RSS, 7.283 s. Both checks accept it. This is conversion/rendering only, not a claimed full-route RSS measurement. The calculated reservation is 5,677,248 bytes, already exceeded by the note alone.
A 1 MiB label with 4,000 same-group email properties still fits the 2 MiB line, 4,096 physical-line, card-byte and allocation checks, but requires about 3.9 GiB of note text from roughly 1.1 MiB of wire input. Subsequent note/plan copies can exceed a 7 GB-class host. This larger case was calculated, not run. The HTTP upload cap cannot prevent it, and quota admission occurs too late. The large existing-book caveat is not needed to reproduce this issue.
New P2: the documented full-scale RSS gate fails on an independent rerun
scripts/contacts-import-memory.py:64failed at the disk fixture: 282,856 KiB versus its 262,144 KiB ceiling. Consequently, the script did not reach HTTP. I ran the unchanged HTTP test separately with a diagnostic 512 MiB measurement ceiling; it passed functionally at 280,796 KiB, which also exceeds the original 256 MiB ceiling. That diagnostic run is not a pass of the published resource gate.The 228.1 MiB number comes from absolute child-process peak RSS (
os.wait4) for a specific 20,000 × 5,242-byte fixture into an empty Home. Most wire content isX-PADDING, retained in the spool rather than the visible note. Ten percent of cards are unsupported 2.1; some accepted cards contain a 128-byte NOTE or a small photo. The peak includes retained upload strings, parser/converter scratch, naming/matching facts, bulk-plan/seed/serialized representations, SQLite, summary and completed background publication. There is no allocation profile attributing the exact peak among those components.Thus this is a fixture measurement, not a proof that all accepted 100 MiB files stay under 256 MiB. More visible NOTE/field content can retain larger plans even without the P1. A single 228–276 MiB import is reasonable on a 4-core/7 GB-class host; multi-GiB rendered output is not. Existing book state and concurrent uploads add further memory. Stabilize the representative resource gate and add derived-output cases; merely raising the gate does not fix P1.
Cheap reductions after establishing the bound: move
noteintoStep::Createinstead of cloning it (import.rs:600, compute its length first); omit over-1-KiB matching keys from retainedMatchFacts, not only the lookup maps. Neither substitutes for the rendering limit.Concrete simpler design
Keep sequential conversion and raw spooling, but replace the inferred rendering allowance with explicit derived-byte limits:
skipped: too large; preserve accepted original bytes.This gives direct input, object, rendered-card and aggregate-plan bounds without relying on a payload multiplier to model shared references.
Validation and limits
VM execution used
cua@calternal-dev-02-std, Nix and~/bin/slot. VM checkout wasca779da171dadb6ef1935436f01f05b418a8edbf;git diff ca779da1..7b932eb9 --statconfirms the requested head adds only the measurement documentation, with no code/test difference.~/bin/slot python3 scripts/contacts-import-memory.py: conversion + disk parameter probes passed; full disk fixture failed the RSS ceiling; HTTP was not reached.~/bin/slot cargo test -j4 -p calternal-contacts-actions --locked import: 45 passed, 2 ignored.~/bin/slot cargo test -j4 -p calternal-server --locked contacts_import: 1 unit + 11 route tests passed.binaries()/measure()functions with a diagnostic 512 MiB ceiling: test passed, 280,796 KiB RSS.rustc --edition=2024 /tmp/pr800-review3-label.rs -o /tmp/pr800-review3-label -L dependency=target/debug/deps --extern calternal_contacts=<branch rlib>, under the same Nix/slot wrapper; Pythonos.wait4measured the child. Artifacts:/tmp/pr800-review3-label.{rs,py},~/pr800-review3-label.log; gate logs:~/pr800-review3-{gates,extra,http}.log.No builds/tests ran on the control host. Author-reported fmt/clippy/full-suite results were inspected, not independently rerun. A supplemental visible-NOTE HTTP probe did not compile because its standalone linking selected incompatible duplicate dependency artifacts; no measurement from that attempt is used here.
New severity counts: P0 0, P1 1, P2 1, P3 0. Verdict: stop and simplify.
kayg referenced this pull request2026-10-31 21:04:29 +00:00
On hold pending the contacts import v2 plan in #815 (
docs/plans/0064-contacts-import-v2.md, headf97f322b). No further v1 fixes are proposed after the final review round.The plan puts an incremental byte limit on every converted output, removes shared-label/parameter allocation fan-out, and streams one card through disk-backed preparation, history and publication. It retains exact raw sources and ADR 0063/0064 companions, keeps suggestions capped and exact-key only, and requires full 20,000-card / 100 MiB HTTP and disk measurements below 192 MiB absolute peak RSS. It includes the three review rounds, failure table, salvage list and reviewable slices. Docs only; no implementation or repository settings changed.
kayg referenced this pull request2026-10-31 21:23:29 +00:00
kayg referenced this pull request2026-11-05 23:21:11 +00:00
housekeeping #1009: needs-decision.
Explicit hold and replacement by bounded contacts import v2 plan #815 / WIP #817. Preserve duplicate/import vectors rather than replaying the older importer.
original head:
7b932eb9627b364ddc55bb370eb7f597e1762f2d. against devcd7f84432febfc63b788fbb9b9f9950452982d74, git cherry reports 49 unmatched and 0 equivalent patches. the landing audit lists each candidate missing commit and stable patch match inpr-800.md; unmatched patches can include superseded behavior.left open, source branch unchanged. no rebase or new test claim for this decision lane.
Superseded by #815/#817 (contacts import v2). The branch and original tips are archived under
archive/(see #1009), so nothing is lost; useful regression vectors are noted there for the active lanes. Closing.Pull request closed