Skip to content

Report problems of pending lines when a task problem collector is done - #346122

Merged
Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
Iyanuoluwa007:tasks-background-flush-on-exit
Nov 13, 2026
Merged

Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
Iyanuoluwa007:tasks-background-flush-on-exit

Conversation

@Iyanuoluwa007

@Iyanuoluwa007 Oke Iyanuoluwa Enoch (Iyanuoluwa007) commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #179361

Problem

With the background task from the issue (cat data.txt with a beginsPattern/endsPattern problem matcher), only the problems of the first file show up. The same matcher on a non-background task shows all four.

AbstractProblemCollector.processLine queues each line on a promise chain (this.tail), so lines are processed asynchronously. done() however reported and cleaned the markers immediately. For a background task, terminalTaskSystem calls watchingProblemMatcher.done() synchronously in the terminal's onExit handler. When the process exits right after printing its output (as cat does), the queued lines have not been processed yet at that point:

  1. done() reports nothing, because no markers are recorded yet.
  2. The queued lines are processed afterwards. The markers of file are delivered when the collector switches to file2.
  3. The markers of file2 are recorded, but nothing delivers them any more: a watching collector only delivers a resource's markers when the resource changes, when the end pattern is seen, or in done().

In the issue, End is the last line of data.txt. Without a trailing newline, LineDataEventAddon only emits it when the addon is disposed, which is after the task has stopped listening, so the end pattern is never seen and step 3 applies.

Fix

WatchingProblemCollector.done() (used for background tasks) now waits for the pending lines (this.tail) before reporting and cleaning the markers, and returns a promise that resolves once it has. If no line was ever processed it behaves as before. A rejected line does not prevent the final report.

When a background task exits, terminalTaskSystem awaits done() before it releases the task, disposes the collector and fires the end events. Otherwise a new run of the same task could start while this run's cleanup was still pending, and that cleanup could remove the new run's markers.

Regular tasks (StartStopProblemCollector) are unchanged: done() stays synchronous there, as on main.

Testing

Added a unit test to problemCollectors.test.ts that feeds the issue's output (without the end pattern) to a WatchingProblemCollector and awaits done() right away, the way the task system does on exit.

  • Before the fix it fails: only /file1 (problem1, problem2) is delivered.
  • After the fix both /file1 and /file2 are delivered with all four problems by the time the promise from done() resolves. If done() doesn't wait for the pending lines, the test fails.

The branch is rebased on main. All tests in src/vs/workbench/contrib/tasks/test pass (103 passing), ESLint is clean on the changed files, and tsc -p src reports no errors in them.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 21:04

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.

🟡 Changes recommended

Pending file-location lookups can delay cleanup until after task completion, allowing the old collector to delete diagnostics from a subsequent run unless terminal exit paths await finalization.

1 open issue
What changed in this PR

This PR addresses #179361 by delaying task problem-collector finalization until queued output lines finish processing, so background tasks can report diagnostics for the last file even without an end-pattern line.

Changes:

  • Defer marker reporting and cleanup until pending line processing settles, including rejection.
  • Add a regression test that calls done() immediately after queuing diagnostics for two files.
File Description
src/​vs/​workbench/​contrib/​tasks/​test/​common/​problemCollectors.test.ts Tests delivery of all four diagnostics when finalization starts with pending lines.
src/​vs/​workbench/​contrib/​tasks/​common/​problemCollectors.ts Defers final marker reporting and cleanup until the processing queue settles.

Review effort: Balanced

Lines are fed to a problem collector asynchronously (processLine chains
them on a promise), but done() reported and cleaned markers immediately.
When a background task exits right after printing its output, done() ran
before the queued lines were processed. Markers of the last resource were
then recorded but never delivered, because a watching collector only
delivers a resource's markers when the resource changes, the end pattern
is seen, or done() runs. Only the problems of the first file showed up.

Make done() wait for the pending lines before reporting the markers, and
return a promise for that. When a background task exits, wait for it
before the task is released and its end is signaled, so that the cleanup
of this run can't remove markers from a later run of the same task.

Fixes microsoft#179361

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.

🟡 Changes recommended

Tasks can be released and terminals disposed before asynchronous finalization completes, allowing reruns to race with stale diagnostic cleanup and causing completion signals to be lost.

3 open issues

Review effort: Max

The problems of a background task's last lines were lost because the
task exits before they are processed. Regular tasks report their markers
when the process ends, 100 ms after exit, and don't wait for done(), so
making done() asynchronous for them only delayed the report and the
cleanup into a possible next run.

Keep done() synchronous in AbstractProblemCollector, as before, and only
wait for the pending lines in WatchingProblemCollector, which the task
system awaits when a background task exits.
@tommieboings50-source

tommieboings50-source commented Nov 6, 2026 via email

Copy link
Copy Markdown

@meganrogge
Megan Rogge (meganrogge) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit cd81f02 Nov 13, 2026
52 checks passed
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.

Background task problem matcher does not show all problems

6 participants