Skip to content

fix(telegram): retain preview message on generation mismatch race - #85907

Closed
EnjouZeratul wants to merge 3 commits into
openclaw:mainfrom
EnjouZeratul:fix/telegram-preview-retain
Closed

EnjouZeratul wants to merge 3 commits into
openclaw:mainfrom
EnjouZeratul:fix/telegram-preview-retain

Conversation

@EnjouZeratul

Copy link
Copy Markdown
Contributor

Fixes #85807

Summary

Added retain: true to the onSupersededPreview call in the generation-mismatch block of draft-stream.ts. This prevents Telegram preview messages from being deleted when forceNewMessage() races with an in-flight send.

Problem

When Telegram streaming (streaming.mode = partial/progress) delivers multiple response segments, the first streamed message can be silently deleted due to a race condition:

  1. First response text streams → sendMessage is in-flight
  2. Meanwhile, forceNewMessage() is called → generation increments
  3. Telegram API responds with valid message_id
  4. sendGeneration !== generation → onSupersededPreview called without retain: true
  5. Message is deleted

Solution

Added retain: true to match the behavior of the text-splitting superseded path (line 215-220), which already correctly retains overflow preview pages.

params.onSupersededPreview?.({
  messageId: normalizedMessageId,
  textSnapshot: renderedText,
  parseMode: renderedParseMode,
  visibleSinceMs,
+ retain: true,
});

Testing

  • Updated test in draft-stream.test.ts to verify retain: true is set
  • All 32 tests pass

Real behavior proof

Behavior addressed: Telegram preview messages are no longer deleted when generation mismatch occurs during streaming.

Real environment tested: Unit tests verify the fix. The generation-mismatch test now expects retain: true in the supersededPreview callback.

Evidence after fix: Test output shows 32 tests passed, including the updated generation-mismatch test.

Observed result after fix: Preview messages will be retained when forceNewMessage() races with in-flight sends, matching the documented behavior for overflow pages.

What was not tested: Live Telegram streaming test (requires Telegram bot setup).

Fixes openclaw#85831

When saving config in Control UI, required string fields with minLength
constraint (e.g., z.string().min(1)) were sent as empty strings instead
of being unset. This prevented schema defaults from applying.

Solution: coerce empty strings with minLength > 0 to undefined, allowing
schema defaults to take effect during validation.

Added 5 unit tests covering edge cases.
Fixes openclaw#85807

When forceNewMessage() races with an in-flight Telegram preview send,
the generation-mismatch path in draft-stream.ts was deleting the
successfully sent message instead of retaining it.

Added `retain: true` to the onSupersededPreview call in the
generation-mismatch block, matching the behavior already used by
the text-splitting superseded path at line 215-220.

Test updated to verify retain field is set correctly.
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram app: web-ui App: web-ui size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 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: the Telegram fix is already isolated in #85878, while this branch mixes in unrelated Control UI config-save work that is separately tracked by #85903 and still lacks live Telegram proof.

Canonical path: Close this mixed duplicate PR, continue the Telegram fix through #85878, and keep the Control UI provider-defaults work in #85903.

So I’m closing this here and keeping the remaining discussion on #85878 and #85903.

Review details

Best possible solution:

Close this mixed duplicate PR, continue the Telegram fix through #85878, and keep the Control UI provider-defaults work in #85903.

Do we have a high-confidence way to reproduce the issue?

Yes by source, not by live run: current main’s generation-mismatch path calls onSupersededPreview without retain, and the dispatcher deletes non-retained previews. I did not establish a live Telegram reproduction in this read-only review.

Is this the best way to solve the issue?

No for this branch: the one-line Telegram fix is plausible, but the best maintainable path is the narrower superseding Telegram PR plus the separate UI config-save PR, not a mixed duplicate branch.

Security review:

Security review cleared: No concrete security or supply-chain concern was found; the diff touches Telegram message retention and UI config coercion, with no dependency, workflow, secret, or package-resolution changes.

What I checked:

Likely related people:

  • steipete: Authored the narrower superseding Telegram PR and appears in recent GitHub file history for adjacent Telegram dispatch/topic work. (role: canonical follow-up owner and recent area contributor; confidence: high; commits: 06a890841071, 3cf806d17215, 69cea57f691f; files: extensions/telegram/src/draft-stream.ts, extensions/telegram/src/draft-stream.test.ts, extensions/telegram/src/bot-message-dispatch.ts)
  • obviyus: GitHub file history shows prior work on Telegram draft streaming, including over-limit preview chaining and native draft preview transport changes. (role: draft-stream contributor; confidence: medium; commits: 10bbed8a6d30, 2a4dd8925323; files: extensions/telegram/src/draft-stream.ts)
  • Shakker: Local blame for the current checkout attributes the inspected generation-mismatch and superseded-preview cleanup lines to this current-main snapshot commit; the repository is shallow/grafted, so this is useful but less complete than full PR history. (role: current-main line provenance; confidence: medium; commits: bfcd8017c480; files: extensions/telegram/src/draft-stream.ts, extensions/telegram/src/bot-message-dispatch.ts)

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

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 24, 2026
@EnjouZeratul

Copy link
Copy Markdown
Contributor Author

My apologies for the confusion. I made two mistakes here:

  1. I should have checked for existing PRs first - I see now that @NianJiuZst already submitted the fix in Fix Telegram preview retention on generation mismatch #85825.

  2. I forgot to create a clean new branch, which accidentally included unrelated UI config changes from my previous PR.

Thanks to @NianJiuZst for the original fix, and to @steipete for the clean rebuild in #85878.

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 channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram preview message deleted on generation mismatch race in sendMessageTransportPreview (missing retain:true)

1 participant