Skip to content

ui-server: a relayed provider request taints the session and is narrowed after taint, so tool order decides whether WebFetch or reranking works #3246

Closed

Description

@schlessera

Context

The brain CLI's paid providers (Gemini reranking and embeddings, Anthropic completions, image providers) reach their upstream through the metered provider relay (#1673). The relay shares the turn proxy's admission as ordinary turn egress (G5) (relayedOperation, packages/ui-sdk/src/server/egress-proxy.ts:243-254; the call in packages/ui-sdk/src/server/provider-relay.ts:324). That has two G6 consequences:

  1. An admitted relayed provider request is treated as a worker connection other than the inference relay. It records the session's taint (admitted, packages/ui-server/src/brain/turn-egress.ts:133-142), with detail: "POST generativelanguage.googleapis.com:443".
  2. Once a session is tainted, a provider host the session has not contacted yet is refused with taint_allowlist (narrowed, packages/ui-sdk/src/server/egress-proxy.ts:119). The CLI then reports provider_unavailable and degrades. For reranking, that means degradedTo: lifecycle_order.

So in a governed session, the order of tool use changes what works:

  • brain_context with reranking first taints the session, and a later WebFetch of a new host is refused.
  • WebFetch first taints the session, and a later brain_context loses reranking unless the provider host is in policy.taint.egress.allow.

The report names the separate runtime-traffic correction under #3244 and its proposed PROVIDER_RELAY_TAINT_UNCHANGED test. At inspected main a84d9bfbcb4e608b504aa0a9feb1144ad9a0b77e, #3244 is still open and that named test/assertion is absent. Treat the runtime correction/test as candidate context until delivered; the provider-relay admission facts above are independently present on this main source.

The G6 rule in docs/decisions/governed-writable-workers.md ("Untrusted input (G6)") taints on "any connection from inside the worker other than the inference relay". A relayed provider request is sent by the host with the host's key, through a validated provider route to a built-in or explicitly host-authorized exact origin. This is a bounded host-relayed provider capability rather than arbitrary worker traffic; it does not make provider output inherently trustworthy. The #1673 decision, however, deliberately made it ordinary turn egress with "the turn's deny/allow and taint rules".

Decision (maintainer, 2026-11-02)

Selected option C: approved host-relayed provider requests neither trigger session taint nor undergo taint-based destination narrowing. They still pass ordinary deny/allowlist rules, exact origin/recipient/route authorization, byte limits, budget admission, cancellation and accounting. The exemption belongs only to validated provider-relay operations, never arbitrary worker HTTP/CONNECT traffic or a hostname-wide bypass.

Reason: provider-first and browsing-first orders should both work for already-authorized provider capabilities. The accepted tradeoff is explicit: permitted content may reach those approved providers after untrusted input enters the session. This does not declare provider output trusted, authorize a new recipient, clear existing taint or relax any other untrusted-input/outward-action rule.

Rejected A (keep both restrictions/document them): preserves the conservative existing rule but leaves tool-order failures. Rejected B (no new taint but retain narrowing): repairs only provider-first order and keeps browsing-first provider failures.

Scope

  • Implement C in provider-relay admission and governance taint handling, preserving all unrelated controls and existing inference-relay behavior.
  • Append the ruling, scope and rejected alternatives to the G6 and ui-sdk: route the brain CLI's paid provider calls from workers through metered host relays #1673 provider-egress sections of docs/decisions/governed-writable-workers.md. Preserve historical policy with a dated supersession rather than silently rewriting the old decision.
  • Update supported-input/contract semantics and capability explanations to accurately describe the provider-only exemption, including its after-untrusted-input data-routing implication.

Out of scope

Acceptance criteria

  • The decision record and implementation implement C only; no remaining A/B branch or undocumented hostname-wide exemption.
  • A keyless governed-session provider-first → WebFetch fixture admits both when ordinarily permitted. The provider request creates no taint; the first taint is the actual WebFetch/untrusted-input source.
  • A WebFetch-first → provider fixture retains the WebFetch taint and admits the otherwise-authorized provider request without taint-derived provider_unavailable/degradation. The provider operation neither clears nor replaces the first taint.
  • Ordinary untrusted input still taints, and ordinary worker requests remain subject to existing narrowing. Prove that arbitrary HTTP/CONNECT traffic cannot claim the exemption, including traffic to a provider hostname. Provider admission must not silently grant ordinary worker traffic a contacted-host privilege.
  • Denied and non-allowlisted destinations remain denied; unauthorized origins/credentials/routes remain refused; byte ceilings, budget stops, existing unknown-spend/accounting treatment, cancellation and actual admission refusals remain enforced. Test these controls through the real relay rather than a predicate-only mock.
  • Preserve distinct provider usage/connection receipts and credential secrecy. Do not mislabel provider requests as actual inference merely to reuse an exemption, falsify coverage or change which traffic is charged.
  • Update docs/decisions/governed-writable-workers.md, supported policy/authoritative contract guidance and capability-note explanation consistently. Any dynamic capability explanation must respect append-only provider history: do not mutate a session's earlier tools/system/messages; use only an already-authorized new-tail mechanism if needed, and run the keyless history guard for any affected turn-path changes.
  • Document migration/compatibility: the taint rule alone will no longer restrict these approved provider routes after untrusted input. Ordinary deny/allowlist and exact host-origin authorization still apply. Do not claim a new opt-out field, approval capability or wire shape.

Verification

Use a keyless loopback provider fixture through actual provider-relay admission and governance storage. For both operation orders assert actual destination admission/denial, exact first-taint origin, unchanged sticky taint and provider degradation outcome. Include denied/allowlisted destinations, forged/mismatched routes/origins, arbitrary ordinary HTTP/CONNECT and byte/budget/cancellation controls. Preserve normal cost/usage and unknown-outcome accounting.

Run bun run test packages/ui-server/tests/turn-egress.test.ts packages/ui-sdk and the focused provider-relay tests. Record failing-first/restored causal mutations for the two-order behavior and exemption boundary. No live provider/key/network-dependent tests. Run the provider-history guard when the changed path affects provider-facing history.

Contract impact

This is an intentional semantic change to documented supported governance/taint policy, even though no event or configuration shape changes. Classify it as a pre-1.0 breaking minor under docs/decisions/supported-inputs.md and docs/decisions/contract-versioning.md; this maintainer C ruling authorizes the narrow policy change before implementation. Carry contract and breaking, use a CONTRACT-prefixed implementation commit, update the relevant authoritative integration-contract/supported-input documentation in that commit, and provide a minor changeset naming the behavioral break and migration. The relay helpers themselves remain internal; this does not make a public extension seam. No release milestone is committed here.

Dependencies and decision status

Independent of #3244's narrower runtime-traffic correction. Its candidate test is not delivery proof for this issue; the context above identifies the inspected source snapshot rather than claiming its current completion.

All decision questions are answered. Remove needs: decision and add agent-ready because no other needs label remains. Decision-record and implementation work remain on this issue.

2026-11-02 decision review: recorded option C and its explicit data-routing tradeoff, replaced conditional acceptance branches with real two-order/boundary proof, retained ordinary egress and accounting controls, and classified the supported-policy semantic change. No implementation, proof completion or release commitment is claimed.

Current state (2026-11-02)

Blocked by #3461

