Skip to content

fix(automations): sleep a finished run's terminal instead of closing it - #28838

Merged
AmoabaKelvin merged 2 commits into
stablyai:mainfrom
AmoabaKelvin:resume-finished-automation-runs
Oct 14, 2026
Merged

AmoabaKelvin merged 2 commits into
stablyai:mainfrom
AmoabaKelvin:resume-finished-automation-runs

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​132
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52

ELI5

When an automation run finished, Orca closed the terminal the run had used. Opening that run's workspace later found nothing inside, so Orca opened a new empty chat (or an empty shell with Chat UI off) and the run's conversation was nowhere to be seen. Now Orca puts the run's terminal to sleep instead of closing it, and opening the workspace wakes it with the conversation back on screen.

What Changed

Before: clicking a finished run's workspace in the sidebar opened a new "Claude Chat" with an empty "Ask anything" box. The run page's "Resume workspace" button opened the same empty workspace.

After: the sidebar click, and "View run" on the run page, open the run's own terminal, which picks up the agent's conversation again (claude --resume <id>, codex resume <id>, opencode --session <id>).

How:

  • When a run finishes in a workspace that was created for that run, and the agent reported its conversation id through its hooks, the cleanup now calls the existing single-pane hibernation (shutdownCompletedAgentPaneForHibernation) instead of closing the tab. The agent process still stops; the tab stays, along with a resume record. The run keeps its tab and pane ids and drops only the stopped process's id.
  • "View run" treats a run that has a pane but no process id as "slept in place" and opens that pane, which wakes it. After the wake it still finds that pane, even when another tab is selected.
  • Everything else closes as before: runs in a shared workspace (each run would leave a sleeping tab behind), agents that report no conversation id, runs that ended because their process exited, and runs the user took over. If the stop fails, the terminal is left running rather than closed.
  • "Resume workspace" is now "Open workspace", since that button never resumed anything.
  • Separate commit, needed for the above: the hibernation helper writes the resume record before it stops the process. The agent dies before its shell, the shell reports "command finished", and the pane's foreground tracker took that as the agent exiting and deleted the record. The pane now ignores that signal while Orca is stopping the terminal on purpose (suppressedPtyExitIds). The experimental auto-hibernation uses the same helper, so it gets the same fix.

Why

The terminal was closed on purpose in #9493, so recurring runs don't pile up hidden tabs and agent processes. Sleeping the pane keeps that benefit: the process still stops, and the only thing left is one tab in a workspace that exists for that run anyway.

Other options were saving the agent's session id on the run and building a new reopen path, which would repeat what hibernation and its wake already do, and importing the conversation into native chat, which is bigger and changes a terminal run into a chat.

Linked Issue

Fixes #28645

Visual Proof

Opening a finished Claude run's workspace from the sidebar, Chat UI on.

Before After
before after
A new empty Claude Chat The run's terminal, resumed with its prompt and reply

Testing

Tested by hand on macOS in a hidden dev build, with real runs of Claude Code 2.1.300, Codex 0.162.1 and OpenCode 1.18.35:

  • opening a finished run from the sidebar, with Chat UI on and off
  • "View run" before the wake, and after it with a different tab selected
  • quitting and relaunching the app: nothing restarts until the run is opened, then it resumes
  • a run in a shared workspace still closes its tab as before

Not tested: SSH and WSL hosts. An agent with no conversation id and a stop that fails are covered by unit tests only.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Worth a close look: the guard in pane-agent-identity.ts, since it changes shared terminal-pane behaviour, not only automations.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Runs on an SSH workspace go through the same existing helper, and the ownership rules (remote runtime and takeover exclusions) are unchanged.
  • Paired servers and headless hosts keep their own retention policy; nothing changes there.
  • The run record gets no new fields. Older runs, which have all three terminal ids cleared, open the workspace as before. An older client reading a slept run sees no terminal id and offers to open the workspace.
  • A phone opening a slept run's workspace should wake it through the existing hibernation wake. I have not tried this on a phone.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The agent dies before its shell, so the shell's command-finished mark read
as the agent exiting and deleted the record the hibernation had just written.
Closing it left the run's own workspace empty, so opening it later showed a
blank chat or shell instead of the run's conversation.

Fixes stablyai#28645
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cca5ed85-3250-4b2d-bbc2-de4f77588d34
📥 Commits

Reviewing files that changed from the base of the PR and between 6f92984 and 00e375f.

📒 Files selected for processing: 12
  • src/renderer/src/components/automations/automation-run-open-target.test.ts
  • src/renderer/src/components/automations/automation-run-open-target.ts
  • src/renderer/src/components/automations/automation-run-view-state.test.ts
  • src/renderer/src/components/automations/automation-run-view-state.ts
  • src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/hooks/automation-dispatch-completion.ts
  • src/renderer/src/hooks/automation-dispatch-handler.ts
  • src/renderer/src/hooks/automation-dispatch-unverifiable-loss.test.ts
  • src/renderer/src/hooks/useAutomationDispatchEvents.test.ts
  • src/renderer/src/lib/automation-terminal-ownership.test.ts
  • src/renderer/src/lib/automation-terminal-ownership.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Automation terminal finalization now returns a closed, hibernated, or no-retirement result. Eligible run-owned panes can be hibernated, and dispatch completion updates terminal identities according to that result. Confirmed shell handling preserves sleeping-session records for suppressed PTYs. Terminal run targeting can resolve an existing pane when its PTY is absent, and the workspace action label is now “Open workspace.”

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 00e37

Finished automation runs in their own workspace now hibernate their terminal instead of closing it, and opening the run wakes it. The changes look consistent and no concrete merge-blocking problem was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue [#28645] requires a terminal-kind automation session to open in the terminal view instead of an empty Chat UI. The PR preserves the run-owned pane by hibernating it, retains its pane key, clears…
Out of Scope Changes check Passed The production changes stay within the linked issue. They update automation terminal retirement, hibernation state, pane-exit handling, open-target resolution, and the related action label. The added …
Title check Passed The title clearly and concisely describes the primary change: hibernating finished automation run terminals instead of closing them.
Description check Passed The description follows the required template and explains the user impact, implementation, rationale, linked issue, visual proof, testing, review focus, compatibility notes, and checklist status. It …
  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Chat UI: opening a terminal-kind automation session renders an empty chat (session content invisible)

1 participant