Skip to content

CONTRACT: feat(ui-sdk,ui-server,ui-react): serve on-demand GitHub detail pages and avatars outside the model's context - #4077

Merged
schlessera merged 5 commits into
mainfrom
feat/3796-github-detail-pages
Nov 16, 2026
Merged

schlessera merged 5 commits into
mainfrom
feat/3796-github-detail-pages

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

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's comments, reviews, review-comments, commits, files or checks (at most 30 items a page, opaque cursor) under the dedicated BRAIN_UI_GITHUB_TOOLS_TOKEN. GET /api/sessions/:id/github/avatars/:login?size= serves avatars from the brain's own origin: fetched from avatars.githubusercontent.com with no credential, accepted only as PNG, JPEG, GIF or WebP by their bytes within a 512 KiB / 1024 px cap, served with nosniff, and kept in a bounded in-memory LRU cache. Only the chat's owner account may read, and only objects and logins that a successful brain_github_* result in that session's recorded history returned. Page items reuse the tools' contract types, and each html_url passes githubDirectUrl or comes back null. Failures are typed: unavailable, rate_limited with reset_at and Retry-After, not_found, forbidden and upstream_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 internal fetchGithubDetailPage and githubAvatarUrl helpers for #3795.

Why this shape

  • Membership comes from the session's recorded history, not a new table. The route reads the session's history from its owning backend and parses the GitHub tool outputs with GITHUB_RESULT_SCHEMAS, so "returned in S" means exactly what the model saw. It still works after a restart, adds no write to ui.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.
  • Ownership uses the safety route's same-account rule (ui-server: an owner continuing a chat from another device is refused as a safety principal mismatch #3952): resolveChat names the chat's owner principal, and sameAccount accepts 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.
  • The avatar cache lives in memory (256 entries, 8 MiB, 6 h). It is bounded and disposable, and never touches disk, the brain or brain.db, so no new private state path needs masking.
  • Avatar logins also include authors from detail pages already served for that session (in memory, bounded), so a comment loaded on demand gets its avatar rather than initials. Those logins still come only from validated GitHub data, under the same session and owner checks.
  • The host.ts shaping 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

bun run check:pr --base origin/main   # passed, receipt below (head dd28029, after merging #4076 from main)
bun run test packages/ui-server/tests/github-details.test.ts packages/ui-server/tests/ws-github-details.test.ts packages/ui-react/tests/github-details.test.ts \
  packages/ui-server/tests/github-tools-host.test.ts packages/ui-server/tests/ws-github.test.ts packages/ui-server/tests/http-inventory.test.ts \
  packages/ui-server/tests/http-principal-boundaries.test.ts packages/ui-sdk/tests/github-tool-contract.test.ts   # 68 pass, 0 fail
tsc --noEmit (root)   # clean
bun run build         # exit 0 (exports changed; TS2883 check)

Acceptance criteria, each covered by a keyless test against loopback stand-ins for the GitHub API and the avatar host:

  • Paging with cursors and the page-size bound. github-details.test.ts: 45 comments arrive as 30 + 15 with next_cursor "2" then null, asked with per_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.
  • 404 / 403 / 400. An object no result in S returned, including feat: cost tracking — dynamic pricing, effective spend, detail retention, tool I/O capture #7 asked through another session, is 404 not_in_session and nothing is sent upstream. A non-owner is 403 not_owner; through the real app, a delegated agent principal gets 403. A part outside the set is 400 part, and an unissued cursor is 400.
  • History, taint and next turn. ws-github-details.test.ts: after three detail reads, GET /api/sessions/:id is byte-identical, the session's taint events are unchanged (the tool read's one), and the next turn's StartTurnRequest (prompt, attachments, profile, thinking level, budget context and limits, client, posture, surface flags) equals that of a control session which read nothing.
  • No credential and rate limit. 503 unavailable/no_credential with nothing sent. 429 rate_limited with reset_at from x-ratelimit-reset, plus a Retry-After header.
  • Avatars. A login in S's results is served, then cached (one upstream fetch). A login not in S, another session and a non-owner are 404. SVG and HTML labelled image/png, a body over the byte cap and an image over the pixel cap are 404 and not cached. Upstream requests carry no authorization and no cookie. With entries: 2, a third avatar evicts the oldest, the cache stays at 2, and the newest is still a hit.
  • Direct links. 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 back null, and conforming URLs come back unchanged.

