fix(conversation): avoid creating a conversation on chat reconnect#43
Merged
jasonchen922 merged 1 commit intoJul 8, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the backend conversation chat reconnection flow so that Reconnect no longer performs a get-or-create on conversations. Instead, it performs a read-only lookup and, when no conversation exists, it terminates the SSE stream cleanly by emitting a done event—preventing stray empty conversation records from being created as a side effect of reconnecting.
Changes:
- Updated
Service.Reconnectto useconversationRepo.Get(read-only) instead ofensureConversation(get-or-create). - Added an explicit “no conversation” fast-path that emits a terminal
doneSSE event and returns without touching the ongoing-turn cache. - Added a unit test covering the “no conversation -> don’t create one, send done” reconnect behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
backend/internal/biz/conversation/impl/chat.go |
Switches reconnect to read-only conversation lookup and cleanly ends the stream when no conversation exists. |
backend/internal/biz/conversation/impl/chat_test.go |
Adds coverage ensuring reconnect doesn’t create a conversation and only emits a terminal done event when none exists. |
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
Reconnectpreviously calledensureConversation(get-or-create). A reconnectonly resumes an in-progress turn, so when a client reconnects to an agent
instance that has no existing conversation, creating one is unnecessary and a
side effect — it leaves a stray empty conversation and then immediately ends the
stream because there is no ongoing turn.
This changes
Reconnectto look the conversation up read-only(
conversationRepo.Get). If none exists, it sends the terminaldoneevent andreturns without creating a conversation or touching the ongoing-turn cache.
Chatstill usesensureConversation, where first-turn creation is expected.Validation
make precommit-runcd backend && go test ./...cd core && uv run pytestBackend-only change.
make precommit-run,go test ./..., andgolangci-lint runall pass locally. Core and frontend suites were not runbecause neither is touched by this change.
Checklist
CHANGELOG.mdunder## [Unreleased]for user-facing changes.Notes for reviewers
TestReconnectcovers the "no conversation -> don't create, senddone" path. The cache-backed resume paths still require Redis and aren't
unit-tested here (
s.cacheis a concrete*redis.Client); covering them wouldneed miniredis or a cache interface — possible follow-up.
chat.go(fix) andchat_test.go(test).main.