Skip to content

fix(providers/anthropic): preserve Anthropic replay fidelity#35

Merged
ethanndickson merged 3 commits into
coder_2_33from
codagt-409-anthropic-replay-fidelity
May 14, 2026
Merged

fix(providers/anthropic): preserve Anthropic replay fidelity#35
ethanndickson merged 3 commits into
coder_2_33from
codagt-409-anthropic-replay-fidelity

Conversation

@ethanndickson
Copy link
Copy Markdown
Member

@ethanndickson ethanndickson commented May 14, 2026

Summary

Anthropic replay is sensitive to exact assistant content block ordering and metadata. When a prior assistant turn contains signed thinking or redacted_thinking, replay has to preserve those reasoning blocks and any interleaved provider-executed web search blocks without changing their structure. Our Anthropic adapter had two gaps in that contract: it never emitted a ReasoningEnd event for redacted_thinking, and it only surfaced thinking signatures on signature_delta instead of also attaching the canonical signature to the final ReasoningEnd event. On the encode path, lossy provider-executed web_search_tool_result metadata could degrade into malformed assistant history.

Why this fixes it

  • emit ReasoningEnd for redacted_thinking, carrying RedactedData on the final event
  • attach the final Anthropic signature to ReasoningEnd for normal thinking blocks
  • lock interleaved reasoning and provider web search ordering with focused regression coverage
  • make missing, wrong-type, and empty replay metadata paths explicit with targeted warnings
  • when a provider-executed web_search_tool_result cannot be reconstructed, drop the matching server_tool_use too so we do not emit orphan provider blocks

Why this belongs in fantasy

Treating signed reasoning replay as a first-class provider contract leads to a cleaner split of responsibilities. coder/fantasy is the boundary that translates Anthropic SSE and message parts into fantasy stream parts and Anthropic wire blocks, so provider-specific lifecycle rules and replay invariants should be enforced there. That keeps downstream applications from reimplementing Anthropic quirks like missing redacted end events, signatures that only appear on deltas, or partially reconstructed provider tool blocks. The result is a provider adapter that behaves as though replay fidelity had been a foundational assumption from the start, while applications can keep their own persistence and sanitization logic focused on their own boundaries.

Relates to CODAGT-409

@ethanndickson
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81c8a9f59a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread providers/anthropic/anthropic.go Outdated
@ethanndickson
Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson
Copy link
Copy Markdown
Member Author

Upstreaming @ charmbracelet#237 & charmbracelet#238

@ethanndickson ethanndickson requested a review from ibetitsmike May 14, 2026 07:57
@ethanndickson ethanndickson merged commit cfca5fd into coder_2_33 May 14, 2026
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