Repository navigation
Upload: retry finalize alone instead of re-running the flow - #237
Merged
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
f566d18
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://60182536.nemar-website.pages.dev |
| Branch Preview URL: | https://fix-issue-201-finalize-retry.nemar-website.pages.dev |
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.
Fixes #201 — note: closing keywords only auto-close on merges into the default branch (
main), and this PR targetsstaging, so the issue must be closed manually after merge, with a comment naming this PR and the merge commit.Problem
In
src/pages/upload.astro, the catch-all around the upload flow re-enabled the whole form after afinalizeDatasetfailure. Clicking Submit again re-ran the entire flow fromcreateDraftDataset— creating a duplicate draft and re-uploading every byte, the opposite of what the error message tells the user to do. Since #198 gave finalize a 60s deadline, this path is reachable via a mere backend hang, not only a genuine failure.Fix
runUploadQueuecompletes, the page keeps the draft id inpendingFinalizeIdbefore callingfinalizeDataset.finalizeDataset(draftId)directly — nocreateDraftDataset, no re-upload. A retry that fails again stays on the retry path, so it is repeatable.pendingFinalizeIdis null). "Drop something else" (resetPrecheck) clears the retry state and restores the original button label, which is the deliberate escape hatch back to the full flow.resolveSubmitActioninsrc/lib/upload-client.ts, unit-tested insrc/lib/upload-client.test.ts(null / id / repeated id / empty id).Stale-finalize hardening (review follow-up)
The in-flight finalize window (up to 60s) previously left "Drop something else" clickable, and a reset during that window could race the pending promise into a duplicate draft or a stale
/upload/successnavigation. Three layers close this:finalizeDatasetcall sites (initial and retry) now pass{ signal: uploadAbort.signal }, soresetPrecheck()'s existing abort actually cancels a hanging finalize. Aborting finalize is safe — the route is idempotent and the draft stays visible on the dashboard.submitGenerationcounter (bumped byresetPrecheck()) is captured at submit/retry start and re-checked after every await: a stale closure that outlives a reset bails out without navigating, without writingpendingFinalizeId, and without touching the new flow's UI — even if the abort somehow did not throw.Why finalize-only retry is safe
The backend finalize route is explicitly idempotent — nemar-cli
routes/datasets/upload.tsstates "finalize is idempotent — can be called multiple times". Every byte is already in S3 when finalize runs, so repeating finalize against the same draft is safe and cheap, and needs no new backend support.Verification
bun run typecheck— 0 errors, 0 warnings, 0 hints (216 files)bun run lint— clean (212 files)bun run test— 1037/1037 passed (53 files), including 4 newresolveSubmitActiontestsManual QA (test.nemar.org, after this lands on staging)
[email protected]via the email-code form; the code is echoed asdev_codeand prefilled on/login/verify, so no inbox is needed./upload, drop a tiny BIDS set (e.g. adataset_description.jsonplus onesub-01file) and submit./api/v1/datasets/*/finalizeURL), so finalize fails. While finalize is pending, the progress label reads "Finalizing..." and "Drop something else" is disabled.POST /api/v1/datasets/<id>/finalize— noPOST /api/v1/datasets(create) and no S3 PUTs — and that the page lands on/upload/success./dashboardand confirm exactly one dataset was created, with no duplicate draft./upload/success, no stale error over the new flow, and the old draft (still un-finalized) simply remains on the dashboard.