Repository navigation
fix(download): pre-count files+bytes for accurate progress (#346) - #373
Conversation
DownloadProgressTracker was constructed with filesTotal=0 and pinned the denominator to filesCompleted on each completion event, guaranteeing the bar showed 100% from the first file. Byte totals also drifted run-to-run because they accumulated only from per-file 'total-size' events. - Add countPendingDownload() wrapping 'git annex find --not --in=here --json' to seed authoritative file count and total bytes before 'git annex get'. - Tracker now prefers byte-based percent when bytesTotal>0, falls back to file-based when filesTotal>0, and renders no bar in degraded mode. - Remove the filesTotal=filesCompleted fallback in processLine. - 'nemar dataset get' now uses the streaming tracker (was spinner only) and short-circuits when nothing is pending. - Add test/progress.test.ts: monotonic 0->100%, regression test for the fillsTotal pin, degraded-mode null percent, byte-vs-file divergence on uneven sizes, parser sanity.
Three high-confidence findings from /review-pr addressed:
1. Parallel-mode (-J N) byte misattribution (CRITICAL, code-reviewer):
The tracker stored per-file state in single shared fields. With
concurrent transfers git-annex interleaves --json-progress events on
stdout, so file A's 'ok' would credit whichever file most recently
emitted byte-progress (often a still-in-flight file B), pinning
percent to 100% mid-download. Replace with Map<file,{transferred,
total}> keyed on parsed.file. Match by file key on completion to
credit only the completing file's bytes.
2. Short-circuit conflated 'nothing pending' with 'parse failure'
(HIGH, silent-failure-hunter):
countPendingDownload returned {0,0} when stdout had only non-JSON
lines (warnings, locale info). The 'dataset get' command then
printed 'All data files already present' and returned, hiding a
real download. Now distinguish empty stdout (authoritative zero)
from non-empty-but-unparseable (returns null -> degraded mode ->
actual 'git annex get' runs).
3. Stderr discarded on non-zero exit (MEDIUM, silent-failure-hunter):
Surface git-annex stderr behind VERBOSE env (matches existing
pattern in update-check.ts/notices.ts) so a stale lock or other
underlying defect is debuggable.
Tests:
- progress.test.ts: interleaved -J events, ok-without-progress for
tiny files, more-ok-than-precount clamps at 100, fewer-ok stays
below 100. (4 new tests, 9 total)
- git-annex-precount.test.ts: real git-annex repos verifying empty/
non-annex/local-only/scoped/missing-files cases (5 tests). Follows
the no-mock policy in .rules/testing.md and the pattern in
test/datalad-commands.test.ts.
/review-pr findings + responsesRan pr-review-toolkit (code-reviewer, pr-test-analyzer, silent-failure-hunter) in parallel. All high-confidence findings addressed in 973ca99. Critical — parallel-mode byte misattribution (code-reviewer, conf 90)The original tracker held Fix: High — short-circuit conflated "nothing pending" with "parse failure" (silent-failure-hunter)
Fix: Distinguish empty-stdout (authoritative zero) from non-empty-but-unparseable (returns null → degraded mode → actual Medium — stderr discarded on non-zero exit (silent-failure-hunter)Fix: Surface Test coverage gaps (pr-test-analyzer)Addressed in this PR:
Deferred (low value vs. complexity, would need network/fixtures):
Verification
|
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR373Version: 🤖 Updated on each push. |
Summary
Fixes #346 —
nemar dataset download/getshowed100% N/N filesfrom the first file completion and reported different totals run-to-run on the same dataset.Root cause
DownloadProgressTrackerwas constructed withfilesTotal=0and pinned the denominator tofilesCompletedon each completion event, guaranteeing 100% display. Byte totals accumulated only from per-filetotal-sizeevents as git-annex queried the S3 remote, so they varied run-to-run depending on which files git-annex had inspected when the user looked.Fix
countPendingDownload()(wrapsgit annex find --not --in=here --json, sums thebytesizefield). Returnsnullon failure so callers degrade gracefully.bytesTotal > 0(more stable than file count when sizes vary wildly); falls back to file-based when onlyfilesTotalis known; degraded mode (no totals) shows file count without a misleading bar.filesTotal = filesCompletedfallback inprocessLine.nemar dataset getnow uses the streaming tracker (was spinner only) and short-circuits when nothing is pending.Files
src/lib/progress.ts— tracker math, newsetBytesTotal/getPercent/getProgresssrc/lib/git-annex.ts— newcountPendingDownload()src/commands/dataset.ts— wire precount intodownloadandgettest/progress.test.ts— 5 tests / 40 assertionsTest plan
bun test test/progress.test.ts— 5/5 pass (monotonic 0→100%, filesTotal-pin regression, degraded-mode null, byte-vs-file divergence, parser)tsc --noEmitcleanbiome checkcleanbun run buildcleannemar dataset download nm000132shows bar progressing monotonically 0% → 100% with byte total matchingdu -shof annexed filesAcceptance criteria (from #346)
du -shwithin rounding (precount uses authoritativebytesizefrom annex metadata)