Skip to content

fix: remap compaction references when forking sessions - #1420

Open
salma2vec wants to merge 4 commits into
anthropics:mainfrom
salma2vec:codex/remap-fork-compaction-references
Open

salma2vec wants to merge 4 commits into
anthropics:mainfrom
salma2vec:codex/remap-fork-compaction-references

Conversation

@salma2vec

@salma2vec salma2vec commented Oct 20, 2026 •

Copy link
Copy Markdown

Fixes #1419.

Forking gives transcript records new UUIDs while compaction metadata still points to the source IDs. This changes the shared disk/store fork builder so copied messages and their known compaction references use the same mapping.

  • Remap preservedSegment.headUuid/tailUuid/anchorUuid, preservedMessages.anchorUuid/uuids/allUuids, and runningTurnSends.openerUuid/uuids/summarisedOnly.
  • Generate IDs only for records actually written. Progress records remain available for parent traversal.
  • For partial forks and sidechain/progress exclusions, trim known excluded IDs from lists. Drop a metadata block when its anchor/opener or segment endpoint was excluded; do not pull excluded messages into the fork or guess replacement endpoints.
  • A fork whose cutoff is a compact boundary ends just before that boundary. The boundary's preserved blocks are anchored after it, and @tonydzi measured that resuming a fork that kept the boundary without them lost the earlier compaction summaries (CLI 2.1.317 against a stub).
  • Preserve IDs already absent from the source, malformed values, and uninterpreted fields in retained blocks. Historical running-turn bookkeeping can outlive transcript records, so a blanket UUID-shaped-string validator would reject legitimate input.
  • Copy changed metadata containers; source entries and arbitrary message content remain unchanged.

Retains the original parameterized disk/store, segment/list/both, partial-fork, malformed-metadata, and source-preservation coverage. Adds 56 cases across both public APIs and both AnyIO backends, with schema-aware assertions against the IDs actually emitted. These assertions are test safeguards, not runtime rejection or automatic discovery of future metadata fields.

Validation on main 2d485201617258867dd0f74b9e7307056f5938fe plus this branch (Python 3.12, MCP 2.3.0):

Update for the boundary cutoff (e70a802, Python 3.12):

  • Full tests/ suite: 1,713 passed, 6 skipped. The three new boundary-cut tests (both APIs, both AnyIO backends) fail on the previous head and pass now. The existing store partial-fork test now expects the fork to stop before the boundary.
  • Ruff check, formatting and mypy pass on the changed files.

The new evidence is synthetic public-API testing and local CLI code inspection. No end-to-end CLI/model resume was run; existing malformed or incomplete source metadata is not repaired.

Thanks to @tonydzi for the release reproduction and running-turn field report, @xg-gh-25 for the partial-fork/integrity suggestions, and @somuai for the overlapping implementation in #1428. This retains #1420's boundary-scoped helper and broader regression coverage; the follow-up can move to whichever PR maintainers select so only one implementation lands.

Developed with Codex assistance.

Co-authored-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.
A fork cut at a compact boundary could not keep that boundary's preserved
blocks, because their anchor follows it, and resuming such a fork lost the
earlier conversation (anthropics#1419). End the fork just before the boundary instead.
@somuai

somuai commented Nov 8, 2026

Copy link
Copy Markdown

Hi @salma2vec, following up on our coordination in #1428. Could you add the Git co-authorship trailer to the bottom of the PR description?

Co-authored-by: Soumyajit Ghosh <[email protected]>

Adding it directly to the PR body ensures GitHub automatically populates the co-author attribution trailer in the squash-and-merge commit message when maintainers land the PR. Thank you!

@salma2vec

Copy link
Copy Markdown
Author

Done, @somuai: the co-author line is now at the end of the PR description. Thanks for the coordination on #1428.

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.

Forking a compacted session leaves preserved-message references pointing to source UUIDs

2 participants