Repository navigation
fix(daemon): defer artifact cleanup until active downloads close - #4165
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
thymikee
left a comment
There was a problem hiding this comment.
Independent review: one P2 finding at head d7b2350866de48ec17dba50e50c45948b49e6b2d (merge-base a0e7c7dc239922bf93adaceff20a2f7e78579146).
- P2 — Release the acquired stream when HTTP setup throws —
packages/daemon/src/server/downloadable-artifact-http.ts:94-105(catch at:133-134).openDownloadableArtifactnow incrementsactiveDownloadsand returns an already-created stream, butsetHeaderruns before the stream error/response-close handlers are installed. A valid artifact filename such astrace-💥passessafeArtifactFilenameand makes Node reject the Content-Disposition header. The catch sends 500 without destroying the stream, which remains paused/open and never releases its reader count. Unlike base, expiry/disposal can now leave the source and generated archive permanently undeleted because cleanup always sees an active download. Reproduced through the real HTTP route: after the 500 and explicit cleanup,streamClosed=false,destroyed=false,sourceExists=true,archiveExists=true; manually destroying the abandoned stream immediately permits cleanup. Keep the acquired stream available to the catch and destroy it on every setup failure; install its error handling before operations that can throw. Add a regression covering cleanup after this failure.
Validation (no CI wait): installed/built each checkout, then ran the same affected selection once per checkout: pnpm exec vitest run --project unit-core packages/daemon/src/server/downloadable-artifact-http.test.ts packages/daemon/src/resources/artifact-tracking.test.ts packages/daemon/src/server/__tests__/http-server-artifacts.test.ts packages/daemon/src/server/http/daemon-runtime-artifacts.test.ts. Head: 14 passed. Base with only the new regression test copied into a disposable checkout: 12 passed, 2 failed, both at the intended archive-exists assertion (downloadable-artifact-http.test.ts:89).
Additional scratch probes passed for mid-read abort/error release, a real HTTP disconnect, blocked admission after cleanup/expiry, one shared in-flight archive build for overlapping downloads and inventory/download overlap, inventory filtering during cleanup, and last-reader deletion. Existing tests cover ordinary file artifacts and retained sources. The map identity guard prevents duplicate cleanup; the timer is cleared rather than rearmed while readers remain active. Design: the reader counter plus terminal cleanup-request flag is a small, sufficient state model; the remaining issue is exception-safe ownership transfer to HTTP.
Reviewed source stayed read-only. Logs: /tmp/r4165-head-tests.log, /tmp/r4165-base-tests.log, /tmp/r4165-probe.log.
Apex SentinelVerdict: Since the last review: 6 new · 1 still open · 7 no longer raised 7 finding(s): 4 minor, 3 nit. Verdict: approve. 🟡 Minor (4)
🔵 Nit (3)
Reply under an inline comment with Earlier reviewsReview of
|
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:214 |
One download's cancellation aborts the archive tar another active download is waiting on |
packages/daemon/src/resources/artifact-tracking.ts:188 |
🆕 An orphaned directory archive is never removed when the download's own deadline fires |
packages/daemon/src/server/downloadable-artifact-http.ts:113 |
🆕 The HTTP byte threshold cleanup no longer honors retainArtifacts |
packages/daemon/src/server/downloadable-artifact-http.ts:122 |
🆕 A truncated artifact read no longer retires the artifact: flush error returns before cleanup |
🔵 Nit (4)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:20 |
🆕 Download deadline constant is duplicated with the cleanup timeout and only works because the two values are equal today |
packages/daemon/src/resources/artifact-tracking.ts:110 |
🆕 New public API OpenedDownloadableArtifact has no doc on its two behavioural members |
packages/daemon/src/resources/artifact-tracking.ts:131 |
Shared source-cleanup refcount is monotonically sticky: one caller opting out of deletion permanently disables deletion of the file for later registrations of the same path |
packages/daemon/src/resources/artifact-tracking.ts:419 |
🆕 canReadArtifact now answers three different questions |
Review of 89f63cbc · 02.11.2026 12:08 UTC
Apex Sentinel
Verdict: approve
Since the last review: 5 new · 2 still open · 5 no longer raised
7 finding(s): 5 minor, 2 nit. Verdict: approve.
🟡 Minor (5)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:131 |
Shared source-cleanup ownership silently drops the delete intent of the first registration |
packages/daemon/src/resources/artifact-tracking.ts:198 |
🆕 cancelArtifactDownload aborts the shared entry.archiveAbortController when the canceled download has no stream yet, s… |
packages/daemon/src/resources/artifact-tracking.ts:445 |
🆕 Shared source-cleanup counter is lost when every registration for a path is still deferred, leaking the source directory forever |
packages/daemon/src/resources/artifact-tracking.ts:445 |
🆕 A stalled download can permanently orphan an artifact source file (and its archive temp dir) |
packages/daemon/src/server/downloadable-artifact-http.ts:113 |
A mid-stream size overrun deletes the artifact before the declared length is validated, turning a truncated response into a lost artifact |
🔵 Nit (2)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:21 |
🆕 Two 15-minute constants with one value, and one of them names the wrong thing |
packages/daemon/src/resources/artifact-tracking.ts:376 |
🆕 Tar's spawn timeout reuses the download lifetime and is silently required to stay >= it |
Review of f401c7d1 · 02.11.2026 11:38 UTC
Apex Sentinel
Verdict: approve
Since the last review: 4 new · 3 still open · 8 no longer raised
7 finding(s): 3 minor, 4 nit. Verdict: approve.
🟡 Minor (3)
| Where | Finding |
|---|---|
packages/daemon/src/server/downloadable-artifact-http.test.ts:107 |
🆕 fireDeadlines in the new fixture fires the artifact expiry timer too, so the deadline case does not test what its name claims |
packages/daemon/src/server/downloadable-artifact-http.ts:118 |
🆕 Truncated artifact read leaves the source and its temp archive undeleted until the 15-minute expiry |
packages/daemon/src/resources/artifact-tracking.ts:131 |
Any pending download entry now blocks registering another tenant's artifact at the same path |
🔵 Nit (4)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:76 |
Disposal correctness depends on an unstated call ordering between requestArtifactCleanup and cancelArtifactDownload |
packages/daemon/src/resources/artifact-tracking.ts:445 |
A stalled or aborted download holds the whole artifact source on disk for a second 15 minutes |
packages/daemon/src/server/downloadable-artifact-http.ts:109 |
🆕 Mid-stream cleanup now unlinks the source before the final chunk reaches the socket |
packages/daemon/src/server/downloadable-artifact-http.ts:124 |
🆕 retainArtifacts skips a size check that is the pipeline's only failure signal |
Review of 56cf7bb7 · time not recorded
Apex Sentinel
Verdict: request_changes
Since the last review: 6 new · 0 still open · 7 no longer raised
6 finding(s): 1 major, 2 minor, 3 nit. Verdict: request_changes. reached max rounds (1).
Required fixes
- pipeArtifactDownload leaves the response unfinished when the file read fails or the stream ends early, unlike the piped predecessor
🟠 Major (1)
| Where | Finding |
|---|---|
packages/daemon/src/server/downloadable-artifact-http.ts:142 |
🆕 pipeArtifactDownload leaves the response unfinished when the file read fails or the stream ends early, unlike the piped predecessor |
🟡 Minor (2)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:125 |
🆕 Doomed entries stay in the registry, so trackDownloadableArtifact can hand back an id that 404s and whose file is then deleted |
packages/daemon/src/resources/artifact-tracking.ts:370 |
🆕 Deferred cleanup drops the timer, so a hung download can leak the entry forever |
🔵 Nit (3)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:57 |
🆕 New runtime-slot teardown path is never exercised and the new test never disposes its runtime, so the dispose-time leak stays hidden |
packages/daemon/src/resources/artifact-tracking.ts:138 |
🆕 openDownloadableArtifact returns a widened type instead of its own name |
packages/daemon/src/server/downloadable-artifact-http.ts:150 |
🆕 pipeArtifactDownload ignores stream.resume()'s return value and its own end path |
There was a problem hiding this comment.
Apex Sentinel: 7 new findings on d7b2350. The verdict and the full list are in the summary comment.
There was a problem hiding this comment.
Apex Sentinel: 6 new findings on 56cf7bb. The verdict and the full list are in the summary comment.
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
321 explicit tests passed; the full exact-head affected gate passed ( |
There was a problem hiding this comment.
Apex Sentinel: 4 new findings on f401c7d. The verdict and the full list are in the summary comment.
|
Pushed |
There was a problem hiding this comment.
Apex Sentinel: 3 new findings on 89f63cb. The verdict and the full list are in the summary comment.
|
Pushed test-only head |
There was a problem hiding this comment.
Apex Sentinel: 3 new findings on 3a4f158. The verdict and the full list are in the summary comment.
|
Pushed |
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on e4ad2f3. The verdict and the full list are in the summary comment.
|
The code looks good at e4ad2f3. All 21 checks are green at that commit, and there are no conflicts. Not blocking, and fine to take or leave: (1) a client that disconnects while a directory archive is still being prepared does not cancel the download, so a lone waiter leaves tar running until it ends or hits the 15-minute timeout (the rule: a download is cancelled when its HTTP client goes away, in every phase, e.g. by passing an AbortSignal into openDownloadableArtifact and aborting on response close); (2) after a deadline aborts the shared tar, a new download can join the aborted archive promise and get RESOURCE_EXPIRED for a live artifact (artifact-tracking.ts#L334); (3) the post-tar I did not re-run the tests or check:affected, so I relied on green CI and code reading. I could not see a log of the live daemon run or the red-first result against 3a4f158, and I did not reproduce the race in (2). |
Summary
Keep directory archives and sources owned until downloads settle, with abortable pipelines, bounded lifetimes, teardown, immediate ID retirement, and JSON open errors. Cancel shared archive preparation only after every active download is cancelled.
FU-ART; seven files; artifact-download scope. Prior blocker: #4060 (not reproduced).
Validation
a0e7c7dc239922bf93adaceff20a2f7e78579146; prior reviewed head:3a4f1582ae989b722b3c428c90fa2a232b1a6ab1; tested head:e4ad2f37e3381dc09ad1b382e1ffe17e3599d5f1.pnpm format: passed.pnpm check:affected --run --head e4ad2f37e3381dc09ad1b382e1ffe17e3599d5f1: passed; receiptrun-SWZ47c,exactCommit=true,checkoutChanged=false; 16,988 unit passed, 304 related passed; all runnable stages passed.