Skip to content

[Bug]: Assistant turns render twice with CLI backends — live per-block view plus a concatenated aggregate record #123792

Open

Description

@spunzon

Version: 2026.8.1-beta.1 (ff8a3fe)
Runtime: claude-cli backend, anthropic/claude-opus-5
Surfaces affected: Control UI (webchat) and the Android app. Telegram is not affected.

Summary

With the claude-cli backend, every assistant turn is persisted twice through two independent writers, and clients that render the transcript show both. The user sees the full turn, then immediately a second copy of the same turn as one plain block.

The two copies are not byte-identical, so the Control UI's "consecutive duplicate text-only messages collapse into one bubble with a count badge" rule (documented in web/control-ui.md) never fires.

Expected vs actual

Expected: one assistant turn appears once.

Actual: the turn appears twice:

  1. Live/canonical view — each assistant text block as its own bubble, interleaved with tool-call cards, imported from the Claude Code transcript (importedFrom: "claude-cli", api: "anthropic-messages", stopReason: "end_turn").
  2. Aggregate record — a single message whose content holds one text block with every intermediate narration line and the final answer concatenated (api: "cli", stopReason: "stop", idempotencyKey: "cli-assistant:<runId>"), written ~650 ms later.

The more intermediate text a turn emits, the larger the visible duplicate.

Evidence

Session store: ~/.openclaw/agents/<agentId>/agent/openclaw-agent.sqlite, table transcript_events.

select seq, event_json, created_at
from transcript_events
where session_id like '<session>%'
order by seq;

A turn that emitted two narration lines plus a final answer produced this aggregate:

seq 44  api=cli  len=1835  text blocks in content: 1
"Son 18 (16 "New chat", una sin etiqueta y la del móvil). Voy con la del móvil primero…
 \n\nLa herramienta está limitada a mi propio árbol de sesiones. Voy por la CLI.
 \n\nHecho. Las 18 archivadas, verificado contra la base de datos. …"

That single record reproduces, verbatim and in order, the three separate bubbles the client had already rendered for the same turn.

Across the whole store: 84 duplicated turns out of 307 assistant messages carrying text. The pattern is constant — a cli record paired with a twin whose api differs (anthropic-messages, openclaw-transcript or openai-responses) and whose byte length is identical.

Where it comes from

persistCliAssistantTranscript() in dist/cli-runner-*.js writes the aggregate via appendExactAssistantMessageToSessionTranscript with idempotencyKey: cli-assistant:${runParams.runId}.

It is gated by runParams.persistAssistantTranscript, computed in dist/agent-runner.runtime-*.js as:

persistAssistantTranscript:
  turn.followupRun.currentInboundEventKind !== "room_event" &&
  turn.followupRun.run.suppressTranscriptOnlyAssistantPersistence !== true

and suppressTranscriptOnlyAssistantPersistence is only set for room events (get-reply-*.js: suppressTranscriptOnlyAssistantPersistence: isRoomEvent). So for ordinary DM turns the aggregate is always written, in addition to the per-block import from the CLI transcript. There is no user-facing setting to disable it.

Possibly related condition

openclaw doctor reports on the same install:

- Main session transcript missing (~/.openclaw/agents/<agentId>/sessions/<sessionId>.jsonl).

That directory holds 138 *.trajectory-path.json pointers and zero .jsonl transcripts. With no native transcript to reconcile against, the two writers never converge.

Why Telegram is unaffected

Channel delivery sends the final text once — the gateway log shows a single outbound send ok per message. Telegram renders what was delivered, not the transcript, so the aggregate is never shown there.

Related

PR #98117 (fix(ios): avoid transient duplicate final replies) addresses a neighbouring symptom in the shared chat view model, where a live chat.final row is adopted by the canonical session.message instead of being appended twice. This report is one layer lower: two rows are genuinely persisted, so adopting at render time would hide the duplicate rather than prevent it.

