You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Retain terminal processes between window reloads #20013
Reacted by David Alan Hjelle, Yukai Huang, Mariusz Dugin, Benjamin Pasero, Temitope, Neil Stevens, Ahmad Awais, Noam Ben Shabat, Yoz Grahame, Simon Chan and 76 more
This would be cool, I'm not sure it could be done in the sense of retaining the processes (as they should be killed once VS Code is done). Maybe the shell and environment could be restored though?
Daniel Imms (@Tyriar) Yes restoration is exactly what i was referring to, e.g If I'm working on a Laravel Project and I run the serve artisan command, after restarting VS due to an update, it would be a great implementation if VS would automatically run the "php artisan serve" command on its own.
Looks like my extension mitigates this issue almost entirely.
It would be pretty cool to retain the output of those terminals between sessions, but I guess an API for getting it as text, and another one for writing it (without executing it as a command) are necessary for this (Daniel Imms (@Tyriar) do you think it would be possible to add them?) . We can leverage the fact that by using this extension no two terminals opened by it would probably have the same name, so we could safely link terminals' names with their text.
I guess it would also be nicer to have the terminals ready as soon as you open the project's folder, without the need to run the Terminals: Run command, I'll add an option for this tomorrow 👍
This issue is a little ambiguous at the moment, here's what I see covered by it:
1. Support reloading VS Code without terminating terminal processes
This can be accomplished by moving the terminal process to live under Electron's main process instead of the browser process, then reinstating the terminals after a load occurs. There is quite a bit of refactoring that needs to happen here, probably most significantly is splitting node-pty into 2 components; one that launches the process and exposes the file descriptorunix socket/named pipe (under the main process), and one that takes the file descriptorunix socket/named pipe and connects to it (under the browser process). We do not want the pty's data stream to just be passed through IPC as it will slow down everything.
2. Restore terminals with their cwd/environments they were created with when restoring a workspace
Note that this should only happen when 1. does not occur. The solution for this should allow for split terminals to be restored in the future #7504
Reacted by Thomas Willheim, Jayden Seric, Yukai Huang, MrChriZ, mudont, Benny Samuelsson, Ian Huang, Michael Wu, Carsten Führmann, westr029 and 8 more
one that launches the process and exposes the file descriptor (under the main process), and one that takes the file descriptor and connects to it (under the browser process)
Daniel Imms (@Tyriar) Some OSes do not allow the pty master fd to be duped/cloned, e.g. used by another process than the original creating process. IPC is the only platform independent way imho (os pipes are pretty fast though).
jerch good to know. The sheer amount of data that's possible to go through the terminal is the concern as it could lock up the main process which is shared between all VS Code windows 😕. Maybe I'm just overestimating the impact it would have on the main process? Any more details on the some OSes part?
Daniel Imms (@Tyriar) It is still possible to carry the master fds around without duping it, if O_CLOEXEC is not set. It is important to reenable it in the browser process, otherwise the fds will leak to all subprocesses (assuming you have no control of electron's subprocess creation, the fds could also be closed by hand between fork and exec).
I'm thinking this is the way forward as node-pty is a standalone project (not just VS Code), plus plumbing terminal data streams through the standard main process IPC could block other communication if the terminal is spitting out lots of data.
mmis1000 (@mmis1000) Again not sure what you are trying to say, as it is somewhat self contra-dictionary:
That didn't work unless there is a reset control code somewhere in the response, then it can serve as a cut point.
True, but unreliable for a "skip-over" replay, as sequences like RIS or DECSTR typically dont happen during normal session run.
Still your observation here contradicts this:
You can't get the correct result unless you actually replay all of it.
If you find a state-destructive sequence (like RIS, and DECSTR to some degree), you dont have to replay it all. Note that for me there is a difference between full replay (as full emulation) vs. search accumulated data for for those points.
Again - thats not reliable, as it is likely to never happen (thus you are likely to never find a clean state entrypoint for replay beside the very beginning). But before replaying everything, there is another option you didnt consider - do some state back reporting from an active terminal endpoint, and link this to the stream data position. This way you get an unclean entrypoint (a replay from that point needs to apply the state itself first, before working on the follow-up stream data). Those unclean entrypoints can be managed by the daemon, even with discarding older stream data completely, while a healthy looking replay from there is still possible. No second full replay needed at all. (This is abit like doing terminal state snapshots, and starting from there.)
I'd consider assume you can always read data from client not reliable at all. As it always have been, client may lost/corrupt data for some reason, like a app crash, system BSOD. A recovery method that require client not encounter error at all is …weird? Even in the vscode case. If it is going to run in the browser, then things like such is very likely to happen.
mmis1000 (@mmis1000) Sorry I cannot see how your last comment is related to anything above. Plz lets not jump to random conclusions without proper context, as it derails the discussion.
From the beginning, the only reason I think it is a terminal multiplexer protocol is the reconnect without resend everything', nothing more is included.
Terminal protocol is a stream of patch, and unlike video, you don't have a P frame somewhere by default to skip over to near the end of stream unless user issue a 'reset' manually (which is basically does not exist and does not matter at all because user seldom do that).
In order to able skip over without break the output completely. Somewhere in the system need to generate the P frame. So you can 'start from here' or you just can't (think of a video that trying to start from a I frame, it really can't).
It can be client (the terminal send all its last state to server, and the server response with it when reconnect), or it can be server (something like tmux but with far less function). Or probably mixed, server only do it if client is unavailable.
But I feel completely rely on client and assume the client will just do it well is a bad assumption, clients always break for variable of reasons. I am not not think of it. I am assume it is going to break.
So the only reliable option will be the server render it (always or on required).
Is there a third way can handle the reconnect correctly without show you a half broken screen?
Or show you a non broken screen on reconnect isn't one of the goal?
There are different scenarios possible to get better fault tolerance (imho thats what you are trying to say above). But note that currently a short terminal disconnect/reconnect is simply not possible for vscode by any means, thus even a best effort approach, which has to bail out for rare edge cases, is already a huge overall win.
What you describe as "it is going to break" is currently the default case from where developing a better idea would start. Whether the final concept should aim for 99% fault tolerance or is good enough to cover most cases (80:20 rule), depends alot on the circumstances, like manpower to implement such a solution and last but not least its technical implications like additional runtime costs (more CPU/memory hungry for "play along emulation", storage needs on server side etc). Since I am not going to implement it, I wont judge about it. From a user's perspective anything into that direction will be better than now, as easy as that.
If you have some profound terminal interface experience and time to share, maybe try helping to get it shaped. I for myself have not enough time for that, thus can only give some ideas here.
Usually I close all terminals before exit because of "loss" of terminal tabs. But yesterday I didn't. Today I've noticed, that after I've connected to remote container my terminal was restored. It lost terminal tabs, but scroll history is here. It work even with multiple terminals. And it is able to processing executed commands. For example, I can execute sleep 60; echo "test", quit and connect again. It seems like it doesn't lost running command and after 60 seconds pass, it prints "test". Tested it with simulation of network failure and "reload window". It worked as expected.
For me, everything is already here. I'm very happy :D
(the only one wish - terminal tabs should be restored too or integrated)
Activity
Tyriar commentedon Feb 6, 2017
This would be cool, I'm not sure it could be done in the sense of retaining the processes (as they should be killed once VS Code is done). Maybe the shell and environment could be restored though?
There's a PR out for hyper which is relevant vercel/hyper#945
ppot commentedon Feb 12, 2017
Daniel Imms (@Tyriar) Thanks. I'm here if you have questions!
sibowilldo commentedon Feb 13, 2017
Daniel Imms (@Tyriar) Yes restoration is exactly what i was referring to, e.g If I'm working on a Laravel Project and I run the serve artisan command, after restarting VS due to an update, it would be a great implementation if VS would automatically run the "php artisan serve" command on its own.
Tyriar commentedon Jul 13, 2017
Fabio Spampinato (@fabiospampinato) just published an extension which allows you to configure several terminals and launch them all at once! https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-terminals
fabiospampinato commentedon Jul 13, 2017
Looks like my extension mitigates this issue almost entirely.
It would be pretty cool to retain the output of those terminals between sessions, but I guess an API for getting it as text, and another one for writing it (without executing it as a command) are necessary for this (Daniel Imms (@Tyriar) do you think it would be possible to add them?) . We can leverage the fact that by using this extension no two terminals opened by it would probably have the same name, so we could safely link terminals' names with their text.
I guess it would also be nicer to have the terminals ready as soon as you open the project's folder, without the need to run the
Terminals: Runcommand, I'll add an option for this tomorrow 👍Tyriar commentedon Jul 13, 2017
Fabio Spampinato (@fabiospampinato) no plan on adding the ability to read or write right now.
Something that will help you though is that you will be able to add/remove environment variable from the environment in 1.15.
Tyriar commentedon Oct 27, 2017
This issue is a little ambiguous at the moment, here's what I see covered by it:
1. Support reloading VS Code without terminating terminal processes
This can be accomplished by moving the terminal process to live under Electron's main process instead of the browser process, then reinstating the terminals after a load occurs. There is quite a bit of refactoring that needs to happen here, probably most significantly is splitting node-pty into 2 components; one that launches the process and exposes the
file descriptorunix socket/named pipe (under the main process), and one that takes thefile descriptorunix socket/named pipe and connects to it (under the browser process). We do not want the pty's data stream to just be passed through IPC as it will slow down everything.2. Restore terminals with their cwd/environments they were created with when restoring a workspace
Note that this should only happen when 1. does not occur. The solution for this should allow for split terminals to be restored in the future #7504
jerch commentedon Oct 28, 2017
Daniel Imms (@Tyriar) Some OSes do not allow the pty master fd to be duped/cloned, e.g. used by another process than the original creating process. IPC is the only platform independent way imho (os pipes are pretty fast though).
Tyriar commentedon Oct 28, 2017
jerch good to know. The sheer amount of data that's possible to go through the terminal is the concern as it could lock up the main process which is shared between all VS Code windows 😕. Maybe I'm just overestimating the impact it would have on the main process? Any more details on the some OSes part?
jerch commentedon Oct 29, 2017
Daniel Imms (@Tyriar) It is still possible to carry the master fds around without duping it, if
O_CLOEXECis not set. It is important to reenable it in the browser process, otherwise the fds will leak to all subprocesses (assuming you have no control of electron's subprocess creation, the fds could also be closed by hand betweenforkandexec).Tyriar commentedon Feb 7, 2018
I amended my commend in #20013 (comment) to replace file descriptor with named pipe (Windows) and unix socket (Linux/macOS) as file descriptors are per-process. Implementation would use the
netmodule https://nodejs.org/api/net.html#net_ipc_supportI'm thinking this is the way forward as node-pty is a standalone project (not just VS Code), plus plumbing terminal data streams through the standard main process IPC could block other communication if the terminal is spitting out lots of data.
38 remaining items
jerch commentedon Sep 11, 2020
mmis1000 (@mmis1000) Again not sure what you are trying to say, as it is somewhat self contra-dictionary:
True, but unreliable for a "skip-over" replay, as sequences like RIS or DECSTR typically dont happen during normal session run.
Still your observation here contradicts this:
If you find a state-destructive sequence (like RIS, and DECSTR to some degree), you dont have to replay it all. Note that for me there is a difference between full replay (as full emulation) vs. search accumulated data for for those points.
Again - thats not reliable, as it is likely to never happen (thus you are likely to never find a clean state entrypoint for replay beside the very beginning). But before replaying everything, there is another option you didnt consider - do some state back reporting from an active terminal endpoint, and link this to the stream data position. This way you get an unclean entrypoint (a replay from that point needs to apply the state itself first, before working on the follow-up stream data). Those unclean entrypoints can be managed by the daemon, even with discarding older stream data completely, while a healthy looking replay from there is still possible. No second full replay needed at all. (This is abit like doing terminal state snapshots, and starting from there.)
mmis1000 commentedon Sep 12, 2020
I'd consider
assume you can always read data from clientnot reliable at all. As it always have been, client may lost/corrupt data for some reason, like a app crash, system BSOD. A recovery method that require client not encounter error at all is …weird? Even in the vscode case. If it is going to run in the browser, then things like such is very likely to happen.jerch commentedon Sep 12, 2020
mmis1000 (@mmis1000) Sorry I cannot see how your last comment is related to anything above. Plz lets not jump to random conclusions without proper context, as it derails the discussion.
mmis1000 commentedon Sep 12, 2020
From the beginning, the only reason I think it is a terminal multiplexer protocol is the reconnect without resend everything', nothing more is included.
Terminal protocol is a stream of patch, and unlike video, you don't have a
P framesomewhere by default to skip over to near the end of stream unless user issue a 'reset' manually (which is basically does not exist and does not matter at all because user seldom do that).In order to able skip over without break the output completely. Somewhere in the system need to generate the
P frame. So you can 'start from here' or you just can't (think of a video that trying to start from aI frame, it really can't).It can be client (the terminal send all its last state to server, and the server response with it when reconnect), or it can be server (something like tmux but with far less function). Or probably mixed, server only do it if client is unavailable.
But I feel completely rely on client and assume the client will just do it well is a bad assumption, clients always break for variable of reasons. I am not
not think of it. I am assumeit is going to break.So the only reliable option will be
the server render it (always or on required).Is there a third way can handle the reconnect correctly without show you a half broken screen?
Or show you a non broken screen on reconnect isn't one of the goal?
jerch commentedon Sep 13, 2020
mmis1000 (@mmis1000)
There are different scenarios possible to get better fault tolerance (imho thats what you are trying to say above). But note that currently a short terminal disconnect/reconnect is simply not possible for vscode by any means, thus even a best effort approach, which has to bail out for rare edge cases, is already a huge overall win.
What you describe as "it is going to break" is currently the default case from where developing a better idea would start. Whether the final concept should aim for 99% fault tolerance or is good enough to cover most cases (80:20 rule), depends alot on the circumstances, like manpower to implement such a solution and last but not least its technical implications like additional runtime costs (more CPU/memory hungry for "play along emulation", storage needs on server side etc). Since I am not going to implement it, I wont judge about it. From a user's perspective anything into that direction will be better than now, as easy as that.
If you have some profound terminal interface experience and time to share, maybe try helping to get it shaped. I for myself have not enough time for that, thus can only give some ideas here.
Bessonov commentedon Dec 5, 2020
Usually I close all terminals before exit because of "loss" of terminal tabs. But yesterday I didn't. Today I've noticed, that after I've connected to remote container my terminal was restored. It lost terminal tabs, but scroll history is here. It work even with multiple terminals. And it is able to processing executed commands. For example, I can execute
sleep 60; echo "test", quit and connect again. It seems like it doesn't lost running command and after 60 seconds pass, it prints "test". Tested it with simulation of network failure and "reload window". It worked as expected.For me, everything is already here. I'm very happy :D
(the only one wish - terminal tabs should be restored too or integrated)
Version: 1.51.0
Commit: fcac248
Date: 2020-11-05T18:16:10.374Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.4.0-56-generic
Bessonov commentedon Dec 7, 2020
Unfortunately, it doesn't work every time. It seems like something dying after some time...
Tyriar commentedon Feb 22, 2021
Done in #116449 🎉