Skip to content

fix(annotate): include original file annotations when submitting from linked doc view#536

Merged
backnotprop merged 4 commits intomainfrom
fix/crossdoc-annotations
Apr 11, 2026
Merged

fix(annotate): include original file annotations when submitting from linked doc view#536
backnotprop merged 4 commits intomainfrom
fix/crossdoc-annotations

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

  • Fixes a data loss bug where annotations on the original file were silently dropped when clicking "Send Annotations" while viewing a linked document in annotate mode
  • getDocAnnotations() now includes stashed original-file annotations via a new sourceFilePath option on useLinkedDoc
  • docAnnotationCount updates immediately on navigation (not only on back()), so button visibility and exit warnings reflect the true annotation count

Root cause

useLinkedDoc.open() stashes original-file annotations into savedPlanState (a ref), then swaps React state to the linked doc's annotations. But getDocAnnotations() only read from docCache + the current linked doc — never from savedPlanState. The original file's annotations became invisible to the entire submission pipeline (annotationsOutput memo → handleAnnotateFeedback/api/feedback).

Confirmed via runtime instrumentation: at submit time, savedPlanState held 1 annotation but getDocAnnotations() returned a Map without it.

Scope

  • Plan mode: Unaffected — buttons are already hidden while viewing linked docs, forcing back() first
  • Folder mode: Unaffected — the "original" document is an empty shell with no annotations to lose
  • annotate-last: Unaffected — no file path to key against

Test plan

  • plannotator annotate original.md where original.md links to linked.md
  • Annotate original, follow link, annotate linked doc, click "Send Annotations" without navigating back
  • Verify terminal output contains feedback from both files
  • Verify navigating back then submitting still works correctly
  • Verify folder annotation mode (plannotator annotate <dir>) is unaffected

Closes #535

… linked doc view

When using `plannotator annotate` on a file with markdown links, annotations
on the original file were silently dropped if the user clicked "Send
Annotations" while viewing a linked document. The root cause was that
`getDocAnnotations()` only read from `docCache` (previously-visited linked
docs) and the current linked doc — it never read from `savedPlanState`, where
the original file's annotations are stashed during navigation.

This adds a `sourceFilePath` option to `useLinkedDoc` so the hook can key the
stashed annotations in the returned Map. Also updates `docAnnotationCount` in
`open()` so button visibility and exit warnings reflect reality immediately,
not only after calling `back()`.

Closes #535

For provenance purposes, this commit was AI assisted.
…navigation

The first branch of open() set docAnnotationCount from only the original
file's annotations, ignoring any linked docs already cached from prior
navigation. After original → linkedA → back → linkedB, the count dropped
to 0 if the original had no annotations, hiding the Send Annotations button
despite linkedA's annotations sitting in docCache.

Also adds defensive spread copies for savedPlanState arrays in
getDocAnnotations() to match the hook's existing pattern.

For provenance purposes, this commit was AI assisted.
…vent double-counting

When navigating to a previously-cached linked doc, the destination's
cached annotations were included in docAnnotationCount AND loaded into
allAnnotations, causing the exit warning to report an inflated count.
Skip the destination filepath when summing the non-active total.

For provenance purposes, this commit was AI assisted.
When a linked document contains a link back to the source file (e.g.,
original.md → design.md → backlink to original.md), opening it as a
linked doc created two competing Map entries for the same filepath in
getDocAnnotations(). The empty linked-doc entry overwrote the stashed
annotations, silently dropping them.

Now detects when the resolved destination matches sourceFilePath and
routes through back() instead, which caches the current linked doc
and restores the source file with its annotations intact.

For provenance purposes, this commit was AI assisted.
@backnotprop backnotprop merged commit 171691c into main Apr 11, 2026
7 checks passed
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.

Bug: annotations on original file lost when sending from linked document view

1 participant