Fix Anthropic replay normalization for adjacent text blocks - #2343
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
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
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.
Summary
\n\n\nuser-message separatorRoot 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