Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupt running shell tool commands #365

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

jsibbison-square
Copy link
Collaborator

@jsibbison-square jsibbison-square commented Nov 28, 2024

This PR makes it so that interrupts to the agent.reply stream kills the running the bash process if there is one. Essentially it is relying on resources being cleaned up when the stream is cleaned up (leaves scope). So its a shortish term solution that is ok given the majority of systems will be network calls in the future and the shell commands are the most important to be killing atm. To make this work required 2 changes:

  • Switch from std::process::Command to tokio::process::Command for running bash commands as this has an option to kill_on_drop which allows it to be killed when the parent scope is cleaned up.
  • In the goose server use a timeout every 500ms on the stream to detect when the client has closed the stream connection. When the server detects the closed connection it drops the streams which cleans up the process. This works with the existing 'Stop current Goose' button from the GUI or Ctrl+C on CLI.

Tested via checking if a running shell command was halted part way through on interrupt. Eg. run a shell command for 15 seconds that every seconds writes its current iteration number to test.md

Note I have not included an updated ui/desktop/src/bin/goosed so this will be required for people to see the difference. Let me know if I should be including it

Copy link
Collaborator

@baxen baxen left a comment

Choose a reason for hiding this comment

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

Very clean 💯

break;
}
Err(_) => { // Heartbeat, used to detect disconnected clients and then end running tools.
if let Err(e) = tx.try_send(ProtocolFormatter::heartbeat()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: should we use tx.is_closed instead of sending a heartbeat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That worked somehow, I've removed the sending of heartbeat events.

@jsibbison-square jsibbison-square merged commit ceb80ca into v1.0 Nov 28, 2024
2 checks passed
michaelneale added a commit that referenced this pull request Nov 28, 2024
* v1.0:
  fix: During configure remove 'recommended' from provider descriptions (#372)
  [cli] On interrupt repair messages (#370)
  feat: add low priority user output for bash
  feat: collapse long tool args (#368)
  feat: Hardened runtime and notarization (#367)
  feat: use mac main menu (#366)
  [app] Turn send button into stop button when goose is responding so user can cancel if needed
  [app] Fix position for MoreMenu and make top region a little smaller
  feat [cli]: Add keyring management for OpenAI API keys (#361)
  Interrupt running shell tool commands (#365)
  [GUI multiprocess] tabless multiple goosed processes per window (#355)
  feat: simplify initial session splash (#362)
  fix: hide response form behind flag
@yingjiehe-xyz yingjiehe-xyz deleted the jsibbison-20241128-interrupt-shell branch February 5, 2025 21:04
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.

2 participants