Repository navigation
CONTRACT: feat(ui-sdk,ui-server,ui-react): serve on-demand GitHub detail pages and avatars outside the model's context - #4077
Merged
Conversation
…ail pages and avatars outside the model's context Two internal ui-server routes give the chat's GitHub components what a host GitHub tool result left out (#3796): - `GET /api/sessions/:id/github/:owner/:repo/:number/:part?cursor=` pages an object's `comments`, `reviews`, `review-comments`, `commits`, `files` or `checks`, at most 30 items a page, with an opaque cursor, under the tools' dedicated `BRAIN_UI_GITHUB_TOOLS_TOKEN` and the fixed API origin. - `GET /api/sessions/:id/github/avatars/:login?size=` serves a login's avatar from the brain's own origin, fetched from GitHub's avatar host without any credential, accepted only as PNG, JPEG, GIF or WebP by its bytes within a 512 KiB and 1024-pixel cap, with `nosniff`, and kept in a bounded in-memory LRU cache that evicts and never grows. Every failure is an empty 404. Authority is bounded: the caller must be the chat's owner account (any of its logins, by the safety route's same-account rule), and only an object or login that a successful `brain_github_*` result in the session's recorded history returned is served. Anything else is 403 or 404 and sends nothing upstream. Page items reuse the tools' contract types; each `html_url` passes `githubDirectUrl` for its kind and identity or is `null`. Failures are typed (`unavailable`, `rate_limited` with `reset_at`, `not_found`, `forbidden`, `upstream_error`). Nothing either route serves is added to the conversation, journaled as turn input or recorded as taint. The SDK adds the detail part list, page size, review-comment, changed-file and check-run item schemas, the page schema and the detail error schema. The host's GitHub GET and payload shaping are shared with the new module, and a spent rate limit now carries its reset time internally. ui-react adds the internal `fetchGithubDetailPage` and `githubAvatarUrl` helpers. The HTTP inventory, the integration-contract index and package-API component, the API report and a changeset are updated. Refs #3796 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Collisions (
None blocks review. Whichever PR lands second resolves the textual overlaps when it merges |
…il-pages # Conflicts: # docs/integration-contract.md
schlessera
marked this pull request as ready for review
November 16, 2026 02:31
Owner
Author
|
Candidate confirmation at |
7 of 8 tasks
schlessera
marked this pull request as draft
November 16, 2026 03:27
schlessera
marked this pull request as ready for review
November 16, 2026 03:27
This was referenced Nov 16, 2026
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.
Closes #3796
What changed
The chat's GitHub components can now load what a host GitHub tool result left out, without any of it reaching the model. Two internal ui-server routes serve it.
GET /api/sessions/:id/github/:owner/:repo/:number/:part?cursor=pages an object'scomments,reviews,review-comments,commits,filesorchecks(at most 30 items a page, opaque cursor) under the dedicatedBRAIN_UI_GITHUB_TOOLS_TOKEN.GET /api/sessions/:id/github/avatars/:login?size=serves avatars from the brain's own origin: fetched fromavatars.githubusercontent.comwith no credential, accepted only as PNG, JPEG, GIF or WebP by their bytes within a 512 KiB / 1024 px cap, served withnosniff, and kept in a bounded in-memory LRU cache. Only the chat's owner account may read, and only objects and logins that a successfulbrain_github_*result in that session's recorded history returned. Page items reuse the tools' contract types, and eachhtml_urlpassesgithubDirectUrlor comes backnull. Failures are typed:unavailable,rate_limitedwithreset_atandRetry-After,not_found,forbiddenandupstream_error. Nothing served is added to the conversation, journaled as turn input or recorded as taint. The SDK adds the page, item and error schemas (CONTRACT, additive). ui-react adds the internalfetchGithubDetailPageandgithubAvatarUrlhelpers for #3795.Why this shape
GITHUB_RESULT_SCHEMAS, so "returned in S" means exactly what the model saw. It still works after a restart, adds no write toui.db(the hosted-app write guard forbids app-connection writes while serving), and needs no backfill. Recording objects on the host when a tool returns was the alternative. It would have needed a migration and a writer procedure, and could drift from the transcript.resolveChatnames the chat's owner principal, andsameAccountaccepts any of that account's logins. The host mints a principal at every sign-in, so strict principal equality would lock the owner out after signing in again. A delegated agent, another account and unknown ownership all get 403.brain.db, so no new private state path needs masking.host.tsshaping helpers and its GET are exported for reuse, not duplicated. A spent rate limit now carries its reset time internally. The tool result envelope is unchanged.Proof
Acceptance criteria, each covered by a keyless test against loopback stand-ins for the GitHub API and the avatar host:
github-details.test.ts: 45 comments arrive as 30 + 15 withnext_cursor"2"thennull, asked withper_page=30. An upstream commits page of 40 is cut to 30 (GITHUB_DETAIL_PAGE_SIZE_BOUND). Reviews, review comments, files (no diff) and checks (runs, then statuses) are also covered. Through the real app (ws-github-details.test.ts), the owner and a second owner login page all 45 comments.not_in_sessionand nothing is sent upstream. A non-owner is 403not_owner; through the real app, a delegated agent principal gets 403. A part outside the set is 400part, and an unissued cursor is 400.ws-github-details.test.ts: after three detail reads,GET /api/sessions/:idis byte-identical, the session's taint events are unchanged (the tool read's one), and the next turn'sStartTurnRequest(prompt, attachments, profile, thinking level, budget context and limits, client, posture, surface flags) equals that of a control session which read nothing.unavailable/no_credentialwith nothing sent. 429rate_limitedwithreset_atfromx-ratelimit-reset, plus aRetry-Afterheader.image/png, a body over the byte cap and an image over the pixel cap are 404 and not cached. Upstream requests carry noauthorizationand nocookie. Withentries: 2, a third avatar evicts the oldest, the cache stays at 2, and the newest is still a hit.github.com.evil.example, another owner/repo, another number, a mismatched comment id,http:, a mismatched review-comment id and a mismatched commit sha all come backnull, and conforming URLs come back unchanged.After merging #3798 (#4076,
ee55de168) into this branch:docs/integration-contract.mdkept both index entries;host.tsgot back thetimeoutMslocal that #4076'spostuses (this PR had moved it intogithubGet). Root typecheck (NODE_OPTIONS=--max-old-space-size=8192 bun run typecheck) exits 0. GitHub host, write-tool, detail, HTTP-inventory, contract and client tests: 81 pass, 0 fail.Mutation receipts (each restored, suite back to green):
routes/github-details.ts: fall back to the requested object when the scope has none).refusals > an object no GitHub result in the session returned is 404failed:error: GITHUB_DETAIL_NOT_IN_SESSION /sessions/sess-aiaia/github/odysseus/ithaca/7/comments — Expected: 404, Received: 200. Restored: 15 pass.ownsalways true inapp.ts.ws-github-details.test.tsfailed:error: GITHUB_DETAIL_APP_AGENT_NOT_OWNER — Expected: 403, Received: 200. Restored: 1 pass.Provider-history guard: nothing on a turn's path changed. The backends are untouched, and the routes only read history. Locally,
packages/ui-backend-{claude,pi}/tests/provider-history.test.tscannot start on this host, inside or outside the sandbox:WorkerHostError: ... bwrap: No permissions to create a new namespace, raised before any request. That is environmental and unrelated to this diff. The guard runs in hosted candidate CI (the backends are affected throughui-sdk).Collisions (
bun scripts/collisions.ts --json --pr <n>): see the comment below.{"version":1,"kind":"brain-check-pr-receipt","head":"dd280296ae7b89fe0b024fba513786b6a396a853","base":"origin/main","mode":"focused","startedAt":"2026-11-16T02:02:49.095Z","finishedAt":"2026-11-16T02:03:58.544Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12577.04286},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":105.70874000000185},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":79.57027899999957},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.59305999999924},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":56652.86037400001}]}Checklist
.changeset/3796-github-detail-pages.md).docs/integration-contract.md) and package-API component are updated in this commit; the routes are in the HTTP inventory asI.docs/reflect the change (docs/http-api.mdsection and inventory rows, 189 routes).Proportionate-containment checklist (the owner and membership guard)
not_owner,not_in_session), which the component renders. Nothing durable is needed for a refused display read.github-details.test.tsrefuses feat: cost tracking — dynamic pricing, effective spend, detail retention, tool I/O capture #7 asked through another session while the same object stays readable in S. Inws-github-details.test.ts, the agent's 403 leaves the owner's pages working.Anything left open
total_count: null: GitHub's list endpoints give no totals, and the tool payloads already carry them.🤖 Generated with Claude Code