Skip to content

fix(orchestration): fail worker-start promptly when the agent exits to its shell - #37563

Merged
AmoabaKelvin merged 2 commits into
mainfrom
fix/worker-start-agent-exit
Nov 3, 2026
Merged

AmoabaKelvin merged 2 commits into
mainfrom
fix/worker-start-agent-exit

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​296 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​296
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​159

ELI5

When an agent CLI refuses to start, say because it doesn't know the model you asked for, it quits at once and its terminal drops back to the shell prompt. worker-start couldn't tell the agent had gone, because the terminal itself was still alive. It now notices within a second or two and tells you what the agent printed.

What Changed

Before, a rejected launch ended in one of two ways, and neither mentioned the agent's error:

  • It waited out all of --timeout-ms, then reported failedStage: agent_readiness and lastError: timeout. This happened for agents that wait on a composer marker (OpenCode, zcode), and for Cursor when the shell took 6 s to start.
  • It failed after about 4 s at dispatch_input with agent_not_in_foreground, because a cached process name read as a live agent.

Now the receipt comes back with failedStage: agent_readiness and:

The agent's launch command exited before the agent was ready. Its output:
Cannot use this model: not-a-model. Available models: auto, gpt-5.3-codex-low

Readiness waits on a fresh launch now run alongside a small watcher on the PTY's bytes. When the shell reports that a command started and then finished (OSC 133;C, then 133;D), the watcher asks the same foreground read the brief's write guard uses. If that read proves a shell is in front, the wait fails with what the command printed, capped at 2,000 characters with terminal controls removed. The read repeats on the existing FOREGROUND_COMMAND_READS schedule, because a prompt's own commands (a git status, starship) lead the foreground group for a moment after the finish.

This covers local and federated worker-start, and the agent launch prompt, which now gives up early instead of waiting 60 s to report it couldn't deliver. A slow agent keeps its full budget, since no finish arrives while it starts.

Why

Neither signal is enough alone. A shell nested inside the agent leaks 133;D onto the pane, and the shell is also in front until the agent starts. Requiring both needs no matching on any vendor's error text.

I tried counting bracketed paste (?2004l then ?2004h) as a shell return too, since relay shells without integration would then be covered. An rc file that toggled those bytes failed a healthy launch, so only OSC 133 counts. Exit codes stay out of the message because PowerShell's are made up.

A per-PTY record that settles waiters would also cover startup draft pastes and submit holds, but it needs changes to the daemon's facts and the waiter registry. Those two paths have no receipt to fix, so this stays with the watcher.

Linked Issue

Fixes #29741

Linear: STA-10843. launch.effective echoing the request is STA-5528 and isn't touched here.

Visual Proof

N/A: nothing on screen changes. The change is in a CLI receipt, shown above and in the timings below.

Testing

Real worker-start runs on macOS against a throwaway orca serve built from this branch. Cursor isn't installed here, so a stand-in cursor-agent printed the error from the issue and exited 1. Real Claude doesn't reject --model at launch: it starts, and reports the bad model on its first turn. So Claude only covered the healthy and slow cases.

Case main this branch
Rejected launch, shell takes 6 s to start, 20 s budget 20.4 s, timeout 6.7 s (25 s budget), agent's output
Rejected launch, OpenCode, 12 s budget 12.4 s, timeout about 1 s, agent's output
Rejected launch, Cursor, zsh and bash 3.2 about 4.5 s, agent_not_in_foreground about 1 s, agent's output
Error with no final newline, zsh not run 1.4 s, agent's output
Prompt with a 0.5 s command in it not run about 3 s, agent's output
Agent exits 8 s in, 25 s budget not run 8.9 s, agent's output
Nested shell leaks 133;D, agent stays up not run ready
Real Claude behind an 8 s delay, 30 s budget not run ready at 11 s
Same, 5 s budget not run timeout at 5.7 s

The 8 s exit ran before the last changes to the read schedule and output cleanup. The rest of the "this branch" column re-ran on the final rule, except the shell-takes-6-s row and the zsh and bash Cursor row, which ran on earlier builds of it.

Not run: Linux, Windows, WSL, SSH, fish, PowerShell, a federated start and the agent launch prompt. Those stay covered by reading the code and by unit tests of the marks and reads.

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

Risk

The riskiest part is a false "exited" on a healthy agent: the coordinator would see a failed start while the agent runs with no Task. That takes a finished command plus a foreground read proving a lone shell. Shell wrappers, nvm-style loaders, asdf shims, several commands on one line and slow rc files all kept running in testing against the design. A launch with several real lines, submitted separately on a shell with no bracketed paste, could fail this way if the next line takes longer than the 350 ms settle to start. No built-in launch does that, so it would take a user's own multi-line agent command.

Panes with no shell integration (cmd.exe, older fish) and hosts that can't prove a shell (WSL, Windows SSH) wait as they do today.

No saved data, settings or wire fields change, and older clients only see a different lastError string. A plain revert backs it out.

Level: Medium

AI Disclosure

Review

N/A: no notes for reviewers beyond the above.

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

Security: agent output in lastError is untrusted text, the same as worker-read, and has its terminal controls stripped. Cross-platform: guarded by the foreground read, which only says shell with proof on each host. Mobile: no changes. Performance: no extra process reads unless a command finishes during readiness; the watcher adds one scan per output chunk while readiness runs.

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

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: f179a791-c97f-4a76-9491-a8849e47cd02
Commits

Reviewing files that changed from the base of the PR and between 7d7c92f and b2aa742.

Files selected for processing: 1
  • src/main/runtime/launched-agent-exit-watch.test.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.

Walkthrough

Fresh agent readiness waits can detect an agent that exits after a completed command and report sanitized launch output or a no-output message. Exit watching applies only to eligible fresh launches when the runtime provides the required methods. Worker readiness waits accept an optional abort signal. The runtime exposes recent terminal output. Tests cover output parsing, foreground checks, readiness outcomes, and reused terminals.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to b2aa7

The changed tests cover prompt reporting of rejected launches. No actionable merge risk remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: failing worker-start promptly when the agent exits back to the shell.
Description check Passed The description is complete and closely follows the required template. It explains the user impact, implementation, rationale, linked issue, testing, visual proof, risks, compatibility considerations,…
Linked Issues check Passed [#29741] The readiness path watches fresh, non-reused launches for OSC 133 command completion and confirms that the shell is foreground. It then fails before the readiness timeout and includes sanitiz…
Out of Scope Changes check Passed The production changes support #29741. The readiness integration detects the fresh launch PTY, the output accessor supplies the receipt text, and the tests validate the watcher and its integration. No…
Full details: Description check

Explanation

The description is complete and closely follows the required template. It explains the user impact, implementation, rationale, linked issue, testing, visual proof, risks, compatibility considerations, and rollback path. It also documents untested platforms and marks the required checklist items.

Full details: Linked Issues check

Explanation

[#29741] The readiness path watches fresh, non-reused launches for OSC 133 command completion and confirms that the shell is foreground. It then fails before the readiness timeout and includes sanitized launch output capped at 2,000 characters. The worker readiness path and launched-agent composer path use this watcher. Tests cover rejected Cursor, OpenCode, and Claude launches, output capture, replayed output, slow starts, nested shells, and reused terminals. The separate launch.effective behavior from #16527 is not changed.

Full details: Out of Scope Changes check

Explanation

The production changes support #29741. The readiness integration detects the fresh launch PTY, the output accessor supplies the receipt text, and the tests validate the watcher and its integration. No unrelated product behavior or data change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • 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

@AmoabaKelvin
AmoabaKelvin force-pushed the fix/worker-start-agent-exit branch from 7d7c92f to b2aa742 Compare November 2, 2026 22:05
@AmoabaKelvin
AmoabaKelvin merged commit 94f2be1 into main Nov 3, 2026
92 of 94 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.

[Bug]: worker-start waits out the full readiness budget after the agent exits on a rejected --model

1 participant