Skip to content

fix(tui): render external-channel session messages live - #41964

Closed
zerone0x wants to merge 1 commit into
openclaw:mainfrom
zerone0x:fix/tui-telegram-live-display
Closed

zerone0x wants to merge 1 commit into
openclaw:mainfrom
zerone0x:fix/tui-telegram-live-display

Conversation

@zerone0x

Copy link
Copy Markdown
Contributor

Summary

Fixes #41937

Inbound Telegram (and other external-channel) messages update the session correctly, but the TUI never renders the assistant response live — it only appears after a manual session/history reload. The root cause is the isControlUiVisible gate added in #36030: runs originating from non-webchat channels set isControlUiVisible: false, which suppresses chat event broadcasts (delta/final) entirely. The TUI relies on these broadcasts to stream assistant responses.

Fix: Remove the isControlUiVisible condition from the chat-event emission path in createAgentEventHandler. The TUI already filters events by session key (isSameSessionKey), so there is no risk of cross-session noise. The isControlUiVisible flag remains in use for pre-tool-start delta flushing.

Changes

  • src/gateway/server-chat.ts: Change if (isControlUiVisible && sessionKey) → if (sessionKey) so chat delta/final events are broadcast for all runs that have a resolved session key.
  • src/gateway/server-chat.agent-events.test.ts: Update the test that previously verified suppression to now verify that external-channel runs emit chat events.

Test plan

  • pnpm test -- --run src/gateway/server-chat.agent-events.test.ts — 23/23 pass
  • pnpm test -- --run src/tui/tui-event-handlers.test.ts — 17/17 pass
  • pnpm test -- --run src/infra/agent-events.test.ts — 4/4 pass
  • pnpm tsgo — no type errors
  • pnpm check — lint/format clean

…renders live

The isControlUiVisible gate in the agent-event handler prevented chat
delta/final broadcasts for runs originating from non-webchat channels
(Telegram, Discord, etc.). This meant TUI clients viewing a Telegram
session would never receive live assistant-response events — messages
only appeared after a manual history reload.

Remove the isControlUiVisible condition from the chat-event emission
path. The TUI already filters by session key, so cross-session noise
is not a concern. External-channel runs now broadcast chat events
identically to webchat-originated runs.

Fixes #41937

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@aisle-research-bot

aisle-research-bot Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium Hidden (non-control-UI-visible) agent runs now broadcast chat/session events to all subscribers

1. 🟡 Hidden (non-control-UI-visible) agent runs now broadcast chat/session events to all subscribers

Property Value
Severity Medium
CWE CWE-200
Location src/gateway/server-chat.ts:593-601

Description

In createAgentEventHandler, the guard isControlUiVisible && sessionKey was changed to sessionKey.

isControlUiVisible is explicitly documented as: “Whether control UI clients should receive chat/agent updates for this run” (see src/infra/agent-events.ts). It is set to false for runs originating from non-internal message channels (e.g., Telegram/iMessage) via registerAgentRunContext(..., { isControlUiVisible: shouldSurfaceToControlUi }).

With the new condition, runs marked not control-UI-visible will still:

  • forward agent events to node session subscribers via nodeSendToSession(sessionKey, "agent", ...) (including tool metadata when verbose is enabled)
  • emit chat delta/final events via broadcast("chat", ...) and nodeSendToSession(sessionKey, "chat", ...)

This can cause privacy/information disclosure because the codebase does not show any per-session authorization on the broadcast path, and node session subscription (chat.subscribe) is based solely on a provided sessionKey.

Vulnerable code (post-change):

if (sessionKey) {
  if (!isToolEvent || toolVerbose !== "off") {
    nodeSendToSession(sessionKey, "agent", isToolEvent ? toolPayload : agentPayload);
  }
  if (!isAborted && evt.stream === "assistant" && typeof evt.data?.text === "string") {
    emitChatDelta(sessionKey, clientRunId, evt.runId, evt.seq, evt.data.text, evt.data.delta);
  }
  ​// ... emits chat final/error as well
}

Impact depends on deployment, but in a multi-session/multi-device environment it can expose external-channel conversations (and potentially sensitive tool metadata) to connected UI clients or any node subscribed to the session key.

Recommendation

Reintroduce explicit visibility/authorization gating for external-channel runs, or replace it with a more precise allowlist:

  • Only forward/broadcast external-channel session events to clients that have explicitly subscribed/are authorized for that sessionKey.
  • If TUI needs these events, gate on a dedicated capability/role rather than removing isControlUiVisible globally.

