Skip to content

Keep the Terminal's shell when the agent starts a new turn - #406

Merged
abhishekgahlot2 merged 1 commit into
useagenthq:mainfrom
coolestnick:fix/terminal-keeps-shell-across-turns
Nov 2, 2026
Merged

abhishekgahlot2 merged 1 commit into
useagenthq:mainfrom
coolestnick:fix/terminal-keeps-shell-across-turns

Conversation

@coolestnick

@coolestnick coolestnick commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #405

The Shell tab started over every time the agent started a new turn: the folder, scrollback and any running command were lost. InteractiveTerminal reconnected whenever runId changed, and the backend kills a PTY when its WebSocket closes. Every run in a thread resolves to the same sandbox, so switching runs gained nothing.

What changed

  • InteractiveTerminal keeps one connection for as long as it is mounted. The latest runId is read only when it connects or reconnects.
  • A new run while no shell is open (no sandbox yet, or the terminal was unavailable) connects at once instead of waiting for the back-off.
  • A back-off timer whose socket was already replaced does nothing, so there is never a second connection.
  • TerminalPane takes threadId and keys the terminal by it, so another thread still gets its own fresh shell.

Tests

frontend/components/chat/interactive-terminal.test.tsx mounts the real TerminalPane with a stand-in terminal and WebSocket:

  • a new turn in the same thread keeps the open shell (fails on main)
  • a dropped connection reconnects through the newest run (fails on main)
  • with no sandbox yet, the new run connects at once, with no duplicate
  • an unavailable terminal tries again on a new turn
  • opening another thread closes the old shell and starts its own
  • leaving the pane closes the shell

Checks: root bun run typecheck passes; in frontend/, bun run test (1774 pass, 0 fail), bun run lint (nothing in the changed files) and bun run build pass; bun test scripts/agent-docs.test.ts passes.

Not yet checked in the running app with a live sandbox; I can add a recording once I have one.

Out of scope: switching Shell to Log and back still starts a new shell, because the terminal unmounts with the tab.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@abhishekgahlot2
abhishekgahlot2 merged commit a31defc into useagenthq:main Nov 2, 2026
21 checks passed
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

Merged, thanks @coolestnick. Keeping the shell across turns is a big one.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the Terminal's shell when the agent starts a new turn

2 participants