Skip to content

feat: stream LLM replies over SSE and show progress while verbs wait - #55

Merged
simensen merged 11 commits into
mainfrom
beau/llm-streaming-progress
Oct 8, 2026
Merged

simensen merged 11 commits into
mainfrom
beau/llm-streaming-progress

Conversation

@simensen

@simensen simensen commented Oct 2, 2026

Copy link
Copy Markdown
Member

The LLM verbs (retro, wake, brief) used to sit on an empty line for minutes. This PR adds a one-line status on stderr while they wait, and streams replies over SSE. It carries two wip Matters, llm-streaming and llm-progress, with one commit per verified step.

Streaming (internal/llm)

  • Observer seam: llm.WithObserver(ctx, o) reports call phases: start, connected, request-sent, first-byte, thinking, delta, done. Done comes only on success. With no observer, the code path does not change. Complete keeps its signature.
  • SSE by default: the client sends stream: true and parses the SSE reply. Reasoning deltas emit PhaseThinking and stay out of the result. Content deltas emit PhaseDelta. When the reply is not text/event-stream, the client uses the existing JSON reader. llm.stream: false in config turns streaming off.
  • Timeouts: the 30 s whole-request limit is gone. FirstByteTimeout (30 s) bounds the wait for headers, IdleTimeout (30 s) bounds silence between body reads, and MaxDuration (5 min) caps the call. A long stream is no longer cut at 30 s. A parent cancel still satisfies errors.Is(err, context.Canceled).
  • llmtest stub: new SetStream, SetStreamRaw and SetDelay. Default replies are byte-identical to before.

Progress (internal/progress and the verbs)

  • Reporter: draws <spinner> <label> · <phase> · <N>s on stderr and clears it before any other output. It is a no-op when --json is set, when TERM=dumb, or when stderr is not a character device. It travels in the context, so no verb function signature changes.
  • retro: summarizing 7/15 · 3 cached.
  • wake --auto: drafting 3/15 · <project> with the call phase.
  • wake interactive: drafting · <project>, and redrafting · <project> for an Edit. The full draft and menu still print as before.
  • brief: synthesizing brief · <project> with the call phase.

Decisions to confirm

Two defaults were set at planning time and are not confirmed yet:

  • brief shows phases only. It does not stream the brief text to stdout.
  • No progress shows when stderr is not a terminal, even with --verbose.

Known limits

  • Narrow terminals: the reporter reads the width from COLUMNS, which shells usually do not export, so it assumes 80. At 40 columns the line wraps and the clear leaves the first row on screen. A fix needs the real window size (x/term or TIOCGWINSZ).
  • Test gap: the reporter is off when stderr is not a TTY, so no unit or e2e test catches a removed Status, Clear or observer in a verb. Live pty runs are the evidence.
  • Empty summaries: retro caches an empty summary. A reasoning model that spends its whole budget on reasoning leaves one for that session. This predates the PR.
  • Duplicated prefix: error lines read clast: brief: brief: …. This predates the PR.
  • SURFACE: V12 still says "no streaming", and V31 does not list llm.stream. Those amendments belong in clast-reboot.

docs/llm-streaming/decisions.md and docs/llm-progress/decisions.md record every decision and follow-up.

Testing

  • make check passes. The e2e suite needed no expected-output changes.
  • New tests cover the observer phases and concurrency, every SSE case (chunks, fallback, keepalives, reasoning precedence, error and malformed events, a missing [DONE], a held-open connection after [DONE], a raw-body check that stream is absent when off), and each timeout on both the SSE and JSON paths. Mutation checks confirmed that these tests fail when the behavior breaks.
  • A live clast brief against the configured LiteLLM endpoint succeeds with streaming on and with llm.stream: false.
  • Live pty runs (script, with a scratch cache) of retro --since -7d --refresh and brief draw the status line and leave no residue at 80 columns. The pyte terminal emulator confirmed the final screens. Pty runs of wake, against a stub and a scratch journal, covered --auto, Edit, a failed redraft, and the EOF paths.

Complete reports call phases (start, connected, request-sent,
first-byte, done) to an Observer carried in the context, via
net/http/httptrace. With no observer, the code path is unchanged.

wip: llm-streaming/step-01
Reporter draws one spinner line on stderr with a label, the llm call
phase, and elapsed time. It is nil (a no-op) when --json is set,
TERM=dumb, or stderr is not a character device.

wip: llm-progress/step-01
While Summarize runs, stderr shows 'summarizing <done>/<total>', plus
the cache-hit count once it is non-zero. The line clears before any
output or error.

wip: llm-progress/step-02
wake builds a progress reporter before the mode branch and puts it in
the context. RunAuto shows 'drafting <i>/<n> · <project>' with the
llm call phase, and clears the line before any stderr output.

wip: llm-progress/step-03
After the session header, stderr shows 'drafting · <project>' with the
llm call phase. An Edit regeneration shows 'redrafting · <project>'.
The line clears before the draft and menu reprint, which are unchanged.

wip: llm-progress/step-04
While Synthesize waits on the LLM, stderr shows 'synthesizing brief ·
<project>' with the call phase. The line clears before the brief text
or an error prints.

wip: llm-progress/step-05
The stub records whether a request asked for stream:true and can answer
with SSE chunks (SetStream), verbatim SSE lines (SetStreamRaw), and
configurable delays (SetDelay). Default replies are unchanged.

wip: llm-streaming/step-02
Complete sends stream:true by default and parses the SSE reply,
emitting PhaseThinking for reasoning deltas and PhaseDelta for content.
A reply that is not text/event-stream uses the existing JSON path.
llm.stream: false turns streaming off.

wip: llm-streaming/step-03
…nd total limits

A long stream is no longer cut at 30s. Complete now fails when no
response headers arrive within FirstByteTimeout, when the body stalls
for IdleTimeout, or when the call runs past MaxDuration. A parent
context cancel still returns the parent's error.

wip: llm-streaming/step-04
docs/llm-streaming/decisions.md records the observer seam, streaming
by default with a JSON fallback, the parser rules, and the three
timeouts. The package doc no longer says the client does not stream.

wip: llm-streaming/step-05
docs/llm-progress/decisions.md records the reporter design, the TTY
gate, the per-verb status labels, the two defaults Beau has not
confirmed, and the live pty smoke results, including the narrow-terminal
wrap risk.

wip: llm-progress/step-06
@simensen
simensen merged commit e50c908 into main Oct 8, 2026
5 checks passed
@simensen
simensen deleted the beau/llm-streaming-progress branch October 8, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant