finalizeTurn freezes the finished turn's wall-clock summary into the status bar (shown at idle until the next submit) and logs the totals. outcome is the finish glyph: ✓ clean, ✗ abort/stall. The bar's avg tok/s divides lastTokens by lastElapsed (wall-clock), so it stays self-verifying against the d
(outcome turnOutcome)
| 877 | // drop the pending queue, reset turn state. |
| 878 | // |
| 879 | // Unless the drop is replayable. llm sets MidStream for a socket that died |
| 880 | // after delivering at least one frame and that is not the server's own refusal. |
| 881 | // Only applyDone writes an assistant message to history, so a round that never |
| 882 | // reached EventDone left history untouched: reissuing the identical request |
| 883 | // duplicates nothing. Discard this round's partial buffers first: they are |
| 884 | // display and queue state, not context: and go again. Without this, one |
| 885 | // transient drop three hours into an unattended run ends it and waits for a |
| 886 | // human. |
| 887 | func (m *Model) applyError(e llm.Event) tea.Cmd { |
| 888 | dbgWritef("error", "%v", e.Err) |
| 889 | if e.MidStream && m.phase.active() && m.streamReplays < maxStreamReplays { |
| 890 | m.streamReplays++ |
| 891 | dbgWritef("replay", "mid stream drop, replaying request (%d/%d): %v", m.streamReplays, maxStreamReplays, e.Err) |
| 892 | m.streaming.Reset() |
| 893 | m.streamingEstimate = 0 |
| 894 | m.reasoning.Reset() |
| 895 | m.pending = nil |
| 896 | // Ride the retry hint machinery so the hint is cleared by the next |
| 897 | // non retry event and by endTurn; without it the idle status bar keeps |
| 898 | // reading "retrying" long after the turn finished cleanly. |
| 899 | m.retrying = true |
| 900 | m.status = fmt.Sprintf("stream dropped, retrying (%d/%d)", m.streamReplays, maxStreamReplays) |
| 901 | m.phase = phaseThinking |
| 902 | return m.startChat() |
| 903 | } |
| 904 | if isUnreachable(e.Err) { |
| 905 | m.connected = false |
| 906 | } |
| 907 | m.abortTurn(styleError.Render(m.errorMessage(e))) |
| 908 | return nil |