Skip to content

fix(automations): record failure reason on failed automation runs - #4343

Merged
tlgimenes merged 1 commit into
mainfrom
fix/automation-failure-reason
Jul 6, 2026
Merged

tlgimenes merged 1 commit into
mainfrom
fix/automation-failure-reason

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Automation runs that fail — including the 5-minute timeout abort — were marked status = 'failed' with failure_reason and failure_kind left NULL. The UI then shows a reason-less "errored" with no explanation.

Found while investigating a real prod thread (thrd_J5cKVKyrKLyEHM-Dc3wT7, Deco org): an automation fire ran for exactly 5:00 and was aborted by AUTOMATIONS_RUN_TIMEOUT_MS mid-run (task 1 of a 17-task commerce-discovery workflow). The DBOS hostedHarnessWorkflow recorded SUCCESS (a timeout abort is a clean cancellation), but the thread showed a bare "failed" with no reason.

Root cause

  • AutomationsStorage.markRunFailed(taskId) (storage/automations.ts) set only status: 'failed' — never failure_reason/failure_kind (the columns exist and are used elsewhere).
  • fireAutomationWorkflow already computes the error message (runError) and even classifies permanent vs transient — but discarded it when calling markRunFailedStep(taskId).

Changes (small, contained)

  • markRunFailed(taskId, reason?, kind?) now persists failure_reason/failure_kind when provided. It only sets them when non-null, so it never clobbers an existing reason.
  • fireAutomationWorkflow passes the reason + a kind at all three failure sites:
    • build/setup failure → kind: "setup" (reason = built.reason)
    • permanent dispatch error → kind: "permanent" (reason = runError)
    • transient error → kind: "error" (reason = runError)
  • The opt-in run timeout now calls abortController.abort(new Error("Run exceeded its 5m time limit and was aborted")) instead of a bare abort(), so a timeout surfaces as a legible error that flows into failure_reason (and logs), rather than a generic abort.

Net effect: a timed-out or otherwise-failed automation now shows why it failed instead of a mystery error.

Testing

  • tsc --noEmit clean for the changed files; bun run fmt clean.
  • (oxlint wasn't runnable in my local shell this session — CI lint will cover it. Changes are plain server-side edits with no lint-sensitive patterns.)
  • No automated test added: the markRunFailed change is DB I/O (e2e tier per TESTING.md, not unit). The behavior is a straightforward column write; happy to add an e2e assertion on failure_reason if you'd like.

Notes / possible follow-ups

  • This fixes the automation failure path (where the reason is dropped today). Interactive (non-automation) hosted runs don't set a timeout, so they're unaffected.
  • A separate, larger option we discussed — making the 5-minute cap configurable per-automation — is intentionally not in this PR.

🤖 Generated with Claude Code


Summary by cubic

Record and surface failure_reason and failure_kind for failed automation runs, including timeout aborts, so the UI shows a clear failure reason instead of a blank "errored".

  • Bug Fixes
    • markRunFailed(taskId, reason?, kind?) now persists failure_reason/failure_kind when provided (never overwrites with null).
    • fireAutomationWorkflow passes reason/kind for all failure paths: setup ("setup"), permanent ("permanent"), transient ("error").
    • Hosted harness run-timeout aborts with a human-friendly error (e.g., "Run exceeded its 5m time limit and was aborted") so timeouts populate failure_reason.

Written for commit 616c4dd. Summary will update on new commits.

Review in cubic

@tlgimenes
tlgimenes force-pushed the fix/automation-failure-reason branch 2 times, most recently from e83a861 to 87a482d Compare July 6, 2026 21:23
Automation runs that fail (including the 5-minute timeout abort) were marked
`status='failed'` with `failure_reason`/`failure_kind` left NULL, so the UI
showed a reason-less "errored" with no explanation.

Root cause: `AutomationsStorage.markRunFailed(taskId)` set only the status, and
`fireAutomationWorkflow` computed the error message (`runError`) but discarded
it when calling `markRunFailedStep`.

Changes:
- `markRunFailed(taskId, reason?, kind?)` now persists `failure_reason` /
  `failure_kind` when provided (never clobbers an existing reason with null).
- `fireAutomationWorkflow` passes the reason + a kind at all three failure
  sites: setup (`"setup"`), permanent dispatch error (`"permanent"`), and
  transient error (`"error"`).
- The opt-in run-timeout now aborts with a descriptive reason
  ("Run exceeded its 5m time limit and was aborted") instead of a bare abort,
  so a timeout surfaces as a legible error that flows into failure_reason.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@tlgimenes
tlgimenes force-pushed the fix/automation-failure-reason branch from 87a482d to 616c4dd Compare July 6, 2026 21:27
@tlgimenes
tlgimenes merged commit 7e2321e into main Jul 6, 2026
14 checks passed
@tlgimenes
tlgimenes deleted the fix/automation-failure-reason branch July 6, 2026 21:47
decocms Bot pushed a commit that referenced this pull request Jul 6, 2026
PR: #4343 fix(automations): record failure reason on failed automation runs
Bump type: patch

- decocms (apps/mesh/package.json): 3.100.0 -> 3.100.1

Deploy-Scope: server
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.

1 participant