Repository navigation
fix(review): persist annotation deletions so they don't resurrect on refresh (#948) - #951
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:So deleting the last annotation never overwrote the stale draft on the server. On refresh the mount-time
GET /api/draftfound 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
useAnnotationDraftpattern:DELETE /api/draft?generation=Nwith a tombstone (so it can't resurface and a late save can't revive it) instead of skipping.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.restoreDraft/dismissDraftso a stale debounced save can't fire after restore/dismiss.Tests
New real-stack regression tests (real hook + real disk layer via an
/api/draftshim), each verified to fail against the corresponding bug:DOM_TESTS=1 bun test codeAnnotationDraftPersistence— 3/3. Typecheck clean,build:reviewclean, 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