Skip to content

Conversation

@rtfeldman
Copy link
Contributor

@rtfeldman rtfeldman commented Jan 8, 2026

Screenshot 2026-01-07 at 8 34 00 PM

When the user presses Esc or the Stop button to interrupt a thread, terminal tools now capture their output and include it in the tool result. This allows the model to see what was happening in the terminal when the user interrupted, so it can answer questions about the output.

Changes

  • Thread::cancel() now returns a Task that waits for tools to respond to cancellation before flushing pending messages
  • Terminal tool uses select! to detect cancellation signal and immediately kills the terminal and captures output
  • run_turn_internal uses select! to break out of event loop on cancel
  • Added test for terminal tool cancellation output capture

This is a follow-up to #46218 which added similar functionality for the "Stop" button on individual terminal tool cards.

Release Notes:

  • Interrupting the agent now captures terminal output so the model can see what was running when you stopped it

When the user presses Esc or the Stop button to interrupt a thread,
terminal tools now capture their output and include it in the tool
result. This allows the model to see what was happening in the terminal
when the user interrupted, so it can answer questions about the output.

Changes:
- Thread::cancel() now returns a Task that waits for tools to respond
  to cancellation before flushing pending messages
- Terminal tool uses select! to detect cancellation signal and
  immediately kills the terminal and captures output
- run_turn_internal uses select! to break out of event loop on cancel
- Added test for terminal tool cancellation output capture

Release Notes:
- Interrupting the agent now captures terminal output so the model can
  see what was running when you stopped it
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 8, 2026
- Fix race condition in run_turn where detached cancel task could flush
  the new turn's pending message instead of the old one
- Improve test_terminal_tool_cancellation_captures_output with helper
  functions and recovery verification
- Add test_truncate_while_terminal_tool_running
- Add test_terminal_tool_cancellation_with_timeout_configured
- Add test_cancel_multiple_concurrent_terminal_tools with
  MultiTerminalEnvironment helper
- Fix assertion strings to match actual output format ('The user stopped this command')
- Add test for terminal-card stop button (was_stopped_by_user path)
- Add test for timeout actually expiring
- Make FakeTerminalHandle deterministic using channels instead of polling
- Add verify_thread_recovery helper to reduce test duplication
- Use GPUI executor timer instead of smol::Timer for deterministic testing
@rtfeldman rtfeldman marked this pull request as ready for review January 8, 2026 14:40
@rtfeldman rtfeldman merged commit 9be436b into main Jan 8, 2026
23 checks passed
@rtfeldman rtfeldman deleted the interrupted-terminal branch January 8, 2026 14:40
baldwindavid added a commit to baldwindavid/zed that referenced this pull request Jan 8, 2026
* main: (349 commits)
  component_preview: Fix license symlink (zed-industries#46379)
  Do not react on already observed buffer edits' versions (zed-industries#46308)
  Fix EP CLI output flicker (zed-industries#46313)
  vim: Fix bug where repeat operator could lead to unrecoverable replaying state (zed-industries#46376)
  vim: Implement text-based matching bracket logic for Vim '%' motion to correctly find pairs within comments (zed-industries#45559)
  Improve LSP button error message (zed-industries#46377)
  agent: Make reject/accept keybindings consistent with restore/stage (zed-industries#46373)
  Enable test-support features for some dev dependencies (zed-industries#46370)
  Capture terminal output when thread is interrupted (zed-industries#46306)
  Inline assistant tools: no more feature flag (zed-industries#46107)
  Add `ep split` subcommand for dataset splitting (zed-industries#46364)
  lsp_button: Fix long LSP version label (zed-industries#46359)
  remote: Introduce a proper mock remote connection (zed-industries#46337)
  ep: Allow matching patches against files without trailing newlines (zed-industries#46357)
  docs: Update "Custom Keybindings for Extension-Based Agents section" to include a troubleshooting note for defining an agent name (zed-industries#46144)
  Fail early if clangd is downloaded on aarch Linux (zed-industries#46346)
  ep: Handle errored requests in Anthropic batches (zed-industries#46351)
  settings_ui: Fix settings search missing results when BM25 finds partial matches (zed-industries#46349)
  workspace: Unpreview active tab when closing other tabs (zed-industries#46294)
  terminal: Skip SHLVL when loading login shell environment (zed-industries#46273)
  ...
rtfeldman added a commit that referenced this pull request Jan 8, 2026
<img width="707" height="778" alt="Screenshot 2026-01-07 at 8 34 00 PM"
src="https://github.com/user-attachments/assets/59842820-079b-4d47-9bdd-f77300f8a60e"
/>

When the user presses Esc or the Stop button to interrupt a thread,
terminal tools now capture their output and include it in the tool
result. This allows the model to see what was happening in the terminal
when the user interrupted, so it can answer questions about the output.

## Changes

- `Thread::cancel()` now returns a `Task` that waits for tools to
respond to cancellation before flushing pending messages
- Terminal tool uses `select!` to detect cancellation signal and
immediately kills the terminal and captures output
- `run_turn_internal` uses `select!` to break out of event loop on
cancel
- Added test for terminal tool cancellation output capture

This is a follow-up to #46218 which added similar functionality for the
"Stop" button on individual terminal tool cards.

Release Notes:

- Interrupting the agent now captures terminal output so the model can
see what was running when you stopped it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants