Files
Mason Daugherty dfcd9417a8 fix(code): retry interrupted model streams (#5905)
A transient provider failure after partial output no longer ends the
turn: the model call is retried, and already-streamed output is marked
as incomplete instead of being joined to the replay.

---

Previously, retries stopped once any message chunk had been emitted.
This change separates retry policy from presentation:

- The middleware emits attempt lifecycle and retry correlation events.
- Streaming clients preserve and annotate superseded partial output.
- Buffered `--no-stream` mode drops failed-attempt text before writing
to stdout.
- Transcript, usage, and tool-hook state are scoped by attempt so
replayed output is not merged or suppressed.

Failed attempts still count toward usage, and clients tolerate missing
or malformed lifecycle events for compatibility. Design details and
alternatives are documented in `libs/code/STREAMING_RETRY_DESIGN.md`.

<details>
<summary>Test plan</summary>

- Retry behavior before and after output begins
- Streaming, buffered, and TUI presentation
- Transcript, usage, and tool-hook settlement across retries
- Missing, malformed, duplicated, and out-of-order lifecycle events

</details>

### Screenshot

![dcode model stream retry
recovery](https://raw.githubusercontent.com/langchain-ai/deepagents/mdrxy/code/stream-retry-design/libs/code/images/model-stream-retry.png)

Made by [Open
SWE](https://openswe.vercel.app/agents/722f8e40-29e4-5eb0-9fd5-368416105bee)

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-08-27 21:33:03 -04:00
..