Repository navigation
fix(automations): a headless host closes finished run terminals, keeping the newest few - #25831
Merged
OrcaWin merged 5 commits intoOct 6, 2026
Conversation
…ing the newest few The desktop closes a run's terminal when the run completes; orcad had no renderer to do it, so hourly automations left a shell and PTY per run open forever (28 after ~6h on a real host). The headless service now closes a finished run's terminal after a 10-minute grace, keeps the newest three per automation viewable, and never touches a run that has not finished.
OrcaWin
marked this pull request as draft
October 6, 2026 07:55
added 2 commits
October 6, 2026 00:56
…s viewing Mirrors the desktop's take-over rule on headless hosts: a finished run's terminal stays open when any client drove input to it since spawn, is attached to or viewing it, or when this process cannot tell (it adopted the PTY rather than spawned it).
OrcaWin
marked this pull request as ready for review
October 6, 2026 07:57
OrcaWin
marked this pull request as draft
October 6, 2026 08:09
A failed run can still hold a live agent (blocked on a prompt, past the watch window, or after an observer error), so like the desktop only a completed run's terminal is closed. And only the run's own pane closes, so a pane a user split into the same tab survives.
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:10
OrcaWin
marked this pull request as draft
October 6, 2026 08:29
…s PTY The use check read run.terminalPtyId, but the close hit whatever PTY now occupies the run's pane. Restart-exited-pane and the Codex account-switch restart put a new PTY there, so a terminal a user was using could be killed. The close now resolves the pane's current PTY and closes only when it is the run's own; otherwise it closes nothing and only clears the run's terminal.
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:30
OrcaWin
marked this pull request as draft
October 6, 2026 08:31
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:34
This was referenced Oct 6, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Each time an automation runs on a remote Orca server, it opens a terminal. On the desktop, Orca closes that terminal when the run finishes. On a remote server nobody did that, so every run's terminal stayed open. One test host had 28 open shells after about six hours of three hourly automations. Over days that adds up to hundreds of shells, until the host runs out of resources. Now the server closes a completed run's terminal after 10 minutes and keeps the newest three per automation so you can still look at them.
What Changed
Before:
orca serve) there is no renderer, and the server-side automation path had no equivalent. Every run's terminal tab, shell and PTY stayed open forever.After:
completedand 10 minutes have passed since the server first saw it completed. The newest three completed runs per automation are always kept open. The close goes through the runtime'scloseTerminal, which closes only the run's own pane, so a pane a user split into the same tab survives. Before closing, it checks which PTY the pane holds now. It closes only when that is still the run's own PTY. If a restart put a new PTY in the pane (restarting an exited pane, or the Codex account-switch restart), it closes nothing and only clears the run's terminal fields.dispatch_failedrun can still hold a live agent: one blocked on a permission prompt, one past the 6-hour watch window, or one after an observer error;driving; the automation's own launch writes are classedlaunchand don't count) and one a client is attached to or viewing (a raw or remote terminal view subscriber);Why
Linked Issue
Fixes # (Phase 3 real-host finding on r7-b: 28 open shells after ~6h)
Visual Proof
N/A. No UI change.
Testing
All tests use fake timers.
Retention unit tests:
closeTerminal, nevercloseTerminalTab).Takeover unit tests: a terminal a client typed into is never closed. Neither is one a client is viewing, or one whose use can't be told.
Runtime tests for
readTerminalClientUse:unused.used.used, and goes back tounusedwhen the subscriber releases.unknown.Service test: a server-side service closes the oldest run terminals through
closeTerminalTab, clears them from the run record, and stops sweeping with the service. A desktop service never closes them. Run against the old service, the server-side test fails.Local results: the automations and orcad-automations suites pass (36 files, 250 tests).
pnpm tc:nodeand the changed-code quality gate are clean.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Server hosts on every platform get this, local and over SSH alike. It closes only terminals that belong to runs, never other terminals. No wire changes.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)