Skip to content

fix(orchestration): let a worker brief wait for the agent to lead the foreground - #63

Merged
DoozyX merged 1 commit into
mainfrom
DoozyX/retro-18-brief-foreground
Nov 15, 2026
Merged

DoozyX merged 1 commit into
mainfrom
DoozyX/retro-18-brief-foreground

Conversation

@DoozyX

@DoozyX DoozyX commented Nov 15, 2026

Copy link
Copy Markdown
Owner

ELI5

When Orca starts a worker, it opens a terminal, launches the agent, and then types the task in. If the agent hadn't quite taken over the terminal yet, Orca gave up on the spot and left a failed start behind. Now Orca checks a few times a second, for up to 10 seconds, and types the task as soon as the agent is in front.

What Changed

Before: orca orchestration worker-start could fail with stage=dispatch_input / lastError=agent_not_in_foreground because the worker brief was only allowed through after a single foreground read. The new terminal was left in residualResources, and the same terminal became ready moments later.

After: the worker-brief write guard resamples the foreground every 250 ms for up to 10 s, never past the start's remaining readiness budget, and writes once the launched agent leads. If a shell prompt returns while waiting, or time runs out, it refuses and the task is never pasted into a shell. The refusal text now names the last foreground sample and the elapsed time.

Mechanism: createLaunchedAgentWriteGuard takes an optional settleDeadlineMs. Only createWorkerBriefWriteGuard sets it, from a new readinessDeadline that deliverWorkerDispatchPreamble and the federation attach path now pass in. Launch-prompt guards keep their single read and the exact bare agent_not_in_foreground message that external-conversation-send.ts matches. The terminal identity and incarnation abort check from main is kept and runs after every sample. The federation path keeps the reminted-handle rebinding from #61 and takes its deadline just before that wait.

Why

Raising the readiness timeout would not help: the agent was ready, the read was just early. Skipping the check would type a task into a bare shell when the agent has exited, which is what the guard exists to prevent. A bounded resample inside the existing readiness budget keeps the guard and removes the race, without new flags, retries or failure semantics.

Linked Issue

Fixes #18

Supersedes #46, which carried the same change on an older base.

Visual Proof

N/A: runtime behaviour in worker start; no UI change.

Testing

  • pnpm tc:node exit 0 on the rebased branch.
  • pnpm test src/main/runtime/rpc/methods/orchestration src/main/runtime/terminal/wait src/main/runtime/orchestration/legacy-remote --maxWorkers=2: 99 files, 629 tests passed. New case: a first unknown read followed by agent writes once after 250 ms; the shell-in-front test now waits out the settle window.
  • pnpm check:changed against fork/main: see CI.
  • Not run against a live Orca. macOS only.
  • I manually tested these changes locally (no live Orca run; verified by tests only)
  • Automated tests added/updated

Risk

Level: Medium

A worker whose agent really exited without the shell printing a prompt marker now fails after up to 10 s instead of immediately. The riskiest part is the loop's exit conditions; it is bounded by both the 10 s window and the readiness deadline. Plain revert backs it out.

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.

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 (typecheck and scoped tests ran locally; the rest is left to CI)

Copilot AI balanced review requested due to automatic review settings November 15, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 716e462a-2f6a-4d4b-9cce-c0cc06bfc82c
  • 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

@DoozyX
DoozyX merged commit ee12a17 into main Nov 15, 2026
@DoozyX
DoozyX deleted the DoozyX/retro-18-brief-foreground branch November 15, 2026 10:55
@DoozyX
DoozyX restored the DoozyX/retro-18-brief-foreground branch November 15, 2026 11:00
DoozyX added a commit that referenced this pull request Nov 15, 2026
@DoozyX
DoozyX deleted the DoozyX/retro-18-brief-foreground branch November 15, 2026 20:45
DoozyX added a commit that referenced this pull request Nov 23, 2026
Upstream origin/main 0b23e7a (388 commits) into fork main 6f98610.

Accepted upstream's test-suite cut (stablyai#46786) and dead card components (stablyai#46833)
on all 44 modify/delete conflicts. Fork-feature regression tests removed with it:
- #63: federation-worker-brief-agent-in-front, orchestration-structured-worker-retry
- #67: federated-release-safety, federated-transport-safety, worker-release
- #69: worker-list-pagination
- claude accounts: repo-update-host-guard, claude-session-account-move
- git graph: hosted-review-creation-gitlab-self-hosted
- passkeys: main-process-ready-persistence-cleanup
- branch cleanup: remove-worktree-branch-cleanup, worktree-remove-branch-deletion, remove-worktree
- test isolation: dependency-security-release
Fork-only tests that imported upstream-deleted fixtures were removed too.

Code conflicts keep both sides:
- Claude background evidence helper now uses upstream's running-task map
  (stablyai#47081); status payload carries fork monitoredWork + upstream backgroundCommands.
- Worker start: upstream bindTerminal/handOver split reads the re-minted pane
  handle from setupStage (#29/#61); fork deadline brief guard (#63) plus upstream
  abort checks in preamble delivery.
- Status bar: fork per-account usage roster with upstream's unreachable-host
  gating (stablyai#42644); a null account owner now shows no roster instead of local
  accounts.
- client-ui-params.ts: moved feature-interaction schemas to their own module to
  stay under max-lines with the fork's omp status-bar fields.

Gates: install:release, mobile frozen install, pnpm tc, mobile typecheck and
typecheck:tests, conflict-area tests (38 files), independent review (1 finding,
fixed), check:changed vs fork parent (only finding: upstream's unchanged
bot-run-results.test.ts casts).
@DoozyX DoozyX mentioned this pull request Nov 23, 2026
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.

Orchestration: dispatch input rejected after worker terminal creation

2 participants