Repository navigation
feat: the external decision hook, ingress stage - #60
Merged
Merged
Conversation
fold's one out-of-process seam, and what makes declining a plugin runtime honest: an organization that needs its own judgement on the request path now has a place to put it that is a wire contract rather than a code-loading mechanism — reviewable, versionable, and runnable by a different team than the one running the gateway. The hook decides and cannot rewrite. fold either forwards a request verbatim or refuses it, which is what keeps the invisibility rule intact; a hook that could edit traffic would be the transformation non-goal with an extra hop. A hook that wants content changed refuses the call and says why, and the reason reaches the caller — unlike a policy denial, where the expected value is the operator's configuration, a hook denial is usually about the caller's own content, and a refusal nobody can act on becomes a support ticket rather than a fix. Ingress runs after policy, so the hook's allow is necessary but never sufficient and its operator is never handed traffic the gateway already refused. The compromise of a hook therefore costs availability, not authorization. timeoutMs and onError are required with no defaults. A hook without a bound is a gateway without one, and fold will not guess between fail-open and fail-closed: both readings are legitimate and guessing would be wrong half the time, in a direction an operator discovers during an incident. A timeout abandons the request rather than waiting, because a slow hook is more dangerous than a broken one — failing open turns it into an invisible bypass. Which is why a fail-open error is recorded on the event that proceeded: hookOutcome "error" under onError "allow" is the only record that a call went uninspected, and FoldHookErrors alerts on exactly that. Two scope decisions the design record did not make. resources/read is not inspectable yet — its probe fallback tries several upstreams for one URI, so inspecting it would multiply one decision by the size of the federation — and naming it in methods is a config error rather than a silent no-op, because a method fold does not inspect is a hook an operator believes is running and is not. And opting in takes two acts: configuring an endpoint does not put it on the request path until a stage is named. Cost is published rather than asserted: ~42 µs per decision against a local no-op endpoint, 107 allocations, with fold_hook_duration_seconds reporting the real thing in production. The added-latency gate is unmoved at 181 µs, because a deployment without a hook pays a nil check. Conformance 40/40. Phase 1 of docs/design-decision-hook.md. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Aug 13, 2026
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.
Phase 1 of
docs/design-decision-hook.md(#59) — Horizon 2, item 9.fold's one out-of-process seam, and what makes declining a plugin runtime honest: an organization that needs its own judgement on the request path now has somewhere to put it that is a wire contract rather than a code-loading mechanism — reviewable, versionable, and runnable by a different team than the one running the gateway.
{ "url": "https://inspector.internal/decide", "timeoutMs": 300, // required — no default "onError": "deny", // required — no default "stages": ["ingress"] // nothing runs unless a stage is named }The line the feature is built on
It decides; it cannot rewrite. fold either forwards a request verbatim or refuses it. A hook that could edit traffic would be the transformation non-goal with an extra hop. A hook that wants content changed refuses and says why — and the reason reaches the caller, deliberately, because unlike a policy denial (where the expected value is the operator's config) a hook denial is usually about the caller's own content.
Ingress runs after policy. The hook's allow is necessary but never sufficient, and its operator is never handed traffic the gateway already refused. A compromised hook therefore costs availability, not authorization —
TestHookRunsAfterPolicyasserts it never sees a policy-denied call.Both bounds are required, with no defaults. A hook without a timeout is a gateway without one, and fold will not guess between fail-open and fail-closed: both are legitimate, and guessing is wrong half the time in a direction operators discover during an incident. A timeout abandons rather than waits — a slow hook is more dangerous than a broken one, because failing open makes it an invisible bypass. So a fail-open error is recorded on the event that proceeded:
hookOutcome: "error"underonError: "allow"is the only record that a call went uninspected, andFoldHookErrorsalerts on exactly that.Two scope decisions the design record did not make
resources/readis not inspectable yet, and says so. Its probe fallback tries several upstreams for one URI, so inspecting it would multiply one decision by the size of the federation. Naming it inmethodsis a config error, not a silent no-op — a method fold does not inspect is a hook an operator believes is running and is not. It joins with the egress stage, where a resource's content is what mattered anyway.Opting in takes two acts. Configuring an endpoint does not put it on the request path until a stage is named. Deliberate for a feature whose misconfiguration is either an outage or an unnoticed bypass.
Cost, published rather than asserted
fold_hook_duration_secondsreports the real number in production, withFoldHookLatencyHighframed as what inspection costs, not a fold regression.Verification
make checkincludinggolangci-lint(which caught an unhandledBody.Close()— the drain-then-close matters here, since a fresh connection per decision would dominate the cost),make conformance40/40,make helm-check, and 8 integration tests: the deny path with its reason, the wire envelope asserted field by field, both failure postures across four broken-hook shapes, a hanging hook against its bound, and the two off-by-default guarantees.Docs: README
hooksection, security-model (it is both a trust boundary and a data-egress path), deploy checklist, operations. Phases 2–4 (egress, the reverse path, docs pass) remain.🤖 Generated with Claude Code