Skip to content

A transient thread-read failure permanently disables every automation targeting that thread #2635

Closed

Description

@MGrin

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 = 1

One unreadable moment disables every automation targeting that thread, permanently.

Two things this makes hard to diagnose

  1. last_error = 'target thread deleted' is never observable. closeAutomationRun
    with status:"failed" calls recordAutomationFailure, which overwrites last_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.
  2. consecutive_failures still moves, which reads as strikes. The same call increments
    it, so the row shows consecutive_failures = 1 or 2 with 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 !== null is genuinely permanent; a status outside {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

  1. MGrin commented on Aug 28, 2026

    @MGrin
    ContributorAuthor

    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:

    target_thread_id   automations
    thr_3phhrj72ms     1    radar
    thr_3waqz7vb9w     1    orchestrator tick     <- the one that was disabled
    thr_aeg57s5skx     1    standup brief
    thr_p2sprd5c23     1    dream
    

    Every targeted automation on this machine is the only one aimed at its thread, so keying
    the disable on target_thread_id has 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.

  2. MGrin commented on Aug 28, 2026

    @MGrin
    ContributorAuthor

    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_runs table gives 7 occurrences across 4 automations and 4 distinct target threads, 2026-08-20 to 2026-08-27:

    auto_ey3ygbadd3o  2026-08-20 08:45:45  thr_aeg57s5skx  missing, deleted, archived, or not runnable
    auto_ey3ygbadd3o  2026-08-20 11:17:41  thr_aeg57s5skx  missing, deleted, archived, or not runnable
    auto_ob3v8-53bpe  2026-08-22 19:30:05  thr_p2sprd5c23  BB request timed out after 75 seconds.
    auto_ey3ygbadd3o  2026-08-25 02:46:25  thr_aeg57s5skx  missing, deleted, archived, or not runnable
    auto_9sinflbfqzm  2026-08-25 02:46:25  thr_3phhrj72ms  missing, deleted, archived, or not runnable
    auto_rtjxxl-vfki  2026-08-27 08:00:04  thr_3waqz7vb9w  missing, deleted, archived, or not runnable
    auto_rtjxxl-vfki  2026-08-27 21:30:48  thr_3waqz7vb9w  missing, deleted, archived, or not runnable
    

    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-53bpe 2026-08-22 reads Target 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_ey3ygbadd3o and auto_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":

    07:00:00 succeeded   07:15:00 succeeded   07:30:04 succeeded   07:45:07 succeeded
    08:00:04 FAILED -> enabled=0
    

    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.

  3. MGrin commented on Aug 28, 2026

    @MGrin
    ContributorAuthor

    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 thread thr_3waqz7vb9w, read from ~/.bb/plugins/automations/data.db (live, ?mode=ro):

    1787923803863  2026-08-28T13:30:03Z  failed  Thread interrupted because the host daemon disconnected
    1787923844036  2026-08-28T13:30:44Z  failed  Target thread thr_3waqz7vb9w is unavailable: missing, deleted, archived, or not runnable
    

    Before those two: 11 consecutive successes, the most recent at 13:15Z. After them the automation was switched off with enabled = 0, next_run_at empty, consecutive_failures = 2, and no (automation paused after N consecutive failures) marker in last_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 unavailable message. 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_error empty, next_run_at 13: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:

    1. Do not treat a dispatch failure as evidence about the target thread's lifecycle. The disable is keyed on 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.
    2. Distinguish "cannot reach the thread right now" from "this thread cannot be reached again." Only the second warrants a terminal disable; the first is what the three-strike budget already exists for.
  4. MGrin commented on Aug 28, 2026

    @MGrin
    ContributorAuthor

    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:

    unavailable at automation preceding run gap
    2026-08-20T08:45:45Z auto_ey3ygbadd3o failed — Turn failed 40.1s
    2026-08-20T11:17:41Z auto_ey3ygbadd3o failed — …is unavailable… 9115.4s
    2026-08-25T02:46:25Z auto_ey3ygbadd3o failed — Turn failed 40.4s
    2026-08-25T02:46:25Z auto_9sinflbfqzm failed — Turn failed 40.4s
    2026-08-27T08:00:04Z auto_rtjxxl-vfki succeeded, no error 896.8s
    2026-08-27T21:30:48Z auto_rtjxxl-vfki failed — Thread interrupted because the host daemon disconnected 40.4s
    2026-08-28T13:30:44Z auto_rtjxxl-vfki failed — Thread interrupted because the host daemon disconnected 40.2s

    5 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-cause unavailable sentence every time.

    So unavailable: missing, deleted, archived, or not runnable is 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:

    • The rate limit I relayed last time is at best one cause of a first failure, and it is unverified as either sufficient or proximate.
    • A daemon-disconnect / reconnect race accounts for 2 of the 7. Turn failed accounts 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_error retains the generic message and the more specific first-failure text survives only in automation_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 of thr_3waqz7vb9w.

    The two exceptions are stated rather than filed off. 2026-08-20T11:17:41Z follows a previous unavailable by 2.5 hours — a later retry of an already-disabled automation, a different shape. 2026-08-27T08:00:04Z has 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 unavailable regardless 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_id should not be reachable from a message that is emitted on every retry failure alike.

  5. added theissue type on Aug 28, 2026
  6. added
    threads
    automations
    confirmed-repro
    on Aug 28, 2026
  7. bb-slop-cop commented on Aug 28, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

  8. MGrin commented on Aug 28, 2026

    @MGrin
    ContributorAuthor

    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_id is NULL on every one of these failures and the run finishes in 2–74 ms.

    thread_id NULL thread_id set
    succeeded (120) 0 120
    failed (17) 8 9

    All 8 null-thread failures carry Target thread … is unavailable: …. None of the 9 set-thread failures does. A successful run never has a null thread_id. So thread_id IS NULL and 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 real thread_id and 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:

    2026-08-22T19:30:05Z  auto_ob3v8-53bpe  dur=104165ms
        Target thread thr_p2sprd5c23 is unavailable: BB request timed out after 75 seconds.
    

    A real cause, and a duration consistent with it. The other seven read missing, deleted, archived, or not runnable and 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:

    • Corrected: I called it "a property of the ~40s retry path." More precisely it is a property of dispatch-time attach failure. The ~40s spacing describes when a second dispatch happens, not why it fails — real, but a weaker claim than I made it.
    • Resolved: 2026-08-27T08:00:04Z, the row I flagged as having no precursor, has the identical shape — thread_id NULL, 12 ms. It is the same failure; only its timing was unusual. 7 of 7.
    • Unchanged: the enumeration has been false in every instance checked, and the overwrite still holds — the second dispatch runs last, so last_error keeps this generic string while the specific first-failure text survives only in automation_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 on target_thread_id should not be reachable from a message the dispatcher emits without testing anything about that thread.

    Queries are all against ~/.bb/plugins/automations/data.db opened ?mode=ro; happy to paste them if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    automationsconfirmed-reprothreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions