Skip to content

fix(llmprovider): extend authoritative history in legacy Ask - #145

Merged
mudler merged 1 commit into
masterfrom
fix/legacy-append-messages
Oct 19, 2026
Merged

mudler merged 1 commit into
masterfrom
fix/legacy-append-messages

Conversation

@mudler-agent

Copy link
Copy Markdown
Collaborator

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 through replaceMessages, this leaves Messages one entry longer than the authoritative history. cogito then fails the next Conversation() call with ErrConversationProjectionMismatch.

How it was reproduced

A test that calls Ask on an authoritative fragment against a stub HTTP server and then calls Conversation(). 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 fragment

What changed

  • New internal/fragmentreply.Append: uses Fragment.AppendMessages when the fragment has authoritative history, and keeps the plain Messages append for legacy fragments so they stay legacy.
  • All 11 Ask methods use it.
  • No user-facing behavior change, so no README change.

Tests

  • Ask tests for Anthropic, Ollama, OpenAI Responses and Google (authoritative fragment stays consistent, legacy fragment stays legacy).
  • Unit tests for the helper.
  • First unit tests for chat.replaceMessages: prefix and suffix retention, legacy fallback, stale fallback, provider data dropped for removed messages.
  • Not covered by a per-adapter Ask test: 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=1 passes.

🤖 Generated with Claude Code

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>
@mudler
mudler merged commit 980de91 into master Oct 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants