fix: keep failed chat continuations out of conversation cache#2947
Merged
Conversation
docker-agent
reviewed
Jun 1, 2026
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This PR correctly implements the transactional conversation-cache pattern. The changes were reviewed across all 8 modified files.
What was reviewed:
- Transactional clone logic in
pkg/chatserver/server.go(resolveSession/commitConversation): the clone→run→commit-on-success-only flow is correct and race-free. - Deep-copy completeness in
pkg/session/session.goandpkg/session/branch.go: all mutable slice/map/pointer fields (messages, tool definitions, eval criteria, eval results, configs) are properly deep-copied; cloned sessions do not share mutable state with the original. - Error handling for the "no usable new user message" rejection path: correctly returns 400 for empty/missing user messages rather than silently replaying the prior turn.
- Test coverage in
conversations_test.go,conversations_transaction_test.go,clone_test.go, ande2e/chatserver_test.go: tests are well-structured and assert the intended behavior. - The
return nilin the refactored non-streaming handler path is intentional and correct —chatCompletionalready writes the error response directly, so returning the error to Echo would cause a double-response. The tradeoff is acknowledged in the inline comment.
No confirmed bugs found in the changed code.
aheritier
approved these changes
Jun 1, 2026
Contributor
aheritier
left a comment
There was a problem hiding this comment.
LGTM. CI is green for head SHA 72b361c2a50e47925fa43a4124aefee83edd892c (build-and-test, build-image, license-check, lint, PR Review, and save-context all succeeded; build-and-push-image was skipped).
I reviewed the cache/transaction semantics and concurrency path in detail:
- Continuations now work on a clone of the cached session before appending the latest user message (
pkg/chatserver/server.go:423-430), so failed turns cannot mutate the canonical cached pointer. - The cache is advanced only on successful runs (
pkg/chatserver/server.go:449-453), while both streaming and non-streaming handlers pass the actual agent run error into that commit decision (pkg/chatserver/server.go:398-407). - Per-conversation locking still prevents two concurrent continuations for the same
X-Conversation-Idfrom racing (pkg/chatserver/server.go:373-377,pkg/chatserver/conversation_lock.go:25-39). - The clone path deep-copies mutable session/message state rather than sharing slices/maps/pointers (
pkg/session/session.go:339-404), with regression coverage for config, eval fields, tool definitions, sub-sessions, and item metadata. - Test coverage includes focused transaction tests (
pkg/chatserver/conversations_transaction_test.go) and an e2e regression proving a failed continuation is not replayed on the next successful turn (e2e/chatserver_test.go:88-104).
No blocking findings.
aheritier
added a commit
that referenced
this pull request
Jun 3, 2026
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
Fixes #2890.
X-Conversation-Idcontinuations transactional: work on a cloned cached session and commit it back only when the run succeeds.Session.Clone()as a faithful deep-copy primitive and harden clone helpers so cloned sessions do not share mutable message/config/eval/tool-definition state.Validation
task linttask testtask build