Repository navigation
fix(llmprovider): extend authoritative history in legacy Ask - #145
Merged
Merged
Conversation
Every legacy adapter appended its reply to Fragment.Messages directly. On a fragment built with WithConversation this leaves the legacy projection one message longer than the authoritative history, and cogito then fails the next Conversation() call with ErrConversationProjectionMismatch. Route the reply through a small helper that uses AppendMessages when the fragment has authoritative history and keeps the plain append for legacy fragments, so they stay legacy. Add Ask tests for the Anthropic, Ollama, OpenAI Responses and Google adapters, tests for the helper, and the first unit tests for replaceMessages (prefix and suffix retention, legacy and stale fallbacks). Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
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.
What was wrong
Every legacy adapter (Anthropic, Azure Responses, Bedrock, Codex, Copilot, Gemini CLI, Google, Google Vertex, Ollama, OpenAI Responses, and the Codex app-server client) appended its reply with
fragment.Messages = append(fragment.Messages, ...).On a fragment built with
WithConversation, which nib produces throughreplaceMessages, this leavesMessagesone entry longer than the authoritative history. cogito then fails the nextConversation()call withErrConversationProjectionMismatch.How it was reproduced
A test that calls
Askon an authoritative fragment against a stub HTTP server and then callsConversation(). Before the change it failed for Anthropic, Ollama, OpenAI Responses and Google:Conversation() after Ask: fragment conversation projection mismatch at index -1: direct Messages edits cannot update provider history; use WithConversation to explicitly replace history or AppendMessages to extend a consistent fragmentWhat changed
internal/fragmentreply.Append: usesFragment.AppendMessageswhen the fragment has authoritative history, and keeps the plainMessagesappend for legacy fragments so they stay legacy.Askmethods use it.Tests
Asktests for Anthropic, Ollama, OpenAI Responses and Google (authoritative fragment stays consistent, legacy fragment stays legacy).chat.replaceMessages: prefix and suffix retention, legacy fallback, stale fallback, provider data dropped for removed messages.Asktest: Azure Responses, Bedrock, Codex, Copilot, Gemini CLI, Google Vertex and the Codex app-server client. Their wire formats need heavier stubs; they share the helper, which has its own tests.go vet ./...clean.go test ./llmprovider/... ./chat/... ./internal/... ./codexapp/... -count=1passes.🤖 Generated with Claude Code