Repository navigation
policy: govern the requests upstreams make of the caller - #51
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.serverInitiatedDecisionputssampling/createMessageandelicitation/createbehind 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 carriesdirection: "server_initiated", which is the one place the exchange is legible, since the caller never sees it.The default is
allow, deliberatelyThat 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.TestServerInitiatedDefaultFlowsholds that guarantee; the production checklist is where operators are told to opt in.Notes from implementation
logging/setLevelbridges to every visible upstream at once, so it takesbridgeKeynow — options carry a decision about one upstream and cannot be shared across a fan-out.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 ./...) — greenmake conformance— 40/40, and CI agreesmake bench— added p50 280 µs against a 5 ms gateDesign record:
docs/design-server-initiated.md, added to the roadmap as Horizon 2 item 13.🤖 Generated with Claude Code