Skip to content

[codex] Fix main-session web UI reply routing to Telegram#29328

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
BeeSting50:codex/issue-29301-main-routing
Mar 2, 2026
Merged

[codex] Fix main-session web UI reply routing to Telegram#29328
Takhoffman merged 2 commits intoopenclaw:mainfrom
BeeSting50:codex/issue-29301-main-routing

Conversation

@BeeSting50
Copy link
Copy Markdown
Contributor

Fixes #29301

Title

Reply routing fails when session.dmScope=main and replies are sent from chat.send (Web Control UI): replies stay in web history and are not delivered to Telegram.

Severity Assessment

Medium. Message delivery silently fails on a supported configuration (session.dmScope=main) and can cause operators to believe users received responses when they did not.

Impact

When users send Telegram messages that are unified into the main session, replying from the web Control UI can keep the assistant response only in session history, without delivering it back to Telegram.

Affected Component

  • src/gateway/server-methods/chat.ts (chat.send context construction)
  • src/auto-reply/reply/dispatch-from-config.ts (origin routing decision path)

Technical Reproduction

  1. Configure session.dmScope to main.
  2. Send a Telegram DM to OpenClaw so the message lands in the main session.
  3. Open the Web Control UI and reply in that same session.
  4. Observe the reply appears in web session history but is not delivered to Telegram.

Root cause:
chat.send always set OriginatingChannel to internal webchat, which prevented dispatch-from-config from routing final replies to the stored external session delivery context.

Demonstrated Impact

In runtime logs during reproduction, UI-originated runs executed with messageChannel=webchat, and no Telegram outbound send occurred for that reply path. User-observed behavior matched this: response visible in session history only, not in Telegram.

Environment

  • OpenClaw version tested: 2026.2.26
  • Platform: macOS (Darwin)
  • Channel under test: Telegram (DM)
  • Session mode: session.dmScope=main

Remediation Advice

  • In chat.send, inherit routable origin metadata from session delivery fields (deliveryContext / lastChannel) when available, instead of forcing internal webchat origin.
  • Preserve OriginatingChannel, OriginatingTo, AccountId, and MessageThreadId for downstream route-reply logic.
  • Keep regression tests for:
    • mixed Provider/Surface origin routing behavior
    • chat.send origin inheritance from session delivery context

Validation

  • pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts

@openclaw-barnacle openclaw-barnacle bot added app: web-ui App: web-ui gateway Gateway runtime size: S labels Feb 28, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 28, 2026

Greptile Summary

Fixes message delivery routing when replies are sent from the Web Control UI to Telegram messages unified in the main session. The fix correctly inherits routing metadata (OriginatingChannel, OriginatingTo, AccountId, MessageThreadId) from session delivery context in chat.send, and updates the routing decision logic in dispatch-from-config.ts to prefer Provider over Surface for determining the current surface. The changes are well-tested with new test cases covering the main scenarios and edge cases. The implementation follows existing patterns in the codebase for field-by-field fallback between deliveryContext and last* fields.

Confidence Score: 4/5

  • This PR is safe to merge with low risk. The fix addresses a clear bug in message routing without breaking existing functionality.
  • The implementation is sound and well-tested. The logic correctly inherits routing metadata from session delivery context and updates the routing decision to prefer Provider over Surface. The changes follow existing patterns in the codebase. Minor point deduction because there's a theoretical edge case where partial deliveryContext population could lead to inconsistent routing metadata (mixing channel from deliveryContext with to from last* fields), but this is unlikely in normal operation if deliveryContext is set atomically.
  • No files require special attention - all changes are straightforward and well-tested

Last reviewed commit: 11e8e47

@masatohoshino
Copy link
Copy Markdown
Contributor

Additional field report (real-world, Telegram-only operator)

Summary

I can reproduce reply-routing drift even when I never send replies from Control UI (I reply 100% from Telegram).
Control UI may be open, but no UI-side reply action is used.

