fix(runtime): rewrite parentOperationId when copying conversations - #3806
Merged
Astro-Han merged 1 commit intoAug 25, 2026
Conversation
rewriteRuntimeEventReferences rewrote refs.operationId but let refs.parentOperationId fall into ...preserved, carrying the source session's operation identity into the target. toolOperationIdMap rebuilds every operation id under a freshly minted target invocation, so a copied nested Code Mode call always pointed at the source operation while its parent was renamed — breaking parent/child pairing in the projected StoredMessage. Route parentOperationId through the same rewriteOwnedId(..., references.operationIds) as operationId. Closes apache#3800 Generated-by: Claude
Astro-Han
reviewed
Aug 25, 2026
Astro-Han
left a comment
Contributor
There was a problem hiding this comment.
Update on de71830f59:
CODE GO — no P0-P3. Rewrites parentOperationId via runtime-owned operationIds map while preserving parentToolCallId; cross-run operation reuse is rejected, missing mapping fail-closes. Hosted test: SUCCESS (32859305478).
简体中文
该头无阻断。
This was referenced Aug 25, 2026
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
rewriteRuntimeEventReferencesinconversation-copy.tsrewroterefs.operationIdbut letrefs.parentOperationIdfall into...preserved, so it was carried into the copied session unchanged:This is always wrong after a copy, not sometimes.
toolOperationIdMaprebuilds every operation id asbuildToolOperationId({ invocationId: <target>, providerToolCallId })under a freshly minted target invocation, and the write site (ai-sdk-backend.ts) setsparentOperationId: context.operationId— the same namespace. So a copied nested Code Mode call keeps pointing at the source session's operation while its parent has been renamed in the target.runtime-event-read-model.tsprojects the field intoStoredMessage, so parent/child pairing breaks, andtool-ledger-scanner.tsonly shape-checks — the corruption is silent (like #3775).The fix routes
parentOperationIdthrough the samerewriteOwnedId(..., references.operationIds, 'tool operation')asoperationId, in the same destructure. The provider-ownedparentToolCallIdis deliberately left in...preserved(it is not runtime-owned).Fixes #3800
Verification
conversation copy rewrites the parent operation id of a nested Code Mode call, which copies a Code Mode session and asserts the nested call'sparentOperationIdis rewritten to the target operation id whileparentToolCallIdis preserved.packages/runtimetypecheck (tsc) passes.biome checkon both changed files passes.conversation-copy.test.jssuite passes (20/20).AI use
Select exactly one:
Tool(s) and scope: Claude Code — diagnosed the gap, implemented the one-line-scope fix in
rewriteRuntimeEventReferences, and wrote the regression test. Human-reviewed.Checklist
Does this PR entail a change in behavior?