Skip to content

feat: add response streaming#22

Open
fahimmehraj wants to merge 4 commits intomainfrom
response-streaming
Open

feat: add response streaming#22
fahimmehraj wants to merge 4 commits intomainfrom
response-streaming

Conversation

@fahimmehraj
Copy link
Copy Markdown
Collaborator

@fahimmehraj fahimmehraj commented Apr 7, 2026

Implements #23

Replaces the chat UI's 500ms job polling with live token streaming from the daemon. The OpenCode SDK already emits message.part.delta events; we now route them to running jobs, accumulate them into job state, and push them over a long-lived connection to subscribed clients.

Features

  • New job.stream protocol method: opens a stream that yields a snapshot of the job's accumulated text, then live deltas, then a terminal done/error event.
  • client.streamJob() async generator on the client.
  • Chat UI iterates the stream and renders tokens as they arrive.

Refactors (and why)

  • handleRequest is now an async generator. Previously the connection handler had a special-case branch for job.stream that kept the socket open while every other method used a different code path. Making every handler yield 1+ messages unifies the dispatch — the connection handler just for awaits, no branching. New streaming methods cost zero special-casing.
  • Job state unified: outputText accumulates throughout the run, not just at completion. Without this, the daemon and the live delta stream are two sources of truth, and a late/reconnecting subscriber can't recover what they missed. Now subscribeJob emits a snapshot of the current accumulated text before live deltas begin, so subscribers always see a complete picture regardless of when they join.

Tests
9 new tests covering snapshot delivery, terminal-state short-circuit, delta accumulation, the extractText fallback when no deltas arrive, end-to-end generator dispatch, late-subscribe ordering (catches lost or duplicated deltas), and end-to-end client.streamJob over a real Unix socket.

@fahimmehraj fahimmehraj linked an issue Apr 7, 2026 that may be closed by this pull request
@chenxin-yan chenxin-yan changed the title Response streaming feat: response streaming Apr 8, 2026
@chenxin-yan chenxin-yan changed the title feat: response streaming feat: add response streaming Apr 8, 2026
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.

daemon agent reponse steaming

2 participants