Skip to content

Progress: store scoped while state with start time and delay swapped - #332735

Merged
SteVen Batten (sbatten) merged 3 commits into
microsoft:mainfrom
VaggelisGian:fix-scoped-progress-delay-replay
Oct 29, 2026
Merged

SteVen Batten (sbatten) merged 3 commits into
microsoft:mainfrom
VaggelisGian:fix-scoped-progress-delay-replay

Conversation

@VaggelisGian

Copy link
Copy Markdown
Contributor

Fixes #332734

ScopedProgressIndicator.showWhile passed the configured delay as whileStart and Date.now() as whileDelay into ProgressIndicatorState.While, reversing the parameter contract. Wrong since the class was introduced, and line 305 remains the only construction site.

Honest scope note: today this produces no visible misbehavior, because the single replay formula whileDelay - (Date.now() - whileStart) happens to be algebraically symmetric under exactly this swap (verified symbolically, on a numeric grid, and by executing both orders against the compiled module). The defect is latent: the whileDelay > 0 guard reads a wall-clock timestamp and can never be false, and any future reader of these fields gets values opposite to their names. The change puts start time and delay back in the declared order; the new test pins the stored fields so any future re-swap fails immediately.

Draft until #332734 receives triage.

How was this tested

node build/next/index.ts transpile
ELECTRON_ENABLE_LOGGING=1 ".build/electron/Code - OSS.exe" test/unit/electron/index.js --crash-reporter-directory=.build/crashes --run vs/workbench/services/progress/test/browser/progressIndicator.test.js

The new test constructs a scoped indicator with a delayed showWhile, asserts the stored state fields (whileDelay === 5000, whileStart within the capture window), and exercises the replay on scope reopen. Against the unfixed source it fails with whileDelay holding a raw timestamp; with this change: 3 passing, 0 failing.

Additional verification performed during development:

  • symbolic evaluation plus a numeric grid over delay x elapsed combinations: old and new orders produce identical replay outcomes for every reachable input today, confirming this is a semantic correction rather than a behavior fix
  • grep confirmed line 305 is the only construction site of ProgressIndicatorState.While

ScopedProgressIndicator.showWhile passed the configured delay as
whileStart and Date.now() as whileDelay into ProgressIndicatorState.While,
reversing the parameter contract introduced with the class. The replay
formula happens to be symmetric under this particular swap so no visible
misbehavior exists today, but the delay-vs-timestamp guard reads a wall
clock value and any future reader of these fields gets wrong meanings.
Pass start time and delay in the declared order and pin the stored
fields with a regression test.

Test Plan:
  node build/next/index.ts transpile
  ELECTRON_ENABLE_LOGGING=1 .build/electron/Code-OSS.exe test/unit/electron/index.js --crash-reporter-directory=.build/crashes --run vs/workbench/services/progress/test/browser/progressIndicator.test.js
  3 passing (1 failing before the change: whileDelay held a timestamp)
Copilot AI balanced review requested due to automatic review settings August 26, 2026 12:00

Copilot AI 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.

Pull request overview

Corrects swapped whileStart and whileDelay arguments in scoped progress state.

Changes:

  • Restores the declared argument order.
  • Adds regression coverage for stored state and replay behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
progressIndicator.ts Corrects While state construction.
progressIndicator.test.ts Adds regression coverage.
Suppressed comments (1)

src/vs/workbench/services/progress/test/browser/progressIndicator.test.ts:161

  • This assertion assumes fewer than two seconds pass before scope activation, so a preempted or debug CI run can fail even though replay is correct. Once the full delay has elapsed, onDidScopeActivate intentionally calls show(undefined); accept that case (or use a fake clock) rather than imposing the > 3000 wall-clock bound.
		assert.strictEqual(true, typeof testProgressBar.fShowDelay === 'number' && testProgressBar.fShowDelay > 3000 && testProgressBar.fShowDelay <= 5000, `unexpected show delay: ${testProgressBar.fShowDelay}`);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Same content, matching the one-line inline comment convention.
@VaggelisGian

Copy link
Copy Markdown
Contributor Author

Addressed in 39418af: both explanatory comments condensed to single lines.

@sbatten SteVen Batten (sbatten) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Approving. showWhile now passes (promise, Date.now(), delay || 0), which matches the ProgressIndicatorState.While constructor order (whilePromise, whileStart, whileDelay). Initial display is unchanged; the fix only affects the stored state replayed when a scope reactivates.

Verification: source-based controlled-clock checks against main and this head. For ordinary reopen timing the replay arithmetic gives the same result for both argument orders, so the swap is masked there. With a zero/omitted delay and the wall clock moving backward, main replays show(1000) while this PR replays show(undefined) (immediate). The repository Electron test suite was not run.

Nonblocking suggestion: the new test reads private state and asserts a real-time bound (> 3000 ms), which passes on main too and can flake under scheduling pauses. Consider a controlled clock instead: start at a positive timestamp (e.g. 100000), showWhile(promise, 0) in an inactive scope, move the clock back to 99000, activate the scope and assert show received exactly undefined.

@sbatten
SteVen Batten (sbatten) marked this pull request as ready for review October 27, 2026 05:00
@sbatten
SteVen Batten (sbatten) enabled auto-merge (squash) October 27, 2026 05:00
@sbatten
SteVen Batten (sbatten) merged commit 0e821c4 into microsoft:main Oct 29, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 29, 2026
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.

ScopedProgressIndicator stores whileStart and whileDelay swapped in showWhile

6 participants