Skip to content

CONTRACT: feat(backends,ui-sdk,ui-server): admit each web provider request for the calling turn - #3991

Merged
schlessera merged 3 commits into
mainfrom
feat/3687-web-call-admission
Nov 13, 2026
Merged

schlessera merged 3 commits into
mainfrom
feat/3687-web-call-admission

Conversation

@schlessera

@schlessera schlessera commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #3687 (part B; part A, the mandatory egress route, landed in #3990). Part of #2765.

What changes

Every external recipient a Pi web call reaches is now admitted for the calling turn, using the admission the turn already has.

  • Per-turn authority. The ws web slice builds it from the turn's frozen policy, the conversation's recorded exposures and the turn budgets (createWebAccess). Nothing the worker or the executor says goes into it, and it is never sent to the executor.
  • Before dispatch. Each provider a call names is checked before anything is queued (broker.ts).
  • Each connection.
    • Every connection the executor opens is attributed to the call in flight through the egress proxy's admitted hook (admitConnection, web-tools/host.ts).
    • A connection to a provider's API host is admitted again for that turn. This covers the automatic chain, extraction fallbacks (Jina's reader) and nested model calls (Gemini URL context), which no call field names.
    • A refusal is recorded as denied / call_not_admitted (new EgressAdmissionRefused). The call answers with the authority's code, not whatever the extension made of the failed connection.
    • A connection with no call in flight is refused, and so is one that could belong to two turns.
  • One request per connection. The executor sets keepalive: false, so a reused TLS tunnel cannot carry a request the host did not admit. The first test run proved this was needed: one tunnel carried two Exa requests.
  • Recipients (web-tools/recipients.ts). Curated ids and the pinned extension's API hosts map to provider-policy names. Gemini is google and OpenAI is openai, matching the inference recipients. A host-configured exaBaseUrl or firecrawlBaseUrl names its provider.
  • Data routing (G2) (web-tools/routing.ts). It applies Apify consent's rules: nothing goes to a recipient from a conversation that has shown it a folder the policy keeps from it, and an exposure the host cannot judge is refused. This extends ruling 3 of ui-server: let a proven allowed recipient's turn see its provider folders #2695, under which G2 governed only the inference recipient. The decision record says why.
  • Budget.
    • A blocked scope refuses with the budget's own message.
    • Each admitted provider request is recorded as a dispatched relayed attempt with no usage (observeWebProvider). It shows in unknownRuns for the turn, conversation and day, never as zero.
  • Contract (additive): new web tool error codes policy_denied and budget_exceeded, documented in docs/integration-contract/mcp.md.
  • Taint and attribution were already in place since backends: forward the four core Pi web tools over a constrained, recorded host bridge #3685. A new assertion shows the taint in the chat's SafetyHistory, and the session as restricted.

Disclosed gaps, also in the decision record

  • Pages a call fetches fall under the egress policy (G5): the route checks address, port and bytes, not routing.
  • A provider configured by hand outside the curated catalog is reached as a page. Its routing is not checked and its spend is not counted.
  • The budget coverage text is unchanged. It is a closed enum on the wire, and it already says other tool spend is not metered.
  • Two of my own choices are open to review:
    • the recipient names for web providers;
    • refusing every call in flight when one shared-turn connection is refused, since a connection cannot be tied to one of two concurrent calls.

Proof

  • packages/ui-server/tests/web-pi-executor.test.ts, 4 new tests on the real executor, egress route and pinned extension:

    • Every Exa request is admitted and counted once, all under one turn, and a page is not counted.
    • With a rule keeping notes/ from web providers and an exposure that showed notes/, the automatic chain is refused at the connection with policy_denied. Exa receives nothing, the egress record is call_not_admitted, and the page still works.
    • An explicitly named provider is refused before dispatch, with no call id and no request.
    • A blocked turn scope answers budget_exceeded with nothing sent.
  • packages/ui-server/tests/web-tools-admission.test.ts, 3 tests:

    • the recipient table, including configured base URLs;
    • the G2 matrix: unrestricted, allowed, conflicting, masked, unknown exposure, unexpressible selector, untranslated types;
    • connection attribution: no call in flight, a page, admit-and-count once, an ambiguous turn, a refusal that settles every call in flight, a failed admission.
  • packages/ui-server/tests/web-tools-broker.test.ts: in-flight lifecycle, per-owner scoping, the first refusal wins, and the refusal becomes the answer and the receipt.

  • packages/ui-server/tests/provider-relay-budgets.test.ts: a web attempt adds one unknown run to each scope, costs null (not 0), counts once, and does not block by itself.

  • packages/ui-server/tests/web-pi-delivery.test.ts: WEB_TAINT_IN_SAFETY_HISTORY and WEB_TAINT_RESTRICTS_THE_SESSION through SafetyHistory.read.

  • Mutations, each restored:

    Mutation Failing assertion
    connection admission skipped WEB_PROVIDER_REQUESTS_COUNTED, WEB_ROUTING_REFUSED_AT_CONNECTION, WEB_BUDGET_REFUSED
    pre-dispatch check removed "no call id: nothing was dispatched"
    keepalive: false absent (the first run) WEB_PROVIDER_REQUESTS_COUNTED (one request fewer than the provider saw)
    web_search dropped from the taint table fails at the earlier WEB_RESULT_RECORDED_BEFORE_PROVIDER, before the new history assertion runs
  • Broader runs:

    • The web, egress, budget and taint suites across ui-server, ui-sdk and backend-pi pass 112/0. The executor tests ran unsandboxed, because nested bwrap needs that locally.
    • Root tsc --noEmit passes, bun run build passes, and the API report is regenerated.

