Repository navigation
fix(notes): render structured overview markdown on the share email and the web app - #12659
Conversation
…b app Notes v2 stores conversation.structured.overview as markdown. The share email escaped each line as plain text and the signed-in web app put the raw string in a <p>, so two of three surfaces showed literal ## and -. Email now uses a closed markdown-it-py subset; the web app reuses react-markdown. Co-Authored-By: cursor grok-4.6 <[email protected]> Co-authored-by: Cursor <[email protected]>
markdown-it-py is in the runtime lock but not the OpenAPI inventory venv, so importing it from share_email broke route-policy inventory. A closed subset parser keeps the email HTML safe without that import. Co-Authored-By: cursor grok-4.6 <[email protected]> Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
4 issues found across 6 files
Confidence score: 3/5
- In
backend/utils/conversations/overview_markdown.py, the_ITALICpass can treat ordinary asterisks such as2 * 3 * 4as emphasis, producing incorrect email formatting; constrain emphasis matching to valid Markdown delimiters or parse before inserting tags. - In
backend/utils/conversations/overview_markdown.py, underscore emphasis remains visible in email while the web app renders it, causing inconsistent overview presentation; support_italic_and__bold__forms. - In
backend/utils/conversations/overview_markdown.py, link matching truncates URLs containing parentheses and exposes the trailing text, breaking common documentation links; update URL parsing to handle balanced parentheses. - In
web/app/src/components/conversations/ConversationDetailPanel.tsx, default ReactMarkdown link behavior opens overview links in the current tab, potentially taking users away from the app; add a link renderer with the intended target and navigation attributes.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="web/app/src/components/conversations/ConversationDetailPanel.tsx">
<violation number="1" location="web/app/src/components/conversations/ConversationDetailPanel.tsx:173">
P3: Overview links now render as clickable <a> tags (the backend change emits https links), but ReactMarkdown is used with no custom link renderer, so clicking a link navigates the current tab away from the app and loses SPA state. Add a components prop that renders links with target="_blank" and rel="noopener noreferrer".</violation>
</file>
<file name="backend/utils/conversations/overview_markdown.py">
<violation number="1" location="backend/utils/conversations/overview_markdown.py:18">
P2: The link URL pattern `[^)\s]+` stops at the first `)`, so URLs containing parentheses (common on Wikipedia and many docs sites) are truncated and the trailing `)` leaks as visible text. For example `[wiki](https://en.wikipedia.org/wiki/Foo_(bar))` renders as `<a href="https://en.wikipedia.org/wiki/Foo_(bar">wiki</a>)`. Support balanced parentheses in the URL so the closing `)` of the markdown is not mistaken for a URL character.</violation>
<violation number="2" location="backend/utils/conversations/overview_markdown.py:20">
P2: When an overview uses standard underscore emphasis such as `_italic_` (or `__bold__`), the email leaves the Markdown delimiters visible while the web app renders emphasis. Support the underscore delimiter forms as part of the same subset, or explicitly normalize the generated overview syntax before sharing.</violation>
<violation number="3" location="backend/utils/conversations/overview_markdown.py:20">
P2: The `_ITALIC` regex is applied after `_LINK`/`_BOLD` insert their tags, and it over-matches. Two concrete failures: (1) ordinary prose asterisks get wrapped, e.g. `2 * 3 * 4` renders as `2 <em> 3 </em> 4` (CommonMark does not treat `* 3 *` as emphasis because the inner text starts/ends with whitespace); (2) when a URL contains `*`, the already-inserted `<a href="...">` is re-processed, e.g. `[a*b](https://x.com/foo*bar)` renders as `<a href="https://x.com/foo<em>bar">a</em>b</a>`, injecting `<em>` inside the href attribute and splitting the anchor into invalid HTML. Run the link substitution last (after emphasis), and tighten the emphasis delimiters so they don't match asterisks that are already inside emitted tags or that enclose whitespace.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| _OL_ITEM = re.compile(r'^\d+\.\s+(.+)$') | ||
| _LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)') | ||
| _BOLD = re.compile(r'\*\*(.+?)\*\*') | ||
| _ITALIC = re.compile(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)') |
There was a problem hiding this comment.
P2: When an overview uses standard underscore emphasis such as _italic_ (or __bold__), the email leaves the Markdown delimiters visible while the web app renders emphasis. Support the underscore delimiter forms as part of the same subset, or explicitly normalize the generated overview syntax before sharing.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/conversations/overview_markdown.py, line 20:
<comment>When an overview uses standard underscore emphasis such as `_italic_` (or `__bold__`), the email leaves the Markdown delimiters visible while the web app renders emphasis. Support the underscore delimiter forms as part of the same subset, or explicitly normalize the generated overview syntax before sharing.</comment>
<file context>
@@ -0,0 +1,82 @@
+_OL_ITEM = re.compile(r'^\d+\.\s+(.+)$')
+_LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)')
+_BOLD = re.compile(r'\*\*(.+?)\*\*')
+_ITALIC = re.compile(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)')
+
+
</file context>
| _HEADING = re.compile(r'^(#{1,6})\s+(.+?)\s*$') | ||
| _UL_ITEM = re.compile(r'^[-*+]\s+(.+)$') | ||
| _OL_ITEM = re.compile(r'^\d+\.\s+(.+)$') | ||
| _LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)') |
There was a problem hiding this comment.
P2: The link URL pattern [^)\s]+ stops at the first ), so URLs containing parentheses (common on Wikipedia and many docs sites) are truncated and the trailing ) leaks as visible text. For example [wiki](https://en.wikipedia.org/wiki/Foo_(bar)) renders as <a href="https://en.wikipedia.org/wiki/Foo_(bar">wiki</a>). Support balanced parentheses in the URL so the closing ) of the markdown is not mistaken for a URL character.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/conversations/overview_markdown.py, line 18:
<comment>The link URL pattern `[^)\s]+` stops at the first `)`, so URLs containing parentheses (common on Wikipedia and many docs sites) are truncated and the trailing `)` leaks as visible text. For example `[wiki](https://en.wikipedia.org/wiki/Foo_(bar))` renders as `<a href="https://en.wikipedia.org/wiki/Foo_(bar">wiki</a>)`. Support balanced parentheses in the URL so the closing `)` of the markdown is not mistaken for a URL character.</comment>
<file context>
@@ -0,0 +1,82 @@
+_HEADING = re.compile(r'^(#{1,6})\s+(.+?)\s*$')
+_UL_ITEM = re.compile(r'^[-*+]\s+(.+)$')
+_OL_ITEM = re.compile(r'^\d+\.\s+(.+)$')
+_LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)')
+_BOLD = re.compile(r'\*\*(.+?)\*\*')
+_ITALIC = re.compile(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)')
</file context>
| _OL_ITEM = re.compile(r'^\d+\.\s+(.+)$') | ||
| _LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)') | ||
| _BOLD = re.compile(r'\*\*(.+?)\*\*') | ||
| _ITALIC = re.compile(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)') |
There was a problem hiding this comment.
P2: The _ITALIC regex is applied after _LINK/_BOLD insert their tags, and it over-matches. Two concrete failures: (1) ordinary prose asterisks get wrapped, e.g. 2 * 3 * 4 renders as 2 <em> 3 </em> 4 (CommonMark does not treat * 3 * as emphasis because the inner text starts/ends with whitespace); (2) when a URL contains *, the already-inserted <a href="..."> is re-processed, e.g. [a*b](https://x.com/foo*bar) renders as <a href="https://x.com/foo<em>bar">a</em>b</a>, injecting <em> inside the href attribute and splitting the anchor into invalid HTML. Run the link substitution last (after emphasis), and tighten the emphasis delimiters so they don't match asterisks that are already inside emitted tags or that enclose whitespace.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/conversations/overview_markdown.py, line 20:
<comment>The `_ITALIC` regex is applied after `_LINK`/`_BOLD` insert their tags, and it over-matches. Two concrete failures: (1) ordinary prose asterisks get wrapped, e.g. `2 * 3 * 4` renders as `2 <em> 3 </em> 4` (CommonMark does not treat `* 3 *` as emphasis because the inner text starts/ends with whitespace); (2) when a URL contains `*`, the already-inserted `<a href="...">` is re-processed, e.g. `[a*b](https://x.com/foo*bar)` renders as `<a href="https://x.com/foo<em>bar">a</em>b</a>`, injecting `<em>` inside the href attribute and splitting the anchor into invalid HTML. Run the link substitution last (after emphasis), and tighten the emphasis delimiters so they don't match asterisks that are already inside emitted tags or that enclose whitespace.</comment>
<file context>
@@ -0,0 +1,82 @@
+_OL_ITEM = re.compile(r'^\d+\.\s+(.+)$')
+_LINK = re.compile(r'\[([^\]]+)\]\((https?://[^)\s]+)\)')
+_BOLD = re.compile(r'\*\*(.+?)\*\*')
+_ITALIC = re.compile(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)')
+
+
</file context>
| function OverviewMarkdown({ overview }: { overview: string }) { | ||
| return ( | ||
| <div className={OVERVIEW_MARKDOWN_CLASS}> | ||
| <ReactMarkdown>{overview}</ReactMarkdown> |
There was a problem hiding this comment.
P3: Overview links now render as clickable tags (the backend change emits https links), but ReactMarkdown is used with no custom link renderer, so clicking a link navigates the current tab away from the app and loses SPA state. Add a components prop that renders links with target="_blank" and rel="noopener noreferrer".
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At web/app/src/components/conversations/ConversationDetailPanel.tsx, line 173:
<comment>Overview links now render as clickable <a> tags (the backend change emits https links), but ReactMarkdown is used with no custom link renderer, so clicking a link navigates the current tab away from the app and loses SPA state. Add a components prop that renders links with target="_blank" and rel="noopener noreferrer".</comment>
<file context>
@@ -163,6 +164,17 @@ function ActionItemRow({ item }: { item: StructuredActionItem }) {
+function OverviewMarkdown({ overview }: { overview: string }) {
+ return (
+ <div className={OVERVIEW_MARKDOWN_CLASS}>
+ <ReactMarkdown>{overview}</ReactMarkdown>
+ </div>
+ );
</file context>
| <ReactMarkdown>{overview}</ReactMarkdown> | |
| <ReactMarkdown | |
| components={{ | |
| a: ({ href, children }) => ( | |
| <a href={href} target="_blank" rel="noopener noreferrer"> | |
| {children} | |
| </a> | |
| ), | |
| }} | |
| > | |
| {overview} | |
| </ReactMarkdown> |
What changed and why
Notes v2 stores
conversation.structured.overviewas markdown (headings, bullets, bold), but two of the three surfaces that show it still treated the field as plain text. The share email escaped each line and joined with<br>, so every external recipient of a notes-v2 summary saw literal##and-. The signed-in web app put{overview}in a<p>. Theh.omi.meshared page already rendered it withmarkdown-to-jsx; that is the reference behaviour.The web app now renders overview through
react-markdown, which it already ships (same approach asAppSummaryCard). Share email renders a closed markdown subset inoverview_markdown.py(stdlib only: headings, paragraphs, lists, bold, italic, andhttp(s)links). Every text node is escaped first, so injected HTML from the model never reaches the email. Quota, idempotency, sender, and subject logic are unchanged.Product invariants affected
none
How it was verified
Red-proof against the unfixed renderers:
_md.render(overview).strip()with the old'<br>'.join(overview.splitlines())madetest_build_summary_email_renders_notes_v2_markdownfail:assert '<h2>' in html.<ReactMarkdown>{overview}</ReactMarkdown>with{overview}made both vitest cases fail:Unable to find an accessible element with the role "heading" and name "Key points"; the DOM showed literal## Key points.After the fix:
cd backend && BACKEND_PYTEST_FILE_ISOLATION=1 .venv/bin/python -m pytest tests/unit/test_share_email.py::test_build_summary_email_renders_notes_v2_markdown tests/unit/test_share_email.py::test_build_summary_email_escapes_injected_html tests/unit/test_share_email.py::test_build_summary_email_plain_text_keeps_line_breaks tests/unit/test_share_email.py::test_build_summary_email_allows_https_links_only tests/unit/test_share_email.py::test_build_summary_email_escapes_and_links -q→ 5 passed.cd backend && BACKEND_PYTEST_FILE_ISOLATION=1 bash scripts/run-unit-ci.sh --changed-files /tmp/omi-notes-changed.txt→ exit 0.cd web/app && bunx vitest run --config vitest.config.mts src/components/conversations/__tests__/ConversationDetailPanel.overview.test.tsx→ 2 passed.cd backend && .venv/bin/python -m pyright --pythonpath .venv/bin/python utils/conversations/overview_markdown.py utils/conversations/share_email.py→ 0 errors.Mutation: replacing
_md.render(overview).strip()withreturn overviewmadetest_build_summary_email_renders_notes_v2_markdownfail again (assert '<h2>' in html). Restored.Could not exercise a live Resend send or a logged-in browser session against production data in this worktree; the unit tests drive the same
build_summary_emailandSummaryTabpaths those surfaces use.Tests
backend/tests/unit/test_share_email.py: notes-v2 sample renders<h2>/<ul>/<ol>/<strong>rather than literal##/-; injected<script>is escaped; pre-v2 plain-text overviews still keep line breaks;javascript:links are not emitted ashref.web/app/src/components/conversations/__tests__/ConversationDetailPanel.overview.test.tsx: heading and bullet list render as elements on both overview call sites (full-width and beside the location map).Failure class (fixes)
Failure-Class: FC-serialiser-dialect-mismatch-retypes-values