Skip to content

[Bug]: Scheduled terminal run whose launch line was eaten is stored as completed, or as dispatch_failed when Orca quits #47366

Open

Description

@char-yb

Where were you using Orca?

Desktop only

Operating system

macOS

Remote host operating system

No response

Orca version

1.4.269 → 1.4.271 (the same pattern goes back to September builds)

Details

Short summary:
A scheduled terminal run whose launch line was eaten by a shell startup prompt is stored as completed although its agent never started. If Orca quits while it is watching the run, the run is stored as dispatch_failed instead.

What happened?

One scheduled terminal automation (Claude Code, existing workspace, weekdays 09:10) has 78 runs.
Five of them never started their agent. All five are the runs where oh-my-zsh showed its update
prompt (shell-ready-timeout in daemon.log for that run's PTY, 15000 ms each time).

Run Stored status What the pane shows
Sep 8 completed [oh-my-zsh] Would you like to update? [Y/n] ^[[200~claude '--dangerously-skip-permissions' …
Sep 21 completed same
Oct 19 dispatch_failed (no snapshot)
Nov 9 completed [Y/n] . '/var/folders/…/orca-launch-….sh' then zsh: permission denied: …/orca-launch-….sh
Nov 23 dispatch_failed same as Nov 9

The launch-line part is #12170 (open PR #47013). This issue is about what the run history records
afterwards. There are two separate problems.

How can we reproduce it? I have not run a minimal version; these steps follow from the logs.

  1. Use zsh with oh-my-zsh in its default update mode, with an update due (it asks [Y/n] at shell start).
  2. Let a scheduled terminal automation (Claude Code) fire. After the 15 s shell-ready deadline the launch line is written into the prompt.
  3. Leave it: after two minutes the run is completed with no agent output. Or quit Orca while the run is still dispatched: it becomes dispatch_failed.

1. A run whose agent never started is stored as completed.
judgeIdleAgentTurn (src/main/runtime/agent-state-rules/agent-turn-idle-verdict.ts) completes a pane
with no agent status rows once AGENT_START_GRACE_MS (2 min) has passed, unless the tail shows a
missing-command refusal that names the agent command. The refusal here is
zsh: permission denied: …/orca-launch-<id>.sh: the prompt's read -k 1 took the . of
. '<staged script>', so zsh ran the script as a program. It matches no pattern and does not name the
agent, so the run completes. Three scheduled runs were missed without any failure shown.

2. Quitting Orca while a terminal run is watched stores it as dispatch_failed.
On Nov 23 the run was dispatched at 09:10:34. At 09:27:17 Orca quit to install 1.4.271
(updater_quit_and_install_started in main.trace.ndjson), and the run's error was written at
09:27:17: "Orca stopped watching this run before it reported completion."

Reading the source, the order on quit is:

  • mainWindow.on('closed') → runtime.markGraphUnavailable() → terminalWaiters.rejectRendererBound('terminal_handle_stale')
  • the observer's waitForTerminal rejects; observeTerminalRun rethrows anything that is not a proven
    exit, runtime_unavailable or a wait timeout
  • AutomationRunCompletionWatcher.observeUntilTerminal sees a signal that is not aborted yet
    (core.automations.stop() runs later, in will-quit) and finalizes dispatch_failed

So the run is failed instead of being left for reconcileRetainedRuns at the next start. This is not
specific to a broken launch: a healthy run that is still working when Orca quits or installs an update
takes the same path. I have not reproduced that case in a running build; it follows from the code path
above and from the timestamps.

The stored error is also the same fixed sentence for every cause, and the real error only goes to
console.error, which a packaged app does not keep, so the cause cannot be read from a user's machine.

Update: #47368 now covers problem 1 and the failure code only. Problem 2 is held until it is shown in a real reload-and-quit run (see the maintainer's comment on the PR); I will file it separately with that evidence.

Expected

  • A run whose staged launch script the shell refused fails as "agent did not start".
  • A run being watched when the window closes, reloads or the app quits keeps its status and is picked
    up again.
  • The stored error carries the runtime failure code.

Anything else that might help:
A launch line that is consumed whole (nothing refused, nothing printed) still completes after the
grace. Telling that apart needs to know whether the run's agent reports status on this host
(AGENT_HOOK_TARGETS, agentStatusHooksEnabled, remote hosts), which I left alone.
I have a branch with the three fixes and tests and will open a PR against this issue.

Metadata

Metadata

Assignees

Labels

os:macos

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions