Skip to content

Recover malformed Nova citation closing tags - #1389

Open
ishaanxgupta wants to merge 1 commit into
codex/nova-thread-settings-persistencefrom
codex/nova-citation-markup-recovery
Open

Recover malformed Nova citation closing tags#1389
ishaanxgupta wants to merge 1 commit into
codex/nova-thread-settings-persistencefrom
codex/nova-citation-markup-recovery

Conversation

@ishaanxgupta

@ishaanxgupta ishaanxgupta commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recover Nova citations whose closing tag contains a stray quote
  • remove duplicated repair text such as today</response>
  • preserve source allowlisting and code-block safety

ishaanxgupta commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

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.
Learn more


How to use the Graphite Merge Queue

Add 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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 4d55720 Jul 31 2026, 02:10 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

Comment thread apps/web/lib/source-annotations.test.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishaanxgupta why citiations are being malformed in the first place? maybe we have fix from the root itself if i am not wrong

@ishaanxgupta
ishaanxgupta marked this pull request as ready for review August 3, 2026 14:30
@claude

claude Bot commented Aug 3, 2026

Copy link
Copy Markdown

Claude finished @ishaanxgupta's task in 2m 23s —— View job


PR Review Complete

  • Load review tools
  • Get PR diff and existing comments
  • Analyze code changes for bugs/security issues
  • Submit review

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.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • parseClosingTagAt correctly identifies both valid and malformed closing tags using a safe regex /^[\s"']*$/ that only allows whitespace and quotes between </response and >
  • findClosingTag properly advances the cursor to prevent infinite loops
  • consumeDuplicatedMalformedClose has 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 isSafeSourceId before 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 parseSourceAnnotatedMarkdown and stripSourceMarkup are 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants