Skip to content

Stream chat messages (Rebased)#29

Open
kevinthai256 wants to merge 4 commits into
mainfrom
feature/stream-chat-messages-rebased
Open

Stream chat messages (Rebased)#29
kevinthai256 wants to merge 4 commits into
mainfrom
feature/stream-chat-messages-rebased

Conversation

@kevinthai256

@kevinthai256 kevinthai256 commented Mar 18, 2026

Copy link
Copy Markdown

Summary

  • wire the tutoring agent + provider clients for token response streaming with fallback to non-stream responses
  • update the frontend chat flow to consume SSE incrementally, render live assistant text, and finalize with persisted metadata (artifacts, actions, widgets)

Test plan

  • Start backend and frontend locally
  • Send a normal message and verify tokens stream progressively in the chat UI
  • Confirm final message replaces the placeholder and includes widgets/artifacts when returned
  • Simulate a slower first token and verify the stream stays open (no premature disconnect)
  • Verify non-stream fallback still works when SSE content type is not returned

@kevinthai256 kevinthai256 linked an issue Mar 18, 2026 that may be closed by this pull request
@kevinthai256 kevinthai256 changed the title Feature/stream chat messages rebased Stream chat messages (Rebased) Mar 18, 2026
@Youdahe123

Copy link
Copy Markdown
Contributor

Really solid work Kevin. The streaming-with-fallback pattern in client.py is well architected — handles partial output, falls back gracefully, and logs appropriately. The SSE parsing on the frontend is clean too.

Two things:

  1. Merge conflicts — needs a rebase onto main.
  2. Minor: missing newline at EOF in client.py.

This is a good-to-merge once conflicts are resolved. Nice work on the fallback handling especially — that's production-quality thinking. 👍

@kevinthai256 kevinthai256 force-pushed the feature/stream-chat-messages-rebased branch from 9d6ab5e to c31a7e8 Compare May 4, 2026 22:39
@Youdahe123

Copy link
Copy Markdown
Contributor

Code Review

Cannot merge — all 4 CI checks are failing. Like PR #27, the frontend failures are mostly pre-existing issues unrelated to this PR's changes. The backend changes here are solid.

What's good

  • Clean streaming implementation in client.py with proper AsyncIterator return types
  • Correct fallback logic: if streaming fails after partial output, it doesn't retry (avoids duplicate tokens); only falls back to non-stream when nothing was emitted
  • on_token callback in agent.py is a clean hook — doesn't force callers to care about streaming internals
  • Fixing response.choices[0].message.content or "" and the Anthropic content block join are good defensive fixes

Issues to fix

1. Conflict with PR #27 (markdown renderer)

This PR adds MarkdownLine and renderInline inline inside MessageBubble.tsx. PR #27 moves those same functions into frontend/src/lib/markdown.tsx as a shared module. These two PRs will conflict at merge time.

Recommended order: merge PR #27 first, then update this PR to remove the inline MarkdownLine/renderInline definitions and import from ../lib/markdown instead. That way the streaming work lands cleanly without re-introducing the duplication that #27 fixed.

2. Missing newline at end of client.py

The diff shows EOF without a trailing newline on the last line of client.py. Ruff will flag this. Add a newline after the last line.

3. The existing stream() method in client.py

There's already a stream() method in the client. The new chat_stream() appears to overlap in purpose. Before this lands, confirm whether stream() is still used anywhere or if chat_stream() replaces it. If stream() is dead code, remove it to avoid confusion.

4. Pre-existing CI failures

Same pre-existing frontend lint issues as PR #27. These aren't from this PR but block the merge.

Action items

  1. Wait for PR Lightweight Markdown Renderer for Chat Messages (Rebased) #27 to merge, then rebase and switch MessageBubble.tsx to import from ../lib/markdown
  2. Add trailing newline to client.py
  3. Clarify / clean up the stream() vs chat_stream() situation
  4. Re-push so CI re-runs

The backend streaming work is well-written — just needs the ordering sorted out with PR #27.

@Youdahe123

Copy link
Copy Markdown
Contributor

Status

CI: All 4 checks failing. No reviewer assigned.

This PR needs:

  1. A human review
  2. A rebase on main once fix: backend-lint and backend-test CI (#35) #36 and fix: frontend lint tests ci #38 land — CI failures here are pre-existing lint issues resolved in those PRs

Not mergeable until reviewed and CI is green.

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.

Implement response streaming (SSE)

2 participants