Skip to content

fix(orchestration): follow a reminted pane handle during worker readiness - #54

Closed
DoozyX wants to merge 2 commits into
mainfrom
DoozyX/retro-issue-29-terminal-handle-stale
Closed

DoozyX wants to merge 2 commits into
mainfrom
DoozyX/retro-issue-29-terminal-handle-stale

Conversation

@DoozyX

@DoozyX DoozyX commented Nov 13, 2026

Copy link
Copy Markdown
Owner

ELI5

When Orca starts a worker agent it waits for the agent to be ready. Sometimes Orca reloads its internal terminal list during that wait and hands the same terminal a new ID, so the wait fails with "terminal handle stale" and the worker never gets its task. An earlier fix for this existed, but a later upstream merge deleted the code that used it. This puts that fix back.

What Changed

Before: orca orchestration worker-start (and the remote attach start) could fail at agent_readiness with terminal_handle_stale when a session-graph reload re-issued the pane's handle mid-wait. The Task was never injected and the freshly created terminal was left behind.

After: the wait follows the same pane and process to its new handle, waits once more, and carries on. The worker's custody record and setup stage move to the new handle, so later steps and failure cleanup use the live one. A different process, no handle, or a second stale answer still fails the start as before.

Mechanism: waitForWorkerAgentReadyRebinding (already in the tree, but with no caller since merge de99ccc removed the original wiring from fe79e4d) is called again.

  • Local start: new worker-start-agent-readiness.ts calls it and re-binds the custody row through the restored rebindWorkerTerminalResourceHandle; local-worker-start.ts uses it.
  • Remote attach (federation.ts, orchestration.federationAttachStart): same wait via the helper, reassigning the handle before the setup outcome is saved. No DB rebind, because custody is created after readiness on that path.

Why

The helper and its unit tests already existed, so restoring the original wiring is the smallest change and needs no new behavior. The remote attach path had the same unrebound wait, so it is fixed in the same change rather than left as a sibling copy of the bug. Retrying only the stale wait on a new handle for the same process is safe; a replacement process is never adopted.

Linked Issue

Fixes #29

Visual Proof

N/A: backend orchestration runtime change, no UI or interaction change.

Testing

Ran on macOS (Darwin) in a dedicated worktree off fork/main. I could not reproduce the failure against a live Orca; the evidence is the git history, a code trace, and a mocked-harness test.

  • pnpm tc: exit 0.

  • pnpm test src/main/runtime/rpc src/main/runtime/orchestration src/main/runtime/terminal --maxWorkers=2: exit 0, 593 files passed, 2814 tests passed.

  • ORCA_CODE_QUALITY_BASE=4ecd5364fe9 pnpm check:changed --force: exit 0, 26 of 26 checks passed.

  • Revert check: with local-worker-start.ts reverted to base, the new test reminted pane fails (expected 'failed' to be 'ready'); restored, it passes.

  • The remote attach change has no test: no existing federation test drives its readiness wait cheaply.

  • I manually tested these changes locally. Not ticked: no live Orca reproduction; verified through tests and a trace.

  • Automated tests added/updated, or explained why not below. One test added for the local start; none for the remote attach (see above).

  • Every added test fails without this change and avoids the test anti-patterns

Risk

Low to medium. It touches the worker-start readiness path, which every worker launch uses, but the new branch runs only when the wait already failed with terminal_handle_stale for a pane whose process is unchanged. The remote attach path is untested beyond review and typecheck. If wrong, a start that would have failed stale could instead bind to the wrong handle; the rebind only matches the same Dispatch, old handle and process. Back it out with a plain revert; no data or settings are migrated. Known and not changed: if the second wait itself throws after a confirmed remint, the custody row stays on the old handle (same as the original fix).

Level: Low

Review

Two independent full-branch reviews. Round 1 found a failing quality gate (bare type cast in the new test) and the remote attach sibling; both fixed. Round 2 was clean with only optional nits (no test for the DB guard or federation path).

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 (or CI will cover; local preferred). Ran pnpm tc, scoped tests and check:changed; full lint/build left to CI.

…d pane handle

Refs #29. fe79e4d made worker-start's agent_readiness wait follow
the same process when a session-graph reload remints the new pane's handle. The
upstream merge de99ccc ("takes upstream's orchestration wholesale") dropped
its wiring: local-worker-start went back to waitForWorkerAgentReady and the
custody-row rebind DB method was removed, leaving waitForWorkerAgentReadyRebinding
with no caller. A reminted handle again failed the start with
terminal_handle_stale and left the created terminal behind.

Restore the wiring: worker-start waits through waitForWorkerAgentReadyRebinding,
and on a same-incarnation remint moves the creation custody row and the start's
handle to the new one. Another process, no handle, or a second stale answer
still fail the start as before. No schema change.
… readiness

Refs #29. orchestration.federationAttachStart waited for the agent on
the original handle, so a session-graph reload that reminted the pane failed the
attach with terminal_handle_stale, the same failure fixed for local worker-start.
It now waits through waitForWorkerAgentReadyRebinding and carries the same
process's new handle into the attachment stage, authority and dispatch input.
Custody is created after readiness there, so no row moves. Also asserts the
reminted-start test's result shape before its annotated cast, and notes why the
local custody rebind may match no row.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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 commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #61.

@DoozyX DoozyX closed this Nov 14, 2026
@DoozyX
DoozyX deleted the DoozyX/retro-issue-29-terminal-handle-stale branch November 15, 2026 10:55
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: worker readiness fails with terminal_handle_stale before Task injection

1 participant