Repository navigation
refactor(telegram): unify formatted-to-plain send degradation in one orchestrator - #121990
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
…orchestrator Route rich and HTML send/edit degradation through one shared policy. Add parity coverage and empty-content edit/preview regressions.
57584f2 to
e2f0db6
Compare
Telegram E2E proof (exact head e2f0db6)Live drive via the QA userbot lane (TDLib user observer, mock provider, ephemeral gateway from this head; DM to the SUT bot, ids redacted). Degradation drive — mock reply engineered so the rendered HTML contains a Telegram-supported-shape tag with a server-invalid value (
Control drive — same pipeline, valid HTML (
The entity differential (bold entity present in control, zero entities after the invalid-emoji reply) is the discriminator: the degraded turn's HTML send was rejected and recovered as plain text end to end on real Telegram. Note the funnel intentionally suppresses expected-fallback 400s from API-error logging ( Artifacts retained locally: The preview/edit empty-content parity fix is additionally pinned by the regression tests in this PR, which were verified to fail on pre-fix code (plain retry never issued). |
…orchestrator (openclaw#121990) The Telegram send-funnel parity invariant (durable and streaming funnels must degrade formatted sends identically) was prose-enforced and had drifted: draft previews and message edits only degraded on HTML-parse 400s, not empty-content 400s. One orchestrator (withTelegramPlainFallback) now owns classification, guard, logging, and plain-chunk planning for all 11 call sites; withTelegramHtmlParseFallback and buildTelegramPlainFallbackPlan are deleted. Net -29 production LOC. Behavior change: previews/edits recover empty-content 400s as plain text; degrade logs unify to `degrade=plain-fallback:<trigger>`. Co-authored-by: Ayaan Zaidi <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
What Problem This Solves
The Telegram plugin's "send funnel parity" invariant (
extensions/telegram/AGENTS.md: the durable funnel and the streaming funnel must degrade identically on formatted-send 400s) was enforced only by prose and review. The formatted→plain recovery was hand-rolled at 11 call sites acrosssend-message-text.ts,send-edit.ts,bot/delivery.send.ts, anddraft-stream.ts, and had already drifted: draft previews and message edits degraded only on HTML-parse errors, not on empty-content 400s, so the same model output that recovered gracefully as a final message threw mid-preview.Why This Change Was Made
One orchestrator,
withTelegramPlainFallback(inrich-plain-fallback.ts, the file that already owns the shared classification), now owns error classification (richvshtmltrigger sets), the empty-fallback-text guard, the unified degrade log line, and plain-chunk planning. All 11 sites supply only their transport primitives (sendFormatted/sendPlain).withTelegramHtmlParseFallbackandbuildTelegramPlainFallbackPlanare deleted; a new degradation physically cannot land in one funnel only.Intentional behavior changes (the drift this PR kills):
editMessageTelegramnow degrade to plain text on empty-content 400s, matching the durable funnel.telegram <context> degrade=plain-fallback:<trigger>: <error>(previouslyrich-degrade=plain-fallback:plus per-site wordings).Named follow-up: the voice-caption too-long recovery in
bot/delivery.replies.tsremains a separate hand-rolled ladder (different recovery shape: resend captionless + separate text); unifying it belongs with the media ladder (sendTelegramCaptionedMediaWithFallback), not this text-send change.User Impact
Streaming previews no longer die mid-stream on model output that renders empty after formatting; users get the plain-text preview instead of a stalled draft. No config changes, no API surface changes outside the plugin.
Evidence
rich-plain-fallback.test.ts): kind × {rich-entity-invalid, rich-structure-invalid, rich-content-required, html-parse, empty-content, non-degradable} → degrade vs rethrow.draft-stream.test.ts"falls back to plain preview text when an HTML edit renders empty",send.test.ts"falls back to plain text when an HTML edit renders empty" — ran the new tests against the pre-change production sources: 3 failed there, all pass after.node scripts/run-vitest.mjsoversend*,rich-plain-fallback*,draft-stream*,bot/delivery*— 9 files, 526 tests passed (87s).pnpm tsgo:extensionsclean,scripts/run-oxlint.mjs+ telegram boundary dts clean,git diff --checkclean.