Skip to content

fix: IsFinished should return false when a task has not started - #2183

Open
MateusMo wants to merge 1 commit into
spectreconsole:mainfrom
MateusMo:fix/progress-context-isfinished-not-started
Open

fix: IsFinished should return false when a task has not started#2183
MateusMo wants to merge 1 commit into
spectreconsole:mainfrom
MateusMo:fix/progress-context-isfinished-not-started

Conversation

@MateusMo

Copy link
Copy Markdown

Fixes #2182

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

Changes

ProgressContext.IsFinished previously used _tasks.Where(x => x.IsStarted).All(task => task.IsFinished). When no task in the context had started yet (for example, tasks created with autoStart: false), Where(...) produced an empty sequence, and .All() on an empty sequence always returns true (vacuous truth). This caused IsFinished to report true even though no work had actually run, silently breaking the common while (!ctx.IsFinished) usage pattern.

  • ProgressContext.cs: IsFinished now returns true only when there are no tasks in the context, or when every task's own IsFinished is true. Since ProgressTask.IsFinished is false for any task that hasn't reached its MaxValue (including one that hasn't started), this naturally treats "not started" as "not finished" without needing a separate IsStarted check.
  • ProgressTests.cs: added four regression tests covering: no tasks in the context, a single task with autoStart: false, a task that has started and finished, and a mix of one finished task alongside one not-started task.

Please upvote 👍 this pull request if you are interested in it.

@MateusMo

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@patriksvensson

Copy link
Copy Markdown
Contributor

Thanks!

Due to the very long "Changes" section I need to ask; there was no AI involved in this PR?

@MateusMo

MateusMo commented Jul 30, 2026

Copy link
Copy Markdown
Author

Yes, I found the behavior running a console app calling the method and used claude ai to help me to validate the scenarios and improve the test coverage

@MateusMo

Copy link
Copy Markdown
Author

Any update on this one? Happy to make changes if needed

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.

ProgressContext.IsFinished returns true when tasks exist but none have started

2 participants