Skip to content

feat(terminal): a terminal a worker creates closes with that worker - #47371

Merged
Jinwoo-H merged 4 commits into
mainfrom
worker-cleanup-terminal-owner
Nov 23, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
worker-cleanup-terminal-owner

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #47370.

Problem

Terminals a worker's agent opens with orca terminal create (a test runner, a dev server) had no owner, so they stayed open after the worker closed.

Change

  • The host learns the caller from evidence the CLI already sends. terminal.create carried no caller, so the CLI now sends the same caller evidence it sends on orchestration.* calls (local requests only). The host binds the new terminal to a worker only when that evidence names a live worker's own terminal (its resource is owned, not released, and the handle still names the resource's pane) or a worker chat's session. Windows and phones send no caller, and other agents name no worker, so their terminals never get an owner.
  • Bound terminals close with the worker through the same path as the setup terminal (fix(orchestration): close a worker's setup terminal and startup tabs with it #47370), on release, stop, and a paired host's release. No new timer.
  • --keep-open on terminal create creates an unbound terminal. TerminalCreateParams.keepOpen is optional; older hosts drop it and close nothing, and older CLIs send no evidence, so nothing changes for them.
  • orca terminal split from a worker binds the new pane the same way, with --keep-open. Its schema moves to terminal-split-params.ts (the params file hit its line limit).
  • A worker whose shell kept its pre-restart handle is still found by its pane (ORCA_PANE_KEY), so what it opens is bound.
  • A legacy paired host closes a stopped worker's bound terminals too, not only a released one's.
  • Workers get one line in their brief; the CLI help gets one line. The shared --keep-open flag help now reads for both commands.

Verification

  • worker-bound-terminals.test.ts (real orchestration DB): a terminal the worker's agent opened closes with it; one opened with --keep-open survives; terminals from a window or a non-worker agent's terminal get no owner. A worker whose shell outlived a restart still owns what it opens. A terminal a chat worker opens (named by its session) closes with it. The split and legacy-stop wiring reuse the tested binder and close helper; they have no test of their own.
  • Typecheck (node, web, cli) and oxlint on touched files pass locally.

Gaps

  • Not exercised in the app: it needs a live worker, which needs a real agent turn this rig does not run.
  • A terminal created in a workspace where no worker runs closes with its worker but shows no banner.

Performance

None, because binding is one indexed lookup and one row write per terminal create from an agent, and closing reuses the release path from #47370.

Risk

Level: Medium. A wrong owner would close a terminal with a worker it does not belong to. The host binds only when the caller evidence names a live worker's own terminal whose pane still matches, never for windows or phones, and --keep-open opts out. A plain revert backs it out.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​230 $\color{#cf222e}{\Huge{\mathbf{−}}}$​94 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136

@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-terminal-owner branch 2 times, most recently from 084f601 to 444c74c Compare November 23, 2026 04:14
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-close-with-worker branch from ba7ed9a to 0c07f15 Compare November 23, 2026 04:14
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-terminal-owner branch 8 times, most recently from c4804b6 to 5e9a931 Compare November 23, 2026 05:46
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-close-with-worker branch from bd3fb9c to adaba2a Compare November 23, 2026 06:02
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-terminal-owner branch from 5e9a931 to d93056b Compare November 23, 2026 06:02
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-close-with-worker branch from adaba2a to 834c98c Compare November 23, 2026 06:19
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-terminal-owner branch from d93056b to c5b70cb Compare November 23, 2026 06:19
@Jinwoo-H
Jinwoo-H changed the base branch from worker-cleanup-close-with-worker to main November 23, 2026 06:27
orca terminal create run by an orchestration worker's own agent now binds
the new terminal to that worker, so it closes when the worker does, like
the setup terminal and startup tabs.

- The CLI sends the caller evidence it already sends for orchestration
  calls; the host binds only when that evidence names a live worker's
  own terminal or chat. Windows, phones and other agents bind nothing.
- --keep-open creates an unbound terminal. Older hosts drop the field
  and close nothing, as before.
- Workers are told in one line; the CLI help says it in one line.
…s and stops on paired hosts

- orca terminal split from a worker binds the new pane to it; --keep-open
  opts out. The split schema moves to its own file.
- A worker whose shell kept its pre-restart handle is still found by its
  pane, so what it opens is bound.
- A legacy paired host closes a stopped worker's bound terminals.
@Jinwoo-H
Jinwoo-H force-pushed the worker-cleanup-terminal-owner branch from c5b70cb to d348b51 Compare November 23, 2026 06:27
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Terminal create and split requests now support --keep-open. Local CLI requests include orchestration compatibility evidence. Eligible terminals created by a worker can be bound to that worker, and remote worker release and stop paths close bound terminals. CLI specifications, worker guidance, and tests document and cover these behaviors.

Merge Risk: Low · up to 7c641

Terminals that a worker creates now close with that worker, and --keep-open opts out. Cleanup failures no longer break a settled release or stop. Two minor items remain. A --retry-split that omits --keep-open can bind a pane that the original split opted out of. The worker-stop CLI note still says setup terminals and configured tabs are never deleted, although stop now closes them. Neither is likely to affect users broadly, so this is mergeable with the follow-ups noted.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(terminal): a terminal a worker creates closes with that worker" matches the main change. The PR makes terminals created by a worker's agent (via orca terminal create and `orca termin…
Description check Passed The description follows the template's sections: ELI5 is absent, but the Problem/Change/Why content is present, along with Linked Issue, Testing, Performance, and Risk. The Problem and Change sections…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(terminal): a terminal a worker creates closes with that worker" matches the main change. The PR makes terminals created by a worker's agent (via orca terminal create and orca terminal split) bind to that worker and close when it closes, with --keep-open as an opt-out. The title is one specific sentence, under 72 characters, and uses conventional-commit style. It does not cover the legacy-host, restart-handle, or chat-worker details, which is acceptable.

Full details: Description check

Explanation

The description follows the template's sections: ELI5 is absent, but the Problem/Change/Why content is present, along with Linked Issue, Testing, Performance, and Risk. The Problem and Change sections are clear. However, the template's required ELI5 section is missing, the Linked Issue section has no issue reference (it says 'Stacked on #47370' but there is no 'Fixes #' line filled in), Visual Proof is absent for a behavior change, the Review, Agent skill upstream boundary, and Checklist sections are not addressed, and the AI Disclosure section is left blank. Most of the core content is present, so the check is mostly complete.

Resolution

Add an ELI5 section in plain language. Fill in the Linked Issue line with an actual issue, or confirm the maintainer exemption applies. Add a Visual Proof entry for the terminal behavior change, or write N/A with a reason. Complete the Testing checkboxes, the Agent skill upstream boundary checkbox, and the AI Disclosure section if applicable.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1456aa31-d2cc-4c00-b39e-8273436bc251
Commits

Reviewing files that changed from the base of the PR and between d348b51 and 7c64147.

Files selected for processing: 3

  • src/main/runtime/orchestration/db/worker-terminal/worker-bound-terminals.test.ts
  • src/main/runtime/orchestration/legacy-remote/federated-worker-release-host.ts
  • src/main/runtime/rpc/methods/orchestration/worker/release/worker-bound-terminal-close.ts

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Correct the worker-stop safety note. · orchestration-worker-specs.ts:100

src/cli/specs/orchestration-worker-specs.ts:100
Minor · Functional Correctness · Quick win

Correct the worker-stop safety note.

The new remote stop path calls closeStoppedWorkerTerminals. That helper closes bound setup terminals and configured tabs, except failed setups. This note still promises that worker-stop never deletes those terminals.

Update the note to describe those effects and exceptions. Users must not select a destructive command based on an incorrect preservation guarantee.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8346422-f227-46d2-8497-a6628a7f79d6
Commits

Reviewing files that changed from the base of the PR and between faf054c and d348b51.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 16

  • skill-guides/orchestration.md
  • src/cli/discovery/flag-help-text.ts
  • src/cli/orchestration/identity/orchestration-compatibility-envelope.ts
  • src/cli/skills/bundled-skill-guides.ts
  • src/cli/specs/core.ts
  • src/cli/specs/orchestration-worker-specs.ts
  • src/cli/terminals/terminal.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-bound-terminals.test.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-bound-terminals.ts
  • src/main/runtime/orchestration/legacy-remote/federated-worker-release-host.ts
  • src/main/runtime/orchestration/legacy-remote/federated-worker-stop-host.ts
  • src/main/runtime/orchestration/workers/launch/worker-dispatch-preamble.ts
  • src/main/runtime/orchestration/workers/lifecycle/worker-created-terminal-owner.ts
  • src/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.ts
  • src/shared/rpc-contract/terminal/terminal-split-params.ts
  • src/shared/rpc-contract/terminal/terminal-unary-params.ts

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

…ase or stop, and a later release finishes it
@Jinwoo-H
Jinwoo-H merged commit ed420ad into main Nov 23, 2026
61 checks passed
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.

1 participant