Skip to content

policy: govern the requests upstreams make of the caller - #51

Merged
blakebauman merged 2 commits into
mainfrom
policy/server-initiated
Aug 13, 2026
Merged

blakebauman merged 2 commits into
mainfrom
policy/server-initiated

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Deny-by-default applied to one direction. Every client→upstream invocation is authenticated, limited, tenanted, policy-checked, and audited; the sampling and elicitation requests bridged back the other way passed none of it. An upstream could spend the caller's model budget in a loop, or put an arbitrary prompt in front of the caller's human, and the gateway forwarded both without an opinion or a record.

Only bridged sessions carry this traffic — the shared root session declares no such handlers — so the whole surface is the two handlers in bridgeOptions.

What this adds

policy.serverInitiatedDecision puts sampling/createMessage and elicitation/create behind the existing engine, matched on server and method (neither request has a name to match), decided against the principal whose in-flight call the request arrived under:

{
  "defaultDecision": "deny",
  "serverInitiatedDecision": "deny",
  "rules": [{
    "id": "research-may-sample",
    "subjects": { "groups": ["research"] },
    "allow": [{ "server": "corpus", "methods": ["sampling/createMessage"] }]
  }]
}

A denial answers the upstream with -32042 — a client is entitled to decline either request — and the audit event carries direction: "server_initiated", which is the one place the exchange is legible, since the caller never sees it.

The default is allow, deliberately

That is the point of it being a separate field rather than a reading of defaultDecision. This traffic flows in every deployment today, including deny-by-default ones, so folding it under the existing knob would have broken working installs on upgrade — a change of meaning the v1 contract and the frozen-defaults review both forbid. TestServerInitiatedDefaultFlows holds that guarantee; the production checklist is where operators are told to opt in.

Notes from implementation

  • logging/setLevel bridges to every visible upstream at once, so it takes bridgeKey now — options carry a decision about one upstream and cannot be shared across a fan-out.
  • The audit event is emitted after the client answers rather than at the decision: an allowed request is not a terminal response until there is a response, and on an elicitation the interesting number is how long the human took.

Out of scope, on purpose

Content questions — refusing an elicitation that asks for a password — stay out of the gateway and become a call site for the external decision hook. Logging and progress are notifications that cost the caller nothing and carry no answer to authorize; their risk is volume, which is phase 3's limiter. Phases 2–4 (the capability mirror, the reverse limiter and its metric) remain in the design record.

Verification

  • make check (gofmt, tidy, vet, build, go test -race ./...) — green
  • make conformance — 40/40, and CI agrees
  • make bench — added p50 280 µs against a 5 ms gate
  • Named invocations pay 8 bytes more (24 → 32 B, still one alloc, 14.6 ns unchanged): the options thunk captures one more pointer. Measured against a stashed baseline.
  • CI on this branch: run 31666441589, all seven jobs green

Design record: docs/design-server-initiated.md, added to the roadmap as Horizon 2 item 13.

🤖 Generated with Claude Code

blakebauman and others added 2 commits August 12, 2026 21:13
Deny-by-default currently applies to one direction. Every client-to-upstream
invocation is authenticated, limited, tenanted, policy-checked, and audited;
the sampling and elicitation requests bridged back the other way pass none of
it, so an upstream can spend the caller's model budget in a loop or put an
arbitrary prompt in front of the caller's human.

Records the design and settles the three questions it raises: the new decision
defaults to allow because this traffic flows in every deployment today and
folding it under the existing knob would break working installs on upgrade;
the enforcement pair has a reverse analogue worth taking, with the per-request
check as the boundary because a capability declared at initialize goes stale
on reload; and budgets count requests rather than tokens, since fold cannot
see the model call the client makes.

Content questions stay out and become a call site for the decision hook.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sampling and elicitation are bridged back to the originating client and were
forwarded unconditionally: an upstream could borrow the caller's model in a
loop, or ask the caller's human for a secret, and deny-by-default had nothing
to say about either. Only bridged sessions carry this traffic — the shared
root session declares no such handlers — so the whole surface is the two
handlers in bridgeOptions.

policy.serverInitiatedDecision puts them behind the existing engine, matched
on server and method (neither request has a name to match), decided against
the principal whose in-flight call the request arrived under. A denial answers
the upstream with -32042, which a client is entitled to say, and the audit
event carries direction "server_initiated" — the one place the exchange is
legible, since the caller never sees it.

The field defaults to allow, and that is the point of it being a separate
field: this traffic flows in every deployment today, including deny-by-default
ones, so folding it under defaultDecision would have broken working installs
on upgrade. TestServerInitiatedDefaultFlows holds that guarantee. The
production checklist is where operators are told to opt in.

Two notes from implementation. logging/setLevel bridges to every visible
upstream at once, so it takes bridgeKey now — options carry a decision about
one upstream and cannot be shared across a fan-out. And the audit event is
emitted after the client answers: an allowed request is not a terminal
response until there is a response.

Named invocations pay 8 bytes more (24 to 32 B, still one alloc, 14.6 ns
unchanged) — the options thunk captures one more pointer. Added p50 and the
conformance suite are unmoved: 40/40, and the default keeps the reverse path
behaving exactly as it did.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 1defa47 into main Aug 13, 2026
14 checks passed
@blakebauman
blakebauman deleted the policy/server-initiated branch August 13, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant