Skip to content

fix(review): persist annotation deletions so they don't resurrect on refresh (#948) - #951

Merged
backnotprop merged 1 commit into
mainfrom
fix/review-annotation-delete-persist-948
Jun 22, 2026
Merged

backnotprop merged 1 commit into
mainfrom
fix/review-annotation-delete-persist-948

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

The bug (#948)

In plannotator review, you delete annotations from the right sidebar — the list clears — but after a refresh they come back. Reported by @alexanderkreidich (v0.21.0, macOS/Chrome).

Root cause

The code-review autosave (packages/ui/hooks/useCodeAnnotationDraft.ts) skipped saving when the list was empty:

if (annotations.length === 0 && viewedFiles.size === 0) return;

So deleting the last annotation never overwrote the stale draft on the server. On refresh the mount-time GET /api/draft found it and the "Draft Recovered" dialog re-offered the deleted annotations. (Partial deletes persisted fine; the trigger is delete-to-zero with no viewed files.)

Fix

Mirror the proven plan-side useAnnotationDraft pattern:

  1. Delete-on-empty: when cleared, DELETE /api/draft?generation=N with a tombstone (so it can't resurface and a late save can't revive it) instead of skipping.
  2. Engagement guard: an empty state only triggers a delete once the user has actually authored annotations this session — keyed on user-authored (non-source) annotations only. viewedFiles are seeded from GitHub on mount, and external/SSE annotations have their own lifecycle; counting either would let a fresh load or external churn wrongly delete an unrestored draft.
  3. Timer clear in restoreDraft/dismissDraft so a stale debounced save can't fire after restore/dismiss.

Tests

New real-stack regression tests (real hook + real disk layer via an /api/draft shim), each verified to fail against the corresponding bug:

  • delete-to-empty removes the draft → fresh mount shows no recovery banner;
  • a fresh/unengaged session preserves an unrestored draft on disk;
  • external-annotation churn issues no delete (engagement not armed by external tools).

DOM_TESTS=1 bun test codeAnnotationDraftPersistence — 3/3. Typecheck clean, build:review clean, sibling plan-side draft tests 13/13.

Scope note

A separate, pre-existing bug nearby (not this PR): external-tool annotations re-merge from the live SSE stream independent of the draft (App.tsx:394-410) — a different lifecycle, deserves its own issue.

Review

Diagnosed and verified via adversarial review (correctness + regression passes); a regression reviewer caught that engagement must key on user-authored annotations, now fixed and guarded.

Closes #948

…refresh (#948)

The code-review autosave skipped saving when the annotation list was empty
(`if (annotations.length === 0 && viewedFiles.size === 0) return`). So
deleting the last annotation never overwrote the stale draft on the server;
on refresh the draft-recovery dialog offered the deleted annotations back.

Mirror the plan-side useAnnotationDraft pattern: when the list is cleared,
DELETE the draft with a generation tombstone (so it can't resurface and a
late save can't revive it) instead of skipping. Guarded so an empty state
only triggers a delete once the user has actually authored annotations this
session — keyed on user-authored (non-source) annotations only, because
viewedFiles are seeded from GitHub on mount and external/SSE annotations have
their own lifecycle; counting either would let a fresh load or external churn
wrongly delete an unrestored draft. Also clear the pending autosave timer in
restoreDraft/dismissDraft so a stale save can't fire after restore/dismiss.

Adds real-stack regression tests (hook + disk layer via an /api/draft shim):
delete-to-empty removes the draft, a fresh/unengaged session preserves an
unrestored draft, and external-annotation churn issues no delete.

Reported by @alexanderkreidich.

Closes #948
@backnotprop
backnotprop merged commit 567cf80 into main Jun 22, 2026
13 checks passed
@backnotprop
backnotprop deleted the fix/review-annotation-delete-persist-948 branch June 22, 2026 14:05
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: deleted review annotations reappear after refresh

1 participant