CI fix (4e46e0d): the first ready run went red on tests/pi-worker-runtime.test.ts (PI_HOST_WEB_FOUR_TOOLS_EXECUTE: all four tools ok:false). Its governance stand-in had no policy.providers, so the new per-recipient routing refused every call. The fixture and three ui-server stand-ins now carry a frozen provider policy. That test needs unprivileged user namespaces, which this host lacks, so its red→green receipt is CI run 43418819750 (red) and the next run (green).

{"version":1,"kind":"brain-check-pr-receipt","head":"4e46e0dacb21c122696f24d3004912cebfaff102","base":"origin/main","mode":"focused","startedAt":"2026-11-13T12:01:53.929Z","finishedAt":"2026-11-13T12:03:22.762Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12248.097302},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":99.0223590000005},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":67.45828799999981},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":19.91307500000039},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":76381.035523}]}

🤖 Generated with Claude Code

…quest for the calling turn

Every external recipient a Pi web call reaches is admitted for its turn:
a named provider before dispatch, and every request the executor sends to
a provider's API host while the call runs, extraction fallbacks and
nested model calls included. Data routing follows Apify consent's rules
over the conversation's recorded exposures, a blocked budget scope
refuses, and each admitted request counts as unknown spend, never zero.
A connection with no call in flight is refused, and the executor opens
one connection per request so a reused tunnel carries nothing unadmitted.

Adds the web tool error codes policy_denied and budget_exceeded.

Closes #3687

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 12, 2026
@schlessera schlessera added the contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. label Nov 12, 2026
…mission

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

Copy link
Copy Markdown
Owner Author

CI failure triage for exact head 9796df61deb4aa6f42374fa0a1a13064f53dc464, run 43418819750, unit (3):

tests/pi-worker-runtime.test.ts:85 reaches PI_HOST_WEB_FOUR_TOOLS_EXECUTE and fails because fetch_content, get_search_content, source_check and web_search all return ok: false. This is an assertion failure, not the earlier superseded draft cancellation.

The source exposes a concrete fixture mismatch: tests/fixtures/pi-worker-probe.ts:337 composes createWebAccess with only { policy: { hash: "rev-odyssey" } }. The new authority reads governance.policy.policy, then webRoutingRefusal dereferences policy.providers. That missing policy throws and the broker maps the admission exception to unavailable before dispatch.

The same hash-only real-web composition appears in packages/ui-server/tests/web-pi-worker.test.ts:57 and packages/ui-server/tests/web-pi-delivery.test.ts:65; packages/ui-server/tests/ws-web-access.test.ts:14 also supplies the old shape to its broker double. Please audit those compositions alongside this fixture, preserving the production admission refusal and the successful-call assertions.

This is a log/source diagnosis. I have not edited this branch, rerun native proof, or established the full runtime cause beyond the recorded assertion and missing fixture input. #3662 remains draft while this candidate owns the integration reservation.

Admission now routes each web recipient under the turn's frozen provider
policy (#3687), so a stand-in governance without policy.providers refused
every call. The Pi worker runtime proof (PI_HOST_WEB_FOUR_TOOLS_EXECUTE)
went red on CI; the three ui-server stand-ins get the same real shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera
schlessera marked this pull request as draft November 13, 2026 12:04
@schlessera
schlessera marked this pull request as ready for review November 13, 2026 12:04
@schlessera
schlessera merged commit 9e0e736 into main Nov 13, 2026
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backends: route host web execution through mandatory egress and per-call admission

1 participant