Skip to content

Commit 083adfb

Browse files
committed
docs(adr): detail tool-loop cancellation checkpoints + cancellation recording (ADR-0057 s5)
1 parent bc584ca commit 083adfb

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎adr/0057-ai-request-cancellation.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ required anywhere.
131131

132132
### 5. Tool-loop propagation
133133

134-
`AbstractClient`'s auto-execute loop checks the token at the top of each
135-
iteration and before executing each tool, and threads the token into every
136-
nested `chat()`/`streamChat()` call, so a cancel during a long multi-tool turn
137-
aborts promptly rather than only at the next HTTP boundary.
134+
`AbstractClient`'s auto-execute loop checks the token at three points: at the
135+
**top of each iteration**, **before executing each tool** (inside
136+
`executeTools`, ahead of the per-tool try/catch so the cancellation propagates
137+
rather than being captured as a tool failure), and **after tool execution,
138+
before the next provider round-trip** (so a cancel that lands while a tool is
139+
running stops the loop immediately rather than waiting for — or issuing — the
140+
next HTTP call). The token is also carried on every nested request (via the
141+
`withCancellationToken` wither), so an in-flight provider call during the loop
142+
aborts at the HTTP layer too. A cancellation detected in the loop surfaces as
143+
`OperationCancelledException`, which `chat()` records as a **cancellation** (a
144+
`request.cancelled` metric + `Status::CANCELLED` status + a cancelled audit
145+
entry — not `request.failed`) before rethrowing to the caller.
138146

139147
### 6. Granularity (the guarantee)
140148

0 commit comments

Comments
 (0)