Skip to content

fix(telegram): restore DM draft streaming#39398

Merged
obviyus merged 2 commits intomainfrom
fix/telegram-restore-draft-streaming
Mar 8, 2026
Merged

fix(telegram): restore DM draft streaming#39398
obviyus merged 2 commits intomainfrom
fix/telegram-restore-draft-streaming

Conversation

@obviyus
Copy link
Copy Markdown
Contributor

@obviyus obviyus commented Mar 8, 2026

Summary

Restore native sendMessageDraft preview transport for Telegram DM answer streaming.
Keep DM reasoning on message transport, and add a regression test proving draft materialization does not send a duplicate final message.

Testing

  • pnpm test -- src/telegram/draft-stream.test.ts src/telegram/lane-delivery.test.ts src/telegram/bot-message-dispatch.test.ts

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Mar 8, 2026

🤖 We're reviewing this PR with Aisle

We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛
We'll post the results here as soon as they're ready.

Progress:

  • Analysis
  • Triage
  • Finalization

Latest run failed. Keeping previous successful results. Trace ID: 019ccb589dacf8b1fd43f80e23700122.

Last updated on: 2026-03-08T02:48:45Z

@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram size: XS maintainer Maintainer-authored PR labels Mar 8, 2026
@obviyus obviyus self-assigned this Mar 8, 2026
@obviyus obviyus force-pushed the fix/telegram-restore-draft-streaming branch from fa25774 to b6ad588 Compare March 8, 2026 02:53
@obviyus obviyus merged commit 722c5e5 into main Mar 8, 2026
9 checks passed
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: fa25774233

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

maxChars: draftMaxChars,
thread: threadSpec,
previewTransport: useMessagePreviewTransportForDm ? "message" : "auto",
previewTransport: useMessagePreviewTransportForDmReasoning ? "message" : "auto",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear DM draft when final fallback bypasses materialize

Switching the DM answer lane to previewTransport: "auto" means answers now use draft transport when sendMessageDraft is available, but finals with inline buttons/media/error/oversized text cannot take the materialize path (canMaterializeDraftFinal returns false in createLaneTextDeliverer) and instead fall back to sendPayload; in that path no draft-clear call is issued, and the later clear() cleanup only removes message previews, not draft IDs. In DM chats this leaves stale answer text in the Telegram draft/input area after the real final message is sent, which is a user-visible regression introduced by enabling draft transport for the answer lane.

Useful? React with 👍 / 👎.

@obviyus obviyus deleted the fix/telegram-restore-draft-streaming branch March 8, 2026 02:53
@obviyus
Copy link
Copy Markdown
Contributor Author

obviyus commented Mar 8, 2026

Landed via temp rebase onto main.

  • Gate: targeted only per request:

[email protected] test /Users/obviyus/Developer/clawdbot
node scripts/test-parallel.mjs -- src/telegram/draft-stream.test.ts src/telegram/lane-delivery.test.ts src/telegram/bot-message-dispatch.test.ts

RUN v4.0.18 /Users/obviyus/Developer/clawdbot

✓ src/telegram/draft-stream.test.ts (27 tests) 63ms
✓ src/telegram/lane-delivery.test.ts (14 tests) 8ms
✓ src/telegram/bot-message-dispatch.test.ts (59 tests) 25ms

Test Files 3 passed (3)
Tests 100 passed (100)
Start at 08:24:00
Duration 2.42s (transform 1.71s, setup 368ms, import 2.44s, tests 96ms, environment 0ms)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR surgically narrows the DM preview transport workaround originally introduced in #33453. The previous fix forced "message" transport for all DM lanes when answer streaming was active, which inadvertently prevented native sendMessageDraft from being used on the answer lane. This PR restores "auto" (native draft) transport for the answer lane in DMs, while keeping "message" transport only for the reasoning lane — which still needs a tracked messageId for later deletion.

Key changes:

  • bot-message-dispatch.ts: Renamed and rescoped useMessagePreviewTransportForDmuseMessagePreviewTransportForDmReasoning to apply only when laneName === "reasoning". This allows the answer lane to use efficient native draft streaming while the reasoning lane retains message-based transport.
  • Draft materialization handling: The answer lane's "auto" transport in DMs is handled correctly via the existing canMaterializeDraftFinaltryMaterializeDraftPreviewForFinal pathway in lane-delivery-text-deliverer.ts, which calls stream.materialize() to atomically convert the live draft into a permanent sendMessage and then clears the draft.
  • Regression test: Added a targeted test proving the materialization path fires exactly once (materialize called once) and neither deliverReplies nor editMessageTelegram is triggered (confirming no duplicate final message).

The production materialize() implementation in draft-stream.ts correctly: calls stop() to flush the final draft text, sends a real sendMessage with the last rendered text (preserving parse_mode), then clears the draft as a best-effort cleanup to avoid a stale draft appearing alongside the real message.

Safety assessment: This PR is safe to merge. It replaces an over-broad workaround with a more precise, targeted fix backed by a direct regression test that validates the draft materialization behavior.

Confidence Score: 4/5

  • Safe to merge — replaces an over-broad workaround with a more precise fix, backed by direct regression testing.
  • The logic is sound: the answer lane's "auto" transport in DMs is handled correctly via the existing canMaterializeDraftFinaltryMaterializeDraftPreviewForFinal path, verified end-to-end in the new test. The reasoning lane correctly retains "message" transport for messageId tracking. The one-point deduction from 5/5 is because this partially reverts a prior fix ([Bug]: Telegram Duplicate Messages with Partial Streaming #33453) and relies on the materialize() production path being robust. However, the implementation in draft-stream.ts handles stop-flush, fallback retry with thread-param handling, and draft-clear correctly, making this a well-engineered change.
  • No files require special attention — all changes are correctly scoped and tested. The draft-stream.ts materialize() implementation (not directly modified in this PR) was verified to correctly handle the materialization flow.

Last reviewed commit: b6ad588

@obviyus
Copy link
Copy Markdown
Contributor Author

obviyus commented Mar 8, 2026

Landed via temp rebase onto main.

  • Gate: targeted only per request: pnpm test -- src/telegram/draft-stream.test.ts src/telegram/lane-delivery.test.ts src/telegram/bot-message-dispatch.test.ts
  • Source branch head: b6ad588
  • Landed commit: 722c5e5

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Mar 8, 2026

🤖 We're reviewing this PR with Aisle

We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛
We'll post the results here as soon as they're ready.

Progress:

  • Analysis
  • Triage
  • Finalization

Latest run failed. Keeping previous successful results. Trace ID: 019ccb5d03e376138199af53d353709d.

Last updated on: 2026-03-08T02:56:35Z

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 8, 2026
* main: (290 commits)
  test: stabilize exec resolver timeout fixture
  chore: add changelog and format fix for openclaw#39414
  fix(chat): preserve sender labels in dashboard history
  docs: clean up latest changelog sections
  docs: dedupe changelog contributor attribution
  fix(ci): resolve current gate regressions
  refactor(voice-call): share tts deep merge
  fix: land openclaw#39337 by @goodspeed-apps for acpx MCP bootstrap
  fix(ci): resolve type regressions on main
  fix: document discord agentComponents schema parity (openclaw#39378) (thanks @gambletan) (openclaw#39378)
  fix(discord): validate agentComponents config
  test: cover daemon probe auth seam
  refactor: preserve explicit mock voice-call values
  refactor: register gateway service adapters
  refactor: reuse shared gateway probe auth
  refactor: split daemon status gathering
  refactor: centralize strict numeric parsing
  refactor: normalize voice-call runtime defaults
  fix(ci): pin multi-arch docker base digests
  docs: add changelog for Telegram DM draft restore (openclaw#39398)
  ...
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 8, 2026
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
alexey-pelykh added a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
…r live test fixes (#1795)

* Changelog: credit openclaw#39328 to @vincentkoc

(cherry picked from commit 2ec478c)

* Changelog: move openclaw#39328 credit to section end

(cherry picked from commit 5b30c9d)

* Pi Runner: gate parallel_tool_calls to compatible APIs (openclaw#39356)

* Pi Runner: gate parallel_tool_calls payload injection

* Pi Runner: cover parallel_tool_calls alias precedence

* Changelog: note parallel_tool_calls compatibility fix

* Update CHANGELOG.md

* Pi Runner: clarify null parallel_tool_calls override logging

(cherry picked from commit daecd2d)

# Conflicts:
#	CHANGELOG.md
#	src/agents/pi-embedded-runner-extraparams.test.ts
#	src/agents/pi-embedded-runner/extra-params.ts

* docs: add changelog for Telegram DM draft restore (openclaw#39398)

(cherry picked from commit 722c5e5)

* fix: document discord agentComponents schema parity (openclaw#39378) (thanks @gambletan) (openclaw#39378)

Co-authored-by: Shadow <[email protected]>
(cherry picked from commit 9c8e34d)

* fix: land openclaw#39337 by @goodspeed-apps for acpx MCP bootstrap

Co-authored-by: Goodspeed App Studio <[email protected]>
(cherry picked from commit 5659d7f)

# Conflicts:
#	extensions/acpx/openclaw.plugin.json
#	extensions/acpx/src/config.test.ts
#	extensions/acpx/src/config.ts
#	extensions/acpx/src/runtime-internals/test-fixtures.ts
#	extensions/acpx/src/runtime.test.ts
#	extensions/acpx/src/runtime.ts
#	extensions/acpx/src/service.ts

* docs: clean up latest changelog sections

(cherry picked from commit c743fd9)

* fix: land contributor PR openclaw#39516 from @Imhermes1

macOS app/chat/browser/cron/permissions fixes.

Co-authored-by: ImHermes1 <[email protected]>
(cherry picked from commit d15b6af)

# Conflicts:
#	CHANGELOG.md
#	apps/macos/Sources/RemoteClaw/NodeMode/MacNodeBrowserProxy.swift
#	apps/macos/Sources/RemoteClaw/NodeMode/MacNodeModeCoordinator.swift
#	apps/macos/Sources/RemoteClaw/NodeMode/MacNodeRuntime.swift
#	apps/macos/Sources/RemoteClaw/PermissionsSettings.swift
#	apps/macos/Tests/RemoteClawIPCTests/MacNodeBrowserProxyTests.swift
#	apps/shared/RemoteClawKit/Sources/RemoteClawChatUI/ChatView.swift
#	apps/shared/RemoteClawKit/Sources/RemoteClawKit/BrowserCommands.swift
#	apps/shared/RemoteClawKit/Tests/RemoteClawKitTests/ChatComposerPasteSupportTests.swift

* fix: stage docker live tests from mounted source

(cherry picked from commit 21df014)

* fix: add minimal process shim for acpx mcp-agent-command

The upstream process.ts depends on gutted runtime-api, so provide a
minimal spawnAndCollect implementation that satisfies the import.

---------

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: gambletan <[email protected]>
Co-authored-by: Shadow <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant