Repository navigation
fix(bots): render Markdown in saved answers to item questions - #51002
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
A free-text answer to a closed bot item question showed its raw Markdown and bot mention syntax on the folded "Question → answer" line. The line now draws the owner's own words with the item's Markdown renderer, so formatting and mentions look as they do in a regular item comment. Picked quick replies, including labels whose runs of spaces were collapsed when sent, stay plain text as their chip wrote them. Fixes stablyai#50996 Co-authored-by: Daniel Lafraia <[email protected]>
dda68f1 to
de6b40a
Compare
ELI5
When you answer a bot's question on an item in your own words, and later look back at that item, your answer now shows formatting (bold, code, links) and bot mentions the same way a normal item comment does, instead of raw
**and[Bot: ...](bot:...)text.What Changed
BotItemMarkdown, the same memoized renderer item comments use. The first paragraph runs on after the arrow. Picked quick replies stay plain text, written as their chip wrote them, so a label like1. Merge itdoes not become a numbered list.botItemAnswer(insrc/shared/bots/bot-item-answer-lines.ts) now returns{ words, picked }instead of only the words. Picks are read from the line's own answer instead of a rebuilt comment. A sent line collapses runs of spaces, so a label likeThe *lead*is also matched against its space-collapsed form and still counts as a pick.botItemAnswerWordsstays as a wrapper with the same output for existing callers, including mobile and older clients.BotItemAnswerLinerenders a<div>(Markdown blocks cannot sit inside a<p>), and a plain answer keeps its line breaks.Why
Saved free-text answers should look the same whether they show as a comment or folded into the question. Reusing the item comment renderer gives the same sanitizing, mention chips and link handling, with no second Markdown path. Quick replies stay plain because those words are fixed labels, not something the owner wrote.
Linked Issue
Fixes #50996
Original fix by @lafraia in #51002; final version reworked during the bug bash.
Visual Proof
N/A for new captures. No proof artifacts were recorded for the reworked version, and GUI runs are not allowed on the build machine for this landing. The contributor's original before/after captures of the same component, from the first version of this PR, show the user-facing change:
The
answeredInWordsfixture inBotItemCommentCard.fixture.tsxrenders the after state.Testing
**bold**, inline code and a[Bot: Name](bot:id)mention showed the raw syntax on the closed question line.BotItemQuestionLines.test.tsx(Markdown and mention chip drawn, no nested<p>, quick replies including1. ...and space-run labels stay literal, plain line breaks kept) andbot-item-answer-lines.test.ts(picks matched against space-collapsed labels per question).vitest runacrosssrc/renderer/src/components/bots/itemsandsrc/shared/bots/bot-item-answer-lines.test.ts: 12 files, 85 tests pass. oxfmt, oxlint, anti-slop oxlint, native code-quality oxlint, ast-grep and the changed-code quality gate are clean on the touched files.Performance
None that matters. The parsing runs per answered question line when an item card renders, not on a terminal, polling or startup path. Measured
botItemAnswerWordsold vs new (µs per card, 2000 runs): typical pick 0.55 → 0.59, typical free text 0.80 → 0.82–0.89, a 19 KB free-text answer 1.72 → 1.65–1.70, an adversarial 8 questions × 10 space-run labels 1.89 → 1.87–1.92. All within noise. The space-collapsed matching only runs when a label has a run of spaces. Free-text answers now go through the memoizedBotItemMarkdown, the same cost as the matching comment. The work is per card, with no shared store or selector change, so updating one item does not recompute any other.Risk
Level: Low. The riskiest part is how a saved free-text answer wraps and displays on its question line. If it broke, users would see formatting or spacing problems in historical answers. Saved data, sends and the shared
botItemAnswerWordsoutput are unchanged. Back out with a plain revert.Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance. Markdown goes through the existing chat sanitizer and mention handling. No platform, SSH or remote-specific code. Mobile and older clients keep using
botItemAnswerWords, whose output is unchanged.Reported by @lafraia