Repository navigation
fix(review): derive a suggestion draft's cid from the hunk it materialises - #337
Merged
Merged
Conversation
nownabe
force-pushed
the
fix/308-stable-suggestion-cid
branch
from
September 20, 2026 07:36
fa20383 to
9a19848
Compare
nownabe
force-pushed
the
fix/308-stable-suggestion-cid
branch
from
September 20, 2026 08:38
9a19848 to
4c22ff7
Compare
nownabe
force-pushed
the
fix/308-stable-suggestion-cid
branch
from
September 20, 2026 08:56
4c22ff7 to
5c97c93
Compare
nownabe
force-pushed
the
fix/308-stable-suggestion-cid
branch
from
September 20, 2026 08:59
5c97c93 to
e49d4e0
Compare
…lises suggestionsToDrafts minted a fresh uuid on every Submit, so after a partial failure the retry created a second draft for an edit whose first draft was still parked (#307 keeps it) — both went out, two comments for one hunk. A hunk identical in (path, baseSha, range, replacement) to a Comment already in LocalState IS that Comment, so submitReview's existing inRepo skip now resubmits the parked draft instead of re-minting one.
nownabe
force-pushed
the
fix/308-stable-suggestion-cid
branch
from
September 20, 2026 09:02
e49d4e0 to
6cfdfd0
Compare
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
…#350) ## Why `docs/` had accumulated statements that no longer describe the code: a wire format two versions old, a storage backend that was never built, an ADR rule the UI does not follow, and superpowers specs that contradict the ADRs without saying so. A newcomer following the reading order AGENTS.md prescribes was being misled. Documentation only — no behaviour change. The ADRs were amended heavily between the issue and this PR (#303–#348), so every item was re-audited against the code on `main` (`9465718`) before editing; two were already fixed and are recorded as such below. ## What Per item of #294: 1. **ADR 0003 §7 "Legacy metadata is discarded"** → rewritten as "read, never rewritten". `lib/pr/metadata.ts` accepts `bark:v1` and its `docreview:v1` alias read-only (`extractMetadata` → `parseV1`) and maps them to the v2 shape; only an unparseable, invalid or unknown-version payload is dropped. The note says why there is no migration path: v1 payloads live in comment bodies on github.com, which no client release can rewrite. The two cross-references that repeated the old claim (ADR 0001 and ADR 0002 closing notes) now distinguish local legacy keys, which *are* dropped, from on-GitHub metadata, which is not. 2. **ADR 0004 §5 force-push bullet** → replaced. `GET contents?ref={sha}` addresses a commit object, not a ref, so a force-pushed sha normally stays fetchable (and PR heads are retained under `refs/pull/N/head`); re-anchoring proceeds through the line map as usual, and only a real 404 (garbage-collected commit, path or repo gone) leaves `FileContent` missing and yields `outdated`. Design doc §12-3 is closed accordingly. 3. **ADR 0005 §1/§5 manual refresh** → amended to match the code rather than gating the fab. `DebugFab` is always rendered; the Refresh button lives one click deeper, inside the debug popover, next to the internal-state dump. §5 carries an explicit amendment note saying that is accepted for v1 and why. `docs/design-principle.md`'s floating-controls bullet now states the rule the two FABs actually follow: reveal-only may ship, behaviour-changing is build-gated (`.role-fab` / `BARK_DEV_ROLE_SWITCH`). 4. **Design doc §7.1 / §7.7 / §10** → the raw-JSON `bark:v1` example is replaced by a real `bark:v2` base64 envelope with its decoded payload, the optional `resolved` and `quoteDigest`/`quoteLength` (#334) fields, and a pointer to `lib/pr/metadata.ts` as the authoritative field list. §7.7 now describes `chrome.storage.local` as the only store, lists the three per-PR keys, and states plainly that the IndexedDB plan was never built; §10's "persist state to IndexedDB" bullet and its ETag sentence are rewritten to what the client does. 5. **2026-06-18 resolve spec** → the superseded banner added by #310 is present and correct; verified, not touched. Its *plan* had none, so it got one. The design doc's authority paragraph now covers `docs/superpowers/` explicitly: history, not authority, and the absence of a banner is not a promise of currency. 6. **§7.9 `addressed` vs ADR 0004 `shifted`** → ADR 0004 §4 gains a paragraph stating that `shifted` is the raw mechanical signal and R9's `addressed` (#3) is derived from it plus the review rounds, specified separately and stored nowhere. Design doc §7.9 now references the ADR statuses instead of inventing its own, and notes that the `addressedBySha` in `lib/github.ts` is an unreferenced legacy type, not part of the model. 7. **Design doc §11 status** → R8 cross-file navigation is marked shipped (the changed-`.md` selector in `Topbar.tsx`, fed by `RemoteState.changedFiles`), so M5 is done and M4 (R9/R10) is the remaining open work. 8. **ADR statements not implemented** — decided in favour of the code: - **ADR 0002 §6** rewritten to describe materialise-at-submit as implemented: `SuggestionEdit` is persisted on its own `:suggestion-edits` key (400 ms debounce, read-modify-write per path), stays "live" in the editor until Submit, and only then becomes draft `Comment`s whose id is derived, not minted, from `(path, baseSha, range, replacement)` (#337/#308). The stale "lost on reload" trade-off and the auto-save Deferred item are replaced by the real consequence: two persistence paths, with folding `SuggestionEdit` into the Repository as the deferred work. - **ADR 0005 §2** "already-fetched pairs are retained" deleted. A full refresh replaces `RemoteState` wholesale, refetching every pair; the sentence is replaced by why that is fine (ETag `If-None-Match` on every GET, 304 costs no rate limit) and a pointer to the still-deferred persistent cache. - **ADR 0001 §4 `useAppState`** — already fixed by #329; §4 is the conflict policy and names no hook. Verified, no change. Also folded in (from the #299 agent, found while reviewing PR #349): - **AGENTS.md / README.md layout** described `lib/github.ts` as "GitHub API". It is not: it holds PR types and four pure helpers, while the client, the Repository pipeline, re-anchoring and the wire format all live in `lib/pr/`. Both are rewritten around `lib/pr/` as the place to start, and the non-existent `lib/reanchor.ts` is dropped. (`CLAUDE.md` is a symlink to `AGENTS.md`, so one edit covers both.) - **2026-06-21 author-role-derivation spec and plan** describe `deriveRole` and a `GitHubClient.getAuthenticatedUser` lookup; the live derivation is `computeRole` in `lib/pr/appstate.ts`, which also withholds `author` when `headRepo` is `null` (#273). Both files get a Superseded banner pointing there and at ADR 0002 §4. Every ADR amended here records it in the header in ADR 0004's existing `- Amended: <date> (#issue) — <what>` format; two prior amendments that had changed an ADR body without a header line (#267 on ADR 0004/0005, #289 on ADR 0001) are backfilled from their commits, and ADR 0002's in-place 2026-07-22 note is now also listed in the header. ## Testing No test accompanies this change: it edits only Markdown, and there is no assertion a docs edit could make fail. The verification was reading each claim against the code it describes — `lib/pr/metadata.ts`, `lib/pr/reanchor.ts`, `lib/pr/remote-fetcher.ts`, `lib/pr/chrome-storage.ts`, `lib/drafts.ts`, `entrypoints/review/hooks/useSuggestionEdits.ts`, `entrypoints/review/components/DebugFab.tsx`, `entrypoints/review/reviewItems.ts` — and the base64 example in §7.1 is generated, not hand-written, so it decodes to the JSON printed beneath it. ## Checks `bun run test` (822 pass / 0 fail, 65 files) · `check:lint` · `check:format` · `typecheck` · `build` — all clean. Note for future docs PRs: `oxfmt` **does** format Markdown in this repo, and it reflowed the README table. ## Noted, out of scope - `lib/storage.ts:2-3` still promises "IndexedDB: per-PR pending comments/ suggestions, snapshots (later slice)" in its header comment — the same drift as item 4, but in code. Left for a code PR since this one touches no `.ts`. - `lib/github.ts` keeps the dead `CommentStatus` / `ReviewComment` / `addressedBySha` types that nothing imports. PR #349 removes them. - Nothing links to `docs/superpowers/` or `docs/chrome-web-store/`, and `docs/adr/` has no index page. The authority paragraph now explains what `superpowers/` is, which covers the misleading part; an index is a separate question. Closes #294
nownabe
pushed a commit
that referenced
this pull request
Sep 20, 2026
🤖 I have created a release *beep* *boop* --- ## [0.4.0](bark-v0.3.0...bark-v0.4.0) (2026-09-20) ### Features * **pr:** accept .markdown and .mdx as Markdown ([#322](#322)) ([e22ee68](e22ee68)), closes [#293](#293) * **pr:** commit fork pull requests to the fork's repository ([#342](#342)) ([4e2adef](4e2adef)), closes [#273](#273) * **pr:** create a top-level draft Comment's Thread with it ([#323](#323)) ([6e192f3](6e192f3)), closes [#272](#272) * **pr:** resolve out-of-diff threads via the root comment fence ([#310](#310)) ([7e0ecb9](7e0ecb9)), closes [#270](#270) * **reanchor:** bounded region search for single-line anchors and line-local suggestion merge ([#309](#309)) ([0f735da](0f735da)), closes [#269](#269) * **reanchor:** locate multi-line anchors per endpoint in the region search ([#347](#347)) ([f4fd457](f4fd457)), closes [#311](#311) * **review:** preview the merge for shifted suggestions in the editor ([#354](#354)) ([f822f41](f822f41)), closes [#312](#312) ### Bug Fixes * **anchor:** define anchor.quote as the source text at anchor.range ([#327](#327)) ([11a935d](11a935d)), closes [#276](#276) * **background:** focus an existing review tab instead of opening a second one ([#325](#325)) ([58efa63](58efa63)), closes [#277](#277) * **pr:** compose the quote and permalink for every out-of-diff post ([#351](#351)) ([f85b99b](f85b99b)), closes [#282](#282) * **pr:** count patch lines starting with ++ or -- in parseRightRanges ([#314](#314)) ([9dfbd46](9dfbd46)), closes [#284](#284) * **pr:** keep the rel=next link in the ETag cache so 304 pages still paginate ([#318](#318)) ([6472de2](6472de2)), closes [#286](#286) * **pr:** offer Resolve only when GitHub would accept it ([#335](#335)) ([b05fdcc](b05fdcc)), closes [#274](#274) * **pr:** park a failed resolve toggle in synced, not draft ([#320](#320)) ([56e815b](56e815b)), closes [#275](#275) * **pr:** post drafts in the current head's coordinates ([#303](#303)) ([28ef345](28ef345)) * **pr:** recover comments stuck in syncing instead of re-posting them ([#305](#305)) ([3548086](3548086)) * **pr:** refuse commits to a merged or closed PR ([#330](#330)) ([2a239ff](2a239ff)), closes [#288](#288) * **pr:** refuse to submit a draft whose quoted text changed upstream ([#346](#346)) ([d4118a4](d4118a4)), closes [#313](#313) * **pr:** route replies on the parent's GitHub object kind ([#326](#326)) ([1df6462](1df6462)), closes [#285](#285) * **pr:** serialise refresh and execution under one Repository lock ([#336](#336)) ([1864488](1864488)), closes [#281](#281) * **pr:** sweep entities left syncing at the end of a submit ([#331](#331)) ([108caa9](108caa9)), closes [#271](#271) * **release:** pin publish-browser-extension to ^4.0.5 ([#263](#263)) ([b77104f](b77104f)) * **review:** derive a suggestion draft's cid from the hunk it materialises ([#337](#337)) ([963339d](963339d)), closes [#308](#308) * **review:** end a whole-line selection on the line it actually covers ([#319](#319)) ([3364d18](3364d18)), closes [#291](#291) * **review:** map comment positions between head and edited coordinates ([#348](#348)) ([9465718](9465718)), closes [#283](#283) * **review:** reject a suggestion by resolving its thread on GitHub ([#340](#340)) ([d088a8d](d088a8d)), closes [#287](#287) * **review:** resolve accepted-suggestion threads only after the commit lands ([#341](#341)) ([770f901](770f901)), closes [#278](#278) * **review:** surface failed comment posts and keep the reviewer's edits ([#307](#307)) ([48cb675](48cb675)) * **review:** validate the PR number from the review URL ([#321](#321)) ([457a942](457a942)), closes [#295](#295) * **storage:** bound chrome.storage.local growth and stop quota errors losing drafts ([#332](#332)) ([1f96120](1f96120)), closes [#289](#289) * **suggest:** consume a longer closing fence instead of leaking a backtick ([#316](#316)) ([d2e0683](d2e0683)), closes [#290](#290) ### Performance Improvements * **reanchor:** replace the LCS table with a memoised line-level Myers diff ([#344](#344)) ([8caebdd](8caebdd)), closes [#280](#280) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please-nownabe-bark[bot] <295690643+release-please-nownabe-bark[bot]@users.noreply.github.com>
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.
Why
suggestionsToDraftsmintedcrypto.randomUUID()for every suggestion-derived comment on every Submit. After a partial failure, #307 keeps the reviewer's persisted edits (so the work is not lost) and parks the failed draft in LocalState — but the retry then re-materialises the same hunk under a new id, sosubmitReview'sinRepo.has(d.cid)skip does not fire and both drafts go out: two comments on GitHub for one edit.What
A suggestion-derived draft's cid is a pure function of the hunk:
suggestion:${sl}-${el}:${contentDigest(path + "\0" + baseSha + "\0" + replacement)}(baseShaiss.baseSha ?? headSha, the same value stamped intosha;quoteis implied by(baseSha, path, range)and left out).threadstays= cidfor top-level suggestions.The semantics that follow, documented on the helper: a hunk identical in
(path, baseSha, range, replacement)to a Comment already in LocalState is that Comment — retried when it is a parked draft, and not posted again when it is alreadysynced(GitHub has it, with this exact content). No new skip logic was needed; the existinginRepocheck now does the right thing, and the deterministic id also survives #305's hydrate-timerevertOrphanedSyncing(same id → same draft).Rejected: reusing the parked draft by content lookup (the same identity-by-content, but re-derived at every submit with a body parse), and a per-edit nonce persisted in
SuggestionEdit(needs a new persisted field and a migration for existing edits).Interactions checked:
mergeRemoteIntoLocal's adopt-by-id (#266/#305) — if the failed-looking post did reach GitHub, the refresh adopts the remote copy under the same id, the next Submit's re-materialisation is skipped byinRepo, and with no failure reporteddiscardAllPersistedEdits()runs. The remote-fetcher's fence-owner map is unaffected: a second post with the same cid is prevented locally, and if one ever happened the earliest bearer would win, exactly as for any duplicate today.ADR 0002 §6 gains one sentence; no other ADR change is needed (§2 already says
idis "generated at creation", and a deterministic generator satisfies that).Known limitations (not fixed here)
buildPendingItemsby the deterministic cid is a follow-up.Red-test evidence (before the fix)
tests/reviewItems.test.ts—suggestionDraftCid:SyntaxError: Export named 'suggestionDraftCid' not found in module '.../entrypoints/review/reviewItems.ts'.tests/AppSubmitFailure.test.tsx—App — retrying a suggestion submit after a failed post > posts exactly one comment for the hunk across both attempts(the fix(review): surface failed comment posts and keep the reviewer's edits #307 harness driving the real App against a transport that fails once then succeeds):— the retry's batch carried a second, freshly minted uuid alongside the parked draft.
Manual verification (after
bun run build)Make an edit, submit with the network offline (it fails), go online, submit again: GitHub shows one suggestion comment.
Checks
bun run test717 pass / 0 fail (63 files),check:lint,check:format,typecheck,buildall clean.Closes #308