Skip to content

fix(automations): replace fixed timeout with progress-based stall detection - #4355

Merged
tlgimenes merged 3 commits into
mainfrom
feat/automation-stall-detection
Jul 7, 2026
Merged

tlgimenes merged 3 commits into
mainfrom
feat/automation-stall-detection

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Automation runs were being killed after a fixed 5-minute wall-clock timeout regardless of progress — a legitimately long, actively-streaming run (e.g. the 17-task commerce-discovery audit) died mid-work, on task 1 of 17. This replaces the crude cap with the progress-based idle reaper that already governs interactive runs, unifying both under one mechanism.

Observed on prod thread thrd_J5cKVKyrKLyEHM-Dc3wT7: ran exactly 5:00, aborted while streaming tool calls with a null failure_reason.

What changed

  1. Record a real stall reason — when the RunRegistry idle reaper force-fails a stalled run (RUN_FAILED / reason: "reaped"), it now writes failure_reason: "Run stalled — no progress within the idle timeout window" and failure_kind: "stall" instead of a bare status: "failed". Reuses the columns added in fix(automations): record failure reason on failed automation runs #4343. Applied only to "reaped"; "error"/"cancelled"/"ghost" are unchanged.
  2. Remove the fixed wall-clock cap on the hosted automation path (AUTOMATIONS_RUN_TIMEOUT_MS, the runHostedHarness setTimeout, formatTimeoutReason, and the timeoutMs plumbing). Automations now fall under the existing 10-min progress-based idle reaper (RUN_IDLE_TIMEOUT_MS) — a run lives as long as it keeps streaming, and is aborted only after 10 min of no progress. No absolute cap (per design); blast radius is bounded by per-org queue concurrency (10). The AbortController stays for cancellation + the reaper's force-fail.
  3. Clear stale stall columns on RUN_STARTED so a re-run of a previously-stalled thread doesn't carry a stale reason.

Design decisions (see spec)

  • Stall-only, no absolute cap; 10-min idle window for both automations and interactive (interactive was already 10 min — unchanged); reuse the existing reaper rather than build a parallel watchdog.
  • The heartbeat that feeds the reaper (tapProgress → last_progress_at) is already wired on the hosted path, so a progressing automation run is protected.

Scope

Hosted (cluster) path only. The sandbox/link (user-desktop CLI) timeout branch in thread-gate-workflow.ts is intentionally left untouched.

DBOS / recovery

Recovery-compatible workflow-source change — logic inside the existing runHostedHarness step + removal of an unused workflow-input field that replayed journals simply ignore. No DBOS_WORKFLOW_VERSION bump; the workflow-source-guard snapshot was re-baselined instead.

Testing

  • New reactor unit tests: reaped → stall failure_reason/failure_kind; error/cancelled unchanged; RUN_STARTED clears the columns.
  • DB-tier assertions added to the reaped path in run-reactor.integration.test.ts (verifies the update() whitelist actually persists the fields, via a raw column read).
  • bun run check, fmt:check, lint (0 errors) green; workflow-source-guard 5/5.

Follow-ups (out of scope)

🤖 Generated with Claude Code


Summary by cubic

Replaced the 5‑minute wall‑clock timeout for automations with progress-based stall detection shared with interactive runs. Runs keep going while streaming and only fail after 10 minutes of no progress; stalled runs record a clear reason.

  • Bug Fixes
    • Removed the hosted automation cap; rely on the 10‑minute idle reaper (RUN_IDLE_TIMEOUT_MS).
    • On reaped runs, write failure_reason: "Run stalled — no progress within the idle timeout window" and failure_kind: "stall"; other reasons unchanged.
    • Clear failure_reason/failure_kind on RUN_STARTED to avoid stale data on re-runs.
    • Kept AbortController for cancellation; removed timeout plumbing and timeoutMs from the hosted harness, thread gate, and automations workflow.
    • Added unit and real-Postgres tests and whitelisted the new fields in storage updates; hosted path only (CLI path unchanged).

Written for commit 692d202. Summary will update on new commits.

Review in cubic

tlgimenes and others added 3 commits July 7, 2026 14:58
Automations were killed after 5 min regardless of progress. Remove the
hosted-path wall-clock timeout so automations fall under the existing
10-min progress-based idle reaper (unified with interactive runs). A
stalled run is now reaped + failed with a legible stall reason.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
RUN_STARTED didn't clear failure_reason/failure_kind, so a re-run of a
previously-stalled thread carried a stale reason. Also adds real-Postgres
assertions proving the stall reason set on RUN_FAILED(reaped) is actually
persisted by the update() whitelist, not just accepted by the fake storage
used in unit tests.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tlgimenes
tlgimenes force-pushed the feat/automation-stall-detection branch from acdfba9 to 692d202 Compare July 7, 2026 17:59
@tlgimenes
tlgimenes enabled auto-merge (squash) July 7, 2026 18:00
@tlgimenes
tlgimenes merged commit 88783ae into main Jul 7, 2026
14 checks passed
@tlgimenes
tlgimenes deleted the feat/automation-stall-detection branch July 7, 2026 18:03
decocms Bot pushed a commit that referenced this pull request Jul 7, 2026
PR: #4355 fix(automations): replace fixed timeout with progress-based stall detection
Bump type: patch

- decocms (apps/mesh/package.json): 3.102.0 -> 3.102.1

Deploy-Scope: server
tlgimenes pushed a commit that referenced this pull request Jul 16, 2026
…TS.md (#4475)

Mined ~300 merged PRs for the delta between the first PR proposal and the
work added before merge. The dominant shape: a first draft ships the happy
path, then a hardening pass (often a different engineer who takes over the
branch and merges — the vibecoder→engineer handoff) adds the same categories
every time. Encoded those 9 categories as an actionable first-pass checklist,
each citing a real PR (#4008, #4230, #4365, #4409, #4426, #4445, #4357, #4355,
#4449, #4350, #4373, #4416, #4446, #4461, #4134, #4469).

Covers: variant/edge-case handling, tenant/permission scoping, concurrency &
silent-data-loss, test-per-fix + invert-bug-tests + real-PG, dead-code/knip,
lifecycle symmetry + state reset, kill-switch/GC/git-exclude for risky infra,
input validation vs over-engineering, compile-time type-safety.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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