Open History to see the last commit
1---
2id: RunDetachedCapability
3title: RunDetachedCapability
4---
5
6```ts
7const RunDetachedCapability: Capability<true, "run-detached">;
8```
9
10Defined in: [packages/ai/src/activities/chat/middleware/run-store.ts:414](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/middleware/run-store.ts#L414)
11
12Whether this run's teardown DID detach — the disconnect was survived, the
13agent is still working, and a later attach can take the run over.
14
15The past-tense counterpart of [DetachableRunCapability](DetachableRunCapability.md), and the two must
16not be confused:
17
18- **detachABLE** is published at `setup`, and only says a disconnect *may* be
19 survived (a `RunStore` and a durable log are wired).
20- **detachED** is published on the ABORT path, by the middleware that actually
21 makes the call — `withSandbox`'s `onAbort`, which is the only actor that has
22 resolved BOTH out-of-band cancel bands (`AbortInfo.cancelRequested` and
23 `wasCancelRequested` on the record) and `detachOnDisconnect`. An explicit
24 cancel, a non-detachable disconnect, an error, and a normal finish all leave
25 it unpublished.
26
27Its consumer is the durable DELIVERY sink in `stream-to-response.ts`: a
28detached run's log must stay OPEN and un-terminalized so the takeover can
29continue it (see `wasRunDetached` in `../../../delivery-detach`). Reading it
30is safe and race-free only because a `for await` over the chat stream awaits
31the generator's `return()` — and therefore the whole `onAbort` chain — before
32the sink's own `finally` runs.
33
34Read with `{ optional: true }`: absent means "not detached", which is every
35other exit path and every app that has not wired durability.
36
37Typed `true`, not `boolean`, for the same reason as
38[DetachableRunCapability](DetachableRunCapability.md): absence is the only negative, so publishing
39`false` must not be representable.