Skip to content

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

Merged
BYK merged 1 commit into
mainfrom
feat/upgrade-progress-bar
Jul 22, 2026
Merged

BYK merged 1 commit into
mainfrom
feat/upgrade-progress-bar

Conversation

@BYK

@BYK BYK commented Jul 22, 2026

Copy link
Copy Markdown
Owner

What

Adds live progress bars to lore upgrade so the slow phases aren't a silent wait.

  • Apply phase (the slow part of a delta upgrade): a determinate bar — Applying 3 patches [███████░░░░░░░░░] 152 MB / 310 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 87.0 MB. The decompressed size isn't knowable ahead (Content-Length only covers the compressed stream), so it shows an honest live byte count, not a fake fraction.

The tiny parallel patch downloads (KBs) intentionally get no bar.

How

  • New packages/gateway/src/cli/lib/progress.ts: makeByteProgress(label, totalBytes) — reusable, modeled on the existing makeSyncProgress. TTY-only; cosmetic (rendering must never abort the operation); clears its line on done().
  • Progress callback (onBytes) threaded through transformPatch → applyReaderToMemory/applyReaderToFile → applyPatchChainInMemory → applyPatchChain, reporting bytes-written per output chunk.
  • Apply bar created in applyChainAndReturn; download bar in streamDecompressToFile.

Tests

packages/gateway/test/progress.test.ts (6 tests): determinate/indeterminate rendering, non-TTY header-only behavior, full-bar clamping, byte accumulation, and the never-throws contract — which caught an unguarded done() (a throwing output stream could propagate); fixed.

Verification

  • 23/23 tests pass (6 progress + 17 bspatch), typecheck clean, lint 0 errors, format:check clean.
  • No behavior change to the apply/download logic — purely additive progress reporting.

Adds a reusable makeByteProgress() bar (TTY-only, cosmetic — never aborts the
operation, done() guarded) and wires it into the self-upgrade flow:

- Apply phase: determinate bar in applyChainAndReturn. Total is the final
  binary size (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
  transformPatch -> applyReaderToMemory/applyReaderToFile ->
  applyPatchChainInMemory -> applyPatchChain, so the bar advances smoothly
  through the whole chain.

- Full-binary download: indeterminate byte counter in streamDecompressToFile
  (used by both nightly and stable). The decompressed size isn't knowable
  ahead (Content-Length only covers the compressed stream), so it shows a live
  byte count rather than a fake fraction.

The tiny parallel patch downloads get no bar — they're KBs and fast.

Adds packages/gateway/test/progress.test.ts (6 tests): determinate/
indeterminate rendering, non-TTY header-only, clamping, byte accumulation,
and the never-throws contract (caught an unguarded done() — fixed).
Comment on lines +655 to +665
chain,
oldBinaryPath,
destPath,
progress.onProgress,
);
return {
sha256,
patchBytes: chain.totalSize,
chainLength: chain.patches.length,
};
} finally {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: In a multi-patch delta upgrade, the progress bar's reported bytes accumulate across all patches, while the total is only the final patch's size, causing the counter to exceed its maximum.
Severity: MEDIUM

Suggested Fix

To align with the intent of showing progress toward the final file, only pass the onBytes progress callback to the final patch application step (applyReaderToFile). Do not pass it to the intermediate steps that write to memory (applyReaderToMemory). This will ensure the progress bar only tracks bytes written to the final destination file.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/gateway/src/cli/lib/delta-upgrade.ts#L654-L665

Potential issue: The progress bar for delta upgrades is initialized with the size of the
final binary output from the last patch in a chain. However, the progress tracking
function, `onBytes`, is invoked for every byte written during each intermediate patch
application. This causes the displayed number of bytes written to be the sum of the
sizes of all intermediate outputs plus the final output. For any multi-patch upgrade,
the progress bar will show a written amount far exceeding the total (e.g., `9.3 GB / 310
MB`), which is confusing to the user and contradicts the feature's stated intent.

Also affects:

  • packages/gateway/src/cli/lib/bspatch.ts:737~753

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 62.71%. Project has 6836 uncovered lines.
❌ Project coverage is 74.95%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
packages/gateway/src/cli/lib/delta-upgrade.ts 0.00% ⚠️ 12 Missing
packages/gateway/src/cli/lib/upgrade.ts 0.00% ⚠️ 8 Missing
packages/gateway/src/cli/lib/progress.ts 94.29% ⚠️ 2 Missing and 2 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    74.97%    74.95%    -0.02%
==========================================
  Files          166       167        +1
  Lines        27235     27289       +54
  Branches     19282     19306       +24
==========================================
+ Hits         20418     20453       +35
- Misses        6817      6836       +19
- Partials      1963      1965        +2

Generated by Codecov Action

@BYK
BYK merged commit b73c48e into main Jul 22, 2026
24 checks passed
@BYK
BYK deleted the feat/upgrade-progress-bar branch July 22, 2026 12:16
@github-actions

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant