Skip to content

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

Closed

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.

Activity

  1. added
    bug
    help wanted
    on Aug 25, 2026
  2. chinawch007 commented on Aug 25, 2026

    @chinawch007
    Contributor

    Hi, I'd like to take this one.

    I've verified the gap locally: the destructure at conversation-copy.ts:1014 keeps parentOperationId in ...preserved, so it survives the copy unchanged while every operation id is rebuilt by toolOperationIdMap with the fresh target invocation id. The fix is to route it through rewriteOwnedId(..., references.operationIds, 'tool operation') alongside operationId, mirroring the existing strictness.

    I'll also add a regression test in conversation-copy.test.ts covering a Code Mode-style nested call (parent dispatch + child event carrying refs.parentOperationId), asserting the copied child points at the parent's new operation id.

  3. added a commit that references this issue on Aug 25, 2026
    de71830
  4. liuxiaocs7 commented on Aug 25, 2026

    @liuxiaocs7
    Member

    Hi, @Astro-Han, take assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions