You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(core,seed,rest): idempotent batch retry via attempt-aware natural-key recheck (#3149)
bulkWrite's transient retry is at-least-once: when a driver commits a
batch but its response is lost (turso's fetch-based transport fails after
commit), the retry re-inserted the whole batch — 2 input rows became 4
stored rows, all reported success, each firing record-change and summary
recompute twice.
Rather than a generic dedup inside bulkWrite, thread a 1-based `attempt`
counter into writeBatch/writeOne and let each caller enforce batch-level
idempotency with its own natural key:
- core: withRetry passes the attempt number; writeBatch/writeOne gain a
`{ attempt }` context (backward compatible — callers may ignore it).
- seed: on attempt > 1, recheck existing rows by externalId (reusing
loadExistingRecords) and insert only the missing ones; reassemble the
per-row result in order.
- import: on attempt > 1 with matchFields, recheck by matchFields and
create only the missing rows. A short createManyData return is now
surfaced as a failed batch (so degradation, which also rechecks, runs)
instead of being padded. A pure-insert import (no matchFields) has no
natural key and stays at-least-once by documented contract.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01APnSDJneEDRh3Z51KGCLga
0 commit comments