Example (conceptual):

const allowSessionFanout = isControlUiVisible || isTrustedTuiSubscriber(sessionKey);

if (allowSessionFanout && sessionKey) {
  ​// existing nodeSendToSession + emitChatDelta/final logic
}

Also consider adding server-side authorization in chat.subscribe to prevent arbitrary nodes from subscribing to sessions they should not access.


Analyzed PR: #41964 at commit 89c68f1

Last updated on: 2026-03-10T09:15:47Z

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Mar 10, 2026
@greptile-apps

greptile-apps Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a live-streaming gap in the TUI for external-channel (Telegram, iMessage, etc.) sessions by removing the isControlUiVisible gate from createAgentEventHandler's chat-event broadcast path. Previously, delta/final chat events were suppressed entirely for non-webchat runs, so the TUI could only display assistant responses after a manual reload. With the gate removed, all runs that have a resolved sessionKey broadcast their chat events; the TUI's existing isSameSessionKey filter prevents cross-session noise.

Key changes:

  • src/gateway/server-chat.ts: if (isControlUiVisible && sessionKey) → if (sessionKey) to unblock chat event emission for external-channel runs.
  • src/gateway/server-chat.agent-events.test.ts: Updated the previously-suppression-verifying test to assert that chat events are emitted for isControlUiVisible: false runs.
  • The isControlUiVisible guard on the pre-tool-start flushBufferedChatDeltaIfNeeded call (line 575) is intentionally left in place per the PR description, but this means buffered pre-tool assistant text may still arrive late in the TUI for external-channel sessions — a minor residual inconsistency worth addressing in a follow-up.

Confidence Score: 4/5

  • Safe to merge — the change is minimal and well-tested, with no risk of cross-session event leakage.
  • The one-line fix is correct and directly addresses the root cause. The TUI's existing session-key filtering means broadcasting chat events for external-channel runs is safe. All cited test suites pass. The only minor concern is that the isControlUiVisible guard on flushBufferedChatDeltaIfNeeded is not updated consistently, which could leave pre-tool assistant text slightly delayed for TUI viewers of external-channel sessions, but this does not break existing functionality.
  • No files require special attention beyond the noted flushBufferedChatDeltaIfNeeded guard at src/gateway/server-chat.ts:575.

Comments Outside Diff (1)

  1. src/gateway/server-chat.ts, line 575-577 (link)

    Pre-tool delta flush still gated on isControlUiVisible

    The fix correctly removes the isControlUiVisible guard from the chat event emission path (line 593), so TUI clients now receive live delta/final events for external-channel runs. However, the pre-tool-start flush at line 575 still requires isControlUiVisible to be true:

    if (toolPhase === "start" && isControlUiVisible && sessionKey && !isAborted) {
        flushBufferedChatDeltaIfNeeded(sessionKey, clientRunId, evt.runId, evt.seq);
    }

    For an external-channel session (isControlUiVisible: false), this flush will be skipped. The purpose of the flush is to deliver any buffered assistant text before the tool-start event so the TUI renders complete pre-tool prose above tool cards. Without it, TUI clients watching a Telegram (or other external-channel) session may see that pre-tool text arrive slightly late (i.e., after the tool card), or not at all if the throttle window hasn't expired yet.

    This is explicitly noted in the PR description as intentional — the flag "remains in use for pre-tool-start delta flushing" — but the result is an incomplete fix: streaming responses are now live, yet the pre-tool text flush remains broken for the same sessions.

    Consider also removing the isControlUiVisible guard here:

Last reviewed commit: 89c68f1

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded. Current main has not implemented this PR's one-line isControlUiVisible guard removal, and merging it as written would widen a documented hidden-run chat/node fanout boundary for external-channel sessions. The same TUI live-session problem is now covered by the open maintainer PR #73402, which uses the safer sessions.messages.subscribe / session.message transcript path instead of broadcasting hidden external-channel runs through the general chat fanout.

Best possible solution:

Close this PR as superseded by #73402. Review and land #73402, or an equivalent implementation, that subscribes the TUI to sessions.messages.subscribe / session.message for the active session while keeping hidden external-channel chat/node fanout gated by isControlUiVisible and covering both active-session filtering and hidden-run fanout in tests.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex review notes: model gpt-5.5, reasoning high; reviewed against db40ec404a91.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant