Skip to content

fix(pr): compose the quote and permalink for every out-of-diff post - #351

Merged
nownabe merged 1 commit into
mainfrom
fix/282-out-of-diff-body
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
fix/282-out-of-diff-body

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

Out-of-diff comments are supposed to reach GitHub as an issue comment carrying the quoted text and a permalink (design doc D4, ADR 0003 §5) — an issue comment has no position of its own, so without them a reader on github.com sees the words and nothing else.

In practice they went out as the bare body plus the hidden fence. composeDraftBody ran only for drafts that were not already in the Repository, and addDraft / addReply write every comment draft straight to it, so the composition branch was dead for comments and alive only for suggestion drafts (materialised at submit time). In the author submit loop it was dead altogether.

What

  • The Executor composes the out-of-diff body. composeIssueCommentBody (new, in lib/pr/metadata.ts next to the rest of the wire format) appends the bounded quoteBlock excerpt and a blob/{anchor.sha}/{path}#L… permalink; postIssueComment calls it. That is the one place every out-of-diff post goes through, so replies routed out of diff get the same treatment — GitHub cannot nest them, so they are shown flat in the conversation and need the context just as much as a new comment does.
  • LocalState bodies stay the raw user text. The sidebar and re-anchoring are unaffected, and a refetched comment no longer disagrees with its local copy about what the user wrote.
  • The size guard measures what is actually sent. isTooLarge now composes the body for an out-of-diff post before measuring, so the 65,536-character rejection matches GitHub's. The addDraft pre-flight check uses the same function, which it previously approximated with composeDraftBody.
  • Deleted: the never-hit out-of-diff branch of composeDraftBody (it is now suggestion-block only), the entire dead draft loop in submitAuthor, and PendingDraft.permalink with its four build sites — nothing read it once the Executor built the link itself.
  • quoteBlock moved from entrypoints/review/uiHelpers.ts to lib/pr/metadata.ts with its tests; it is wire format, not presentation, and lib/ cannot import from entrypoints/.
  • ADR 0003 §5 now states where the quote and permalink are composed and that the size check measures the composed body.

Out-of-diff suggestions keep their "(Out of diff: this suggestion will not show an Apply button.)" note in composeDraftBody, where the suggestion block it belongs to is already built.

Red-test evidence

tests/pr/github-transport.test.ts — postIssueComment > composes the quoted excerpt and the permalink above the fence:

error: expect(received).toBe(expected)
- "typo here
- 
- > first
- > second
- https://github.com/o/r/blob/h0/f.md#L5-L6"
+ "typo here"

(the reply test failed the same way with "agreed").

tests/pr/planner.test.ts — CreateComment routing > the size check measures the body the Transport will send > an out-of-diff comment is rejected once the composed body goes over:

error: expect(received).toEqual(expected)
-     "error": ObjectContaining {},
-     "kind": "reject-comment",
+     "kind": "post-issue-comment",

The companion case — an out-of-diff comment whose composed body lands exactly on 65,536 — passed before and after, so the guard rejects only what really goes over.

Checks

bun run test 828 pass / 0 fail (65 files), check:lint, check:format, typecheck, build all clean.

Closes #282

@nownabe nownabe self-assigned this Sep 20, 2026
An out-of-diff comment reached GitHub as the bare body plus the hidden fence. The App composed the quote and permalink only for drafts it had not already written to the Repository — which is every comment draft — so only suggestion drafts, materialised at submit time, ever got them.

Composing in the Executor instead makes it one place every out-of-diff post goes through, replies included, and leaves LocalState bodies as the raw user text. The Planner's 65,536-character check now measures that composed body, so it rejects exactly what GitHub would.
@nownabe
nownabe force-pushed the fix/282-out-of-diff-body branch from 4b672b0 to 49388df Compare September 20, 2026 10:17
@nownabe
nownabe merged commit f85b99b into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the fix/282-out-of-diff-body branch September 20, 2026 10:20
nownabe added a commit that referenced this pull request Sep 20, 2026
…per (#352)

## Why

`App.tsx` held the same logic two or three times, so a rule change (a
`baseSha`
fallback, a `parentLocalId` lookup) had to be made in every copy. This
gives each
one a single home.

Folding the FileEdit sync into one helper also removed a latent race,
see
"Behaviour change" below.

## What

Re-audited issue #300's six items against current `main`; three were
already
resolved by earlier PRs and are untouched here:

| # | Item | Status |
|---|------|--------|
| 1 | "drafts → Repository" loop in `submitReview` vs `submitAuthor` |
**already resolved** — #351 (issue #282) deleted `submitAuthor`'s loop;
only `submitReview` still has one |
| 2 | FileEdits sync (mirror effect vs `submitAuthor`) | **done** — #341
(issue #278) had unified the *building* via `fileEditsFromEdits`; the
upsert/discard loop was still duplicated, now
`syncFileEditsToRepository()` |
| 3 | `parentLocalId` resolution (`addReply`, `submitReview`) | **done**
— one `parentLocalIdFor(thread)` |
| 4 | "Drop accepted decisions" (two in-memory copies +
`clearAcceptedDecisions`) | **done** —
`useDismissedSuggestions.clearAccepted(ids)`; the `setDismissed` escape
hatch it existed for is gone from the hook's API |
| 5 | `resetSuggestionEdits(); saveSuggestionEdits(ref, {})` in
`discardAllPending` | **done** — `await discardAllPersistedEdits()`;
`saveSuggestionEdits` is no longer imported by `App.tsx` |
| 6 | `jumpTo` vs `jumpToOffsets` | **already resolved** — #348 (issue
#283) folded `jumpTo` into `jumpToCid` → `jumpToOffsets` |

Net line change: **−30 lines in `App.tsx`** (49 added / 79 removed);
**−15 lines
of production code overall** (`App.tsx` + the two hook files), +37 lines
of test.

## Behaviour change (one, deliberate)

`syncFileEditsToRepository` skips a FileEdit whose current state is past
`"draft"`. `submitAuthor` used to upsert unconditionally, and that
redundant
write was the only thing keeping the mirror effect from re-running
*during*
`submitDrafts()`, seeing the FileEdit as `"syncing"` and writing it back
as a
`"draft"` — cancelling the commit it belonged to. Without the guard,
both
`tests/AppSubmitFailure.test.tsx` author-submit tests fail (no `commit`
call at
all, so the accepted thread is never resolved); with it they pass.
Everything
else is pure extraction.

## Red-test evidence

New hook test, `tests/useDismissedSuggestions.test.tsx` →
`useDismissedSuggestions — clearAccepted`, written before the
implementation:

```
TypeError: result.current.clearAccepted is not a function.
  (In 'result.current.clearAccepted([1])', 'result.current.clearAccepted' is undefined)
(fail) useDismissedSuggestions — clearAccepted > drops only the named ids and purges them from storage
(fail) useDismissedSuggestions — clearAccepted > without a ref: updates state, does NOT touch storage
 5 pass  2 fail
```

The existing App-level suites (`AppSubmitFailure`,
`AppEditedCoordinates`,
`AppPrRef`, `AppRejectSuggestion`) are the safety net for the extraction
itself
and stay green.

## Checks

`bun run test` 818 pass / 0 fail (64 files) · `check:lint` ·
`check:format` ·
`typecheck` · `build` — all clean.

Closes #300
nownabe added a commit that referenced this pull request Sep 20, 2026
#353)

## Why

Comments that say where code *used to* live, or that name a
refactor-plan phase
(`Pack B / R8b`, `L7e-1`, `Phase 4`), send the reader looking for
something that
either moved or was never in this repo. CSS rules with no markup and
exports with
no importer cost the same kind of lookup. Two of them were worse than
noise: the
`pr:{owner}/{repo}#{n}` key prefix and the UTF-8 base64 decoder each had
two
independent definitions that could silently drift.

Net **-130 lines** (135 insertions / 265 deletions) across 29 files,
plus one
deleted file. No behaviour change.

## What

**1. Tombstone / phase-tag comments.** Re-located by content (the
issue's line
numbers are from before #303–#350). Rewritten to say what the code is,
or deleted
where the comment only described history: `App.tsx` (a garbled
half-sentence, six
"now lives in …" markers, and the `L5` / `L6c` / `L6d-1` / `L7e-1` /
`R3` / `R6`
tags), the five `hooks/` headers, both `adapters/` headers plus
`displayPositionToAnchorStatus.ts`, `highlight.ts`, `suggestionView.ts`,
`lib/drafts.ts`, `lib/comments.ts`, `lib/pr/repository.ts`.
`lib/storage.ts`'s
header advertised an IndexedDB layer that does not exist — it now says
chrome.storage.local and points at ADR 0001 §2. Real "why not" sentences
(the
reviewer note on thread visibility, the `canAccept` rationale, every
`simplify:`
and issue-numbered note) are untouched.

**2. Dead CSS.** Deleted `.field--mono`, `.badge--review`,
`.badge--suggestion`,
`.badge--anchored`, `.composer__routing`, `.radio-row` (+ `.radio-row
label`)
after an exact-token search over `entrypoints/`, `lib/`, `tests/` found
no
producer. `.badge--anchored` is unreachable by construction as well:
`ThreadItem`
builds `badge--${status}` from `AnchorStatus` (`current` | `reanchored`
|
`outdated`), gated on `STATUS_LABEL[status]`, which only defines
`reanchored` and
`outdated`. `docs/design-principle.md` no longer lists `.field--mono`.

**3. No-consumer leftovers.**
- Deleted the empty root `components/` directory (nothing in
`wxt.config.ts`,
`tsconfig.json` or the docs configures a root components dir; the real
one is
  `entrypoints/review/components/`).
- Dropped `useUiPanels.closePrInfo` (only the hook's own test called
it).
- Un-exported `APP_SLUG`, `SubmitCommitGroup`, `SubmitSummary` — all
used only in
their defining module. `SubmitGroup` stays exported:
`SubmitConfirmModal` imports it.
- `prStorageKey` / `prStorageKeys` now build on `storageKeys.pr`, the
same prefix
`lib/drafts.ts` builds, so #332's eviction and the drafts keys cannot
drift.
- `base64Decode` is exported from `lib/pr/metadata.ts` and reused by
`remote-fetcher.ts`; the fetcher keeps its own whitespace strip (GitHub
wraps
its base64 at 60 chars) rather than pushing that into the fence decoder.
- Deleted `fetchThreads` (no production caller — `fetchRemoteState`
inlines
  `listReviewThreads` + `threadsFromRaw`). Its four tests now call
`threadsFromRaw(await listReviewThreads(...))` through a 2-line local
helper, so
the paging coverage is unchanged and the only export is a function
production
  actually uses.

**4. `AppState.currentFiles`.** Verified no consumer anywhere in
`entrypoints/`;
deleted it with `buildCurrentFiles` and its two tests.

## Test evidence

This is a deletion PR, so there is no red step except for the two shared
helpers,
where the rule was to pin current behaviour *before* unifying:

- `tests/pr/chrome-storage.test.ts` — "shares its prefix with the keys
  lib/drafts.ts builds": `prStorageKey("acme","site",42)` ===
`` `${storageKeys.pr("acme","site",42)}:state` ``. Added and run **green
against
the two independent definitions**, then `prStorageKey` was rewritten
onto
  `storageKeys.pr`; still green.
- `tests/pr/remote-fetcher.test.ts` — "decodes UTF-8 from the
line-wrapped base64
GitHub returns": multibyte source, base64 wrapped at 60 chars. Added and
run
green against the fetcher's private decoder, then repointed at the
shared
  `base64Decode`; still green.

Full set on the rebased branch: **816 pass / 0 fail** (`bun run test`),
`check:lint`, `check:format`, `typecheck` and `build` all clean.

## Dropped from the issue (already fixed on main)

- `DebugFab.tsx`'s undefined `var(--green)` — gone with DebugFab's
preview.
- `lib/pr/bootstrap.ts:8-17` — the current header describes the live
composition
  accurately; nothing to remove.
- `lib/pr/repository.ts:159` — that line is live code today; only the
`(Phase 4)`
  tag on line 8 needed a fix.

## Left out, on purpose

Two phase tags remain in `App.tsx`'s submit flow — `// already
double-written by
L4/L6a` and `// (the L6d-1 effect is best-effort…)`. Both sit inside the
`composeDraftBody` call regions that the still-open #351 edits, so they
are left
for a one-line follow-up after that merges rather than handed #351 a
conflict.

Closes #301
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.

[Medium] Out-of-diff comments are posted without the quoted text and permalink

1 participant