Skip to content

Transcript mirror can append inbound chat turn after visible assistant delivery, inverting message order and parentId #83681

Description

@realaboo

Problem

For chat-backed sessions, the transcript mirror can write the visible assistant delivery before it appends the inbound user turn that triggered the rollout. This inverts the apparent conversation order in the main session transcript.

Observed effect:

  1. User sends a chat message.
  2. The agent handles it and sends a visible reply via the messaging tool.
  3. The visible assistant delivery mirror is appended to the session transcript immediately.
  4. The original inbound user message is flushed into the transcript later.
  5. The later user message is appended after the assistant reply, and its parentId can point to the assistant message instead of the previous real turn.

This makes the transcript look like the assistant answered before the user asked, and can corrupt follow-up context selection.

Observed case

In one iMessage-backed OpenClaw session, a user turn started at approximately 2026-05-18T07:52Z, but the mirrored user message appeared in the main session transcript at 2026-05-18T07:55:24Z, after the visible assistant delivery mirror had already been appended.

The resulting transcript ordering was effectively:

  1. assistant visible delivery mirror
  2. user inbound message mirror

instead of:

  1. user inbound message mirror
  2. assistant visible delivery mirror

The later user mirror also appeared to attach to the assistant reply as parent, which inverted causality.

Expected behavior

The transcript mirror should preserve source turn order, not write-time order.

For a chat-sourced rollout:

  • The inbound user message should be inserted/anchored before any assistant messages produced by that rollout.
  • Visible delivery mirrors should not become the parent of the triggering user message.
  • If the user message mirror is delayed, it should still be inserted with the correct causal parent/order metadata, or the assistant delivery mirror should wait until the source turn is anchored.

Why it matters

This causes context confusion in later turns. The agent may resolve "above / previous bug / this issue" against the wrong visible item because the transcript says the order was different from the actual chat order.

It also makes debugging very hard because the local transcript no longer represents the real conversation chronology.

Possible cause

The delivery mirror for message sends appears to append immediately, while the app-server/user-turn transcript mirror may flush the rollout later and append to the tail using current write time / last parent rather than preserving the original source turn order.

Acceptance criteria

  • Inbound chat messages keep their original causal position even if mirrored late.
  • Assistant delivery mirrors from the same rollout appear after the triggering inbound user message.
  • parentId for a mirrored inbound user message never points to the assistant reply generated by that same inbound turn.
  • A regression test covers delayed inbound mirror + immediate visible delivery mirror ordering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions