Issue
Inline document citations in assistant chat messages delete the whitespace that follows them. The citation link itself renders correctly, but the text that comes after the citation is jammed onto the end of the closing ) instead of starting a new paragraph, list item, or sentence. This affects every user reading a cited answer in chat.
Steps to Reproduce
-
Ask a question in a workspace that returns document citations (personal, group, or public).
-
Have the model answer with a citation followed by a blank line and then more prose, which is its normal output shape:
... used to support cited answers in chat. (Source: application_workflows.md, Page: 1) [#181b54f7-fcf9-479b-a58b-81a5da3ba251_1]
Admins can configure the extraction approach for images and PDFs under **Admin Settings > Search & Extract**.
-
Look at the rendered assistant message.
Expected Behavior
The paragraph after the citation renders as its own block, exactly as the model wrote it:
... used to support cited answers in chat. (Source: application_workflows.md, Page: 1)
Admins can configure the extraction approach for images and PDFs under Admin Settings > Search & Extract.
Actual Behavior
The blank line is gone and the following paragraph is absorbed into the line — and, when the citation is inside a numbered list, into the list item:
- Grounded chat: ... used to support cited answers in chat. (Source: application_workflows.md, Page: 1)Admins can configure the extraction approach for images and PDFs under Admin Settings > Search & Extract. The available modes are:
Other observed forms in the same message:
...warrants it (Source: document-intelligence.md, Page: 1)For best results, upload clear, readable images.
...(Source: uploading_documents.md, Page: 1)Thank you, Paul.
Impact
- Message structure is visibly wrong: paragraphs collapse into the preceding list item, headings and bullets shift, and sentences run together with no space after
).
- The damage happens before markdown parsing, so it changes how the whole remainder of the block is interpreted, not just the characters next to the citation.
- Copied and exported message markdown is built from the same parsed output, so it inherits the lost line breaks.
- Content is still readable, so this is a presentation defect rather than a data-loss or security issue.
Notes
Suspected root cause is in parseCitations() in application/single_app/static/js/chat/chat-citations.js:
const citationRegex = /\(Source:\s*(...),\s*(Page(?:s)?|Sheet(?:s)?|Location):\s*(...)\)\s*((?:\[#.*?\]\s*)+)/gi;
The trailing \s* inside the repeated bracket group is greedy and matches newlines, so it consumes the whitespace after the [#citation-id] marker. The replacement callback returns only the rebuilt (Source: ...) string and never re-emits that whitespace.
parseCitations() runs on raw markdown before marked.parse() (chat-messages.js, renderAiMessageContent()), so a swallowed \n\n changes markdown block parsing and the following paragraph becomes a continuation of the current block.
The cleanup pass a few lines below has the same class of defect in the other direction — its leading \s* can consume the newlines before a leftover [#guid] bracket that starts its own paragraph.
Reproduced against the production regex in isolation:
Input : "... in chat. (Source: application_workflows.md, Page: 1) [#181b54f7-..._1]\n\nAdmins can configure ..."
Output: "... in chat. (Source: application_workflows.md, Page: 1)Admins can configure ..."
Fix direction: preserve the trailing whitespace captured by the bracket group and re-emit it, and restrict the cleanup pass to horizontal whitespace so line structure survives. Server-side functions_citation_tracking.py is not implicated — it matches with a non-consuming lookahead.
Issue
Inline document citations in assistant chat messages delete the whitespace that follows them. The citation link itself renders correctly, but the text that comes after the citation is jammed onto the end of the closing
)instead of starting a new paragraph, list item, or sentence. This affects every user reading a cited answer in chat.Steps to Reproduce
Ask a question in a workspace that returns document citations (personal, group, or public).
Have the model answer with a citation followed by a blank line and then more prose, which is its normal output shape:
Look at the rendered assistant message.
Expected Behavior
The paragraph after the citation renders as its own block, exactly as the model wrote it:
Actual Behavior
The blank line is gone and the following paragraph is absorbed into the line — and, when the citation is inside a numbered list, into the list item:
Other observed forms in the same message:
...warrants it (Source: document-intelligence.md, Page: 1)For best results, upload clear, readable images....(Source: uploading_documents.md, Page: 1)Thank you, Paul.Impact
).Notes
Suspected root cause is in
parseCitations()inapplication/single_app/static/js/chat/chat-citations.js:The trailing
\s*inside the repeated bracket group is greedy and matches newlines, so it consumes the whitespace after the[#citation-id]marker. The replacement callback returns only the rebuilt(Source: ...)string and never re-emits that whitespace.parseCitations()runs on raw markdown beforemarked.parse()(chat-messages.js,renderAiMessageContent()), so a swallowed\n\nchanges markdown block parsing and the following paragraph becomes a continuation of the current block.The cleanup pass a few lines below has the same class of defect in the other direction — its leading
\s*can consume the newlines before a leftover[#guid]bracket that starts its own paragraph.Reproduced against the production regex in isolation:
Fix direction: preserve the trailing whitespace captured by the bracket group and re-emit it, and restrict the cleanup pass to horizontal whitespace so line structure survives. Server-side
functions_citation_tracking.pyis not implicated — it matches with a non-consuming lookahead.