Repository navigation
Chat backend: streaming answers, cited passages, renaming threads - #40
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The chat answers only after a long wait, with no sign of progress. Its citations are bare file names that can't be read, and threads can't be renamed. The approved chat redesign (spec:
docs/superpowers/specs/2026-09-26-chat-redesign-design.md, mockups:docs/design/chat-redesign/) needs three backend capabilities. This PR is Part A of the plan (docs/superpowers/plans/2026-09-26-chat-redesign.md). The frontend follows in a second PR.Implementation
POST /api/chat/threads/<id>/messages/streamsends Server-Sent Events:user_message,stage,notice,delta,reset,doneanderror;generation.answeris now a thin wrapper over an event generator (answer_events), so the CLI, the evals and the JSON route are unchanged;reset;donecarries exactly what was saved;GET /api/chat/sources/<id>:httpsURLs;changedrather than silently different text. Older citations show asunverified.PATCH /api/chat/threads/<id>trims the title, requires 1–200 characters, and leavesupdated_atalone, so the thread keeps its place in the list.scope="chat_send").{"error": …}instead of Werkzeug's HTML page. Their status codes and headers are kept.Validation
make check: 731 passed, 94.52% coverage (floor 85%). ruff clean, bandit no issues, pip-audit no known vulnerabilities,alembic checkno new operations.test_chat_stream.py,test_passages.pyandtest_api_errors.py, with additions totest_chat.py,test_generation.pyandtest_rate_limits.py.Security, DB and API impact
9c1e4b7a2d10addsmessage_sources.content_sha256(nullable).SourceResponsegainsid;httpsonly and passunsafe_reason;Follow-ups (not in this PR, by choice)
create_engine(hide_parameters=True), so SQL parameters (which can include answer text) never reach error logs.test_the_question_is_committed_before_the_model_is_called, which can't tell the explicit commit apart, and add a test that an error raised mid-iteration closes the model stream.