Recover malformed Nova citation closing tags - #1389
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label Main to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
supermemory-mcp | 4d55720 | Jul 31 2026, 02:10 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
supermemory-app | 4d55720 | Commit Preview URL Branch Preview URL |
Jul 31 2026, 02:12 PM |
There was a problem hiding this comment.
@ishaanxgupta why citiations are being malformed in the first place? maybe we have fix from the root itself if i am not wrong
|
Claude finished @ishaanxgupta's task in 2m 23s —— View job PR Review Complete
Summary: Reviewed the malformed Nova citation recovery implementation. No bugs or security issues found. The code is well-structured with proper safety checks, safe regexes (no ReDoS), and appropriate test coverage. Submitted a clean review with score 10/10. |
There was a problem hiding this comment.
Overview: This PR adds defensive parsing to recover malformed Nova citation closing tags (e.g., </response">) and removes duplicated text artifacts that can result from these malformations.
Issues found: None — this looks good to ship.
Analysis:
The implementation is well-structured with clear helper functions:
parseClosingTagAtcorrectly identifies both valid and malformed closing tags using a safe regex/^[\s"']*$/that only allows whitespace and quotes between</responseand>findClosingTagproperly advances the cursor to prevent infinite loopsconsumeDuplicatedMalformedClosehas appropriate safety checks: it verifies the trailing content matches the inner text (trimmed), contains no HTML (<), and is non-empty before consuming the duplicate
Security considerations are properly handled:
- Source IDs are validated with
isSafeSourceIdbefore use - URI encoding is applied when embedding source IDs in links
- No ReDoS risk in the regexes used
The tests cover the key scenarios:
- Malformed closing tag with duplicated text
- Malformed closing tag without duplicated text
- Both
parseSourceAnnotatedMarkdownandstripSourceMarkupare tested
Re: @MaheshtheDev's question about why citations are malformed — this is defensive coding against LLM output quirks. The model occasionally produces malformed markup, and handling it gracefully here prevents broken UI output. Fixing at the source (prompt engineering) is ideal but this fallback is appropriate.
Score: 10/10

Summary
today</response>