Skip to content

[Bug]: TUI displays assistant reply twice when triggered via Telegram channel #96967

Closed

Description

@daemonegpt

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Root cause:
In tui-D1r4yDv-.js (dist/), handleSessionsChangedEvent (line ~3073) triggers a full loadHistory() when receiving a sessions.changed event with reason: "new". This happens AFTER the assistant message has already been finalized via chatLog.finalizeAssistant(finalText, evt.runId) (line ~3046).
loadHistory() then walks the session record and calls chatLog.finalizeAssistant(text) (line ~3663, no runId passed) for every assistant message in history — including the one already displayed. Because no runId is tracked for history replay, the dedup mechanism in finalizedRuns set doesn't apply, and the message is appended as a new component.
Expected: TUI should not re-render the just-finalized message.
Suggested fix:

  1. After clearTrackedRunState(), also clear recent finalizedRuns entries only after history replay deduplicates against existing chatLog children; OR
  2. Track lastDisplayedFinalRunId and skip replay of that message in loadHistory; OR
  3. handleChatEvent for state === "final" should set a "recently displayed" flag that loadHistory checks before re-appending.
    Affects: openclaw-tui, version 2026.6.10
Config: channels.telegram.enabled: true + openclaw-tui running on the same gateway

Steps to reproduce

Repro:

  1. Open openclaw-tui
  2. Connect to gateway with Telegram plugin enabled
  3. Send a message via Telegram to the bot
  4. Observe: in TUI the assistant's reply is rendered twice (Telegram client itself shows it once)

Expected behavior

  1. Open openclaw-tui
  2. Connect to gateway with Telegram plugin enabled
  3. Send a message via Telegram to the bot
  4. Observe: in TUI the assistant's reply is only once

Actual behavior

Repro:

  1. Open openclaw-tui
  2. Connect to gateway with Telegram plugin enabled
  3. Send a message via Telegram to the bot
  4. Observe: in TUI the assistant's reply is rendered twice (Telegram client itself shows it once)

OpenClaw version

2026.6.10

Operating system

macOS 26.5.1

Install method

npm

Model

minimax-m3

Provider / routing chain

openclaw -> ollama -> minimax-m3:cloud

Additional provider/model setup details

Image

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

Activity

  1. clawsweeper commented on Jun 26, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 26, 2026, 3:04 AM ET / 07:04 UTC.

    Summary
    Keep open: current main and v2026.6.10 still have the TUI sessions.changed new/reset handler unconditionally clearing tracked run state and loading history, while history replay re-adds assistant rows without run IDs. The earlier merged final-event guard at #88004 covers ordinary chat.final reloads, not this session-change path, and no open related PR is a proven canonical fix for this report.

    Reproducibility: yes. at source level, but not as a live Telegram reproduction in this review. Current main and v2026.6.10 directly reload history on matching sessions.changed new/reset events, and history replay rebuilds assistant messages without run IDs; the exact duplicate timing still needs live proof.

    Next step
    This is a narrow TUI bug candidate with clear likely files, but automation should preserve the external reset fix and add proof for the reported Telegram ordering.

    Review details

    Best possible solution:

    Add a narrow TUI guard or reconcile path for post-final sessions.changed history reloads so a just-rendered assistant final is not duplicated or replaced, while preserving legitimate external /new and /reset clearing behavior.

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

    Yes at source level, but not as a live Telegram reproduction in this review. Current main and v2026.6.10 directly reload history on matching sessions.changed new/reset events, and history replay rebuilds assistant messages without run IDs; the exact duplicate timing still needs live proof.

    Is this the best way to solve the issue?

    Unclear for the exact patch shape. The report points at the right failure class, but the best fix should not simply disable all new/reset reloads because those reloads are the shipped fix for external session resets.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    Codex review notes: model internal, reasoning high; reviewed against 81e53202f25f.

    Label changes

    Label changes:

    • add P2: This is a normal-priority TUI plus Telegram display bug with limited blast radius and no crash or data loss shown.
    • add impact:message-loss: The reported failure duplicates a user-visible assistant reply in the TUI after a Telegram-originated turn.
    • add impact:session-state: The suspected cause is live run state diverging from a history replay triggered by session-change state.
    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority TUI plus Telegram display bug with limited blast radius and no crash or data loss shown.
    • impact:message-loss: The reported failure duplicates a user-visible assistant reply in the TUI after a Telegram-originated turn.
    • impact:session-state: The suspected cause is live run state diverging from a history replay triggered by session-change state.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs src/tui/tui-event-handlers.test.ts src/tui/tui-session-actions.test.ts
    • node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui-pty-harness.e2e.test.ts
    • git diff --check
    • Add redacted live or harness proof that a Telegram-originated final followed by the relevant session-change event leaves one visible assistant reply in an open TUI.

    What I checked:

    • Live issue context: The reporter describes OpenClaw v2026.6.10 with Telegram enabled and TUI connected to the same gateway, with a sessions.changed reason: "new" reload after chatLog.finalizeAssistant(finalText, evt.runId).
    • Current session-change handler reloads history: Current main handles matching sessions.changed events only for reason new or reset, then calls clearTrackedRunState() and loadHistory() unconditionally for the current session. (src/tui/tui-event-handlers.ts:734, 81e53202f25f)
    • History replay rebuilds assistant rows without run IDs: loadHistory() clears the chat log and replays assistant messages by calling chatLog.finalizeAssistant(text) without a run ID, so replayed history cannot participate in the live run-ID dedupe path. (src/tui/tui-session-actions.ts:421, 81e53202f25f)
    • Existing final-event guard is narrower: The current maybeRefreshHistoryForRun guard skips reloads when a final event itself has displayable output, but handleSessionsChangedEvent bypasses that helper and reloads directly. (src/tui/tui-event-handlers.ts:466, 81e53202f25f)
    • Latest shipped release has the same session-change path: The v2026.6.10 tag contains the same handleSessionsChangedEvent direct loadHistory() call for new/reset, matching the affected version in the report. (src/tui/tui-event-handlers.ts:734, aa69b12d0086)
    • Regression provenance for the current handler: Merged PR fix(tui): refresh after external session reset #93562 added the current TUI sessions.changed subscription and handler to fix external reset refresh, so this report is a likely follow-up on that session-change path rather than the older final-event reload path. (src/tui/tui-event-handlers.ts:734, 9b49387ad8c2)

    Likely related people:

    • vincentkoc: Authored and merged the current sessions.changed TUI refresh path in fix(tui): refresh after external session reset #93562, the central path this issue reports against. (role: recent TUI session-change contributor; confidence: high; commits: 9b49387ad8c2; files: src/tui/tui-event-handlers.ts, src/tui/tui.ts, src/tui/gateway-chat.ts)
    • SebTardif: Authored the merged displayable-final reload guard in fix(tui): skip history reload when final event has displayable output #88004, which is the closest existing fix but does not cover this session-change reload branch. (role: adjacent final-reload fix author; confidence: medium; commits: 9a1b95c1e63a; files: src/tui/tui-event-handlers.ts, src/tui/tui-event-handlers.test.ts)
    • RomneyDa: Recent current-main history shows work stabilizing optimistic user messages across history reloads and runId reassignment, adjacent to the replay/reconcile behavior a fix must preserve. (role: recent TUI history/reload contributor; confidence: medium; commits: ac9a219692aa; files: src/tui/tui-event-handlers.ts, src/tui/tui-session-actions.ts, src/tui/components/chat-log.ts)
    • wsyjh8: Opened the earlier external reset refresh PR fix(tui): refresh on external session reset and clear stale run state #40472 and discussed the TUI reset-refresh direction later carried forward by PR fix(tui): refresh after external session reset #93562. (role: original external-reset implementation contributor; confidence: medium; commits: b92965ced224; files: src/tui/tui-event-handlers.ts, src/tui/tui.ts, src/tui/tui-types.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.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    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.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    on Jun 26, 2026
  3. locked as resolved and limited conversation to collaborators on Aug 5, 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

    P2Normal backlog priority with limited blast radius.bugSomething isn't workingbug:behaviorIncorrect behavior without a crashclawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.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