After merging #3798 (#4076, ee55de168) into this branch: docs/integration-contract.md kept both index entries; host.ts got back the timeoutMs local that #4076's post uses (this PR had moved it into githubGet). 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):

  1. Dropped the session-membership check (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 404 failed: error: GITHUB_DETAIL_NOT_IN_SESSION /sessions/sess-aiaia/github/odysseus/ithaca/7/comments — Expected: 404, Received: 200. Restored: 15 pass.
  2. Made owns always true in app.ts. ws-github-details.test.ts failed: 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.ts cannot 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 through ui-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

  • Focused local preflight/behavioral receipts passed; hosted proof runs on the ready candidate.
  • Acceptance criteria from the issue are all met.
  • The PR and ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796 carry milestone 0.45.0.
  • A changeset is included (.changeset/3796-github-detail-pages.md).
  • No personal data anywhere in the diff (leakage gate passed).
  • The integration contract index (docs/integration-contract.md) and package-API component are updated in this commit; the routes are in the HTTP inventory as I.
  • Docs under docs/ reflect the change (docs/http-api.md section and inventory rows, 189 routes).
  • Guard checklist answered below.
  • Provider history stays append-only: nothing on a turn's path changed; the guard's local run is blocked by the host's missing user namespaces (above).

Proportionate-containment checklist (the owner and membership guard)

  • Trigger and gaps. It triggers on a caller who is not the chat's owner account, a chat whose ownership is unknown, or an object or login absent from the session's recorded GitHub results. It does not cover what GitHub itself lets the credential read; that is bounded by the token, as for the tools.
  • What it restricts. One request for one session's object. Nothing narrower exists, and nothing wider (the session, the host, the tools) is affected.
  • Restricted mode. A display read either is or is not within authority. There is no partial page worth serving, and the component falls back to the tool result it already shows (and to initials for avatars).
  • How it clears. By itself: once a later tool result in the session returns the object, the next request is served. No human action is needed.
  • Where the cause is recorded. In the typed response (not_owner, not_in_session), which the component renders. Nothing durable is needed for a refused display read.
  • Scope isolation. github-details.test.ts refuses 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. In ws-github-details.test.ts, the agent's 403 leaves the owner's pages working.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 2 commits November 15, 2026 22:49
…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>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. 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 15, 2026
@schlessera

schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner Author

Collisions (bun scripts/collisions.ts --json --pr 4077, head 9db10da00):

None blocks review. Whichever PR lands second resolves the textual overlaps when it merges origin/main.

@schlessera

Copy link
Copy Markdown
Owner Author

Candidate confirmation at b5f9b54f failed in unit (1) (https://github.com/schlessera/brain-kit/actions/runs/43792658010/job/133054768698) on one case: boot probe deadline > claude bounds cleanup with a hung killer (missing helper.pid). It is a known timing flake, unrelated to this diff: none of the modules the test imports changed, and main is green. Recorded on the reopened #1310 (no milestone). The Penelope/Odysseus owns build, lease and maintenance admission lines in that log are a nested self-test's planned failure, and the outer test passed. No code change.

@schlessera
schlessera marked this pull request as draft November 16, 2026 03:27
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 03:27
@schlessera
schlessera merged commit 4c541ad into main Nov 16, 2026
49 of 52 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-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-server: serve on-demand GitHub detail pages to the chat components, outside the model's context

1 participant