Repository navigation
Description
1. A thrown dispatch restores an overdue next_run_at, so the 10s sweep claims it again
When a recurring agent dispatch or a script start throws (provider or server error, bb missing from PATH after an upgrade, a broken script), restoreAutomationAfterFailedRun restores the automation's previous next_run_at, which is already overdue, so the next sweep (10s) claims it again, fails again, and restores again, indefinitely. Missing or unusable target threads and missing projects already disable the automation, and an ordinary non-zero script exit already settles as a failed run; only the thrown path loops. Starting bb after it has been off for a while, with several such automations overdue at once, turns the loop into a machine-wide storm of process trees, DB writes, and memory until bb has to be killed. Expected: every failed run closes once and follows an explicit retry or terminal policy.
Prototype: replace rollback with run settlement. A failed dispatch closes the run as failed; recurring automations retry 30 seconds after the first failure and 60 seconds after the second; the third consecutive failure pauses the automation and clears its next run. One-shot, missing-target, and missing-project failures remain terminal; a successful or skipped run resets the count, and a manual pause is never re-enabled by a failure. consecutive_failures is a new column in the plugin's own database (migration included).
2. Once a run is active, a later scheduled occurrence or "Run now" can start a second process tree
The existing CAS already prevented two claims of the same scheduled occurrence, but nothing tied "one automation" to "one running execution": a later due occurrence or a manual run while one was active created another running row and another process tree. Expected: an automation has at most one running execution.
Prototype: enforce one running row per automation with a partial unique index; scheduled claims no-op while one is active, and "Run now" returns the existing running record. Databases from before that invariant can hold several running rows for one automation, so the migration settles all but the newest as interrupted instead of failing to apply. A run row also survives a server crash, restart, or plugin reload while the process that owned it does not, so on startup, before the first sweep, the plugin settles what nothing owns any more: script runs and agent runs that never got a thread are recorded as skipped (interrupted); agent runs follow their thread (idle succeeds, error fails, a deleted, archived, or missing thread is skipped, a live thread keeps its row for the live event to settle).
3. A timed-out script leaves its descendants running
Script timeout and output-limit termination signalled only the direct child, so anything it spawned kept running. Expected: terminating a script terminates what it started.
Prototype: on POSIX hosts, spawn scripts in a detached process group and terminate the group on timeout or output limit, escalating from SIGTERM to SIGKILL; Windows keeps direct-child termination.
Notes
Plugin code only (plugins/automations): data, run, service, sweep, script runner, tests, and the plugin's SKILL.md ("Execution safety is fail-closed"). No server, daemon, or contract wire files change, so no HOST_DAEMON_PROTOCOL_VERSION bump. Tests cover single-flight at the DB boundary, backoff and auto-pause, the manual-pause guard, counter reset on success, skip, and resume, descendant termination, the migration over duplicate running rows, and startup reconciliation (unit and plugin harness). Related pain reported by others: #1660 (bb host grew to 77GB RSS and froze the machine; orphaned processes) and #1647 (deleting a worktree environment leaves its processes running).
Observed on one long-lived instance: 193,534 failed rows out of 193,846 automation_runs (bb.db 134MB + 80MB WAL) from eight automations whose target threads had errored, on the pre-plugin scheduler (that particular path is disabled today); on the current plugin, one script automation failed 348 times in 58 minutes after a restart broke its script, which is the loop in section 1.
Prototype: lnittman/bb @ bb/automation-hardening (main...lnittman:bb/automation-hardening)
AGENT GENERATED: by Claude Fable 5
Activity
Automation execution: settled failures with backoff and auto-pause, s…
chore: sync upstream 2026-08-18 (#6)
Give every persisted retry schedule one owner, an attempt cap and a n…