Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

feat(upgrade): progress bars for delta-patch apply and full download - #1281

Merged
BYK merged 3 commits into
mainfrom
feat/upgrade-progress-bar
Jul 22, 2026
Merged

BYK merged 3 commits into
mainfrom
feat/upgrade-progress-bar

Conversation

@BYK

@BYK BYK commented Jul 22, 2026

Copy link
Copy Markdown
Member

What

sentry upgrade gives no feedback during its slow phases. This adds two byte-driven progress bars.

  • Apply phase (the slow part of a delta upgrade): a determinate bar — Applying 3 patch(es) [███████░░░░░░░░░] 22.1 MB / 45.0 MB. Total is the final binary size (the last patch's declared newSize), i.e. the real output the user gets — not the sum of intermediate hop writes. Progress is byte-driven across the whole chain, so it advances smoothly rather than stalling per hop.
  • Full-binary download: an indeterminate byte counter — Downloading 38.0 MB. The decompressed size isn't known ahead of time (Content-Length covers only the compressed stream), so it shows an honest live byte count, not a fake fraction.

Both bars are gated on interactive output via the existing isPlainOutput(), so they self-suppress under NO_COLOR, piped stdout, and CI.

How

  • New src/lib/progress.ts — makeByteProgress(label, totalBytes). Reuses the existing formatBytes (formatters/numbers) and isPlainOutput (formatters/plain-detect) helpers. Cosmetic-only: a render failure never aborts the upgrade, and both onProgress and done() are guarded against throwing streams.
  • An optional onBytes callback is threaded through applyReaderToMemory / applyReaderToFile → applyPatchChainInMemory → applyPatchChain, reporting bytes-written per output chunk. Purely additive — no behavior change to the apply/verify logic.
  • Apply bar created in applyChainAndReturn; download bar in streamDecompressToFile.

Tests

test/lib/progress.test.ts (7): determinate/indeterminate rendering, plain-output and non-TTY header-only behavior, byte accumulation, full-bar clamping, and the never-throws contract — mutation-verified: an unguarded done() turns the never-throws test RED.

Verification

`sentry upgrade` currently gives no feedback during the slow phases. Adds two
byte-driven progress bars, gated on interactive output (isPlainOutput()), so
they self-suppress under NO_COLOR, piped stdout, and CI.

- Apply phase: a determinate bar in applyChainAndReturn. Total is the final
  binary size (the last patch's declared newSize), so the number shown is the
  real output the user gets — not the sum of intermediate hop writes. Progress
  is byte-driven across all hops via an onBytes callback threaded through
  applyReaderToMemory/applyReaderToFile -> applyPatchChainInMemory ->
  applyPatchChain, so the bar advances smoothly through the whole chain.

- Full-binary download: an indeterminate byte counter in streamDecompressToFile.
  The decompressed size isn't known ahead of time (Content-Length covers only
  the compressed stream), so it shows a live byte count rather than a fake
  fraction.

New src/lib/progress.ts (makeByteProgress): reuses the existing formatBytes and
isPlainOutput helpers; cosmetic-only — a render failure never aborts the
upgrade, and both onProgress and done() are guarded against throwing streams.

Tests (test/lib/progress.test.ts, 7): determinate/indeterminate rendering,
plain-output and non-TTY header-only behavior, byte accumulation, full-bar
clamping, and the never-throws contract — mutation-verified: an unguarded
done() turns the never-throws test RED.
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-22 22:15 UTC

Comment thread src/lib/upgrade.ts Resolved
Comment thread src/lib/progress.ts Resolved
Comment thread src/lib/delta-upgrade.ts Resolved
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 90.32%. Project has 5489 uncovered lines.
✅ Project coverage is 81.71%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/upgrade.ts 70.59% ⚠️ 5 Missing and 1 partials
src/lib/delta-upgrade.ts 91.67% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.69%    81.71%    +0.02%
==========================================
  Files          426       427        +1
  Lines        29971     30018       +47
  Branches     19499     19513       +14
==========================================
+ Hits         24485     24529       +44
- Misses        5486      5489        +3
- Partials      2045      2046        +1

Generated by Codecov Action

Three fixes from Cursor Bugbot + Seer review of #1281:

1. Multi-hop apply bar total (Seer, medium): onBytes fires for the output
   bytes of EVERY hop — intermediate in-memory hops and the final disk write —
   so the bar total must be the SUM of all hops' newSize, not just the final
   binary's. The last-hop-only total made a multi-patch bar hit 100% after
   hop 1 and freeze. applyChainAndReturn now sums parsePatchHeader(p).newSize
   across all patches.

2. Progress not cleared on download failure (Bugbot, medium):
   streamDecompressToFile called progress.done() after the writer.end await in
   finally, so a rejecting end (ENOSPC/EIO) skipped it, leaving a stale bar
   merged into the error output. Wrapped the body in an outer try/finally so
   done() always runs.

3. Stale characters on shorter redraws (Bugbot, low): interactive redraws now
   pad the new frame with spaces to the previous frame's width, so a shrinking
   line (e.g. KB→MB boundary) can't leave leftover tail characters.

Tests: bspatch onBytes test asserts a 2-hop chain reports sum of both hops'
newSize (mutation-verified: dropping onBytes on in-memory hops → RED); progress
test asserts a shorter redraw is padded to erase the tail (mutation-verified:
removing the padding → RED).

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9c039ad. Configure here.

Comment thread src/lib/delta-upgrade.ts Resolved
Comment thread src/lib/upgrade.ts Resolved
Addresses two review findings on the progress bars:

1. Progress bars clash with the upgrade spinner (Cursor, medium): the main
   `sentry upgrade` path runs under withProgress, which animates a spinner on
   the same terminal line. A second in-place byte bar on stderr fought with it,
   making both unreadable. Reworked so progress feeds the spinner's setMessage
   callback instead of drawing its own bar — one animation, no clash. The
   setMessage is threaded from withProgress through executeUpgrade ->
   downloadBinaryToTemp -> {tryDeltaUpgrade -> attemptDeltaUpgrade ->
   resolve*Delta -> applyChainAndReturn, downloadFullBinary -> download*ToPath
   -> streamDecompressToFile}. When absent (JSON mode / non-TTY) it's a no-op.

2. writer.end() error masks the original stream error (Seer, medium): in
   streamDecompressToFile a rejection from writer.end() in the finally could
   overwrite the root-cause streaming error. Restructured so the original
   stream error is captured and rethrown preferentially; an end() failure that
   follows it is demoted to a debug log.

progress.ts is now a throttled message formatter (determinate bar with % or an
indeterminate byte counter) rather than a stream writer. Cosmetic-only: a
formatting/callback failure never propagates.

Tests: progress.test.ts rewritten for the setMessage API (7) — determinate/
indeterminate formatting, accumulation + clamp, throttling, final done() emit,
no-op without setMessage, never-throws. Mutation-verified: removing the emit
try/catch → never-throws RED; removing the throttle → throttle RED.
@BYK
BYK merged commit edb87d6 into main Jul 22, 2026
31 checks passed
@BYK
BYK deleted the feat/upgrade-progress-bar branch July 22, 2026 22:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant