GeezerVison is showing github.com — fix(core): don't pause automations on failed runs or missing tools by rekram1-node · Pull Request #66422 · anomalyco/opencode
Conversation
Automations no longer pause because a run failed or a tool was briefly missing. A failed run is recorded and the automation keeps its schedule. Automations now pause only for setup problems that can't fix themselves: the owner session was deleted, the directory is gone, or the run child's location or permissions no longer match.
This bit a real hourly automation: an MCP server reconnected for a moment, its tools left the registry, the next run failed with Unknown Code Mode tool, and the automation paused at once. Nothing resumes a paused automation and nothing told anyone, so it stayed paused for about 19 hours.
Other schedulers handle this the same way: a failed run is recorded and the next one goes ahead. Where they do auto-pause, it's only after a long streak and with a notification. Silent self-pausing is the most common complaint about schedulers that do it.
How it works
code run, before running: a tool the script names is missing from the registry
- -> paused, "Paused: Unknown Code Mode tool: <path>"
+ -> script not run, lastOutcome "skipped", lastOutput "skipped: <path> unavailable"
code run fails (throws, times out, bad return value, parse error, needs approval, ...)
- timer: retry in 1 minute; paused after 3 failures in a row, or at once if "invalid"
- event: paused at once
+ lastOutcome "failed", lastOutput <bounded reason>, failures += 1
+ timer: next run at its normal next slot
+ event: cursor moves past that event
event prompt fails to be admitted (e.g. a prompt conflict)
- the watch pauses
+ lastOutcome "failed", cursor moves past that event
owner session deleted, directory gone, run child's location/permissions changed, send target unreachable
-> paused with the reason (unchanged)
- Status stays
active through skips and failures. failures is still counted and reset on success, so it shows a streak, but nothing reads it anymore.
- Deleted: the 1-minute code retry, the 3-failure pause, the immediate pause for
invalid outcomes and for event-trigger failures, and the invalid flag on code outcomes (MAX_CODE_FAILURES and CODE_FAILED_RETRY are gone).
- A code action's
send that fails on an unreachable target now pauses through the same path as a prompt action's target (InvalidError), so its reason no longer has a Paused: prefix. A send that fails for another reason, such as an admission conflict, counts as a failed run.
- Timer prompt actions are unchanged: an admission failure still retries after 5 minutes and never paused.
- No public schema or SDK changes. Skips and failures reuse the existing
skipped and failed values of Automation.Outcome.
Trade-offs
- An automation that fails on every run keeps running and failing until someone looks. Each failure is visible in
lastOutcome/lastOutput, which is better than a silent pause that never resumes.
- Events that arrive while a run fails or a tool is missing are dropped, not replayed. Before, the watch paused on that event, and in practice it stayed paused until someone noticed.
- A one-time (
at) automation whose run fails is now done (with failed), rather than retried and then paused.
Out of scope: telling the owning session when runs keep failing or skipping. That's the follow-up.
Verification
packages/core/test/automation.test.ts:
- A failing timer stays
active through 4 failures in a row, more than the old limit of 3. Each one moves nextDueAt to the next minute and increments failures. Once the tool works again, the next run fires and failures resets to 0.
- An invalid return value is recorded as
failed with its reason, the next slot is unchanged, and a later valid run fires.
- A missing tool is skipped three times without pausing and runs once the tool is back.
- Unreachable send targets still pause with their reasons.
packages/core/test/automation-event.test.ts:
- A throwing code run is recorded as
failed, the cursor moves past the event, and the next event runs.
- A rejected event prompt behaves the same way.
- A missing tool skips its event.
- The existing rejected-handoff test still pauses.
- Existing pause tests still pass: deleted creator session, missing target session, missing directory (timer, code handoff and shell).
bun test for automation, automation-event, automation-shell, tool-automation: 86 pass. These ran with a temporary HOME so local MCP config can't interfere.
bun run typecheck in packages/core and bunx tsc -p tsconfig.build.json --noEmit in packages/simulation, packages/sdk and packages/server all pass.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend merging this. I ran the PR's two new tests on dev: both fail with Paused: Unknown Code Mode tool: …, so the bug is real. With the change, the automation, automation-event, automation-shell and tool-automation tests all pass (84), and tsc -b in packages/core passes.
The skip reuses the existing skipped pattern. Failures and retry_at are left alone, the next run moves to the normal slot, and every other invalid case still pauses. The tests are small and run on the test clock.
Public API: unchanged. skipped is an existing Automation.Outcome value, and unavailable is internal to core.
One inline point on event watches: a skip moves the cursor past the event, so events that arrive during a short MCP reconnect are lost.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rekram1-node
changed the title
fix(core): skip code automation runs while a tool they name is unavailable
fix(core): don't pause automations on failed runs or missing tools
Nov 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commits look sound, apart from the dropped quick retry flagged inline. Thanks for writing up dropped events as a deliberate trade-off; that settles my earlier question about the event cursor.
The automation, automation-event, automation-shell and tool-automation tests pass (86) and tsc -b in packages/core passes. Unreachable send targets and missing directories still pause through InvalidError; everything else now moves the schedule or the event cursor on and keeps the automation active.
Public API: unchanged. Only the lastOutcome/lastOutput values change.
One inline point: removing the 1-minute retry means a short outage costs an hourly, daily or weekly code automation its whole run.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
failures: row.failures + 1,
|
|
|
last_outcome: "failed",
|
|
|
last_output: AutomationCode.boundedOutput(reason),
|
|
|
retry_at: null,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With retry_at: null and advance(...), a failed timer code run now waits for its next normal run. For an hourly, daily or weekly automation, one short MCP or network failure loses that run, while timer prompt actions still retry after FAILED_RETRY. Stopping the pauses doesn't need the retry to go too. Could timer code failures keep a short retry_at, or retry only the first failure of a streak, without pausing?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended. Code automations are single-shot: a failed run is recorded and the next scheduled run goes ahead, with no retry. A script can fail after it has already sent messages or changed things, and the harness can't tell which part failed or whether rerunning is safe, so an automatic retry could repeat side effects. Prompt retries stay because they only cover a prompt that was never delivered, where nothing ran.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
opencodejr[bot] reacted with eyes emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed for failed runs. A script that throws partway may already have sent messages or written state, and codeFailed (automation.ts:432-449) can't tell how far it got, so moving to the next slot with retry_at: null is the safe choice. Prompt retries are different: the catch-all at automation.ts:700-717 only retries after 5 minutes when admission failed, so nothing ran. I'd resolve the bot's comment as intended.
One thing your reasoning doesn't cover is the skip path at automation.ts:609-616. When a tool is unavailable, the script is never started, so no side effects can repeat. It still uses retry_at: null plus advance(...), so the case that motivated this PR still drops a run: an hourly automation whose MCP tool disappears for a few seconds misses that hour. If you want that run back, retry skips only, for example retry_at: now + FAILED_RETRY without advancing the slot on the first skip of a streak, and keep failures single-shot. If losing one slot is acceptable, it's fine as is. It's just a gap, not a bug.
I checked this by reading the code only. I made no changes and ran no tests.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 26, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|