Repository navigation
[sentry:7847994825] A download superseded by a second download() with the same task id kept running after its body ended and published the shared staging file. The abort signal was consult - #113
Merged
Conversation
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.
A download superseded by a second
download()with the same task id kept running after its body ended and published the shared staging file. The abort signal was consulted only inside the chunk branch ofdownloadOne's read loop, so an attempt whose body had already ended — or that was blocked inreader.read()when the abort arrived and then sawdone— reached the publish block: it renamed<save>.tmpto<save>and deleted<save>.url, then failed its own post-transfer verification withValidation cancelled. The verification-failure branch ofDownloader.runthen removed that published file and its directory, so the live attempt's own post-transferstat(tmpPath)threw ENOENT and the download failed as[disk_device_lost] ENOENT— exactly the reported event (component/operationdownloads/download, crash framesdownloadOneline 783 /diskFailureline 240).Repair: one guard in
downloadOneimmediately after the transfer loop closes and before the persisted-size check,if (signal.aborted) throw new Error(DOWNLOAD_CANCELLED). A superseded or cancelled attempt now stands back and leaves the.tmppartial to the newcomer (or to the existingdownloaded === expectedSizeresume branch). No message, tag, telemetry, filter or public contract changes; aborted attempts remain unreported becausedownload()only callsonFailurewhen the task's own signal is not aborted.Task.supersededstays a bookkeeping flag and is deliberately not used for the guard, since cancellation must behave identically.Verification:
src/downloads/downloader-supersede-race.test.tsfailed on the base at the named assertion (gotValidation cancelledwhereDownload cancelledis required) and passes with the patch, asserting the newcomer's bytes are published, its staging file and.urlsidecar are consumed, and no ENOENT occurs. One English ADR added and linked from the decision index.Evidence:
Event 6767e23901504679bc38f0c107d83522 (atomic-chat-core@0.23.4, dist c21d779): component=downloads, operation=download, failure_reason=disk_device_lost, cause_code=ENOENT, exceptions [ENOENT "Underlying failure", Error "downloads download: disk_device_lost"], warning, failure_category operational.
Stack frames: src/downloads/downloader.ts:240 diskFailure, :784, :783 downloadOne — line 783 is the post-transfer
await stat(tmpPath).catch(...)and 784 itsthrow disk(e).Base behaviour of
Downloader.downloadsetsexisting.superseded = trueand aborts the old controller;downloadOneconsultedsignal.abortedonly after a chunk arrived and in sleeps, never between the end of the body and the publish block (rename(tmpPath, savePath)+rm(urlPath)).Downloader.run's verification-failure branch removes the file (rm(savePath, { force: true })) and its directory (rmdir(dirname(savePath))), which converts a superseded attempt's late publish into the live attempt's ENOENT at its ownstat(tmpPath).download()reports only when!task.controller.signal.aborted, so the superseded attempt is silent and the live attempt is the one that reaches Sentry — matching the single reported event shape.Test run on the unmodified base: src/downloads/downloader-supersede-race.test.ts failed with "expected [Function] to throw error including 'Download cancelled' but got 'Validation cancelled'" at the named assertion.
Same test after the patch: 1 passed, 0 failed (whole file green).
The release diff for atomic-chat-core@0.23.4#c21d7796d3b2 contains no hunk in src/downloads/downloader.ts, so release and base share this code.
docs/decisions/2026-11-15-a-superseded-download-does-not-publish.md added and one bullet appended to docs/decisions/INDEX.md.
Regression tests: src/downloads/downloader-supersede-race.test.ts
Full CI and human review are required.
Report: http://127.0.0.1:8080/tenants/707d0855-80ab-4e1f-a156-f1c4546cbf52/runs/18dea3c1-a2b8-436e-8f99-bfbec540d412
Sentry: https://atomic-chat.sentry.io/issues/7847994825/