Skip to content

fix(documents): keep AI document writes when citation parsing fails - #865

Draft
posthog[bot] wants to merge 2 commits into
mainfrom
posthog-self-driving/fixdocuments-keep-ai-document-writes-2e6103
Draft

posthog[bot] wants to merge 2 commits into
mainfrom
posthog-self-driving/fixdocuments-keep-ai-document-writes-2e6103

Conversation

@posthog

@posthog posthog Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • A user can lose a document that the AI creates. A linkedom TypeError in citation parsing escapes resolveDocumentCitations and fails the full workspace_create_items call (also workspace_edit_item).
  • Error tracking shows 1 occurrence in 30 days. The input that triggers the crash is unknown, and the exception carries no data to reproduce it.

Origin

  • Error tracking: issue
  • First signal: 2026-11-08
  • Inbox report: open
  • Task started by: auto-start, after the report was rated P3 and ready to fix

Changes

  • resolveDocumentCitations catches a failure in the citation read or apply step and passes the original HTML on.
  • parseDocumentAiHtml already turns each unresolved <citation> into its plain-text label, so the write continues with labels in place of links.
  • The failure goes to recordOperationalFailure as document_citation_resolution, with html_length, html_sha256, operation_id and workspace_id. The next occurrence gives an input fingerprint, not only a stack.
  • New test in create-items.test.ts: citation parsing throws → the document is created and the citation is plain text. The test fails without the fix.
Before After
Citation parse throws Tool call fails, document lost Document saved, citations as plain labels
Diagnosis data Stack only HTML length + SHA-256 per failure

Warning

parseDocumentAiHtml parses the same HTML with linkedom again. If the crash is deterministic for that input, the second parse can also throw. In that case workspace_create_items returns a per-item invalid_initial_content failure in place of a failed tool call. The model sees the failure and can retry, and other items in the batch continue. This fix does not guarantee that the document is saved in that case.

Testing

  • vp check: format, lint and typecheck pass.
  • vp test --run --project=node: all pass except src/integrations/posthog/build.test.ts. That test also fails on unchanged main in the sandbox, because of missing VITE_POSTHOG_* env.
  • Skipped: the workers test project and ciBuild. They need the Cloudflare runtime and build env, which the sandbox does not have.

Agent context

  • I did not find the trigger input. A short probe with <template> and mis-nested markup parsed cleanly, which matches the report's fuzzing result.
  • The catch is in the caller, not in readDocumentCitationRefs / applyDocumentCitationLocations. One catch covers both calls and has the workspace context for telemetry. It also covers the ref-index lookup, because a citation is not worth the full write.

Created with PostHog Desktop from this inbox report.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

A linkedom crash during citation resolution failed the whole
workspace_create_items call, so the user lost the document. The
resolver now records the failure with the HTML length and SHA-256 and
passes the HTML on unresolved. The sanitize step then keeps each
citation as a plain label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: d4435402-b918-431e-a5ac-3879975d365d
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0c851de9-3c02-4e0b-9a81-d4464dadb788

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: d4435402-b918-431e-a5ac-3879975d365d
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit c544a8a.

This branch has not been deployed

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants