Skip to content

feat(platform): pause a schedule after five permanent failures in a row - #3533

Merged
yannickmonney merged 12 commits into
mainfrom
feat/pause-trigger-after-failures
Sep 28, 2026
Merged

yannickmonney merged 12 commits into
mainfrom
feat/pause-trigger-after-failures

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

A schedule that repeatedly fails with a permanent error now pauses after five consecutive failures, records an audit event, and notifies the organization’s owners and admins. The trigger editor shows its failure count and last failed run; saving the trigger resets its health and clears the pause notice.

Behavior

  • Success resets the streak. Permanent failure codes count; transient or unclassified failures and cancellations leave it unchanged. Outcomes from runs that started before the latest trigger save cannot alter the new streak.
  • Only schedules pause automatically. Webhook and event triggers retain failure health without dropping future deliveries.
  • Pause, audit, and notification bookkeeping use savepoints so a bookkeeping failure cannot leave a run unfinished; notification failure cannot undo a committed pause.
  • Schedule claims check the current enabled flag, trigger kind, and saved revision. A schedule paused or edited after the scanner read its page cannot launch from that stale page.
  • Owners and admins can control Automation alerts in notification settings. The trigger state, notification links, documentation, and labels cover EN/DE/FR.
  • Additive migration 0124_automation_trigger_failure_streak.sql supplies defaults and accepts old-image writes during a rolling deployment. REST contract 3.1.0 and MCP expose the health fields and paused_after_failures; OpenAPI and its fingerprint are regenerated.

Validation

Fresh local checks on the reviewed branch:

  • 902 backend tests across 59 files; 60 component tests across 3 files.
  • Real PostgreSQL: 39/39 checks across checkTriggerPauseAfterFailures, checkAutomations, and checkAutomationTriggerDelivery. This includes the deterministic scanner race: pause after page read but before claim, then verify no extra run. The test failed before the claim guard and passed after it.
  • After merging the deleted-organization scan change from main: 172 focused unit tests and 30/30 real PostgreSQL checks across pause, deleted-org scheduling, and the orphan-row migration passed together.
  • Full platform TypeScript check, targeted type-aware lint, formatting, and manual-suite structure gate passed.
  • Commit-time SAST passed. These are fresh local runs, independent of CI cache replay.

Migration 0124 fills the reserved slot before 0125; #3532 will use 0126. This PR lands before #3526, which must use the next API minor version. Refs #3092.

A schedule whose automation fails the same way at every occurrence used
to fire forever: every run failed, spent what it could and told nobody.
finishRun now keeps a failure streak per trigger, in the transaction that
lands a run a trigger started (`trigger:<id>`):

- a success resets it; a failure with a code the next occurrence would
  repeat (node_error, connector_error, llm_output_invalid, auth_error,
  missing_api_key, credit_exhausted, model_not_found) counts; transient
  codes, unclassified failures and cancels neither count nor reset;
- runs started before the trigger was last saved never count, and every
  save resets the streak;
- the fifth permanent failure in a row turns an enabled schedule off
  (enabled=false, new skip reason `paused_after_failures`), writes an
  `automation.trigger.paused` audit row and notifies each owner and admin
  with the revived `automation_failed` type (bell + email, gated by the
  `automation_alerts` preference, opening the automation's General tab);
- webhook and event triggers keep a streak but are never paused, since a
  paused one would drop the deliveries and events that arrive meanwhile;
- the bookkeeping rides a savepoint so it can never leave a run
  unfinished, and the notice a nested one so a failed bell keeps the pause.

Migration 0123 adds the streak columns (consecutive_failures,
last_failed_at_ms, last_failure_code, last_failed_run_id) and widens the
skip-reason CHECK. The Trigger section shows the pause, the streak, the
last failure's code and a link to its run; saving the trigger clears the
pause and marks the notices read. Settings > Notifications offers
Automation alerts to owners and admins again. REST contract 3.1.0 adds the
streak to `Trigger` and the new reason to `lastSkipReason`; the MCP
trigger view carries the same fields. Docs (EN/DE/FR), manual boxes and a
real-Postgres lane (`checkTriggerPauseAfterFailures`) cover it.

Refs #3092
#3519 landed 0123_project_agent_runs_mention_source.sql on main first,
so the trigger failure streak takes the next free number.
finishRun audited the run (the org's audit-chain lock) and only then
wrote the trigger row, the reverse of the order a producer that stamps
an event trigger and then audits takes, e.g. a comment edit's
comment.mentioned dispatch. The two could deadlock. finishRun now locks
the trigger row first (lockTriggerForRunOutcome, in a savepoint, and only
for the rows the streak will write), audits the run, then keeps the
streak.

A success that lands after its schedule paused (a run that overlapped
the pause) no longer resets the streak: the paused schedule keeps the
count that paused it until someone saves the trigger.
- deleteTrigger and deleteAutomationCascade mark the automation_failed
  notices of a paused schedule read, and only of a paused one.
- The MCP trigger view selects and carries the failure streak, omitting
  a last failure there never was.
- The real-Postgres lane reads the paused schedule back through
  listTriggers and checks that a success landing after the pause keeps
  the streak.
The Trigger section's View run always opened the organization's run
route, even on a project's General tab, dropping the project breadcrumbs
and sidebar. The project route now hands its projectId down and the link
picks the project run route, as the run list does. The failure code and
the streak lines use @tale/ui InlineCode and Text instead of hand-rolled
copies.
9ab5ea7 had finishRun lock the trigger row before its run audit, to
match a producer that stamps an event trigger and audits afterwards. Most
producers do the opposite: they audit, then emit (createTask,
appendTaskComment, the contact writes, addMessageToConversation,
createProject). A run landing a permanent failure, or a success that
resets a streak, then deadlocked against them. Either the producer's
dispatch lost, silently, inside emitEvent's savepoint, or finishRun's
audit row did and the terminal write rolled back.

One order now holds everywhere: the organization's audit chain before
any trigger row.

- finishRun writes the run's audit row and keeps the streak after it
  (lockTriggerForRunOutcome is gone).
- dispatchAutomationEvent takes the chain (lockAuditChain, the advisory
  lock every append takes first) before it stamps a trigger. The
  producers that emit before they audit (editTaskComment,
  upsertTaskByExternalRef's create, and every createConversation caller:
  inbound ingest, compose, API sync) hold it by then as well.
- The schedule scan, the webhook door and trigger saves take no chain.

The checkTriggerStreakLockOrder lane runs the real finishRun beside a
real emitEvent producer held between its audit and its emit, in both
orders: both commit, the dispatch's stamp lands and the streak counts.
It fails on the previous order (finishRun: deadlock detected) and when
only finishRun's order is restored (the streak lost to a deadlock).
@yannickmonney
yannickmonney merged commit 359c7ad into main Sep 28, 2026
57 checks passed
@yannickmonney
yannickmonney deleted the feat/pause-trigger-after-failures branch September 28, 2026 06:45
yannickmonney added a commit that referenced this pull request Sep 28, 2026
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