fix(cli): await trailing progress-log writes before settling download - #1122
Merged
Merged
Conversation
EhabY
force-pushed
the
fix/cli-download-trailing-progress-write-race
branch
from
September 21, 2026 14:12
a5fcadf to
a051b0b
Compare
aqandrew
approved these changes
Sep 22, 2026
aqandrew
left a comment
Contributor
There was a problem hiding this comment.
Appreciate you DRYing up the settle paths in cliManager.ts too 🙂
The download promise settled on a progressWrite captured by value, so a chunk write still in flight could recreate the progress log after cleanup cleared it, leaving a stale binary.progress.log behind. Chain each progress-log write onto the previous one and settle only after the write stream closes, so every write is awaited before cleanup runs.
EhabY
force-pushed
the
fix/cli-download-trailing-progress-write-race
branch
from
September 23, 2026 09:39
a051b0b to
1b498fe
Compare
Merged
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 #1120
Root cause
CliManager.download()settled its promise on aprogressWritecaptured by value at the moment the read stream closed. A chunk write still in flight at that point was never awaited, soclearProgress()could deletebinary.progress.logfirst and the trailing write would recreate it, leaving the file behind permanently. That is why the concurrent test failed only on the progress-log line and novi.waitFortimeout could fix it.Fix
Two changes in
download():progressWriteawaits every write, not just the last.close, which fs guarantees fires after every pending write callback.Cleanup can no longer race a trailing write, on any scheduler.
Tests
close(), like a real stream on a loaded runner. Fails on unfixed code, passes with the fix.withStreamError("write")now emitscloseaftererror, matching real fs withautoClose: true.vi.waitForpolling is removed; cleanup is complete when the download promises settle.🤖 Generated by Coder Agents