Skip to content

CONTRACT: test(ui-server): prove the Network card for raw GitHub API connections and document the GitHub tools (#3799) - #4132

Merged
schlessera merged 7 commits into
mainfrom
test/3799-github-network-card
Nov 17, 2026
Merged

schlessera merged 7 commits into
mainfrom
test/3799-github-network-card

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #3799

What changed

This PR proves end to end that a raw, unclassified shell connection to GitHub's API keeps its Network approval card (#3791 ruling 2). A new test drives the real app's WebSocket handlers, governed admission and the turn's own egress proxy (packages/ui-server/tests/github-network-card.test.ts). The fixture runs the hosted report's compound curl command, which the classifier reads as opaque. The card reaches the connected client with toolName: "Network", input: { host: "api.github.com", port: 443, method: "CONNECT" } and the description CONNECT to api.github.com:443. The client's status reads Waiting for approval: Network, and nothing is contacted before an answer.

  • Allow admits the held tunnel.
  • Deny returns 403 Forbidden - outward connection not approved, with the reason the tool prints.
  • Stop cancels the connection and withdraws the card, and a late answer admits nothing.
  • No client connected: the card is held, logged, and delivered to the next client that connects.

Both backends' fixed system brief (buildSystemPromptAppend, the append each interactive session retains once) now carries one bullet naming the four host GitHub tools under the backend's visible names (mcp__brain-ui__brain_github_* on Claude, the bare names on pi). It tells the model not to use gh, curl or WebFetch for GitHub, and to report and stop when the tools answer unavailable or policy_denied. The input is the new optional githubTools (additive, in the package-API contract and API report). A session retained before this keeps its append byte for byte. The docs now record the shipped behaviour:

  • the decision record's Outward actions section (rulings, dedicated credential, write allow-list, kept card);
  • the MCP contract and the contract index;
  • the policy reference;
  • the BRAIN_UI_GITHUB_TOOLS_TOKEN env reference, which previously covered only the reads, now with fine-grained permissions checked against GitHub's permissions page;
  • a hosting guide section on creating the token.

Why this shape

I found no runtime gap, so no product code changes beyond the note. The issue's suspected gap was a card that never reaches a client that isn't watching. The host already holds such a card and re-sends it on reconnect (resendPendingInteractive); the test now pins that behaviour. The remedy for a phone that stays away is the existing hold, bounded by the turn's timeout. No separate notification exists for a held card; that is recorded in the decision, not filed as a defect.

The first head (0c3661f) put the line in workerOutwardNote. That note travels in each turn's new-tail host context, not the system prompt, so heavy feedback failed: the guard found no line in the system, and worker-sandbox-note.test.ts saw the exact generated note move. The line now lives in the fixed brief, and the outward note is back to main's bytes. Claude's retained append passes github: true like the other always-present tools; pi passes it through its fixed caps (github: true was missing there). The Claude SDK-options snapshot is re-recorded for exactly that one inserted bullet in the four interactive modes. Autonomous modes and every other option stay byte-identical; I checked the diff field by field.

Proof

bun run check:pr --base origin/main   # exit 0, receipt below

Live-client test. github-network-card.test.ts passed 4/4 in three consecutive runs (about 3.5 s each). Each mutation was applied, run and restored:

Mutation Failing assertion
Drop GITHUB_API_HOSTS from outwardHosts (turn-egress.ts) GITHUB_NETWORK_CARD_REACHES_CLIENT (3 tests), GITHUB_NETWORK_AWAY_CARD_HELD
Change the card description GITHUB_NETWORK_CARD_NAMES_METHOD_AND_HOST (all 4)
Make approveOutward admit on deny GITHUB_NETWORK_DENY_REFUSES
Stop the turn's abort reaching the proxy (signal: new AbortController().signal) GITHUB_NETWORK_STOP_RECORDED (denied, not cancelled)
Skip the drain's expiry of a Network card in turns.ts and the safety-subscription expiry in permissions.ts GITHUB_NETWORK_STOP_WITHDRAWS_CARD
Make resendPendingApprovals a no-op GITHUB_NETWORK_CARD_REACHES_CLIENT (reconnect test)

The drain-only mutation survived on its own, because the safety subscription also withdraws the card on abort. That is a genuine second path, so both had to be broken together.

Brief. New tests, each with its mutation:

Test Mutation Failing assertion
ui-sdk/tests/github-tools-brief.test.ts drop the githubToolsLine push GITHUB_BRIEF_NAMES_TOOLS claude
ui-backend-claude/tests/sdk-options-units.test.ts (fixed append) github: false in the retained append CLAUDE_FIXED_APPEND_GITHUB_LINE
ui-backend-pi/tests/github-tools-brief.test.ts (new session, and a retained pre-#3799 append kept byte for byte) drop github: true from pi's fixed caps PI_FIXED_APPEND_GITHUB_LINE

Locally, worker-sandbox-note.test.ts now passes the CLAUDE_EXACT_NEW_TAIL_NOTE assertion that failed on the first head. Its pi half needs user namespaces, which this host lacks.

Provider-history guards. packages/ui-backend-{claude,pi}/tests/provider-history.test.ts now assert the brief's GitHub bullet is in the provider-facing system on every captured request; the existing identity tests hold its bytes. These are runtime-category tests. They cannot run on this host: bubblewrap cannot create an unprivileged user namespace. They fail the same way on an origin/main worktree, even with the sandbox lifted, so their proof is requested from hosted heavy feedback on this draft.

Hosted heavy feedback. Run 44008629928 on 76467d9 completed success, including the unit, runtime and provider-history jobs; the independent review of 76467d9 found nothing. The first head's run (43997233028, 0c3661f) failed for the reason described under Why this shape.

Merge and checks. origin/main merged at 7dfadc2 and again at 16dfb9c (#4124's routing docs landed beside this PR's sections; both merges were clean, no conflicts), then check:pr reran on 7e3d187. Typecheck and build. Root tsc --noEmit passed with NODE_OPTIONS=--max-old-space-size=8192; it runs out of heap at the default size on this host. bun run build and bun run lint passed.

Fixture note. The first draft opened its connection immediately after session_info. The host then refused the card as a stale safety admission, because the session binding landed in between. A real turn cannot reach that state: its first model request passes the inference relay, which settles the binding before any tool runs (settleOperation). The fixture now waits for the committed binding, with a comment saying why.

{"version":1,"kind":"brain-check-pr-receipt","head":"7e3d187ff6b6d412f2453f2a68af45a93f9487b3","base":"origin/main","mode":"focused","startedAt":"2026-11-17T04:34:20.889Z","finishedAt":"2026-11-17T04:35:34.411Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":13076.318677},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":123.60387700000138},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":96.25088099999994},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":23.376659000001382},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":60184.36686400001}]}

Checklist

  • Focused local preflight/behavioral receipts passed; heavy feedback run 44008629928 on 76467d9 succeeded (unit, runtime, provider-history). Ready-candidate confirmation runs at landing.
  • Acceptance criteria from the issue are all met.
  • The PR and ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799 carry milestone 0.45.0.
  • A changeset is included (.changeset/3799-github-tools-brief.md).
  • No personal data anywhere in the diff.
  • The integration contract index, MCP and package-API components and the API report are updated in the CONTRACT: commits.
  • Docs under docs/ reflect the change.
  • No fail-closed guard added or changed.
  • Provider history stays append-only: the bullet is in the once-retained append, and both keyless guards passed in heavy feedback run 44008629928 on 76467d9.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 2 commits November 17, 2026 00:40
…on at a live client (#3799)

An unclassified shell connection to api.github.com raises the Network card
at the connected client, naming method and host; allowing admits the held
tunnel, declining refuses it with the reason the tool sees, stopping the
turn cancels it and withdraws the card, and a card raised with no client
connected is held and delivered to the next client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st tools and record the kept Network card (#3799)

Both backends' fixed outward note now names the host GitHub tools under the
backend's visible names, says the worker holds no GitHub credential so gh,
curl and WebFetch cannot act as the user, and says to report and stop when
the tools are absent or answer unavailable or policy_denied. Each keyless
provider-history guard asserts the line is in the provider-facing system
on every request.

The governed-writable-workers decision records the #3791 rulings: host
tools, the dedicated credential, the write allow-list and the kept Network
card with its proven allow, deny, stop and reconnect behaviour. The MCP
contract, the contract index and the policy reference describe the raw
connection path. The BRAIN_UI_GITHUB_TOOLS_TOKEN reference now covers the
write tools and their fine-grained permissions, and the hosting guide
gains a token setup section.

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: test Coverage, harness or proof work with no behaviour change. 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: backends AgentBackend implementations and the seam they share. area: docs The docs/ tree and the README / AGENTS / CONTRIBUTING surfaces. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 17, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Collisions (bun scripts/collisions.ts --json --pr 4132, head 0c3661f511d17acebc1a2e972627c9592857e3ac): 20 reports, all of kind closure (shared test selection); none of kind path or unknown. Changed files that open PRs also edit:

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 0c3661f against base 40779d4. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4132,
  "head": "0c3661f511d17acebc1a2e972627c9592857e3ac",
  "base": "40779d4983def309fc5a036ce585c581a68839c1",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

schlessera and others added 3 commits November 17, 2026 02:13
…e fixed system brief, not the per-turn note (#3799)

The outward note travels in each turn's new-tail host context, not the
system prompt, so the previous commit's line moved the exact generated note
and never reached the fixed system. The line now lives in
buildSystemPromptAppend behind an optional githubTools input. Claude
passes it in the append each interactive session retains once; pi passes
it through its fixed caps. A session retained earlier keeps its append
byte for byte. The outward note is back to its main bytes.

The Claude SDK-options snapshot re-records only the inserted bullet in the
four interactive modes. The API report records the additive
GithubToolsBrief type and option, and the package-API contract describes
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…type (#3799)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Collisions at head 76467d9984693329a15c7dcc2f41e022d2ab47ac (bun scripts/collisions.ts --json --pr 4132): 17 closure and 1 textual; no path or unknown.

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 76467d9 against base 7dfadc2. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4132,
  "head": "76467d9984693329a15c7dcc2f41e022d2ab47ac",
  "base": "7dfadc217c406255935f7fc626594acf2c2e8b9a",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backends AgentBackend implementations and the seam they share. area: docs The docs/ tree and the README / AGENTS / CONTRIBUTING surfaces. 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: test Coverage, harness or proof work with no behaviour change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools

1 participant