Repository navigation
Conversation
…nthropics#1419) When forking a session via fork_session() or fork_session_via_store(), message UUIDs are remapped across transcript entries. However, the embedded compactMetadata on compact_boundary records was previously copied verbatim, leaving preservedSegment and preservedMessages references pointing to source message UUIDs that do not exist in the forked transcript. Remap headUuid, tailUuid, anchorUuid in preservedSegment, as well as anchorUuid, uuids, and allUuids in preservedMessages using uuid_mapping. Unmapped or sliced-out IDs are preserved without error. Source session transcripts remain strictly unmodified. Closes anthropics#1419. Signed-off-by: Soumyajit Ghosh <[email protected]>
Remap runningTurnSends using the same map as the written transcript. Trim lists for records deliberately excluded by a cutoff or sidechain/ progress filtering, and drop blocks whose required endpoint was excluded. Preserve historical IDs absent from the source and uninterpreted metadata. Add public disk/store regressions and checks against actual output IDs. Update the existing partial-fork expectation and retain malformed metadata and source-immutability coverage. Thanks to @tonydzi for the runningTurnSends report and @xg-gh-25 for the partial-fork/integrity suggestions in anthropics#1419. Compared with @somuai's anthropics#1428 to keep the overlapping fixes on one reviewable path. Developed with Codex assistance.
|
Hi @somuai, thanks for working on #1419 and testing both fork paths. I compared our patches: they take the same approach to I've added that follow-up to #1420 in c9fd201. It remaps the three running-turn fields, trims references to deliberately excluded records, drops blocks with excluded endpoints, and preserves historical IDs already absent from the source. The new public disk/store tests also check emitted reference integrity without interpreting arbitrary UUID-shaped strings. On current main plus the update: 215 affected tests pass; full suite 1,701 passed, 6 skipped; Ruff/format/mypy pass. These are local unit results, not end-to-end resume validation; hosted checks await maintainer approval. Could we consolidate into one landing PR? I suggest #1420 because it retains the broader parameterized coverage, but I'm happy to move the follow-up and tests here if maintainers prefer this PR. I've credited your overlapping implementation and both issue contributors in #1420, and posted the technical details on #1419. Let's preserve attribution whichever PR lands. Developed with Codex assistance. |
|
Hi @salma2vec, thanks for the thorough follow-up and for benchmarking both implementations. Consolidating into a single PR makes total sense for the maintainers so they don't have to navigate two competing patches. Proceeding with #1420 works for me, provided co-authorship attribution is preserved in the squash commit message: I will keep #1428 open for reference until the maintainers review and land #1420, and will close it once merged. Thanks again for collaborating on this! |
Summary
When forking a session via
fork_session()orfork_session_via_store(), transcript entries receive fresh UUIDs to ensure branch independence and parent chain integrity. However,compactMetadataoncompact_boundaryrecords was previously copied verbatim via dictionary spread (**original).As reported in #1419, this left:
preservedSegmentreferences (headUuid,tailUuid,anchorUuid)preservedMessagesreferences (anchorUuid,uuids,allUuids)pointing to source message UUIDs that do not exist within the forked transcript, causing downstream compaction normalization and parent relinking to fail.
Changes
_remap_compact_metadata()insrc/claude_agent_sdk/_internal/session_mutations.pyto remappreservedSegment(headUuid,tailUuid,anchorUuid) andpreservedMessages(anchorUuid,uuids,allUuids) usinguuid_mapping.up_to_message_id) are retained safely without raising exceptions.test_fork_remaps_compact_metadata_referencesintests/test_session_mutations.pyverifying disk-backed forks remap all boundary references and preserve source immutability.test_fork_session_via_store_remaps_compact_metadataintests/test_session_helpers_store.pyverifyingSessionStoreasync forks remap all references.Verification
uv run --extra dev pytest tests/test_session_mutations.py tests/test_session_helpers_store.pypassed (145/145 tests).uv run ruff check src/ tests/ scripts/passed with zero errors.uv run ruff format --check src/ tests/ scripts/passed.uv run mypy src/ scripts/passed in strict mode.Closes #1419.