Repository navigation
Description
A transient failure to read the target thread permanently disables every automation
pointed at that thread — no retry, no strike budget, and a message naming four permanent
conditions for a state that cleared in seconds.
Observed on 0.39.0; the code path below is read from the 0.40.0 bundle
(server/dist/builtin-plugins/automations/dist/server.js) and is unchanged.
What happened
orchestrator tick, a */15 agent automation with a targetThreadId, had run 65 times
that day. Then:
2026-08-27 21:15:02 succeeded
2026-08-27 21:30:07 FAILED "Thread interrupted because the host daemon disconnected"
2026-08-27 21:30:38 FAILED "Target thread thr_… is unavailable: missing, deleted,
archived, or not runnable"
-> enabled=0, next_run_at=NULL
The thread was never missing, deleted, archived or unrunnable. It was active before,
active after, and is active now. The two failures are 41 seconds apart. It stayed off ~11
hours and was only noticed because a local watchdog polls the store.
The path
reuseTargetThreadForRun routes two different conditions to the same terminal handler:
try {
thread = sdkThreadSchema.parse(await bb.sdk.threads.get({ threadId: args.targetThreadId }));
} catch (error) {
closeRunForUnusableTargetThread(bb, db, { ...args, detail: errorMessage(error) });
return;
}
if (!isThreadReusable(thread)) {
closeRunForUnusableTargetThread(bb, db, {
...args, detail: "missing, deleted, archived, or not runnable" });
return;
}with
function isThreadReusable(thread) {
return thread.deletedAt === null && thread.archivedAt === null
&& (thread.status === "idle" || thread.status === "active");
}So a thrown threads.get() (an RPC failure — the daemon being briefly unreachable is
exactly this) and any momentary status outside {idle, active} are treated
identically to a deleted thread. Neither is retried.
closeRunForUnusableTargetThread then does two things:
disableAutomationsForDeletedThread(db, { threadId: args.targetThreadId, now });
closeAutomationRun(db, { runId, status: "failed", error: `Target thread … is unavailable: …` });and the disable is keyed on the thread, not the automation:
UPDATE automations SET enabled = 0, next_run_at = NULL,
last_error = 'target thread deleted', updated_at = @now
WHERE target_thread_id = @threadId AND enabled = 1One unreadable moment disables every automation targeting that thread, permanently.
Two things this makes hard to diagnose
last_error = 'target thread deleted'is never observable.closeAutomationRun
withstatus:"failed"callsrecordAutomationFailure, which overwriteslast_error
with the run's message. Across every automation this machine has ever run, 0 rows have
ever carried'target thread deleted'— so the string that names the mechanism never
reaches an operator, and grepping for it finds nothing.consecutive_failuresstill moves, which reads as strikes. The same call increments
it, so the row showsconsecutive_failures = 1or2with no
(automation paused after N consecutive failures)marker. It looks like the 3-strike
auto-pause caught early. The only reliable discriminator is that absent marker.
Why it is costly
AUTOMATION_MAX_CONSECUTIVE_FAILURES = 3 gives ordinary run failures a budget. This path
has none — it is terminal on the first dispatch that hits it. And nothing announces a
disabled automation, so an absent tick is indistinguishable from one not yet due: the
failure is silent by construction and stays silent.
Suggested direction
Distinguish cannot read the thread right now from the thread is gone:
- a thrown
threads.get()is an RPC failure and should take the ordinary failure path
(retry, strike budget), not the terminal one; deletedAt !== nullis genuinely permanent; astatusoutside{idle, active}is not
obviously so, and could at least require repetition before being treated as terminal;- the run error should say which of the four conditions actually held, rather than listing
all four for whichever one fired; - consider not silently overwriting
'target thread deleted', since it is the only field
that distinguishes this path from a strike pause.
Happy to test a patch — this reproduces on a machine that restarts bb regularly.
Activity
MGrin commentedon Aug 28, 2026
Clarifying the blast radius, since the report above states the code's reach and could be
read as claiming we lost several automations at once. We did not, and the honest version is
more useful:
Every targeted automation on this machine is the only one aimed at its thread, so keying
the disable on
target_thread_idhas never yet taken a bystander. Observed radius is 1.The point is that it is latent rather than absent: the moment anyone points a second
automation at a standing thread, one unreadable moment disables both, and nothing warns
them at create time or after. The disable is per-thread while the failure is
per-automation-run — a single run's inability to read its target settles every automation
that shares that target.
So the severity of the main report does not rest on this, and I would rather it were stated
than inferred later.
One correction to my own wording above while I am here: I wrote that this is silent by
construction. It is silent to bb — a local watchdog polling the plugin's sqlite store is
what surfaced it here, after ~11 hours.
MGrin commentedon Aug 28, 2026
Correcting my own blast-radius comment above. I said the observed radius was 1 automation. That was wrong — I had only queried the one automation the report was about. Enumerating the whole
automation_runstable gives 7 occurrences across 4 automations and 4 distinct target threads, 2026-08-20 to 2026-08-27:Query:
select automation_id, started_at, error from automation_runs where error like '%is unavailable%'.Three things in that table that the original report could not show:
1. One occurrence carries the RPC error verbatim, which is direct evidence of the
threads.get()throw branch.auto_ob3v8-53bpe2026-08-22 readsTarget thread thr_p2sprd5c23 is unavailable: BB request timed out after 75 seconds.A 75-second request timeout is unambiguously transient, and it is reported to the operator under a message enumerating four permanent conditions. In the original report I inferred that branch from reading the bundle; here it is measured.2. Two different automations were killed in the same second. 2026-08-25 02:46:25 took out
auto_ey3ygbadd3oandauto_9sinflbfqzm, targeting two different threads. A single host-level event disables every automation it touches, independently, with no strike budget spent by any of them.3. There is an instance with no antecedent failure at all, which is the cleanest statement of "terminal on its own":
Eight consecutive successes (06:00 through 07:45), then one dispatch, then off. The other instance I reported (21:30:48) was preceded 41 seconds earlier by
Thread interrupted because the host daemon disconnected; this one was preceded by nothing. Lifetime tally for that automation is 73 succeeded / 3 failed.None of this changes the mechanism I described, and none of the four affected automations was ever missing, deleted, archived or un-runnable. It changes how often the path is reached: not a single unlucky row, but seven, across four unrelated automations, in eight days, on one machine.
MGrin commentedon Aug 28, 2026
Third instance, and it adds a cause that is not in the enumeration — plus a detail that changes what the enumeration is even claiming.
2026-08-28, automation
auto_rtjxxl-vfki, target threadthr_3waqz7vb9w, read from~/.bb/plugins/automations/data.db(live,?mode=ro):Before those two: 11 consecutive successes, the most recent at 13:15Z. After them the automation was switched off with
enabled = 0,next_run_atempty,consecutive_failures = 2, and no(automation paused after N consecutive failures)marker inlast_error— the terminal unusable-target path, not the three-strike budget. Consistent with the earlier instances.The two failures 41 seconds apart carry different errors. The first names a host daemon disconnect; only the second is the four-cause
unavailablemessage. So the message that ends the automation is not the one closest to the cause — a more specific error was available one run earlier and was superseded by a less specific one.The thread was alive throughout. It is running now and was never deleted or archived. On restart the harness attributed the stop to a provider rate limit, in these words: "Provider capacity is back and this thread was stopped by a rate limit. This is a plain restart rather than a retry of the failed call, so the request that hit the limit was never served."
Stated precisely, because it is the limit of what was observed: the rate-limit attribution comes from the harness's own restart message reported by the thread's operator, not from an independent measurement, and nobody has shown a rate limit is sufficient to produce this. What was verified is that all four enumerated causes were false — the thread was not missing, deleted, archived, or unrunnable — and that a transient provider condition coincided with the two failures.
The consequence worth weighing: if a transient provider condition can reach this path, then two dispatches inside one rate-limit window permanently disable an agent-mode automation, with no next run and nothing announced. The workload most likely to exhaust provider capacity is the agent fleet, which is often the thing the automation exists to supervise.
Recovery was
bb automation resume auto_rtjxxl-vfki --project proj_d43r3agd97→ rc=0, verified against the store rather than the CLI's word (enabled=1,consecutive_failures=0,last_errorempty,next_run_at13:45:00Z).Running total for this issue: 9 runs across 4 automations and 4 threads. Corrects the "radius = 1" in my original report, as noted in this earlier comment.
Two things that would each fix this independently, in preference order:
target_thread_id, so one bad moment takes down every enabled automation aimed at that thread — including, here, a transient that had nothing to do with the thread.MGrin commentedon Aug 28, 2026
Follow-up that supersedes the rate-limit emphasis in my previous comment. I enumerated every occurrence of this error in
~/.bb/plugins/automations/data.db(live,?mode=ro) rather than reasoning from the two I had, and the regularity is sharper and more testable than either thing I said before.All 7 occurrences, with the preceding run for the same automation:
unavailableatauto_ey3ygbadd3oTurn failedauto_ey3ygbadd3o…is unavailable…auto_ey3ygbadd3oTurn failedauto_9sinflbfqzmTurn failedauto_rtjxxl-vfkiauto_rtjxxl-vfkiThread interrupted because the host daemon disconnectedauto_rtjxxl-vfkiThread interrupted because the host daemon disconnected5 of the 7 sit 40.1–40.4 seconds after a first failure, across 3 automations and 3 target threads. The first failure's message varies —
Turn failed×3,host daemon disconnected×2 — and the retry's message is the same four-causeunavailablesentence every time.So
unavailable: missing, deleted, archived, or not runnableis not a diagnosis of the thread. It is what the ~40s retry says when it fails, whatever the first failure was. That is why the enumeration has been wrong in every instance anyone has checked: it is a generic message emitted on a retry path, and it names four lifecycle states none of which was ever tested.This subsumes the two mechanisms proposed earlier in this thread and should replace both:
Turn failedaccounts for 3 and is the more common precursor.It also explains the field a diagnosing reader actually reaches for. The retry is last, so
last_errorretains the generic message and the more specific first-failure text survives only inautomation_runs. bb generates the better message first and then overwrites it with the worse one 40 seconds later. Credit for spotting the overwrite: the operator ofthr_3waqz7vb9w.The two exceptions are stated rather than filed off.
2026-08-20T11:17:41Zfollows a previousunavailableby 2.5 hours — a later retry of an already-disabled automation, a different shape.2026-08-27T08:00:04Zhas no precursor failure at all: the run before it succeeded, 15 minutes earlier, after 31 consecutive successes. That one is unexplained and I am not going to pretend it fits.Testable prediction, which is the point of preferring this to the earlier framings: force any first-failure condition on an agent-mode automation with a target thread, and the retry ~40s later should report
unavailableregardless of the thread's actual state — which is trivially checkable, because the thread can be verified alive at that instant.The narrow fix follows without needing to know what caused the first failure: the retry should not be permitted to assert a lifecycle claim it did not test, and a terminal disable keyed on
target_thread_idshould not be reachable from a message that is emitted on every retry failure alike.bb-slop-cop commentedon Aug 28, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotBug· Priority:High· Effort:Low.threads,automations, andconfirmed-repro.REPRODUCED· Root-cause confidence:high.MGrin commentedon Aug 28, 2026
Third and last from me on the mechanism. This refines my previous comment and resolves the one row I posted there as unexplained — it needed no extra layer, and the corrected reading covers 7 of 7 rather than 5 of 7.
I looked at the columns rather than only the timing. Two facts from
automation_runs,run_mode='agent':1. The run never gets a thread.
thread_idis NULL on every one of these failures and the run finishes in 2–74 ms.thread_idNULLthread_idsetAll 8 null-thread failures carry
Target thread … is unavailable: …. None of the 9 set-thread failures does. A successful run never has a nullthread_id. Sothread_id IS NULLand this error are the same event: a dispatch-time attach failure, before the thread is engaged at all. The precursor runs, by contrast, all have a realthread_idand take 898–15,419 ms.2. The text after
unavailable:is a reason slot, and bb fills it properly when it has a reason. The 8th null-thread failure reads:A real cause, and a duration consistent with it. The other seven read
missing, deleted, archived, or not runnableand complete in 2–74 ms.So that phrase is not a diagnosis and not a wrong guess — it is the fallback string printed when the dispatcher has no reason to give. It is emitted in single-digit milliseconds, on a code path that never contacted the thread, and it names four lifecycle states none of which was tested. The timeout case proves the slot can carry something true.
What this changes in what I said before:
2026-08-27T08:00:04Z, the row I flagged as having no precursor, has the identical shape —thread_idNULL, 12 ms. It is the same failure; only its timing was unusual. 7 of 7.last_errorkeeps this generic string while the specific first-failure text survives only inautomation_runs.The narrow fix is now smaller than what I proposed last time, and needs no decision about causes: when the reason slot is empty, say what is actually known — that the thread could not be attached — instead of substituting an enumeration of lifecycle states.
BB request timed out after 75 seconds.is the shape to copy. And a terminal disable keyed ontarget_thread_idshould not be reachable from a message the dispatcher emits without testing anything about that thread.Queries are all against
~/.bb/plugins/automations/data.dbopened?mode=ro; happy to paste them if useful.Handle transient target thread lookup errors as run failures (#2643)