Activity

  1. added
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:session-state
    impact:ux-friction
    issue-rating: 🦞 diamond lobster
    no-stale
    P2
    on Aug 14, 2026
  2. clawsweeper commented on Aug 14, 2026

    @clawsweeper
    Contributor

    ClawSweeper status: review started.

    Codex review: this still needs some work.

    Summary
    Keep this issue open: text-only duplication is partly fixed, but image-reply duplication and historical attachment aggregates remain outside a complete repair.

    Reproducibility: Current source and the existing coverage matrix establish that an attachment-owning historical aggregate remains alongside imported segments covering its text; reported image-caption failures also match the unnormalized suffix comparison, but no live run was performed.

    Root-cause cluster
    Relationship: canonical
    Canonical: #123792
    Summary: This issue retains the broader aggregate-versus-native history problem, including historical attachment cases beyond the focused image-caption follow-up.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    Review #195959 and establish a failing historical attachment regression before considering this broader issue resolved.

    Review details

    Best possible solution:

    Show native narration and final replies once while preserving canonical attachments and original transcript bytes.

    Do we have a high-confidence way to reproduce the issue?

    Current source and the existing coverage matrix establish that an attachment-owning historical aggregate remains alongside imported segments covering its text; reported image-caption failures also match the unnormalized suffix comparison, but no live run was performed.

    Is this the best way to solve the issue?

    The existing producer and display owners are the right repair boundaries; evaluate the focused image-caption PR and establish a separate historical attachment regression before changing coverage, preserving uncertain imports and attachment visibility.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Historical attachment-owning aggregates still retain repeated text; removing their whole rows would hide canonical attachments.
    • The open image-caption repair does not establish historical attachment reconciliation, and no live reproduction was performed in this review.

    Codex review notes: model internal, reasoning medium; reviewed against 70f100d4ff01.

    Label changes

    Label changes:

    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.

    Label justifications:

    • P2: Repeated history text impairs conversation readability while generation and replies remain usable.
    • impact:session-state: The history projection retains overlapping native segments and canonical aggregate representations of assistant turns.
    • impact:ux-friction: Users see repeated narration or answers when reading web and mobile conversations.
    Evidence reviewed

    Acceptance criteria:

    • Establish a failing historical attachment regression before implementation.
    • pnpm exec vitest run src/gateway/cli-session-history.test.ts
    • pnpm exec vitest run src/gateway/server-methods/chat-transcript-persistence.mirrors.test.ts
    • Exercise built Gateway chat.history and reloaded Control UI with native segments plus historical canonical attachments; verify narration, final text, and each attachment appear once.
    • Run scoped lint, formatting, and type checks for the final changed paths.

    What I checked:

    Likely related people:

    • Teddy Tennant: Raw commit cd3e054 adds src/gateway/cli-session-history.merge-aggregates.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd3e054c9a46; files: src/gateway/cli-session-history.merge-aggregates.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 19, 2026, 2:26 PM ET / 19:26 UTC.

  3. clawsweeper commented on Aug 14, 2026

    @clawsweeper
    Contributor

    🦞🔧
    ClawSweeper is automatically building this issue.

    The issue review finished and no active implementation pull request was found.

    Automatic implementation progress:

  4. added
    clawsweeper:linked-pr-open
    clawsweeper:no-new-fix-pr
    and removed
    no-stale
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    on Aug 14, 2026
  5. 63 remaining items

  6. samiralibabic commented on Nov 10, 2026

    @samiralibabic
    Contributor

    Release status of the three fixes, checked today against the tags and the release branch with GitHub's compare API:

    Fix v2026.11.2 v2026.11.3 v2026.11.5-beta.1 release/2026.11.5 (1d58dfd)
    #184098 (new text-only turns) no no yes yes
    #188333 (replies with a MEDIA: attachment) no no no no
    #137788 (history recorded before the fix) no no no no

    This may matter more for 2026.11.5 than for earlier releases. On release/2026.11.5, isCollapsibleWorkGroup no longer folds assistant groups with visible text (via #183267). On 2026.10.7 the imported per-segment copies of a turn mostly sit inside the collapsed "Worked" group, so the second copy only shows when it is expanded. Without #137788 and #188333, I would expect older Claude CLI turns, and turns whose reply ends with a MEDIA: attachment, to show both copies in full on 2026.11.5. I haven't run the candidate; this is from reading the branch.

    Could #137788 and #188333 be considered for 2026.11.5?

  7. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Nov 10, 2026
  8. openclaw-barnacle commented on Nov 18, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale after 7 days without qualifying human activity.
    Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
    A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

  9. added
    stale
    on Nov 18, 2026
  10. laurencebrown commented on Nov 18, 2026

    @laurencebrown

    Both fix PRs are merged (#184098 on Oct 27, #137788 on Oct 31) but neither is in any release yet, v2026.11.4 included — verified via the compare API against the release tags. Keeping this open until a release actually contains the fix seems right; closing as stale would be misleading while users on every current release still see the bug.

  11. removed
    stale
    on Nov 18, 2026
  12. added
    clawsweeper:needs-maintainer-review
    clawsweeper:no-new-fix-pr
    on Nov 19, 2026
  13. openclaw-barnacle commented on Nov 25, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale after 7 days without qualifying human activity.
    Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
    A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

  14. added
    stale
    on Nov 25, 2026
  15. samiralibabic commented on Nov 25, 2026

    @samiralibabic
    Contributor

    ping

  16. removed
    stale
    on Nov 26, 2026
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

    P2clawsweeper:needs-maintainer-reviewclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:session-stateimpact:ux-frictionissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions