Skip to content

Conversation copy leaves model_call_attempt_recorded payload at the source identity, breaking Daily Review #3775

Closed

Description

@liuxiaocs7

What happened

Copying a conversation (branch, side conversation, or revise/edit-and-resend) leaves the nested identity of any model_call_attempt_recorded AgentRun event at the source session/run, which silently drops the copied session's spend and breaks Daily Review.

cloneAgentRunEvent in packages/runtime/src/conversation-copy.ts has typed rewriters for provider_request_captured, provider_request_attempt_recorded, and history_compact_checkpoint_recorded, but no branch for model_call_attempt_recorded. That event falls through to the tail return, which rewrites only the envelope (id / sessionId / runId) and leaves data untouched. The nested ModelCallAttempt payload therefore keeps the source sessionId / runId / attemptId (the payload identity that, per packages/core/src/model-call-attempt.ts, must agree with the envelope).

Consequences:

  • The model-call projection guard at packages/storage/src/model-call-ledger.ts:293 (attempt.sessionId !== run.session_id || attempt.runId !== run.run_id) throws, and the record is counted as unreadable (usage_model_call_projection_checkpoints.unreadable_events).
  • Daily Review reads canonical usage through readCompleteCanonicalUsage (packages/runtime-host/src/server/canonical-usage-reader.ts), which throws CanonicalUsageProjectionIncompleteError when unreadableRecords > 0. Generation then fails with projection_incomplete — "Daily Review is waiting for canonical Usage repair". Because Daily Review queries the global (no-sessionId) range, a single broken copied session poisons the whole day's review.
  • attemptId is the ledger's global primary key. Rewriting only sessionId/runId (making the guard pass) without also rewriting attemptId would let the copy overwrite the source session's accounting row — so attemptId must be rewritten too.

Note: the Session Inspector ("Trace") does not surface this. Its unreadable counter (packages/runtime-host/src/server/execution-inspect-coordinator.ts) only counts events whose decodeModelCallAttempt throws; the copied payload is a valid ModelCallAttempt with the wrong identity, so decode succeeds and the inspector shows no problem.

How to reproduce

  1. In a session with a configured LLM connection, send a message and get a reply (this writes a model_call_attempt_recorded event; an empty session will not reproduce).
  2. Copy that turn — Branch (turn footer), Side chat (/side, workbar tool, or ⌘K "Open side chat"), or Edit & resend (pencil on a sent user message).
  3. Open Daily Review (Module Hub → Automations → Daily Review, or ⌘K "Open · Daily Review") and generate it.
    • Generation fails with projection_incomplete / "Daily Review is waiting for canonical Usage repair".
  4. Or verify directly in SQLite after the copy + one usage read:
    SELECT session_id, run_id, unreadable_events
    FROM usage_model_call_projection_checkpoints
    WHERE unreadable_events > 0;
    The copied session's run shows unreadable_events > 0.

Environment

  • Maka commit: main @ 902d785 (also present on current main)
  • OS: macOS 15.7.3 (Darwin 24.6.0)
  • Surface: Desktop / Runtime Host (the desktop copy path runs through packages/runtime-host/src/server/session-revision-coordinator.ts:503 → cloneConversationRuntimeLedger)
  • Running from source (Node via repo toolchain)
Image

Logs, screenshots, or additional context

Reproducible and persistent: once a run's projection checkpoint advances past the unreadable record, the bad unreadable_events does not self-heal, so Daily Review keeps failing until the projection is repaired.

A fix (add a model_call_attempt_recorded rewriter that maps the payload sessionId/runId to the target, attemptId to the fresh envelope id, and the owned traceId/logicalCallId/captureArtifactId through the copy's identity maps) plus a regression test is ready and will be linked as a PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions