Repository navigation
fix(review): surface failed comment posts and keep the reviewer's edits - #307
Merged
Merged
Conversation
A failed Submit was silent: submitDrafts() resolves either way, so the modal closed, the drafts quietly returned to pending, and the reviewer's editor edits were discarded although nothing reached GitHub. Closes #268
2 tasks
This was referenced Sep 20, 2026
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
…317) ## Why `bun run typecheck` is red on `main` since #310 merged: it added `setIssueThreadResolved` to the `Transport` interface, while `tests/AppSubmitFailure.test.tsx` (added by #307, which branched before #310) still builds two `Transport` mocks without it. Every open PR's CI inherits the failure. ## What Add a `setIssueThreadResolved` stub (`{ ok: true }`) to `failingTransport()` and `happyTransport()` in `tests/AppSubmitFailure.test.tsx`. No behaviour change; the five tests in that file still pass. Checks: `typecheck` clean, `test tests/AppSubmitFailure.test.tsx` 5 pass, `check:lint` and `check:format` clean. Merge this first so the CI of #315 and the other open PRs goes green.
This was referenced Sep 20, 2026
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
## Why Two pieces of the tree had no consumers and only cost maintenance: - `scripts/check-metadata.ts`, `scripts/check-suggest.ts`, `scripts/check-suggestion.ts` were manual one-off checks never wired into `package.json`, CI or docs. What they assert is already covered by `tests/suggest.test.ts`, `tests/github.test.ts` and `tests/pr/metadata.test.ts`, so they could only drift against the modules they poke at (two of them still import the v1 codec slated for removal in #298). - `lib/linemap.ts` was a second LCS `buildLineMap` with the same contract as `lib/pr/linemap.ts`. Production imports only `lib/pr/linemap` (via `lib/pr/reanchor.ts` and `lib/suggest.ts`); the copy was reachable from its own test alone. Two implementations of one contract silently diverge — and the trailing-newline convention that `lib/anchor.buildLineIndex` depends on is exactly the kind of thing that drifts. ## What - `git rm -r scripts/` (144 lines). - Deleted `lib/linemap.ts` + `tests/linemap.test.ts` (104 lines), after porting the trailing-newline convention case into `tests/pr/linemap.test.ts`. - Dropped the stray `biome-ignore` comment in `lib/pr/linemap.ts` — the repo lints with oxlint, so it directed nothing. **249 lines removed, 9 added.** ### Deletion safety Grepped the whole tree (excluding `node_modules`/`.git`) for `scripts/check`, `check-metadata`, `check-suggest`, `check-suggestion`: three hits, all inside the scripts' own `// Run:` header comments. `package.json`, `.github/workflows/*`, `README.md`, `AGENTS.md` and `docs/` have none. Importers of the top-level `lib/linemap`: exactly `tests/linemap.test.ts:2`. There is no `@/lib` alias and no `lib/index.ts` barrel, so no indirect path existed. ## Test evidence The ported case as written in `tests/linemap.test.ts:47-52` passes against `lib/pr/linemap.ts` unchanged — both implementations split on `"\n"` identically. That makes it a green-on-arrival test, so I checked it actually has teeth by mutating `lib/pr/linemap.ts` to strip a trailing newline before splitting: ``` (fail) linemap > treats a trailing newline as a final (empty) line, matching buildLineIndex error: expect(received).toBe(expected) Expected: 4 Received: undefined at tests/pr/linemap.test.ts:58 ``` The original assertions (`a → 2`, `b → 3`) survived that mutation untouched — they never tested the convention. The ported test therefore also asserts that the trailing empty line maps (`map.get(3) === 4`), which is the assertion that fails when the convention changes. Mutation reverted; suite green. ## Checks `bun run test` 689 pass / 0 fail (61 files, down from 695/62 — the 6 dropped are the deleted `tests/linemap.test.ts`), `check:lint` clean, `check:format` clean, `bun run build` OK. `bun run typecheck` fails on `tests/AppSubmitFailure.test.tsx:81,105` (`Property 'setIssueThreadResolved' is missing ... in type 'Transport'`). This is **pre-existing on `main` at 7e0ecb9** and unrelated to this PR: that file was last touched by #307 and #310 later added `setIssueThreadResolved` to `Transport` without updating its two mock transports. This PR touches neither file. It needs its own fix. Closes #297
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
…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
added a commit
that referenced
this pull request
Sep 20, 2026
…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
added a commit
that referenced
this pull request
Sep 20, 2026
…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
added a commit
that referenced
this pull request
Sep 20, 2026
…lises (#337) ## Why `suggestionsToDrafts` minted `crypto.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, so `submitReview`'s `inRepo.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)}` (`baseSha` is `s.baseSha ?? headSha`, the same value stamped into `sha`; `quote` is implied by `(baseSha, path, range)` and left out). `thread` stays `= cid` for 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 already `synced` (GitHub has it, with this exact content). No new skip logic was needed; the existing `inRepo` check now does the right thing, and the deterministic id also survives #305's hydrate-time `revertOrphanedSyncing` (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 by `inRepo`, and with no failure reported `discardAllPersistedEdits()` 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 `id` is "generated at creation", and a deterministic generator satisfies that). ## Known limitations (not fixed here) - After a partial failure the pending list shows both the parked draft and the live suggestion for the same hunk. This is pre-existing since #307; deduplicating `buildPendingItems` by the deterministic cid is a follow-up. - If the reviewer edits the hunk's text between the failed and the retried Submit, the id changes and the old parked draft stays behind as a stale pending draft with its error. It is visible in the sidebar and discardable. ## 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 #307 harness driving the real App against a transport that fails once then succeeds): ``` expect(received).toEqual(expected) [ "f05440e0-ce84-4c44-89fa-6c34f10a7cd9", + "9f41c14e-77e8-4a3a-87f7-93a912c84865", ] ``` — 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 test` 717 pass / 0 fail (63 files), `check:lint`, `check:format`, `typecheck`, `build` all clean. Closes #308
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
#348) ## Why `displayPosition` and `Comment.anchor` are expressed in the coordinates of `FileContent(headSha, path)`; the editor shows the locally edited `source` (the reviewer's live suggestions, the author's staged accepts). The two spaces were mixed without a mapping: - `addDraft` took `startLine`/`endLine` from the live editor document but stamped `sha: headSha`, so a reviewer who inserted two lines at the top and then commented on base line 10 sent GitHub line 12 — the wrong line, or a 422 when it falls outside the hunk. - Highlights, thread ranges, jumps and `buildSuggestionMarks` applied head-coordinate positions to `lineStarts` built from the edited `source`, so every comment below an insertion was drawn two lines too high. `applyAcceptedSuggestion` already translated head → edited for exactly this reason (#177); the comment paths did not. ## What One direction map, `headToEdited = buildLineMap(baseSource, source)` (memoised in App, `null` when the texts are equal), is the single bridge. Every place that draws or jumps to a comment maps `dp.range` through it and **skips** the comment when either endpoint's line has local edits — the same rule `applyExactQuote` already used, since a line being rewritten has no stable position. `addDraft` maps the selection back through the inverted map and **refuses** a selection that touches a locally edited line or that is not contiguous in head coordinates. - **lib/pr/linemap.ts** — `invertLineMap`. - **lib/suggest.ts** — `headRangeToEditedOffsets` and `editedSpanToHead` next to the existing base→edited mapping; `applyAcceptedSuggestion` takes the map as an optional argument (App passes its memo instead of rebuilding it per click), and `applyExactQuote` now goes through `headRangeToEditedOffsets`. - **entrypoints/review/reviewItems.ts** — `buildSuggestionMarks` takes `headToEdited`. - **entrypoints/review/App.tsx** — the memo, the two-line `toEditedOffsets` helper, and the wiring of the highlight effect, `threadRanges`, `jumpTo`, `jumpToDraft`, `buildSuggestionMarks` and `acceptSuggestion`. Draft highlights, thread ranges and jumps now read the draft's `CommentView.displayPosition` instead of its raw stored range, which also fixes the pre-existing case of a draft anchored at an older sha. `jumpTo` folds into `jumpToOffsets` (the minimal part of #300). - **docs/adr/0004-reanchoring.md** — new §8 *Editor coordinates*. Known consequence, worth stating: a comment on a line the author is currently editing disappears from the editor until the edit is submitted or discarded. It stays in the sidebar with its normal status (no `outdated` badge). This is consistent with accept refusing on the same line, and the alternative — drawing it at a nearby line — would put the highlight over the wrong text. `addDraft`'s refusal is a Snackbar via the existing `reportError`; no new UI. ## Red-test evidence - `tests/pr/linemap.test.ts` → `invertLineMap`: `SyntaxError: Export named 'invertLineMap' not found in module lib/pr/linemap.ts`. - `tests/suggest.test.ts` → "head ↔ edited coordinates (issue #283)": `SyntaxError: Export named 'editedSpanToHead' not found in module lib/suggest.ts`. - `tests/reviewItems.test.ts` → "a suggestion below two locally inserted lines is drawn at its mapped line": `Expected length: 1, Received length: 0` (the head offset landed on the wrong text, so the quote check dropped the mark). - `tests/reviewItems.test.ts` → "a suggestion on a locally edited line is not drawn": `Expected length: 0, Received length: 1`. - `tests/AppEditedCoordinates.test.tsx` → "a comment on unedited text is anchored in head coordinates": the recorded anchor was `{sl: 4, el: 4}` instead of `{sl: 2, el: 2}` — the editor's line numbers stamped with the head sha. - `tests/AppEditedCoordinates.test.tsx` → "a selection on a locally inserted line is refused with a message": no Snackbar appeared and the comment was upserted. The App-level test drives the real App (the `AppSubmitFailure` harness: mocked `wxt/browser` + bootstrap, fetch stub, `happyDOM.setURL`) as a reviewer with `"X\nY\n" + BASE` persisted as the file's edit. It stubs `EditorView.prototype.coordsAtPos` because happy-dom has no layout, so CodeMirror would never place the selection bubble; the stub is restored in `afterAll`. Guards: the `null`-map identity cases in the unit tests and the whole existing suite (including the #307/#308 App harness) cover "no local edits" behaviour unchanged. ## Checks `bun run test` (749 pass, 0 fail), `check:lint`, `check:format`, `typecheck`, `build` all pass. Closes #283
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
Closes #268.
Transport steps never throw — a failed post parks the Comment (and the Thread it
would have created) back as
draft + lastError— so a Submit that posted nothinglooked exactly like one that succeeded: the modal closed, the drafts quietly
returned to "pending", and in reviewer mode
discardAllPersistedEdits()threwaway every file's editor edits although GitHub had received none of them.
#305 already routed the first failed comment to the Snackbar. This finishes the
job: the failure is also visible on the draft that failed, a resolve failure is no
longer swallowed, and no local work is dropped unless the post it came from landed.
What
reportFirstCommentErrorbecomesreportSubmitErrors: it still announces thefirst error via the existing
reportError/ Snackbar path, adds a count whenseveral comments failed, falls back to a Thread's
lastError(a failedresolve, which no comment reflects), and returns the failed comment ids.
submitReviewkeeps the reviewer's editor edits — the open file's source, theper-suggestion comments and every file's persisted edit — when a
suggestion-derived comment failed to post. The parked drafts retry on the next
Submit. The success path is unchanged.
submitAuthoruses the same reporter; its separate commit-failure message(FileEdit
lastError) is unchanged.draftsmemo carriesComment.lastError.messageontoPendingDraft, andThreadItem's pending message renders it with the existingnotice--errorcolour and
comment__bodytypography. No new CSS.Tests
New
tests/AppSubmitFailure.test.tsxdrives the realApp(first test file thatdoes) against a failing
Transport, withwxt/browserand the PR bootstrapstubbed and the contents endpoint stubbed at the fetch layer. The module mocks are
process-wide in bun, so the real exports are copied out by value and restored in
afterAll.Red before the fix (all three failed for the predicted reason):
expect(Object.keys(storedEdits())).toEqual(["README.md"])got[]..comment--pending .notice--errorwasnull.422 Unprocessablewith no count.Two more guard what already worked and must keep working: the Snackbar
announcement, and that a successful submit still discards the persisted edits.
Note
A retry after a partial suggestion failure can post the parked draft and a
freshly derived suggestion for the same edit:
suggestionsToDrafts()mints a newcidper submit, so the two are different entities. Keeping the edits is thelesser evil (the work is otherwise unrecoverable), but stable suggestion ids are
worth a follow-up.