rewriteRuntimeEventReferences rewrites refs.operationId but not refs.parentOperationId:
// conversation-copy.ts:1014
const { operationId: _operationId, traceEventId: _traceEventId, ...preserved } = event.refs;
parentOperationId falls into ...preserved and is carried over unchanged.
It is always wrong after a copy, not sometimes: toolOperationIdMap (:852) rebuilds every operation id as buildToolOperationId({ invocationId: <target>, providerToolCallId }), and the target invocation id is freshly minted. The write site puts the same namespace in — ai-sdk-backend.ts:3101 sets parentOperationId: context.operationId.
Effect. Copy a session that used Code Mode, and nested tool calls point at the source session's operation while the parent has been renamed in the target. runtime-event-read-model.ts:922-937 projects the field into StoredMessage, so parent/child pairing breaks. tool-ledger-scanner.ts:516 only shape-checks, so nothing errors — silent, like #3775.
Fix. Route it through rewriteOwnedId(..., references.operationIds, 'tool operation') in the same destructure.
Found while sweeping for a second instance of the gap #3776 fixed: isCopiedAgentRunEvent only tests whether the build emits a type, not whether a rewriter exists for it. No second case at the AgentRun payload level; this one is on the RuntimeEvent side of the same file.
Also spotted, not worth its own issue: contextBudget.compactionDecisions[].boundaryIds keeps source checkpoint ids in model_stream_started / send_diagnostics_recorded payloads and in copied token_usage messages. No production consumer reads them back, so the ids just dangle.
rewriteRuntimeEventReferencesrewritesrefs.operationIdbut notrefs.parentOperationId:parentOperationIdfalls into...preservedand is carried over unchanged.It is always wrong after a copy, not sometimes:
toolOperationIdMap(:852) rebuilds every operation id asbuildToolOperationId({ invocationId: <target>, providerToolCallId }), and the target invocation id is freshly minted. The write site puts the same namespace in —ai-sdk-backend.ts:3101setsparentOperationId: context.operationId.Effect. Copy a session that used Code Mode, and nested tool calls point at the source session's operation while the parent has been renamed in the target.
runtime-event-read-model.ts:922-937projects the field intoStoredMessage, so parent/child pairing breaks.tool-ledger-scanner.ts:516only shape-checks, so nothing errors — silent, like #3775.Fix. Route it through
rewriteOwnedId(..., references.operationIds, 'tool operation')in the same destructure.Found while sweeping for a second instance of the gap #3776 fixed:
isCopiedAgentRunEventonly tests whether the build emits a type, not whether a rewriter exists for it. No second case at the AgentRun payload level; this one is on the RuntimeEvent side of the same file.Also spotted, not worth its own issue:
contextBudget.compactionDecisions[].boundaryIdskeeps source checkpoint ids inmodel_stream_started/send_diagnostics_recordedpayloads and in copiedtoken_usagemessages. No production consumer reads them back, so the ids just dangle.