Skip to content

fix: preserve Anthropic replay fidelity - #25377

Merged
ethanndickson merged 5 commits into
mainfrom
ethan/chatd-anthropic-replay-fidelity
May 18, 2026
Merged

ethanndickson merged 5 commits into
mainfrom
ethan/chatd-anthropic-replay-fidelity

Conversation

@ethanndickson

@ethanndickson ethanndickson commented May 15, 2026 •

Copy link
Copy Markdown
Member

Anthropic is strict about replaying the latest assistant turn once it contains signed or redacted reasoning. We were still mutating that turn in a few Coder-owned places: dropping empty reasoning blocks on replay, rewriting provider-tool history during sanitization, and in the worst case sending a prompt we already knew Anthropic would reject.

This patch keeps the latest signed assistant immutable through Coder's replay and sanitization paths, preserves empty signed or redacted reasoning anywhere Coder owns the ledger, and fails before the provider call if the prompt is still unsafe.

It also bumps the existing coder/fantasy coder_2_33 fork that main already uses to the commit containing coder/fantasy#35. These fixes have also been upstreamed to charmbracelet/fantasy.

Closes CODAGT-409.

@ethanndickson
ethanndickson marked this pull request as ready for review May 15, 2026 03:37
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown

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: c955d6f573

ℹ️ 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

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

/coder-agents-review

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

Copy link
Copy Markdown

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: a9a0e92384

ℹ️ 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".

coder-agents-review[bot]

This comment was marked as resolved.

@ethanndickson

Copy link
Copy Markdown
Member Author

Also addressed the non-thread DEREM-11 note in f4ef648: retry-time prompt preparation failures now preserve the phase label (prepare prompt: instead of stream response:), and TestRun_ChainBrokenRecoveryPrepareFailureReturnsPreparePhaseError covers that path.

@ethanndickson

Copy link
Copy Markdown
Member Author

/coder-agents-review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All 13 R1 findings addressed in f4ef648. Verified by 4 reviewers (Bisky, Mafuuu, Hisoka, Meruem) across the full delta.

Fix highlights: user-facing error now includes "Start a new chat to continue," the retryPrepareErr retry path has integration test coverage, the signed-reasoning predicate is centralized through hasAnthropicSignedReasoningMetadata, the immutability contract is documented at the top of anthropic.go, call.Prompt is only assigned on success, and the naming inversions are resolved.

Hisoka: "The code held up. Traced the SanitizeAnthropicProviderToolHistory loop with the immutable index exclusion. Each pass removes at least one non-immutable part. When only immutable violations remain, remove empties, loop terminates. No infinite loop."

1 nit (redundant assertion). Otherwise clean.

🤖 This review was automatically generated with Coder Agents.

…ned reasoning boundary

Make the Anthropic signed/redacted reasoning message an immutable transcript
boundary as a property of message content, enforced inside the
appendSanitizedMessage merge primitive itself.

Previously, three call sites preserved the immutable message by branching on
messageIndex == immutableIndex and routing through a separate
appendSanitizedMessagePreservingStructure helper. That left a hole: if
sanitization dropped an intervening message, a later assistant message could
still coalesce into the preserved signed assistant via the normal append path
and mutate the signed reasoning block sequence.

Move the invariant into appendSanitizedMessage: refuse to merge when either
the prior or incoming message carries signed reasoning. The three call-site
branches and the appendSanitizedMessagePreservingStructure helper are gone,
and the local immutableIndex bookkeeping in
stripAnthropicProviderToolHistoryFromMessages is no longer needed.

Add table-driven tests covering signed and redacted reasoning variants on
both the backward edge (prior assistant must not merge into signed) and the
forward edge after a dropped intervening assistant.
Centralize the signed-reasoning predicate in chatsanitize, restrict
immutability to the actual latest assistant turn, and make the guard
contract return nil prompts on error so unsafe re-prepared prompts cannot
leak into retry state.

Also add retry-path coverage for chain-broken recovery, improve the
user-facing recovery guidance, clarify the signed-turn merge boundary, and
simplify the follow-up helpers/tests now that the invariant lives in the
merge primitive.
@ethanndickson
ethanndickson force-pushed the ethan/chatd-anthropic-replay-fidelity branch from a5b6a03 to 24b06fa Compare May 18, 2026 04:44
@ethanndickson
ethanndickson merged commit e75bd3a into main May 18, 2026
26 checks passed
@ethanndickson
ethanndickson deleted the ethan/chatd-anthropic-replay-fidelity branch May 18, 2026 05:20
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants