Bug
The TELEGRAM_FORMAT rule tells the LLM to escape MarkdownV2 special characters (_, *, [, ], (, ), ~, `, >, #, +, -, =, |, {, }, ., !) by prefixing them with \. The outbound pipeline (markdownToTelegramHtml → convertInline) does NOT strip these escape sequences — it ships the reply to Telegram with parse_mode: "HTML", and the HTML parser doesn't interpret \. as ..
Result: every Telegram reply from the bot contains literal \ characters before ., !, -, (, ) throughout. Visible noise, broken formatting.
Source-level trace
| Step |
What |
Where |
| 1 |
TELEGRAM_FORMAT constant with "Escape special characters" rule |
daemon.js:67371-67380 (line 67375 is the rule itself) |
| 2 |
getResponseFormatHint(platform) returns the constant |
daemon.js:67354-67356 |
| 3 |
buildInboundMetaPayload calls it, packs into response_format field |
daemon.js:320838-320850 (line 320841) |
| 4 |
buildInboundContextPrefix wraps payload in payload._meta and emits <inbound-context>...</inbound-context> JSON |
daemon.js:320807-320836 (line 320813 adds _meta wrapper) |
| 5 |
buildMessageParts prepends that JSON to effectiveContent (user-role message to LLM) |
daemon.js:320911-320916 (line 320915) |
| 6 |
applySystemReminder also injects a second copy via inboundMetaProvider → buildInboundMetaBlock as # Inbound Message Context markdown |
daemon.js:334206-334215, daemon.js:339459-339462, daemon.js:339082-339091 |
| 7 |
LLM reads rule, obeys, emits \ before MarkdownV2 chars as part of output tokens |
(model behaviour) |
| 8 |
markdownToTelegramHtml → convertInline runs escapeHtml(processed) (line 230490) which doesn't touch \ |
daemon.js:230405-230504 |
| 9 |
sendWithFallback sends HTML to Telegram Bot API with parse_mode: "HTML" |
daemon.js:230761-230779 |
| 10 |
HTML parser doesn't know about MarkdownV2 — renders \ literally |
(Telegram side) |
Root cause
Mismatch between instruction (LLM must add \ per MarkdownV2) and pipeline (HTML converter + Telegram HTML parser don't process MarkdownV2 escapes).
Reproduction
- Send any message to the bot via Telegram.
- Receive a reply.
- Observe literal
\ before ., !, -, (, ) throughout.
Expected
One of:
- LLM is not instructed to escape (narrow fix — drop the rule), OR
- Outbound converter strips MarkdownV2 escapes before HTML conversion (wide fix — add a pass in
convertInline).
Suggested fixes
Narrow (one-line): Remove line 67375 from TELEGRAM_FORMAT. LLM stops adding \, visual output is clean. Risk: minimal.
Wide: Add a pre-pass in convertInline (around line 230490, before escapeHtml) that strips \ before MarkdownV2 special chars. Rule stays valid for the day the pipeline switches to real MarkdownV2, and current HTML pipeline produces clean output.
Environment
- Product: MiniMax Code (Mac)
- Platform: macOS
- Channel: Telegram (Bot API)
- Affected component:
daemon.js outbound text pipeline for Telegram
Bug
The
TELEGRAM_FORMATrule tells the LLM to escape MarkdownV2 special characters (_,*,[,],(,),~,`,>,#,+,-,=,|,{,},.,!) by prefixing them with\. The outbound pipeline (markdownToTelegramHtml→convertInline) does NOT strip these escape sequences — it ships the reply to Telegram withparse_mode: "HTML", and the HTML parser doesn't interpret\.as..Result: every Telegram reply from the bot contains literal
\characters before.,!,-,(,)throughout. Visible noise, broken formatting.Source-level trace
TELEGRAM_FORMATconstant with "Escape special characters" ruledaemon.js:67371-67380(line 67375 is the rule itself)getResponseFormatHint(platform)returns the constantdaemon.js:67354-67356buildInboundMetaPayloadcalls it, packs intoresponse_formatfielddaemon.js:320838-320850(line 320841)buildInboundContextPrefixwraps payload inpayload._metaand emits<inbound-context>...</inbound-context>JSONdaemon.js:320807-320836(line 320813 adds_metawrapper)buildMessagePartsprepends that JSON toeffectiveContent(user-role message to LLM)daemon.js:320911-320916(line 320915)applySystemReminderalso injects a second copy viainboundMetaProvider→buildInboundMetaBlockas# Inbound Message Contextmarkdowndaemon.js:334206-334215,daemon.js:339459-339462,daemon.js:339082-339091\before MarkdownV2 chars as part of output tokensmarkdownToTelegramHtml→convertInlinerunsescapeHtml(processed)(line 230490) which doesn't touch\daemon.js:230405-230504sendWithFallbacksends HTML to Telegram Bot API withparse_mode: "HTML"daemon.js:230761-230779\literallyRoot cause
Mismatch between instruction (LLM must add
\per MarkdownV2) and pipeline (HTML converter + Telegram HTML parser don't process MarkdownV2 escapes).Reproduction
\before.,!,-,(,)throughout.Expected
One of:
convertInline).Suggested fixes
Narrow (one-line): Remove line 67375 from
TELEGRAM_FORMAT. LLM stops adding\, visual output is clean. Risk: minimal.Wide: Add a pre-pass in
convertInline(around line 230490, beforeescapeHtml) that strips\before MarkdownV2 special chars. Rule stays valid for the day the pipeline switches to real MarkdownV2, and current HTML pipeline produces clean output.Environment
daemon.jsoutbound text pipeline for Telegram