Skip to content

fix(automations): settle chat runs left running when Orca restarts mid-run - #49298

Merged
Jinwoo-H merged 3 commits into
mainfrom
fix/automation-chat-run-restart
Nov 25, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
fix/automation-chat-run-restart

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If Orca restarted while an automation was running in a chat, the run stayed "running" forever, even after the chat finished. Now Orca checks those runs again when it starts, the same way it already does for runs in a terminal.

What Changed

  • Before: on start, Orca re-checks unfinished automation runs, but it skipped every run in a chat (run-completion-watcher.ts, reconcileRetainedRuns). The only thing watching a chat run was an in-memory promise, which a restart loses, so the row stayed dispatched with nothing left to settle it.
  • After: chat runs go through the same restart check as terminal runs. Orca already routes chat runs to the existing chat-run observer (observeAutomationChatRun, via runtime-automation-service.ts), which reads the run's turn from the chat: a finished chat settles as completed (or failed), a chat still working is watched until it ends, and the existing 6-hour limit still applies.
  • Runs that send their own prompt (into a new conversation, an existing chat, or a shared room) had no launch receipt and sent under a random message id, so after a restart nothing could find their turn. Every one of those send paths now uses a message id derived from the run (automationRunOperationId(run, 'run-message'), the scheme reused-chat runs already use), so restart recovery reads that run's own turn and settles it completed or failed by how it ended.
  • Which id recovery looks up comes from how the automation sends its prompt, not from a missing receipt. Runs launched with a receipt stay exactly as before: a failed or expired receipt still settles dispatch_failed ("could not confirm this run's prompt").
  • A run sent before this change (random id) has no message under the derived id. Recovery waits until that chat is idle, so a turn still running can finish first, then settles the run dispatch_failed with "Orca restarted before this run's result was recorded. Open 's chat to see how it ended." No new run status.
  • Not re-run after a restart: posting a run's result somewhere outside its chat. The row settles, but that post is not sent.

Why

The filter is the cause: it was the only thing keeping chat runs out of restart recovery, and the observer for them already exists. Removing it fixes this in one place, with no new recovery path.

Linked Issue

Fixes #48894

Visual Proof

N/A: no UI change. The run history row moves from "running" to its real result after a restart.

Testing

  • run-completion-watcher-quit.test.ts: a restart with two dispatched chat runs, one whose chat already finished (settles at once) and one still working (settles when it ends). It fails without this change (no run settles) and passes with it.

  • runtime-chat-run-observer.test.ts, after a restart: a run found by its derived id settles completed (with its reply) or failed by its turn; a room run reserves its turn under the same derived id and is found by it; a run sent before this change is not settled while its chat is busy, then settles dispatch_failed with the note once the chat's turn ends; a launched Chat run with a missing or failed receipt stays dispatch_failed. The last three fail on the previous head.

  • pnpm check:changed passes.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

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

Performance

None, because this only runs once at startup for unfinished chat runs, and each one gets the same single chat watch it would have had before the restart.

Risk

Level: Low

A chat run that was left dispatched before this change now settles on the next start, as completed or failed; one sent before this change settles failed with a restart note once its chat is idle. No stored data format changes: the derived id is computed from the run's id and creation time, nothing new is saved. Back out with a plain revert.

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)

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The dispatcher assigns a stable message ID to each automation run prompt. Chat sessions and group turn reservations use that ID for the turn’s operation ID. After a restart, the observer uses the ID to find the run’s chat turn and determine its outcome. If the observer cannot find a prompt or recorded result, it records a dispatch failure. Retained-run reconciliation now includes dispatched chat runs.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 14051

Restart recovery now reconciles dispatched chat automation runs using stable run-derived message IDs. Runs whose result was not recorded settle as dispatch_failed once the chat is idle, which the linked issue accepts. No actionable merge-blocking risk was found. The PR description's wording about "completed" for this edge case could be updated to match the behavior.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description follows the template closely and is substantive. It has a clear ELI5, a What Changed section with before/after and mechanism, a Why section, a linked issue (Fixes #48894), a Testing se… Fill in the AI Disclosure section, or state that it does not apply. Fill in or remove the empty Review heading. State which platforms were tested, or note that only automated tests ran. Briefly explain why manual testing was skipped if the …
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: chat runs left running after an Orca restart are now settled. It follows the conventional-commit style and matches the summary and objectives. The title is specific an…
Linked Issues check Passed [#48894] requires that an automation run whose session finished is not left in dispatched after an Orca restart. The reported defect had two parts: chat runs were excluded from restart reconciliatio…
Out of Scope Changes check Passed Every changed file maps to restart recovery for automation chat runs:
- run-completion-watcher.ts: removes the chat-kind exclusion from the restart filter.
- run-completion-watcher-quit.test.ts: t…
Full details: Title check

Explanation

The title names the main change: chat runs left running after an Orca restart are now settled. It follows the conventional-commit style and matches the summary and objectives. The title is specific and does not use vague terms.

Full details: Linked Issues check

Explanation

[#48894] requires that an automation run whose session finished is not left in dispatched after an Orca restart. The reported defect had two parts: chat runs were excluded from restart reconciliation, and runs without a launch receipt could not be matched to their turn.

  1. Exclusion removed: run-completion-watcher.ts (reconcileRetainedRuns) now passes dispatched and dispatching runs to the reconciler regardless of sessionKind. Chat runs reach observeAutomationChatRun in runtime-chat-run-observer.ts. run-completion-watcher-quit.test.ts covers a finished chat run that settles at once and a working chat run that settles when it ends.
  2. Unmatched runs: at head, observeAutomationChatRun with sentByRun=true derives the prompt message ID with automationRunOperationId(run, 'run-message'). When no submission or queued prompt matches and the chat is idle with no actionable prompt, it finishes with dispatch_failed and automationRunResultNotRecorded(agent). It does not wait forever. bot-automation-launch.ts and bot-chat-session.ts send the prompt under the same derived ID.

Discrepancy: the PR description and PR objectives say unmatched runs settle as completed with the "result is unknown" note. The code at head settles them as dispatch_failed. The issue accepts dispatch_failed as the worst acceptable outcome, so the issue requirement is met either way. The PR description should be corrected, not the code. The non-sentByRun path without a receipt still returns dispatch_failed immediately.

Limits: the issue's "process no longer exists" case is not separately tested. Runs sent into shared rooms still produce the unknown-result outcome after restart, as the PR states. I did not inspect automation-chat-run-observation.ts or the test files beyond the change summaries.

Full details: Out of Scope Changes check

Explanation

Every changed file maps to restart recovery for automation chat runs:

  • run-completion-watcher.ts: removes the chat-kind exclusion from the restart filter.
  • run-completion-watcher-quit.test.ts: tests restart settlement for chat runs.
  • automation-run-operation.ts: adds the run-message purpose for a per-run derived prompt message ID.
  • bot-automation-launch.ts, bot-chat-session.ts, bot-automation-sessions.ts, bot-group-automation-run.ts, bot-group-turn-reservation.ts: pass the derived message ID into the prompt send so recovery can find the turn.
  • runtime-automation-service.ts: passes the sentByRun flag to the chat observer.
  • automation-chat-run-observation.ts: adds automationRunResultNotRecorded for unmatched runs.
  • runtime-chat-run-observer.ts and its test: implement the no-receipt handling and the reread on turn completion for runs the run itself sent.

No changed file shows unrelated behavior. The prompt message ID now changes for all new bot-sent automation runs. The PR description states this side effect. The automationRunOperationId signature change is limited to the new purpose value.

Limits: this verdict relies on the whole-PR change summary and one read of runtime-chat-run-observer.ts at head. I did not read the full diff of the other files.

Full details: Description check

Explanation

The description follows the template closely and is substantive. It has a clear ELI5, a What Changed section with before/after and mechanism, a Why section, a linked issue (Fixes #48894), a Testing section, a Performance line, and a Risk section with level and revert path. Two required items are missing or incomplete. First, the Performance section is cut off after 'None, because' in the template, but the author completed it, so this is fine. Second, the Visual Proof section is marked N/A with a reason, which the template allows. The main gap is the Review section and the AI Disclosure section. The template asks for AI disclosure details, and the author left that section blank with no statement. The 'Review' heading is also empty. The Testing checkboxes leave 'I manually tested these changes locally' unchecked, which is acceptable only if the author explains why. The Testing section does not state which platforms were tested (macOS, Linux, Windows, SSH), which the template asks for. The Notes section and the cross-platform checklist item are not addressed beyond the checkbox. These gaps are non-critical, so the description is mostly complete.

Resolution

Fill in the AI Disclosure section, or state that it does not apply. Fill in or remove the empty Review heading. State which platforms were tested, or note that only automated tests ran. Briefly explain why manual testing was skipped if the box stays unchecked.

  • 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

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: 053eb3b8-4283-42b5-a2b4-804375581d80
Commits

Reviewing files that changed from the base of the PR and between 32f94a6 and 14051a6.

Files selected for processing: 6

  • src/main/automations/observation/automation-chat-run-observation.ts
  • src/main/automations/observation/runtime-chat-run-observer.test.ts
  • src/main/automations/observation/runtime-chat-run-observer.ts
  • src/main/automations/runtime-automation-service.ts
  • src/main/bots/bot-group-automation-run.ts
  • src/main/bots/bot-group-turn-reservation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

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]: Bot automation run stays 'dispatched' forever when Orca restarts mid-run

1 participant