Skip to content

Preserve compaction metadata when a delta omits it - #1985

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/retain-omitted-compaction-metadata-20261005-q
Open

sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/retain-omitted-compaction-metadata-20261005-q

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #1984.

Update encrypted_content only when the compaction delta actually supplied the field. The existing model_fields_set compatibility property distinguishes omission from an explicit null on both Pydantic versions. Empty strings and nonempty replacements retain their current behavior.

The change affects the final accumulated block and emitted BetaCompactionEvent snapshots in synchronous and asynchronous beta streams. It leaves summary text assignment unchanged and is independent of the text-accumulation proposals in #1830 and #1665. The Go companion preserving compaction field presence and replay is anthropics/anthropic-sdk-go#467.

Validation

Eight regression cases cover sync/async omission, replacement, empty string and null. They check both event snapshots and serialized final messages. On unchanged main, the two omission cases fail and six controls pass.

The repository test script passes the related message-streaming suites on Python 3.14.7 and 3.10.16: 75 tests with Pydantic v2 on each, and 73 passed / 2 skipped with Pydantic v1 on Python 3.10. Its additional MCP v2 checks pass 39 tests on each interpreter.

Repository formatting and complete ./scripts/lint pass. Lint used the frozen all-extras environment so optional integration imports were available. No test assertions, dependency versions or workflow settings were weakened.

./scripts/test tests/lib/streaming/test_messages.py tests/lib/streaming/test_beta_messages.py -n 2
./scripts/lint

Tested on macOS arm64 without live service calls. The complete generated API suite was not run.

Release note

Keep previously received compaction metadata when a later streaming delta omits encrypted_content, while honoring explicit null and empty updates.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner October 5, 2026 21:39
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

The regression and related tests pass locally; the PR description includes the validation commands. Could a maintainer approve the pending CI workflow?

@sigley sigley 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.

Validated exact head 0a17e05 independently. The accumulator now updates encrypted_content only when the compaction delta actually supplied that field, preserving prior metadata on omission while still honoring explicit null and empty-string updates. The branch merges cleanly with current main; the stable and beta streaming suites pass 75/75, and compile/diff checks are clean. I do not see a blocking correctness issue.

@sylvesterkaczmarek

Copy link
Copy Markdown
Author

Thanks @sigley, appreciate the independent validation and approval.

This branch has not been deployed

No deployments
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.

A compaction delta without encrypted_content clears the accumulated metadata

2 participants