refactor: enhance message handling and billing logic#89
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.
Summary
Fix conversation streaming failure handling so failed turns keep a stable server-backed message chain.
When a streaming request fails after the backend has already created the user/assistant message pair, the stream error now returns those real message IDs even if no visible content was produced. Non-billable failure results release the reserved usage balance instead of recording usage. The frontend reconciles pending messages with server terminal states, avoids losing buffered stream text on failure, and only exposes retry/edit/continue actions for persisted messages that can actually be addressed by the backend.
Change type
Affected areas
Verification
cd backend && go test ./internal/application/conversation/...cd backend && go test ./internal/transport/http/conversation/...cd frontend && pnpm lintgit diff --checkScreenshots, API examples, or logs
No screenshots. This is a streaming/message-chain behavior fix.
Configuration, migration, and compatibility notes
No database migration, environment variable, Docker, or public configuration changes.
Streaming error events may now include
data.userMessageanddata.assistantMessagefor non-billable failed turns when the backend already created the message pair. This keeps frontend branch reconciliation on real server message IDs and does not charge usage for no-output failures.Documentation
Security and privacy
Checklist
.pycfiles,.envfiles, and local storage data are not committed.