Environment

  • OpenClaw: 2026.2.26
  • Channel: Telegram DM
  • Web Control UI: open concurrently at times
  • Date observed: 2026-02-28 (UTC)

What I observed

  • User-visible symptom: assistant outputs are visible in session/history, but some are not delivered to Telegram.
  • This happened after restart windows around:
    • 2026-02-28 09:56:53 UTC
    • 2026-02-28 10:05:45 UTC
    • 2026-02-28 10:21:51 UTC
    • 2026-02-28 10:25:22 UTC

Hard evidence (same incident window)

Window: 2026-02-28 10:26:00–10:32:00 UTC

  • Assistant messages in session transcript: 10
  • Outbound log lines with channel=telegram: 2
  • Telegram API errors (4xx/5xx) in that window: none found

Relevant user messages in transcript:

  • 2026-02-28T10:28:03.236Z: "Messages are not appearing on Telegram. Please send the email."
  • 2026-02-28T10:48:59.330Z: "Okay, but messages are not appearing on Telegram."

Why this may extend scope of current fix

PR #29328 focuses on chat.send from Web UI.
In my case, no UI reply action was used, but drift still occurred.
So there may be another path where route target/origin metadata is overwritten or not restored correctly when webchat is connected and session is unified.

Request

Could maintainers confirm whether there are other non-chat.send paths that can mutate/override OriginatingChannel / deliveryContext / lastChannel in unified sessions (agent:main:main)?
I can provide sanitized timeline IDs/log snippets if needed.

@BeeSting50 BeeSting50 closed this Mar 1, 2026
@BeeSting50 BeeSting50 deleted the codex/issue-29301-main-routing branch March 1, 2026 03:01
@BeeSting50 BeeSting50 restored the codex/issue-29301-main-routing branch March 2, 2026 03:48
@BeeSting50 BeeSting50 reopened this Mar 2, 2026
@Takhoffman Takhoffman force-pushed the codex/issue-29301-main-routing branch from 11e8e47 to 7bbb3be Compare March 2, 2026 13:48
@Takhoffman Takhoffman merged commit 050e928 into openclaw:main Mar 2, 2026
19 of 21 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

PR #29328 - [codex] Fix main-session web UI reply routing to Telegram (#29328)

Merged via squash.

  • Merge commit: 050e928
  • Verified: pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts; pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
  • Changes made:
  • Why these changes were made:
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @BeeSting50!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7bbb3bea54

ℹ️ 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".

Comment on lines +829 to +830
OriginatingChannel: originatingChannel,
OriginatingTo: originatingTo,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Surface route delivery failures from chat.send

Setting OriginatingChannel/OriginatingTo here makes chat.send go through cross-channel routeReply delivery, but that path does not throw on send failure (it logs and returns ok: false/queuedFinal: false), and chat.send still marks the run as successful. In environments where the target channel is unavailable or the stored route is stale, the operator gets an "ok" completion while Telegram/Feishu receives nothing. Please treat failed routed finals as a failed run (or explicitly fallback) before broadcasting success.

Useful? React with 👍 / 👎.

hanqizheng pushed a commit to hanqizheng/openclaw that referenced this pull request Mar 2, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
obviyus pushed a commit that referenced this pull request Mar 2, 2026
…anks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Linux2010 pushed a commit to Linux2010/openclaw that referenced this pull request Mar 2, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 17, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 050e928)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 17, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 050e928)
lukeg826 pushed a commit to lukeg826/openclaw that referenced this pull request Mar 26, 2026
…9328) thanks @BeeSting50

Verified:
- pnpm test src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts
- pnpm exec oxfmt --check src/auto-reply/reply/dispatch-from-config.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/auto-reply/reply/dispatch-from-config.ts src/gateway/server-methods/chat.ts CHANGELOG.md
- CI note: non-required check "check" failed on unrelated src/slack/monitor/events/messages.ts TS errors outside this PR scope.

Co-authored-by: BeeSting50 <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Reply routing fails when session.dmScope is main

3 participants