Repository navigation
feat(cli): launch agents in existing workspaces - #27794
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Retrying a lost launch reply from a different environment could start a second agent. Bind the retry to the original host or avoid generating that command; the risk is otherwise limited to this routing change. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
38142591-e7f4-4fcb-80b0-cc363aec45fb
📒 Files selected for processing (38)
config/scripts/vitest-sqlite-runtime-files.mjsskill-guides/orca-cli.mdskill-guides/orchestration.mdsrc/cli/agent-launch-recovery.tssrc/cli/agent-launch-request.tssrc/cli/agent-launch-test-fixtures.tssrc/cli/agent-workspace-selector.tssrc/cli/bundled-skill-guides.tssrc/cli/handler-group-manifest.tssrc/cli/handlers/agent-launch.tssrc/cli/index-agent-launch.test.tssrc/cli/index.test.tssrc/cli/index.tssrc/cli/root-help-text-primary.tssrc/cli/root-help-text-secondary.tssrc/cli/specs/agent-launch.tssrc/cli/specs/core.tssrc/cli/specs/index.tssrc/main/runtime/orca-runtime-create-terminal-dependencies.tssrc/main/runtime/orca-runtime-create-terminal.tssrc/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-12.spec.tssrc/main/runtime/rpc/methods/agent-launch-caller-selection.test.tssrc/main/runtime/rpc/methods/agent-launch-instant-tab.test.tssrc/main/runtime/rpc/methods/agent-launch-surfaces.tssrc/main/runtime/rpc/methods/agent-launch-tab-publication.tssrc/main/runtime/rpc/methods/agent-launch.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-launch-preferences.tssrc/main/runtime/runtime-notifier-contract.tssrc/main/runtime/runtime-terminal-contracts.tssrc/main/window/runtime-window-lifecycle.tssrc/preload/api/ui-bridge-terminal-and-session-tabs.tssrc/preload/api/ui-command-event-api.tssrc/renderer/src/hooks/ipc-events/terminal-presentation-ipc-bridge.tssrc/renderer/src/lib/agent-launch-tab-presentation.tssrc/renderer/src/lib/agent-launch-tab-publication.tssrc/renderer/src/lib/worktree-creation-backend-startup-focus.test.tssrc/shared/agent-launch-model-preferences.tssrc/shared/agent-launch-runtime-capability.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.
| const args = recovery.rawArgs && recoverableOrchestrationArgs(recovery.rawArgs) | ||
| const retryArgs: string[] = [] | ||
| for (let index = 0; index < (args?.length ?? 0); index++) { | ||
| const arg = args?.[index] | ||
| if (arg === '--retry-launch') { | ||
| index++ | ||
| } else if (arg && !arg.startsWith('--retry-launch=')) { | ||
| retryArgs.push(arg) | ||
| } | ||
| } | ||
| const recoveryCommand = | ||
| args && recovery.operationId | ||
| ? [ | ||
| resolveOrchestrationCliExecutable(), | ||
| ...retryArgs, | ||
| '--retry-launch', | ||
| recovery.operationId |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
set -eu
printf '%s\n' '--- recovery helper ---'
nl -ba src/cli/agent-launch-recovery.ts | sed -n '1,180p'
printf '%s\n' '--- references ---'
rg -n -F --glob '*.ts' -- 'withCliAgentLaunchRecovery' src/ || test "$?" -eq 1
rg -n -F --glob '*.ts' -- '--retry-launch' src/cli src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- launch/worktree references ---'
rg -n -F --glob '*.ts' -- 'agent launch' src/cli src/main src/shared || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'worktreePath' src/cli src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- environment selector references ---'
rg -n -F --glob '*.ts' -- 'ORCA_ENVIRONMENT' src/cli src/main src/shared || test "$?" -eq 1
printf '%s\n' '--- diff summary ---'
git diff --stat ae0ff6315219fa0492bd2e874954f992bc859694 8164b3ea919da937875aa0e7967aeebd2f95e7ad -- src/cli/agent-launch-recovery.ts src/cliRepository: stablyai/orca
Length of output: 45661
🏁 Script executed:
set -eu
for f in \
src/cli/agent-launch-request.ts \
src/cli/handlers/agent-launch.ts \
src/cli/agent-workspace-selector.ts \
src/cli/runtime/orchestration-recovery-command.ts \
src/cli/execution-host-flag.ts \
src/cli/runtime/client.ts \
src/cli/index-agent-launch.test.ts
do
printf '\n--- %s ---\n' "$f"
nl -ba "$f"
doneRepository: stablyai/orca
Length of output: 42731
Do not emit an unbound retry command for ambient ORCA_ENVIRONMENT.
When a remote agent launch --worktree ... loses its reply, callAgentLaunch passes the operation ID and raw arguments to withCliAgentLaunchRecovery. The helper copies the raw arguments but does not copy an ambient ORCA_ENVIRONMENT value. A retry run under another configured environment can therefore reach a different host, find no journal row for the operation ID, and admit it as a new launch.
Keep the executable recovery command when the original arguments contain an explicit --environment or --host selector. When routing came only from ambient ORCA_ENVIRONMENT, omit that command or bind it to the original non-secret selector.
Suggested fix
for (let index = 0; index < (args?.length ?? 0); index++) {
const arg = args?.[index]
if (arg === '--retry-launch') {
index++
} else if (arg && !arg.startsWith('--retry-launch=')) {
retryArgs.push(arg)
}
}
+ const hasExplicitExecutionSelector = retryArgs.some(
+ (arg) =>
+ arg === '--environment' ||
+ arg.startsWith('--environment=') ||
+ arg === '--host' ||
+ arg.startsWith('--host=')
+ )
const recoveryCommand =
- args && recovery.operationId
+ args &&
+ recovery.operationId &&
+ (!process.env.ORCA_ENVIRONMENT || hasExplicitExecutionSelector)
? [
resolveOrchestrationCliExecutable(),
...retryArgs,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const args = recovery.rawArgs && recoverableOrchestrationArgs(recovery.rawArgs) | |
| const retryArgs: string[] = [] | |
| for (let index = 0; index < (args?.length ?? 0); index++) { | |
| const arg = args?.[index] | |
| if (arg === '--retry-launch') { | |
| index++ | |
| } else if (arg && !arg.startsWith('--retry-launch=')) { | |
| retryArgs.push(arg) | |
| } | |
| } | |
| const recoveryCommand = | |
| args && recovery.operationId | |
| ? [ | |
| resolveOrchestrationCliExecutable(), | |
| ...retryArgs, | |
| '--retry-launch', | |
| recovery.operationId | |
| const args = recovery.rawArgs && recoverableOrchestrationArgs(recovery.rawArgs) | |
| const retryArgs: string[] = [] | |
| for (let index = 0; index < (args?.length ?? 0); index++) { | |
| const arg = args?.[index] | |
| if (arg === '--retry-launch') { | |
| index++ | |
| } else if (arg && !arg.startsWith('--retry-launch=')) { | |
| retryArgs.push(arg) | |
| } | |
| } | |
| const hasExplicitExecutionSelector = retryArgs.some( | |
| (arg) => | |
| arg === '--environment' || | |
| arg.startsWith('--environment=') || | |
| arg === '--host' || | |
| arg.startsWith('--host=') | |
| ) | |
| const recoveryCommand = | |
| args && | |
| recovery.operationId && | |
| (!process.env.ORCA_ENVIRONMENT || hasExplicitExecutionSelector) | |
| ? [ | |
| resolveOrchestrationCliExecutable(), | |
| ...retryArgs, | |
| '--retry-launch', | |
| recovery.operationId |
Agent launch QA (macOS, PR commit
|
Only src/cli/bundled-skill-guides.ts conflicted; it is generated, so it was regenerated rather than hand-resolved. Upstream's guidance changes land around this branch's edits without touching them: the circuit-breaker and retry-release paragraphs in references/recovery-and-cleanup.md (stablyai#27795), and the orca-cli launch-flag note in the kernel's role table (stablyai#27794, stablyai#27796). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011nnNsG3p4Do9eiyfXGr2rB
ELI5
In an existing workspace, the CLI's documented way to start a new agent ran a command in a terminal. That bypassed the user's Chat UI setting, so a user who expected a chat got a terminal.
orca agent launch --agent <id>now starts the agent through Orca's normal launch route. It opens a chat when the setting and agent support one, and a terminal otherwise.What Changed
orca agent launchfor an existing worktree or folder workspace, with an optional first prompt, model, reasoning effort, and--focus.--retry-launchwithout starting a second agent.orca-cliguide now point existing-workspace starts to this command.Why
The app already has one launch route that applies the Chat UI setting and delivers the first prompt. The CLI calls that route instead of constructing an agent command for a terminal. #27796 routes
orca worktree create --agentthrough the same path; keeping that change separate makes the new command reviewable on its own.Linked Issue
Part 1 of Linear STA-10160 (agent handoffs bypass the Chat UI preference). This adds the existing-workspace command; #27796 adds the new-worktree fix.
Visual Proof
Chat UI on: chat tab · Chat UI off: terminal tab. These are from the original combined review of the same launch path.
Testing
Focused CLI, host, and renderer suites: 1,446 passed, one skipped.
orca-ci-checks: 24/24 passed, including lint, code quality, localization, and typechecks.The original combined review exercised the compiled CLI in a hidden macOS Electron renderer with Chat UI both on and off. Linux, Windows, and SSH UI flows were not manually run for this split branch.
GitHub CI passed. One unchanged macOS daemon timing test missed its limit by 1 ms on the first run; that five-test file passed locally and the failed CI job passed on its single rerun.
I manually tested this launch path in a hidden macOS Electron renderer during the combined review
Automated tests added/updated
Review
This is the command and the host support it needs. The worktree creation behavior is in #27796, based on this branch.
Agent skill upstream boundary
Notes
The host decides chat versus terminal on local, paired, and SSH workspaces. Older hosts without the required launch capabilities refuse the command before creating anything. The CLI keeps the same replay identity across retries.
Checklist