Skip to content

fix(pr): bound the comment body to GitHub's 65,536-character limit - #334

Merged
nownabe merged 1 commit into
mainfrom
fix/279-bounded-quote-fence
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
fix/279-bounded-quote-fence

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

A comment body embedded the whole anchor.quote in the base64 fence (4/3 inflation) and an out-of-diff body prepended the same quote again as visible text; a suggestion adds the replacement on top. Nothing capped that, so a large selection produced a body over GitHub's 65,536-character limit and got a 422 — and because POST /pulls/{n}/reviews is atomic, one oversized comment failed every other in-diff comment in the same submit.

What

The quote is derivable, not just storable: anchor.sha is content-addressed, so the full quote is exactly extractTextAtRange(FileContent(sha, path), range) — and the fetcher already loads that file for every anchored (sha, path) (#303). So the fence carries a bound, and the full quote is restored on the way back in.

  • lib/pr/metadata.ts — QUOTE_EXCERPT_CHARS = 1000, BODY_LIMIT = 65_536. embedMetadata caps a longer quote to an excerpt and adds quoteDigest + quoteLength; a quote at or under the cap produces the same bytes as before, so every existing fence and fixture is unchanged. contentDigest is cyrb53 — sync and dependency-free. envelopeOf(comment) is the single definition of what the transport posts (it replaces three copies of the same literal in github-transport.ts), and wireBodyLength is the one size estimate both the Planner and addDraft use.
  • Why not SHA-256 via Web Crypto: crypto.subtle.digest is async, which would make embedMetadata — plus four transport call sites and every fence fixture — async for no security gain. The digest guards against mis-restoration (wrong range, corrupt fence), not against an attacker, who can already rewrite any fence field; identity trust is the earliest-bearer rule ([Medium] Bark metadata fence trusts attacker-controlled identity — thread/comment spoofing #190). Stated in a comment on the helper.
  • lib/pr/remote-fetcher.ts — restoreCappedQuotes runs after the file contents come back: for each comment whose fence was capped, it re-extracts the quote at anchor.range and accepts it only when both length and digest match. A missing file or a mismatch keeps the excerpt. bootstrap.refresh is the only caller of fetchRemoteState, so bootstrap and refresh are both covered.
  • lib/pr/planner.ts — a create-comment / create-reply whose wire body exceeds the limit is planned as reject-comment (the mechanism fix(pr): post drafts in the current head's coordinates #303 added for unmappable anchors), so it parks as draft + lastError and the rest of the batch posts.
  • entrypoints/review/uiHelpers.ts — quoteBlock bounds the visible out-of-diff quote to 12 lines / 1,000 characters with a > … trailer; composeDraftBody uses it.
  • entrypoints/review/App.tsx addDraft — refuses an over-limit draft with an immediate Snackbar instead of letting it fail at submit.
  • lib/pr/github-transport.ts — setIssueThreadResolved now spreads the fetched envelope instead of rebuilding it field by field, so a capped fence's digest and length survive a resolve toggle.
  • ADR 0002 §3/§5 and ADR 0003 §5/§7 updated. ADR 0004 needs no change: verification is unchanged and runs on the full, restored quote.

Red-test evidence (before the fix)

  • tests/pr/metadata.test.ts — metadata — bounded quote (issue #279) (all cases): SyntaxError: Export named 'wireBodyLength' not found in module '.../lib/pr/metadata.ts'.
  • tests/uiHelpers.test.ts — quoteBlock (issue #279): SyntaxError: Export named 'quoteBlock' not found in module '.../entrypoints/review/uiHelpers.ts'.
  • tests/pr/github-transport.test.ts — a capped root fence keeps its quoteDigest and quoteLength through the toggle: SyntaxError: Export named 'contentDigest' not found.
  • tests/pr/planner.test.ts — a comment whose wire body exceeds GitHub's limit is rejected, the rest of the batch posts: expect(received).toHaveLength(expected) — Expected length: 2, Received length: 1 (both comments went into the one batch).
  • tests/pr/remote-fetcher.test.ts — capped quote restoration > a digest mismatch keeps the excerpt rather than a wrong quote: Expected: 1000, Received: 3000 (nothing was capped, so nothing was verified).

Manual verification (after bun run build)

Comment on a ~3,000-character paragraph out of diff: on github.com the comment should show a 12-line excerpt ending in > …. Reopen Bark in a fresh session: the sidebar should show the full quote and the highlight should cover the whole paragraph.

Checks

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

Closes #279

@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe added this pull request to stack #338 September 20, 2026 06:26
@nownabe
nownabe removed this pull request from stack #338 September 20, 2026 06:26
@nownabe
nownabe added this pull request to stack #339 September 20, 2026 06:26
@nownabe
nownabe force-pushed the fix/279-bounded-quote-fence branch from 103a2dc to 2bcf1da Compare September 20, 2026 07:36
@nownabe
nownabe force-pushed the fix/279-bounded-quote-fence branch from 2bcf1da to 1313eff Compare September 20, 2026 08:38
@nownabe
nownabe force-pushed the fix/279-bounded-quote-fence branch from 1313eff to 80e6c77 Compare September 20, 2026 08:56
Base automatically changed from fix/276-quote-semantics to main September 20, 2026 08:59
The fence embedded the whole anchor.quote (4/3 inflated) and out-of-diff
bodies repeated it as visible text, so a large selection produced a body
GitHub rejects — and a review batch is atomic, so one oversized comment
took every other comment in the same submit down with it.

The quote is content-addressed by (anchor.sha, path, range), so the fence
can carry an excerpt plus a digest and the fetcher restores the full text
from the file content it already fetches.
@nownabe
nownabe force-pushed the fix/279-bounded-quote-fence branch from 80e6c77 to b7b52c7 Compare September 20, 2026 08:59
@nownabe
nownabe merged commit a88ccd6 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the fix/279-bounded-quote-fence branch September 20, 2026 09:02
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
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] Unbounded quote in comment bodies exceeds GitHub's 65,536-character limit and fails the whole batch

1 participant