Skip to content

fix(pr): recover comments stuck in syncing instead of re-posting them - #305

Merged
nownabe merged 1 commit into
mainfrom
fix/syncing-recovery
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
fix/syncing-recovery

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

Closes #266.

A comment that enters syncing could get stuck there forever: the UI shows neither pending nor submitted items in that state, refresh discards the remote copy because syncing is protected, and the reconciler re-posts it on the next Submit, creating duplicates on GitHub. Three paths caused it:

  • A — POST ok, but GitHub's read-after-write lag left the cid out of the identity listing. applyReviewBatchSuccess left unmapped comments syncing.
  • B — POST ok, but the listing itself failed. The POST and listing shared one try, so the outcome was ok: false, comments reverted to plain draft, and a retry posted a second review.
  • C — tab closed after the POST but before the step result was persisted. Hydrate restored syncing verbatim.

What

  • PostReviewBatchOutcome gains an optional confirmError on the ok: true variant. The transport reports the POST and the confirmation separately, so a failed confirmation is never mistaken for a failed post.
  • The transport re-lists review threads with a small bounded backoff (500 ms, 1500 ms) while any posted cid is still missing before giving up.
  • applyReviewBatchSuccess reverts unmapped comments (and their new threads) to draft + lastError instead of leaving them syncing.
  • mergeRemoteIntoLocal adopts a remote item whose id matches a protected local item that has no remoteId / remoteThreadId yet. The id was minted locally, so the item can only be its own post; adopting it heals paths A–C on the next refresh. A protected thread that already has a remoteThreadId (pending resolve toggle) is still kept.
  • hydrate reverts any persisted syncing entity to draft + lastError; no step is in flight in a fresh session.
  • The review UI surfaces the first comment lastError via the Snackbar after submit; step outcomes never throw, so a failed or unconfirmed post was silent before.
  • ADR 0001 §4, ADR 0003 §6–7 and ADR 0005 §1/§3 document the identity round-trip, the syncing invariant, and the cid-adoption exception to the protection rule.
  • Regression tests for paths A, B and C at the state-machine, transport and repository level.

Notes

The reviewer submit path refreshes before submitDrafts, so cid adoption runs before a re-submit and duplicates are avoided there. The author submit path does not refresh first; if a user re-submits from author mode before any refresh trigger fires, an unconfirmed comment can still be posted twice. Left as-is to keep this change focused; a follow-up can add the refresh there.

A comment left syncing after a submit was invisible in the UI, protected from refresh, and re-posted on the next Submit, duplicating it on GitHub. Three paths caused it: the identity listing lagging behind the review POST, the listing failing after a successful POST (reported as a failed post), and the tab closing before the step result was persisted.

Report POST and confirmation outcomes separately, re-list with a bounded backoff, revert unmapped comments to draft + lastError, adopt remote items by cid when the local copy has no remote identity yet, and downgrade persisted syncing items on hydrate. Closes #266.
@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe merged commit 3548086 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the fix/syncing-recovery branch September 20, 2026 05:06
nownabe added a commit that referenced this pull request Sep 20, 2026
…ts (#307)

## 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 nothing
looked exactly like one that succeeded: the modal closed, the drafts
quietly
returned to "pending", and in reviewer mode `discardAllPersistedEdits()`
threw
away 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

- `reportFirstCommentError` becomes `reportSubmitErrors`: it still
announces the
first error via the existing `reportError` / Snackbar path, adds a count
when
several comments failed, falls back to a Thread's `lastError` (a failed
resolve, which no comment reflects), and returns the failed comment ids.
- `submitReview` keeps the reviewer's editor edits — the open file's
source, the
  per-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.
- `submitAuthor` uses the same reporter; its separate commit-failure
message
  (FileEdit `lastError`) is unchanged.
- The `drafts` memo carries `Comment.lastError.message` onto
`PendingDraft`, and
`ThreadItem`'s pending message renders it with the existing
`notice--error`
  colour and `comment__body` typography. No new CSS.

## Tests

New `tests/AppSubmitFailure.test.tsx` drives the real `App` (first test
file that
does) against a failing `Transport`, with `wxt/browser` and the PR
bootstrap
stubbed 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):

- *keeps the reviewer's persisted edits instead of discarding them* —
  `expect(Object.keys(storedEdits())).toEqual(["README.md"])` got `[]`.
- *shows the error on the failed draft in the sidebar* —
  `.comment--pending .notice--error` was `null`.
- *says how many comments failed when more than one did* — the Snackbar
read
  `422 Unprocessable` with 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 new
`cid` per submit, so the two are different entities. Keeping the edits
is the
lesser evil (the work is otherwise unrecoverable), but stable suggestion
ids are
worth a follow-up.
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 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>
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.

[High] syncing has no recovery path: unmapped or post-write failures leave ghost comments and duplicate posts

1 participant