fix(seed-loader): report deferred reference back-fill failures instead of swallowing them (#2805)#3219
Merged
Conversation
…d of swallowing them (#2805) A circular reference between two seed records is resolved in two passes: the parent is inserted first without the back-reference (deferred), then pass 2 issues an engine.update to fill it in. If that pass-2 update threw, resolveDeferredUpdates only logged a warning — the reference stayed NULL yet the load still returned success: true, errors: [], totalErrored: 0. An incomplete relationship was reported as a clean load. Route both pass-2 failure modes (target still missing, or the back-fill write threw) through a single recordDeferredError helper that pushes a ReferenceResolutionError into the object's per-result errors, bumps its errored count so summary.totalErrored is truthful, and joins allErrors so the load reports success: false — matching how pass 1's update path already reports write failures. Note: a lone transient blip on the back-fill still recovers via withTransientRetry (covered by a test); only a failure that outlasts the retry budget — or a non-transient error — is reported. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MAg2Tzkv69j9zx6ZyyrbHC
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
os-zhuang
marked this pull request as ready for review
July 18, 2026 14:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2805.
A circular reference between two seed records is resolved in two passes: the parent is inserted first without the back-reference (deferred to pass 2), then pass 2 issues an
engine.updateto fill the reference in once the target exists.If that pass-2 back-fill threw,
resolveDeferredUpdatesonly logged a warning — the reference stayedNULL, yet the load still returnedsuccess: true,errors: [],totalErrored: 0. An incomplete relationship was reported as a clean load.Repro (issue scenario)
audit_department.head_id → audit_workerandaudit_worker.department_id → audit_departmentreference each other.Engineeringinserts first (itshead_id → Aliceis deferred);Aliceinserts next; pass 2 back-fillsEngineering.head_idviaengine.update. When that update fails, the link is never written but the loader reported success.Fix
Route both pass-2 failure modes — target still missing, or the back-fill write threw — through a single
recordDeferredErrorhelper that:ReferenceResolutionErrorinto the object's per-resulterrors,erroredcount sosummary.totalErroredis truthful, andallErrorsso the load reportssuccess: false.This matches how pass 1's update path already reports write failures, and closes the latent gap where the "still unresolved after pass 2" branch recorded an error but never bumped
errored.Scope note
A lone transient blip on the back-fill still recovers via
withTransientRetry(the issue's literal one-shot"fetch failed"repro under-specifies this — a single transient error is retried and succeeds). Only a failure that outlasts the retry budget, or a non-transient error, is now reported. Both behaviors are pinned by tests.Tests
New
seed-loader-deferred-failure.test.ts:success: false,totalErrored > 0,head_idleftNULL, error names thehead_idfield (this test fails onmain, passes with the fix);success: true,totalErrored: 0.Existing
seed-loader-replay.test.tsandseed-loader-retry.test.tscontinue to pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01MAg2Tzkv69j9zx6ZyyrbHC
Generated by Claude Code