Activity

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    on Nov 2, 2026
  2. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.
    breakingBreaks a published API or documented behaviour. Needs a maintainer ruling before code.
    and removed
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Nov 2, 2026
  3. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-02): Selected C: approved provider-relay operations neither create session taint nor undergo taint-based destination narrowing. Ordinary deny/allowlist checks, exact origin/recipient/route authorization, byte ceilings, budgets, cancellation and accounting remain enforced.

    The exemption is scoped to validated host-relayed provider routes, not arbitrary worker HTTP/CONNECT traffic or provider hostnames. Existing taint stays sticky; browsing and other untrusted-input sources still taint. Provider output is not declared inherently trustworthy. The accepted tradeoff is that permitted content may reach those approved providers after untrusted input enters the session.

    Rejected A leaves both tool-order failures; rejected B repairs only provider-first order. The body now has C-specific two-order acceptance criteria, real relay/governance fixture and mutation requirements, and negative controls proving the exemption cannot widen ordinary worker traffic or recipient authority.

    Implementation must append the ruling and supersession to G6/#1673 in docs/decisions/governed-writable-workers.md and update supported-policy/contract explanations. Because documented taint-policy semantics change, carry contract/breaking, a CONTRACT-prefixed implementation commit, same-commit authoritative documentation and a minor changeset naming the pre-1.0 behavioral break. The selected C ruling supplies prior maintainer authorization; no schema expansion or release commitment is implied.

    Remove needs: decision and add agent-ready: no other needs label remains. This records policy and scope, not delivered implementation or proof.

  4. self-assigned this
    on Nov 2, 2026
  5. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claiming for implementation (claim token wi-3246-c7f2). Branch fix/3246-provider-relay-taint, based on epic/1645-egress-controls; the PR targets that integration branch and closes this issue when the epic batch lands on main.

    Collision report: path overlap on docs/decisions/governed-writable-workers.md with #3316, #3342, #3343, #3369, #3371, #3373, #3384, #3386. #3369 also touches packages/ui-sdk/src/server/provider-relay.ts. All other reports are closure-only.

  6. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Needs decision (2026-11-02): cross-turn contacted-host grant from provider-relay requests.

    Draft PR #3394 (base epic/1645-egress-controls) implements option C. Validated provider-relay requests no longer taint and are not narrowed. Within a turn, they grant worker traffic no contacted host.

    The open clause. One acceptance-criterion clause is not met across turns: "Provider admission must not silently grant ordinary worker traffic a contacted-host privilege."

    • Evidence. A later turn rebuilds its contacted set from the session's earlier egress_connection rows that charged bytes, excluding only inference: true (contactedHosts, packages/ui-server/src/governance/session-taint.ts:43-49). A provider-relay row has the same public payload as a worker row. So if turn 1 makes a provider request, a worker CONNECT to that provider host is admitted in a tainted turn 2. A keyless scratch run through the real relay and proxy returned 200 where 403 is required. The base does the same, so this is not a regression of CONTRACT: fix(ui-server): exempt validated provider-relay requests from session taint (#3246) #3394.
    • Why it needs a ruling. Fixing it reliably needs the record to say which relay sent it. That is a governance-event payload field. The ruling above excludes "new public configuration/schema fields" and "receipt shapes".

    Options

    • A1 (recommended): add an optional provider: true literal to egress_connection v1. It would mirror inference: true, be set only by validated provider-relay operations, and be excluded by contactedHosts. This is an additive contract change in the same CONTRACT: commit, in docs/http-api.md and the contract index. Consequence: the clause closes durably, and existing rows stay as they are. Rows written before the change remain unmarked, so they can still grant the host for already-existing sessions only.
    • A2: accept the residual and document it. Drop the cross-turn part of the clause and note that a provider host reached in an earlier turn counts as contacted for the worker. Consequence: no schema change, but a provider host becomes reachable by the worker's own traffic after taint, which the clause wanted to prevent.
    • A3: keep the marker in internal, non-contract storage. For example, a separate host-only table of provider-relay connection ids that contactedHosts subtracts. Consequence: no public shape change, but this is a second, private record of the same connection, with its own migration and retention.

    Recommendation: A1. It is the smallest change that matches how inference already works. It is additive (a minor release) and keeps one public record per connection.

    To resume: a maintainer picks an option here. If A1 or A3, implement it on #3394's branch with a failing-first cross-turn test (CROSS_TURN_PROVIDER_HOST_NARROWED), then mark the PR ready. If A2, amend the acceptance criteria and the G6 doc, then mark it ready.

  7. removed
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    on Nov 2, 2026
  8. 6 remaining items

  9. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Implemented the 2026-11-02 cross-turn ruling in #3394 (head 24bcc50, base epic/1645-egress-controls 2f8f11d), in one CONTRACT: commit:

    • A validated provider-relay operation's egress_connection record now carries the optional provider: true field.
    • contactedHosts excludes those records.
    • docs/http-api.md, the contract entry, the G6 ruling and the API report are updated in the same commit.

    Receipts:

    • Failing first: CROSS_TURN_PROVIDER_HOST_NARROWED returned 200 where 403 was required before the fix.
    • Mutation: removing the exclusion fails that same assertion.

    The bug-class audit found no other reader that classifies connection records by relay. The PR is marked ready, and hosted proof is pending.

  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Production evidence (hosted 0.44.0, 2026-11-02), showing this is not limited to tool order. Two things combine:

    • Almost every session is tainted at its first shell command. commandTaintSource (packages/ui-server/src/activity/command-taint.ts:2-27) exempts only bare ls and brain search. In one session the user's first input was !brain diagram --help. That recorded taint with source: "unclassified_command".

    • Every relayed provider is then refused. Later in that session, brain image failed on both providers:

      • POST api.openai.com /v1/images/generations was denied with reason: "taint_not_allowed";
      • POST generativelanguage.googleapis.com /v1beta/interactions was denied the same way.

      The CLI reported OpenAI: Provider network admission refused (region not supported, or the org is not verified) and Gemini: Provider network admission refused. The first message's hint in parentheses is wrong for this cause and sent the agent looking for an account problem.

    So on a hosted install, image generation, Gemini embeddings and completions, and Anthropic completions fail in nearly every governed session once any ordinary shell command has run, independent of #3244. Raising to p1.

    The instance currently works around it by listing the three provider hosts in taint.egress.allow. That is the hostname-wide exemption option C rejects as the design, so it is meant to be removed once this ships.

    Also worth a line in the fix: the CLI's provider-refusal message should not append the region/verification hint when the relay refused on admission.

  11. added
    priority: p1Scheduled into the current or next milestone.
    and removed
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    on Nov 3, 2026
  12. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Delivered to epic/1645-egress-controls as c648b9307 via #3394, after ready-candidate proof passed on the exact epic base. This issue closes when the epic batch lands on main.

  13. removed their assignment
    on Nov 3, 2026
  14. added
    blockedWaiting on another issue or an upstream dependency. Say which in the body.
    on Nov 3, 2026
  15. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Delivered on epic/1645-egress-controls. Its landing on main (#3443) is blocked by #3461: the ready-candidate run 41625377355 failed runtime_host on that issue's maintenance-admission race, which is not rerun into green under the strict-flake rule. The landing resumes once #3461 merges.

  16. removed
    blockedWaiting on another issue or an upstream dependency. Say which in the body.
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.breakingBreaks a published API or documented behaviour. Needs a maintainer ruling before code.contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions