Repository navigation
fix(cli): reject empty --terminal/--from handles instead of falling back to defaults - #16745
Conversation
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
|
Follow-up for the CodeRabbit merge-risk note: empty Pushed in 78fe7da. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7ca79586-7d9b-4a15-9229-53b8e26adf99
📒 Files selected for processing (8)
src/cli/flags.test.tssrc/cli/flags.tssrc/cli/handlers/orchestration-check-identity.test.tssrc/cli/handlers/orchestration/message-check-handler.tssrc/cli/handlers/orchestration/message-inbox-handlers.tssrc/cli/handlers/orchestration/terminal-identity.tssrc/cli/handlers/orchestration/worker-launch-handler.tssrc/cli/selectors.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| terminal: getOptionalPresentStringFlag( | ||
| flags, | ||
| 'terminal', | ||
| '--terminal requires a non-empty handle. Omit --terminal to launch in a new terminal.' | ||
| ), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Validate terminal before the capability probe.
When --model or --effort is present, status.get at Line 21 runs before this helper. An invocation such as worker-start --terminal "" --model ... therefore contacts the runtime and may return a capability or connection error instead of the required local invalid_argument. Read this flag before the capability check, then pass the stored value to orchestration.workerStart.
…ack to defaults An explicit empty --terminal (or orchestration --from) was treated as absent, so `orca terminal send --terminal ""` targeted the active pane and orchestration check/inbox/worker-start fell back to the ambient ORCA_TERMINAL_HANDLE mailbox. Hoist the existing getPresentStringFlag into flags.ts and use it for these handles so a present-but-empty value fails with invalid_argument. Fixes stablyai#16694 Co-authored-by: wusiyuan05 <[email protected]>
78fe7da to
086a377
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Reject an invalid --from before the model/effort capability… · worker-launch-handler.ts:66-70
src/cli/handlers/orchestration/worker-launch-handler.ts:66-70
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReject an invalid
--frombefore the model/effort capability probe.When
worker-startreceives--modelor--effort, it callsstatus.getbefore it validates--from. An explicit empty or valueless--fromis rejected only after that call. A runtime that lacks the capability then reportsincompatible_runtime, so the user does not see theinvalid_argumenterror that the flag contract requires. No worker is launched, because the rejection happens before the mutation call is made.Suggested fix
const terminal = getPresentStringFlag(flags, 'terminal') + getPresentStringFlag(flags, 'from') const model = getOptionalStringFlag(flags, 'model') const effort = getOptionalStringFlag(flags, 'effort')

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:
adca8d38-6b17-4bff-8279-31aff5a520e7
Files selected for processing: 9-
src/cli/flags.tssrc/cli/handlers/orchestration-check-identity.test.tssrc/cli/handlers/orchestration/message-inbox-handlers.tssrc/cli/handlers/orchestration/terminal-identity.tssrc/cli/handlers/orchestration/worker-launch-handler.tssrc/cli/handlers/worktree.tssrc/cli/index-terminal-commands.test.tssrc/cli/selectors.tssrc/cli/worktree-project-target.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
ELI5
When you tell the Orca CLI which terminal to act on, you can pass an empty name by accident, for example from a script variable that never got set (
--terminal "$HANDLE"). Before this fix, Orca treated the empty name as "use whatever terminal is active" without saying anything, so it could read, close, or type into the wrong terminal. Now Orca stops and reports that the value is missing.What Changed
orca terminal send|read|show|wait|close --terminal ""exited 0 and acted on the worktree's active pane, which can belong to another tab or agent.orchestration check|inbox|worker-start --terminal ""andorchestration send|ask --from ""fell back to the ambientORCA_TERMINAL_HANDLEidentity.invalid_argument(Missing value for --terminal/--from), exits 1, and sends no RPC. Leaving the flag out still resolves the default, the same as before.getOptionalStringFlagreturnsundefinedfor'', so callers couldn't tell an empty value from an omitted flag. The codebase already had two private copies ofgetPresentStringFlag(omitted →undefined, present but empty or valueless →invalid_argument) inworktree.tsandworktree-project-target.ts. This PR moves that helper intosrc/cli/flags.ts, removes both copies, and uses it in:getTerminalHandle(selectors.ts), which covers everyterminalverb that takes--terminalresolveOrchestrationTerminalHandle(terminal-identity.ts), which covers--terminal/--fromfor check/send/ask and the related commands--terminal(message-inbox-handlers.ts)--terminal(worker-launch-handler.ts). The flag is now read at the top of the handler, so the command fails before thestatus.getcapability RPC.Why
An empty handle is almost always a script bug. Quietly retargeting the active pane can send input to the wrong agent or close the wrong terminal. Failing closed is the safe default. We reuse the existing helper so all handle-like flags behave the same and there is no new parallel helper. The check runs only in the CLI before any RPC, so it adds no protocol or mixed-version runtime concerns.
Linked Issue
Fixes #16694
Visual Proof
N/A: this is a CLI argument-validation change with no UI. Behavioral proof comes from a probe test that ran
main()across 9 commands with an empty--terminal/--fromandORCA_TERMINAL_HANDLEset:origin/main, all 9 went ahead. Terminal verbs calledworktree.list+terminal.resolveActive, the orchestration verbs calledorchestration.inbox/check/send/askagainst the ambient identity, and worker-start calledterminal.resolveIdentity.invalid_argumentand make zero RPC calls.Testing
Reproduced on main with two new regression tests, then confirmed they pass with the fix:
src/cli/index-terminal-commands.test.ts:terminal send --terminal "" --text x --jsonreturnsinvalid_argumentand makes no RPC.src/cli/handlers/orchestration-check-identity.test.ts:orchestration check --terminal ""withORCA_TERMINAL_HANDLEset rejects without callingorchestration.check.With main's source and the new tests: 2 failed. With this branch: all pass.
Targeted vitest after landing on the latest main (orchestration-check-identity, index-terminal-commands, worktree-project-target, handlers/orchestration): 23 files / 196 tests pass. Earlier full
pnpm test src/cli: 183 files, 2110 passed.oxlint, ast-grep, and oxfmt pass on the touched files (pre-commit hooks).
Platforms: macOS (vitest). The change only touches CLI flag parsing. On PowerShell 5.1,
""argv can be dropped, which turns--terminalinto a valueless flag, and that was already rejected. Remote/SSH: the check runs on the client before any RPC, so older and newer runtimes are unaffected. Older CLI binaries keep the old behavior until upgraded. Folder workspaces are unaffected.Tradeoff: scripts that passed
--terminal ""or--from ""to mean "use the default" must now omit the flag.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Reviewed by Claude and Codex (both approve, low risk). The reviewer cleanups are included: one shared
getPresentStringFlaginstead of a new helper, the standardMissing value for --Xwording, and the worker-start ordering fix.Agent skill upstream boundary
Notes
Security: fails closed. Cross-platform: argv parsing only. Remote SSH: client-side only. Mobile: no impact. Backwards compatibility: only explicit empty values change behavior. Performance: none.
Original fix by @Cunninger in #16745 (authorship preserved via
Co-authored-by).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)