Skip to content

fix(runtime): conversation copy leaves parentOperationId at the source identity #3800

Description

@Astro-Han

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions