Skip to content

CONTRACT: feat(ui-sdk, ui-server, ui-react): per-review line-comment count, so each review gets its own "Show n line comments" (#4147) - #4196

Merged
schlessera merged 2 commits into
mainfrom
feat/4147-per-review-line-comment-count
Nov 17, 2026
Merged

schlessera merged 2 commits into
mainfrom
feat/4147-per-review-line-comment-count

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #4147

What changed

A pull request read now tells each review how many line comments it has, and the chat puts "Show n line comments" on that review. The shared review payload gains an optional, nullable line_comments (GITHUB_REVIEW_SCHEMA), and GITHUB_LIMITS gains reviewComments (100). The host makes one extra request, /pulls/{n}/comments?per_page=100, only when the result carries reviews, groups the comments by pull_request_review_id and gives every review its exact total, a genuine zero included. When that page is not the whole collection (GitHub names a next page), a comment is malformed or names no review, the page disagrees with the pull request's own review_comments total, or the credential cannot read review comments (403/404), every review's count is null; there is never a partial total. Other failures of that request (rate limit, 5xx, timeout) fail the read with their usual typed error, as for the other PR requests. Detail-page reviews carry null. A result recorded before the field existed still parses, and its absence reads as unknown.

In the chat, a review with a known positive count shows the kit's unchanged GitHubReview control. Its press mounts that review's section, which loads #3796's review-comments part, keeps only that review's comments, follows pages that keep none at most four per press (ceil(reviewComments / page size)), and stops paging once the known count is shown. Zero, null and an absent count show no control, and nothing loads before the press. The PR-wide "Show line comments" section is retired when every review in a complete list has its count. It remains, filtered to the comments no counted review reaches, only when some review's count is unknown or absent, or when the result does not carry every review (reviews.has_more). That covers the criterion added on 2026-11-17: line comments can load for every review that has them, including when the result carries none of the PR's reviews.

Why this shape

  • Count from one bounded page, all-or-nothing. The issue rules out a per-review count request and unbounded paging. One page of 100 (GitHub's maximum) bounds the cost at one request per PR read. A single comment with unknown membership could belong to any review, so it makes every count unknown rather than some. GitHub's review_comments total is used only to reject a page, never to produce a number, as the issue requires.
  • A 403/404 on review comments leaves counts unknown rather than failing the read. This is the same treatment checks() already gives a credential without access. The read worked without this request before, so a read must not now fail because of a metadata field. Other errors keep the existing typed refusal path.
  • Remainder section instead of no section. The per-review control can only exist for reviews the result carries and has counted. Criterion 6 asks that line comments still load in the two other cases, so the remainder section mounts only when per-review coverage is not proven complete. Its condition comes from the counts, not from reviews.items.length as before. The kit already has the label slot for this, so the design does not change.
  • Bounded follow, not auto-drain. The existing DetailPart auto-follows pages that add nothing, which is unbounded in principle. Filtered sections switch that off and follow inside useDetail within a per-press page budget. The reader sees either new rows or a truthful "Load more · k of n shown".

Proof

bun run check:pr --base origin/main   # exit 0 at 7e4f0053 (receipt below)
bun run build --jobs=2                # exit 0 (exports changed)
bun run typecheck                     # exit 0

Focused suites: packages/ui-sdk/tests/github-tool-contract.test.ts, packages/ui-server/tests/github-tools-host.test.ts, github-details.test.ts, github-write-tools.test.ts, ws-github*.test.ts, packages/ui-backend-pi/tests/github-tools.test.ts, packages/ui-react/tests/render/github-tools.test.tsx and tests/github-details.test.ts: 203 pass. One unrelated failure, github-reference-git.test.ts ("actual Git uses the fixed bounded HTTPS wire"), fails the same way on an origin/main worktree, so it is environment-only.

Real browser (ui-react-layout, pinned Chromium 1243 on the host): packages/ui-react/tests/browser/github-tools.layout.tsx, 2/2 pass. The new case presses each review's control in turn and checks the following: no detail call before the press, exactly one review-comments call after it, that review's comments under it, another review's never drawn, only GETs, and the chat store byte-identical.

Failing-first and mutation receipts. Each mutation was applied, the named assertion was seen failing, and the code was restored.

Where Mutation Fails
SDK field required (no .optional()) GITHUB_LINE_COMMENTS_LEGACY_ABSENT
SDK z.number() (no int/nonnegative) GITHUB_LINE_COMMENTS_REFUSED -1
host no enrichment (failing-first) GITHUB_LINE_COMMENTS_EXACT_PER_REVIEW
host count a partial page (drop the next-link guard) GITHUB_LINE_COMMENTS_CAPPED_UNKNOWN
host accept a comment with no review id GITHUB_LINE_COMMENTS_UNVALIDATED_MEMBERSHIP null
host drop the GitHub-total cross-check GITHUB_LINE_COMMENTS_TOTAL_MISMATCH
host unknown reads as zero CAPPED_UNKNOWN, FORBIDDEN_UNKNOWN, TOTAL_MISMATCH, UNVALIDATED_MEMBERSHIP
renderer renderer files at origin/main (failing-first) 8 new tests, incl. LINE_COMMENTS_GLOBAL_FALLBACK_RETIRED
renderer remove the review_id filter LINE_COMMENTS_FILTERED_TO_REVIEW, LINE_COMMENTS_EMPTY_FOR_REVIEW, LINE_COMMENTS_FOLLOW_BOUNDED
renderer widen the per-press follow bound LINE_COMMENTS_FOLLOW_BOUNDED
renderer no stop at the known count LINE_COMMENTS_STOP_AT_COUNT
renderer PR-wide section always LINE_COMMENTS_GLOBAL_FALLBACK_RETIRED
renderer remainder ignores reviews the result does not carry "carries none of the PR's reviews" (no control)
renderer mount every review's section on render 7 tests, incl. no detail request before the reader acts
browser remove the review_id filter "another review's comment is not drawn"

Provider history. The keyless guard (packages/ui-backend-claude/tests/provider-history.test.ts, packages/ui-backend-pi/tests/provider-history.test.ts) could not run on this host. Both fail before any turn with worker_host_unsupported (bwrap cannot create a user namespace; kernel.apparmor_restrict_unprivileged_userns=1), including with sandbox escalation. Nothing on the turn's path changed except new tool-result bytes: a new result carries one more field, appended as new content. Tools, the system prompt and earlier messages are untouched. The line comments themselves go only through #3796's display route, which its server test already proves leaves provider history unchanged (GITHUB_DETAIL_HISTORY_UNCHANGED). The render and browser tests check that the chat store and the "Brain read" line stay identical after loading.

{"version":1,"kind":"brain-check-pr-receipt","head":"b5f7de9c6b2e297976674e594b69cae47d2679ce","base":"origin/main","mode":"focused","startedAt":"2026-11-17T20:42:38.665Z","finishedAt":"2026-11-17T20:45:16.400Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":37487.94270199999},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":276.85823600000003},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":196.16299399999843},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":29.973383999997168},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":119722.880693}]}

Checklist

  • Focused local preflight/behavioral receipts passed; hosted proof runs on confirmation.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • Recorded independent review of the head: the orchestrator starts it after hand-back.
  • The PR and the issue carry milestone 0.45.0.
  • A changeset is included (.changeset/4147-review-line-comment-counts.md: ui-sdk and ui-server minor, ui-react patch).
  • No personal data anywhere in the diff.
  • The integration contract index and its MCP and package-API components are updated in the same CONTRACT: commit, with api-report/ui-sdk.txt.
  • Docs under docs/ reflect the change.
  • No fail-closed guard added or changed. The count's unknown state is data honesty, not a containment guard.
  • Provider history: the guard could not run on this host (see Proof). Nothing already sent changes.

Anything left open

  • Overlap with ui-react, ui-server: an honest author for the W4 comment preview, so it can use GitHubComment preview #4154 (honest author for the W4 comment preview), which another worker is doing in parallel: no PR for it existed when this opened. It will most likely touch packages/ui-react/src/components/chat/tool-cards/github-cards.tsx (the W4 GithubCommentPreview, a different region from PullRequestCard/useDetail here) and tests/render/github-tools.test.tsx (this PR only appends a describe).
  • Collisions: see the comment below.
  • Nothing else.

🤖 Generated with Claude Code

…count, so each review gets its own "Show n line comments" (#4147)

The shared review payload gains an optional, nullable `line_comments`, and
GITHUB_LIMITS gains `reviewComments` (100). A pull request read counts each
review's line comments from one bounded page of its review comments, grouped
by pull_request_review_id, and reports null for every review rather than a
partial total when the page is cut short, a comment names no review or is
malformed, GitHub's own total disagrees, or the credential cannot read them.
Detail-page reviews carry null; a legacy result without the field reads as
unknown.

The chat shows "Show n line comments" on each review with a known positive
count. Its press mounts that review's section, which loads #3796's
review-comments part filtered to the review, follows sparse pages at most
four per press and stops at the known count. The PR-wide section is retired
when every review in a complete list is counted; it remains, filtered to the
comments no counted review reaches, when a review's count is unknown or the
result does not carry every review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. area: ui-react React chat/files/voice components, stores, WebSocket transport. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 17, 2026
@uploads-sh

uploads-sh Bot commented Nov 17, 2026

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-react/src/components/chat/tool-cards/github-cards.tsx, packages/ui-react/tests/browser/github-tools.layout.tsx and packages/ui-react/tests/render/github-tools.test.tsx). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4196
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

uploads put after.png --pr 4196 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4196 --app ios --screen "Chat" --state after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4196 and the same screen, state and caption fields.

This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with uploads list --pr 4196. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

@schlessera

Copy link
Copy Markdown
Owner Author

Collisions

bun scripts/collisions.ts --json --pr 4196 at head 7e4f0053d6aca0ab54a148d06a3b8e647266f1bd (graph built at that commit): 14 reports, 13 closure and 1 textual.

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 7e4f005 against base d2b0a81. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4196,
  "head": "7e4f0053d6aca0ab54a148d06a3b8e647266f1bd",
  "base": "d2b0a814bb0a9750fc76c7602c1a41df58579284",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

@schlessera
schlessera marked this pull request as ready for review November 17, 2026 20:47
@schlessera
schlessera merged commit ade18f3 into main Nov 17, 2026
59 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-react React chat/files/voice components, stores, WebSocket transport. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-sdk, ui-server, ui-react: per-review line-comment count, so each review gets its own "Show n line comments"

1 participant