Skip to content

TUI: Telegram messages update session state but do not appear live until session/history reload #41937

Closed
BingqingLyu/openclaw
#346

Description

@sachser66

Summary

In openclaw tui, inbound Telegram messages are written to the correct session, but they often do not appear live in the TUI chat log until a manual reload (/session ..., session switch, or reconnect/history fetch).

This appears to be a TUI live-event subscription/render issue (not routing/session-key mismatch).

Environment

  • OpenClaw: 2026.3.8
  • OS: Linux (Debian), gateway local systemd service
  • Channel: Telegram (3 accounts configured: default/coder/research)
  • Affected agents: main, agentx-coder, agentx-research
  • Session scope: dmScope: per-channel-peer

What works

  • Telegram inbound messages reach the backend and update the expected session keys:
    • agent:main:telegram:direct:<peer>
    • agent:agentx-coder:telegram:direct:<peer>
    • agent:agentx-research:telegram:direct:<peer>
  • TUI -> backend -> Telegram delivery works when /deliver on is enabled.

What fails

  • Telegram -> TUI live display is intermittent/often missing.
  • After manual reload (e.g. /session agent:main:telegram:direct:<peer> or session switch), missing messages appear.

Repro (main agent, similar on coder/research)

  1. Start gateway and TUI:
    • openclaw gateway start
    • openclaw tui --session agent:main:telegram:direct:<peer> --deliver
  2. Keep TUI open on that session.
  3. Send a message from Telegram DM to the bot.
  4. Observe: message is processed (assistant can reply / session timestamp updates), but message is not shown live in TUI.
  5. Run /session agent:main:telegram:direct:<peer> (or switch away/back).
  6. Observe: previously missing message now appears.

Diagnostics / observations

  • Session metadata updates immediately for affected telegram direct sessions.
  • Behavior reproduced across all three agents, suggesting issue is in TUI event subscription/streaming layer rather than agent/channel routing.
  • Gateway restart did not resolve the symptom.

Expected

TUI should render inbound Telegram messages live for the currently selected session without manual history/session reload.

Additional note

There was also an occasional Telegram delivery-recovery warning after restart:
400: Bad Request: message to be replied not found
This may be separate, but mentioning for context.

Activity

  1. sachser66 commented on Mar 23, 2026

    @sachser66
    Author

    Still reproducible on OpenClaw 2026.3.22.

    Tested again after updating to 2026.3.22, and the Telegram ↔ TUI live sync issue is still present.

    Observed behavior:

    • Inbound Telegram messages do not appear live in the TUI until a manual session/history reload.
    • The reverse direction also does not stay live-synced consistently across surfaces.

    Workaround still required:

    • /session agent:main:telegram:direct:<peer>
    • or switch away and back to the same session in TUI

    So from my side this issue is not fixed in 2026.3.22.

  2. steipete commented on Apr 24, 2026

    @steipete
    Contributor

    Closing this as implemented after Codex review.

    Current main already contains the TUI-side fix for external/non-local chat updates: non-local chat final events trigger a history reload for the active session, with regression coverage for that exact path. The same logic is present in release v2026.4.22.

    What I checked:

    • TUI reloads history for non-local finals: maybeRefreshHistoryForRun() calls loadHistory() for non-local runs, and handleChatEvent() invokes it on state: "final" chat events for the current session. This is the code path that makes externally-originated Telegram-backed session updates appear in the TUI without a manual /session reload. (src/tui/tui-event-handlers.ts:240, 7ac35b4f6900)
    • Regression test matches the reported symptom: The TUI test suite now has an explicit case asserting that a non-local chat final causes a history refresh, plus concurrent-run coverage so local streaming is not clobbered while external updates land. (src/tui/tui-event-handlers.test.ts:458, 7ac35b4f6900)
    • Shipped in latest release tag: The v2026.4.22 tag contains the same src/tui/tui-event-handlers.ts logic, so this behavior is not only on current main but also present in the latest released tree. (src/tui/tui-event-handlers.ts:240, 00bd2cf7a376)

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review notes: reviewed against 7ac35b4f6900; fix evidence: release v2026.4.22, commit 00bd2cf7a376.

  3. sachser66 commented on Apr 25, 2026

    @sachser66
    Author

    Thanks for checking. I re-tested this on OpenClaw 2026.4.23 with a fresh TUI, started on the same Telegram DM session with --deliver.

    Result:

    • messages typed in the TUI are not mirrored to Telegram
    • only the assistant replies are delivered to Telegram when the TUI is started with --deliver
    • Telegram/TUI live sync still does not work reliably
    • messages/updates only appear in the TUI after a manual session reload

    So from my side, the issue is still reproducible on 2026.4.23.

  4. locked as resolved and limited conversation to collaborators on Apr 27, 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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions