Repository navigation
Conversation
Greptile SummaryThis PR implements live-tailing of inbound user messages in The core approach is sound and follows the existing
The TUI handler, type extension, regression tests, connect-policy fix, and model-selection TDZ fix all look correct. Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 1235-1236
Comment:
**Broadcast echoes the sender's own message back to the originating TUI client**
`context.broadcast("chat", userMessagePayload)` delivers to **all** connected WS clients — including the TUI that originated the message. If that TUI already adds the user's typed text to its chat log locally (optimistic rendering), it will receive this broadcast and call `chatLog.addUser` a second time, producing a duplicate entry.
The intended recipients are *other* clients watching the session (e.g. a monitoring TUI for a Telegram session). Consider filtering out the originating connection using a `skipConnId` exclusion when calling `broadcast`, similar to how other subsystems avoid self-echo. Adding an origin identifier to the payload would also let the TUI handler discard events it generated itself.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 1228-1234
Comment:
**`parsedMessage` may contain attachment-processing artifacts rather than display-friendly text**
When the request carries attachments, `parsedMessage` is the output of `parseMessageWithAttachments` — it may include internal content markers or structured data intended for the AI model. Broadcasting this as `message.text` in the live-tail event would display that processed content verbatim in the TUI.
For display purposes `inboundMessage` (the sanitized raw user text, before attachment expansion) is the correct field to use here.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 3f24351 |
| context.broadcast("chat", userMessagePayload); | ||
| context.nodeSendToSession(rawSessionKey, "chat", userMessagePayload); |
There was a problem hiding this comment.
Broadcast echoes the sender's own message back to the originating TUI client
context.broadcast("chat", userMessagePayload) delivers to all connected WS clients — including the TUI that originated the message. If that TUI already adds the user's typed text to its chat log locally (optimistic rendering), it will receive this broadcast and call chatLog.addUser a second time, producing a duplicate entry.
The intended recipients are other clients watching the session (e.g. a monitoring TUI for a Telegram session). Consider filtering out the originating connection using a skipConnId exclusion when calling broadcast, similar to how other subsystems avoid self-echo. Adding an origin identifier to the payload would also let the TUI handler discard events it generated itself.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 1235-1236
Comment:
**Broadcast echoes the sender's own message back to the originating TUI client**
`context.broadcast("chat", userMessagePayload)` delivers to **all** connected WS clients — including the TUI that originated the message. If that TUI already adds the user's typed text to its chat log locally (optimistic rendering), it will receive this broadcast and call `chatLog.addUser` a second time, producing a duplicate entry.
The intended recipients are *other* clients watching the session (e.g. a monitoring TUI for a Telegram session). Consider filtering out the originating connection using a `skipConnId` exclusion when calling `broadcast`, similar to how other subsystems avoid self-echo. Adding an origin identifier to the payload would also let the TUI handler discard events it generated itself.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in commit 45dd164 — handleChatEvent now checks isLocalRunId?.(evt.runId) at the top of the user-message branch and returns early for locally-originated runs, suppressing the echo on the originating TUI client.
| const userMessagePayload = { | ||
| runId: clientRunId, | ||
| sessionKey: rawSessionKey, | ||
| seq: 0, | ||
| state: "user-message" as const, | ||
| message: { text: parsedMessage }, | ||
| }; |
There was a problem hiding this comment.
parsedMessage may contain attachment-processing artifacts rather than display-friendly text
When the request carries attachments, parsedMessage is the output of parseMessageWithAttachments — it may include internal content markers or structured data intended for the AI model. Broadcasting this as message.text in the live-tail event would display that processed content verbatim in the TUI.
For display purposes inboundMessage (the sanitized raw user text, before attachment expansion) is the correct field to use here.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 1228-1234
Comment:
**`parsedMessage` may contain attachment-processing artifacts rather than display-friendly text**
When the request carries attachments, `parsedMessage` is the output of `parseMessageWithAttachments` — it may include internal content markers or structured data intended for the AI model. Broadcasting this as `message.text` in the live-tail event would display that processed content verbatim in the TUI.
For display purposes `inboundMessage` (the sanitized raw user text, before attachment expansion) is the correct field to use here.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in commit 45dd164 — the broadcast payload now uses inboundMessage (the sanitized raw user text) instead of parsedMessage, so attachment-processing artifacts are not included in the display text sent to other TUI clients.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f243515f7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (text) { | ||
| chatLog.addUser(text); | ||
| tui.requestRender(); |
There was a problem hiding this comment.
Ignore local user-message echo events
handleChatEvent now appends every "user-message" event to the chat log, but local sends already append the same text before RPC (src/tui/tui-command-handlers.ts:505). Because gateway broadcasts events to all connected clients (including the sender) in src/gateway/server-broadcast.ts:93, each message sent from the same TUI session is rendered twice (immediate local echo + broadcast echo). This regression affects normal interactive use of openclaw tui --session ... whenever the operator sends a message from that TUI instance.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in commit 45dd164 — handleChatEvent returns early when isLocalRunId?.(evt.runId) is true, so the originating TUI client no longer appends its own user message a second time from the broadcast event.
|
Addressed all review findings (commit 45dd164): P1 (Codex Bot) — duplicate user-message rendering: Greptile — use |
|
All three findings addressed in commit P1 (id 2933429545) — Greptile (id 2933422605) — Same fix: the Greptile (id 2933422679) — The broadcast payload now uses |
45dd164 to
593b9b7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 593b9b74eb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| context.broadcast("chat", userMessagePayload); | ||
| context.nodeSendToSession(rawSessionKey, "chat", userMessagePayload); |
There was a problem hiding this comment.
Emit user-message events from channel ingress paths
This broadcast is only wired into chat.send, so it never fires for real inbound channel traffic. I checked the external ingress handlers in src/discord/monitor/message-handler.process.ts:726 and src/slack/monitor/message-handler/dispatch.ts:430; both call dispatchInboundMessage(...) directly and do not go through the chat.send RPC handler. That means openclaw tui --session ... --deliver still won’t receive state: "user-message" events for messages that originate on channels, so the live-tail regression described in #45388 remains for the primary external-message path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Acknowledged — this is a valid gap. The current PR intentionally scopes to the chat.send RPC path (the regression reported in #45388 was triggered via the web/API client, not Discord/Slack channels). The Discord (message-handler.process.ts) and Slack (dispatch.ts) ingress paths call dispatchInboundMessage directly and do not go through the gateway RPC layer, so they cannot reach the broadcast added here.
Extending live-tail coverage to channel ingress paths would require either (a) threading a broadcast callback through dispatchInboundMessage's options, or (b) emitting the event from a lower-level hook inside the dispatch pipeline. Both approaches touch more surface area than this targeted fix warrants. I'll open a follow-up issue to track the channel-ingress gap separately so it doesn't block this PR.
593b9b7 to
8dc0412
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8dc0412c56
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| runId: clientRunId, | ||
| sessionKey: rawSessionKey, | ||
| seq: 0, | ||
| state: "user-message" as const, |
There was a problem hiding this comment.
Add user-message to the shared ChatEvent schema
This commit starts emitting state: "user-message" chat payloads, but the protocol schema still only allows delta|final|aborted|error (src/gateway/protocol/schema/logs-chat.ts:71-76), and validateChatEvent is compiled from that schema (src/gateway/protocol/index.ts:418). As a result, any client/tooling path that validates chat events against the shared schema will reject or drop these new events, so the live-tail behavior can silently fail outside the TUI-specific path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in commit 35a8d5c88bf7 — added Type.Literal("user-message") to the state union in ChatEventSchema so that schema validation now accepts the new event type. All gateway protocol tests pass.
…nfig load (openclaw#45368) When the bundler flattens the module graph it may evaluate model-selection.ts before the module-level const ANTHROPIC_MODEL_ALIASES binding is live, due to circular-dependency ordering between: model-selection.ts -> config/config.js (re-exports config/io.js) -> config/defaults.ts -> agents/model-selection.js <-- cycle This causes a ReferenceError at startup: Cannot access 'ANTHROPIC_MODEL_ALIASES' before initialization at normalizeAnthropicModelId (...) at loadConfigSnapshot (...) Fix: replace the module-level const with a getter function getAnthropicModelAliases(). The object is now allocated at call time, which is always after all module-level bindings have been initialised, regardless of the bundler's module evaluation order. Fixes openclaw#45368, also fixes openclaw#45363 (same root cause, object-style model config).
…#45388) Fixes openclaw#45388 ## Problem When running: openclaw tui --session "telegram:direct:<id>" --deliver the TUI loads history on connect but never receives real-time updates. New inbound messages from Telegram (or any external channel) do not appear until the user kills and relaunches the TUI. ## Root cause The TUI event loop handles three event types from the gateway: "chat" → delta / final / aborted / error (agent reply streaming) "agent" → tool / lifecycle (agent run internals) When an external user sends a message, the gateway writes it to the session transcript and starts an agent run — but it never broadcasts the *user message itself* as a chat event. The TUI therefore has no signal to display the inbound message; it only sees the agent reply once the run completes. ## Fix Two-layer change: ### 1. Gateway (server-methods/chat.ts) Immediately after acknowledging the run (`respond(true, ackPayload)`), broadcast a new `state: "user-message"` chat event containing the raw message text. This is sent to all connected WS clients watching the session, so any TUI in --session mode receives it in real time. ### 2. TUI (tui-event-handlers.ts + tui-types.ts) Handle the new `"user-message"` state in `handleChatEvent`: - Extract the text from `message.text` (object payload) or the message string directly (plain-string payload). - Call `chatLog.addUser(text)` and `tui.requestRender()`. - Return early — no run tracking needed for user messages. The `ChatEvent.state` union type is extended to include `"user-message"`. ## Testing Added 4 regression tests in `tui-event-handlers.test.ts`: 1. Object payload `{ text: "..." }` → appended to chat log 2. Plain-string payload → appended to chat log 3. Different session key → ignored (no cross-session leakage) 4. Empty text → ignored (no empty bubbles) All 201 TUI tests pass.
… display Addresses two review findings on PR openclaw#45417: P1 (Codex Bot): handleChatEvent appended every user-message event to the chat log, but the local send path (tui-command-handlers.ts sendMessage) already calls chatLog.addUser() before the RPC. Because gateway broadcasts to all connected clients including the sender, each locally-sent message was rendered twice. Fix: skip user-message events whose runId is known to isLocalRunId. Greptile: the broadcast payload used parsedMessage which may contain attachment-processing artifacts intended for the AI model. Fix: use inboundMessage (the sanitized raw user text) instead. Adds a regression test for the local-echo suppression.
The user-message chat event state was emitted by the gateway but not included in ChatEventSchema, causing schema validation to reject these events on any client path that validates against the shared schema. Fixes the silent live-tail failure reported in review comment #2934862415.
The live-tail user-message handler (handleChatEvent) calls chatLog.addUser(text) to display inbound messages from remote senders, but addUser was not declared in the EventHandlerChatLog interface, causing a TypeScript compile error: Property 'addUser' does not exist on type 'EventHandlerChatLog'. src/tui/tui-event-handlers.ts#L207 addUser(text: string) is already implemented in ChatLog (src/tui/components/chat-log.ts:59) and called from tui-command-handlers.ts and tui-session-actions.ts. Add the missing declaration to the local interface to fix the type error.
885d0c4 to
1f7ce36
Compare
|
Hey team — just checking in on this one. We've been running into the TUI/TG session isolation issue daily and it's the #1 friction point for users who run both surfaces simultaneously. CI is green, the fix looks solid. Any chance this can get a review and merge soon? Thanks! 🙏 |
|
Hey team — friendly bump on this one. PR has been open since March 13 with all CI green. This fixes a real usability issue with TUI --session mode not live-streaming inbound messages (#45388). The author (kirs-hi) has been responsive to review feedback and iterated through several rounds already. Any chance a maintainer could take a look? Would love to see this land. Thanks! 🙏 |
|
Bumping this — still waiting on maintainer review. CI is passing, fix looks solid. This is causing real pain for users running mode in active workflows. Any chance of getting this merged soon? 🙏 |
|
Bumping again — 28 days open, CI still green, author has been responsive throughout. This is causing real daily pain for users running Telegram + TUI simultaneously. The session hang and missing live-stream messages are the #1 friction point in our workflow. Would really appreciate a maintainer look. 🙏 |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded by #73402; the PR targets a real live-tail bug, but its chat-event implementation misses external-channel ingress and broadens raw user text delivery, while the maintainer PR tracks the scoped transcript-subscription fix. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Close this PR in favor of the maintainer transcript-subscription PR and land the scoped Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible. Current main has scoped Is this the best way to solve the issue? No. The proposed broad Security review: Security review needs attention: The diff introduces a privacy-scope concern by broadcasting raw user message text on the broad
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 2a22eb68aafd. |
Summary
Fixes #45388
When running
openclaw tui --session "telegram:direct:<id>" --deliver, the TUI loads history on connect but never receives real-time updates. New inbound messages from Telegram (or any external channel) do not appear until the user kills and relaunches the TUI.Root Cause
The TUI event loop handles two event types from the gateway:
"chat"→delta / final / aborted / error(agent reply streaming)"agent"→tool / lifecycle(agent run internals)When an external user sends a message, the gateway writes it to the session transcript and starts an agent run — but it never broadcasts the user message itself as a chat event. The TUI therefore has no signal to display the inbound message; it only sees the agent reply once the run completes.
Fix
Two-layer change:
1. Gateway (
server-methods/chat.ts)Immediately after acknowledging the run (
respond(true, ackPayload)), broadcast a newstate: "user-message"chat event containing the raw message text. This is sent to all connected WS clients watching the session, so any TUI in--sessionmode receives it in real time.2. TUI (
tui-event-handlers.ts+tui-types.ts)Handle the new
"user-message"state inhandleChatEvent:message.text(object payload) or the message string directly (plain-string payload)chatLog.addUser(text)andtui.requestRender()The
ChatEvent.stateunion type is extended to include"user-message".Testing
Added 4 regression tests in
tui-event-handlers.test.ts:{ text: "..." }→ appended to chat logAll 201 TUI tests pass (197 existing + 4 new).