Skip to content

Fix Anthropic replay normalization for adjacent text blocks - #2343

Merged
stephentoub merged 1 commit into
mainfrom
stephentoub-fix-anthropic-replay-normalization
Aug 15, 2026
Merged

Fix Anthropic replay normalization for adjacent text blocks#2343
stephentoub merged 1 commit into
mainfrom
stephentoub-fix-anthropic-replay-normalization

Conversation

@stephentoub

Copy link
Copy Markdown
Collaborator

Summary

  • canonicalize adjacent plain-text Anthropic user content blocks with the replay harness's existing \n\n\n user-message separator
  • share the canonical separator with request and snapshot coalescing so those normalization paths cannot drift
  • add adapter and protocol-aware replay regressions while retaining single-block, multimodal, and tool-result coverage

Root cause

github/copilot-agent-runtime#15832 intentionally preserves adjacent user messages as separate Anthropic content blocks for prompt-cache stability. The replay adapter flattened those block boundaries with \n, while captured canonical snapshots and adjacent-user-message coalescing use \n\n\n. Requests therefore failed to match snapshots during compaction and session-limit flows.

This change fixes normalization only at the replay adapter boundary; it does not alter the runtime's Anthropic serialization or broadly relax matching.

Tests

  • cd test/harness && npm test (61 passed)
  • COPILOT_SDK_E2E_BACKEND=anthropic-messages COPILOT_SDK_DEFAULT_CONNECTION=inprocess dotnet test test/GitHub.Copilot.SDK.Test.csproj -f net8.0 --no-restore -v normal --filter FullyQualifiedName=GitHub.Copilot.Test.E2E.CompactionE2ETests.Should_Trigger_Compaction_With_Low_Threshold_And_Emit_Events

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@stephentoub
stephentoub requested a review from a team as a code owner August 15, 2026 20:27
Copilot AI balanced review requested due to automatic review settings August 15, 2026 20:27

Copilot AI 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.

Pull request overview

Aligns Anthropic replay normalization with canonical snapshot coalescing.

Changes:

  • Shares the canonical user-message separator.
  • Normalizes adjacent Anthropic text blocks.
  • Adds adapter and protocol replay regressions.
Show a summary per file
File Description
test/harness/replayingCapiProxy.ts Reuses the shared separator.
test/harness/modelProtocolAdapterShared.ts Defines the canonical separator.
test/harness/modelProtocolAdapters.test.ts Adds normalization regressions.
test/harness/anthropicMessagesAdapter.ts Joins adjacent text blocks canonically.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread test/harness/anthropicMessagesAdapter.ts
@stephentoub
stephentoub merged commit 731317c into main Aug 15, 2026
57 checks passed
@stephentoub
stephentoub deleted the stephentoub-fix-anthropic-replay-normalization branch August 15, 2026 20:42
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