Repository navigation
Reattached tasks are not consistently recognized as running tasks #174792
Description
Type: Bug
- In an empty folder, create
.vscode/tasks.jsonwith:{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "while true; do echo running; sleep 3; done" } ] } - Ensure that
terminal.integrated.enablePersistentSessionsistrue. - Command palette > Tasks: Run Task >
echo> Continue without scanning the task output - Reload the window
- Verify that the task's terminal has reattached and that it is still producing output
- Command palette > Tasks: Show Running Tasks
Actual:
"No task is running", but the task is still running. The running tasks indicator in the status bar is missing. Attempting to re-run the task starts another task.
Expect:
Same behavior as if step 4 had been skipped: The terminal showing the task output is activated (or toggled). The running tasks indicator in the status bar shows a running task. Attempting to re-run the task results in a notification that the task is already active (and options to terminate/restart).
(Alternatively, the task is stopped on reload and not reattached, so it's actually not running.)
Additional info:
This seems to work as expected if I set "isBackground": true above, but I'm not sure that it should be necessary for this scenario to work.
Anectdotally, I have an extension that creates its own tasks on-demand using ProcessExecution, and even when setting isBackground set to true those tasks also have this problem. (The extension can also launch existing tasks retrieved via tasks.fetchTasks, which may or may not have isBackground set.)
My motivating use case is to allow my extension to detect if a particular task is running, even if it wasn't launched by my extension. tasks.taskExecutions could work for this purpose as long as VS Code recognizes that the task is actually running, but this doesn't work when the window is reloaded.
This means that my extension can't even recognize its own background ProcessExecution tasks when they're reattached, so it recreates them instead of reusing them. If the user doesn't notice, they can end up with a number of unnecessary tasks running in the background. Even if they do, they have to manually stop the unwanted ones (and, potentially, avoid stopping the "real," non-reattached task). This is especially counter-intuitive since users may see reloading the window as a way to reset state, but it actually exacerbates the problem.
(Actually, not to go off on too much of a tangent, but for my particular purposes I would also need a way to figure out the process ID for a previously started execution--else I need to start my own execution so I can get the process ID that way. So while I think there's a bug here, I'm still not entirely sure what I'd do on my end even if I could detect that some old task had been reattached. Maybe there needs to be a way to signal that specific tasks shouldn't be reattached, or some API to get a process ID for a task execution that's already started. This is all secondary, but I'm mentioning it here in case it informs something about the approach for this issue.)
VS Code version: Code 1.75.1 (441438a, 2023-02-08T21:34:01.965Z)
OS version: Darwin arm64 22.3.0
Modes:
Sandboxed: No
System Info
| Item | Value |
|---|---|
| CPUs | Apple M1 (8 x 24) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
| Load (avg) | 2, 3, 3 |
| Memory (System) | 16.00GB (0.11GB free) |
| Process Argv | |
| Screen Reader | no |
| VM | 0% |
Activity
meganrogge commentedon Feb 21, 2023
Thanks for the issue, this is as-designed - we restore and reconnect to background tasks only. We still want to show the buffer content from a task that was previously run even if it wasn't a background task.
vscodenpa commentedon Feb 21, 2023
The described behavior is how it is expected to work. If you disagree, please explain what is expected and what is not in more detail. See also our issue reporting guidelines.
Happy Coding!
joshbolduc commentedon Feb 21, 2023
Appreciate the reply! I may not be following exactly, but I think the behavior I am seeing does not quite match up with what I understand the expected behavior to be.
Is it expected that a non-background task would continue to run after the window is reloaded? I'm inferring from your response that it should not, but in my repro above, it does. When I launch the non-background
echotask above and reload the window, I can still see it print "running" to the terminal every 3 seconds. So from that perspective, it looks like it is actually restoring and reconnecting to the task even though it's not a background task. The only part that doesn't seem to work is that it's not enumerated among running tasks (as it would be if it were a background task).Maybe that is the intended behavior? But it seems to me that if the task is going to continue to run, it would make sense to continue to treat it as a running task. Otherwise, the behavior is a little puzzling to me--e.g., if the user tries to start the task again using "run task," VS Code will happily launch another instance of the same task while an earlier instance is still running, even though it wouldn't do so if the window hadn't been reloaded.
If the expectation is the task should be terminated when the window is restored, and the buffered output is just retained for later review--the idea being you can set it as a background task if you want it to survive the reload--then that behavior would also make sense to me. But that would mean the bug here is that the task is not terminated on reloading the window.
I have an extension that launches a background task programmatically. When I reload the window, I see the same behavior for that task as I do for the non-background
echotask--i.e., the task keeps running with its terminal reattached, but it is not enumerated among running tasks the way the background version ofechowould be. From your description, it sounds like this might be a (separate?) bug. I don't have a minimal repro handy for this that would confirm I'm not just doing something wrong in my extension, but now that I have a better understanding of the expected behavior, I could create one and/or open a new bug if that would help.