Repository navigation
feat(platform): pause a schedule after five permanent failures in a row - #3533
Merged
Merged
Conversation
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
This was referenced Sep 27, 2026
#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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
0124_automation_trigger_failure_streak.sqlsupplies defaults and accepts old-image writes during a rolling deployment. REST contract3.1.0and MCP expose the health fields andpaused_after_failures; OpenAPI and its fingerprint are regenerated.Validation
Fresh local checks on the reviewed branch:
checkTriggerPauseAfterFailures,checkAutomations, andcheckAutomationTriggerDelivery. 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.Migration
0124fills the reserved slot before0125; #3532 will use0126. This PR lands before #3526, which must use the next API minor version. Refs #3092.