feat(spec): propose and prototype interceptor response envelopes #133
The proposal is Draft with five decision boxes open (receipt vs metadata, verdict-only envelope validity, the 64 KiB bound, option A to D), while this PR ships MUST text in §5.5 and public SDK types. docs/proposals/README.md says implementation follows the decision. Either set Status to Decided <date> here, tick or delete the decision list and keep the spec text, or hold §5.5 and the SDK surface until it is decided. Also drop the em dash on this line.
Vendor name. Say an existing { verdict, receipt } wrapper. The inline schema earlier in this document also differs from the shipped spec/schema/interceptor-response.schema.json; make them match or point at the file.
Two things. The spec defines only [Pure Specification] and [Default Implementation]; [Optional Transport Artefact] has no legend. Use an existing label or define the new one where the other two are introduced. And because P-005 is Draft, add directly under the heading: > Proposed under P-005 (Draft). Not part of the 0.1 contract until that proposal is decided.
envelope-owned is not defined, and the implemented rule is broader: from_json rejects duplicates at every object level of the text, including inside verdict, receipt and extensions values, while from_wire on a parsed value cannot see them at all. Suggested text: When the response is received as JSON text, a duplicate member at any object level of the text, including inside verdict, receipt and extensions, is invalid. A response received as an already-parsed value cannot carry duplicates; the receiving parser has already collapsed them. §7.7.6 states the same caveat for the declaration loader.
Say the bound is the sum of the two canonical forms, and say how it relates to the §5.3 evidence cap (10,240 bytes) so a reader knows the two are independent. Also state here that the envelope carries no version of its own and rides on the spec wire version; the proposal says it and the spec does not.
No reserved reason covers this. §11 defines host_error:verdict_invalid as a §5 failure only, and §6.3 has three rows without saying which applies. The Rust parser already emits VerdictInvalid, so the spec should say so: MUST treat a malformed envelope as {"decision": "deny", "reason": "host_error:verdict_invalid"} per §6.3, and widen the §11 cause to fails §5 validation, or a transport response that fails §5.5 envelope validation. Mirror the text in spec/reserved-reasons.json. A transport that declares the envelope form also needs a definition; nothing says where a transport declares it.
Receipts are not passed through byte for byte. serde_json turns integers outside i64/u64 into f64 and the JCS writer casts every integer to f64 before formatting. Repro: {"verdict":{"decision":"allow"},"receipt":{"n":18446744073709551616,"f":1E2}} parses and to_envelope_value emits "receipt":{"f":100.0,"n":1.8446744073709552e+19}. A provider signature over that receipt will not verify, and the host cannot tell. The existing ffi_surface::canonical_json rejects the same literal via canonical::scan_raw_integer_domain. Run that scan in from_json after parse_checked, add a Value walk over receipt and extensions for the from_wire path mirroring check_i_json, and add fixture cases for 18446744073709551616 and 9007199254740993. If byte preservation is not the goal, change the proposal row and §5.5 to say receipts are re-serialised as I-JSON and providers sign a canonical form they define.
This makes the response gate stricter than the strict gate on the same bare Verdict. validate_verdict accepts {"decision":"allow","foo":1} and {"decision":"allow","decision":"deny"}; normalize_interceptor_response rejects both. Every SDK inherits the split through the FFI. §5.5 says both gates apply every §5 rule, and verdict.schema.json is additionalProperties:false, so the strict gate is the lax one. Preferred: move the closed-member checks and the duplicate-key parse into verdict::from_wire / ffi_surface::validate_verdict, add #[serde(deny_unknown_fields)] to Evidence, delete validate_verdict_members, add a CHANGELOG line, and add fixture cases bare_verdict_unknown_member and duplicate_nested_verdict_member.
No depth bound on this path. A receipt holding a Value nested 200,000 deep aborts the process with a stack overflow; from_json is only safe because serde_json's default recursion limit of 128 happens to apply. Call crate::canonical::check_depth(raw) first, map to VerdictInvalid, and add a test that a 200-deep receipt returns an error rather than aborting. The from_json doc comment should then say where each check lives.
The offending key is echoed into the error detail unbounded here and at lines 78 and 274, and these checks run before the 64 KiB bound. A 1 MB unknown root member yields a 1 MB host_error detail that hosts log or place on records. Truncate to 64 chars with a marker, or report only the JSON pointer of the enclosing object, as canonical::validate_envelope does.
The receipt is cloned here, each extension value at line 82, and two more owned copies are built at lines 96 and 102 before the length is compared at line 106. Compute canonical_json on the borrowed values first, return the size error, then clone into the struct.
Vendor name in a shared fixture. Rename to provider_receipt. The content already uses the neutral provider/1.0.
Coverage gaps against §5.5. Add: metadata_at_limit (receipt {"p":"x"*65528}, canonical size exactly 65536, valid) and metadata_over_limit (65529, invalid), or build both from the constant in each SDK and correct the CHANGELOG claim; duplicate_receipt_member, duplicate_extension_member, duplicate_nested_verdict_member; non_object_verdict {"verdict":"allow"}; nested_verdict_invalid_decision, nested_verdict_transform_without_body, nested_verdict_host_error_reason. The core rejects each today; nothing pins it across SDKs. Add the fixture to the golden inventory in HARNESS.md and consider pinning error codes so the five SDKs map the same input to the same class.
This reads as a shipped feature. Say: A proposal (P-005, Draft) adds an optional response envelope for hosted transports ... The SDKs carry a prototype parser ... The shape may change before the proposal is decided. and link the proposal.
Say Spec §5.5 (proposed under P-005, Draft) adds .... Further down, kept in drift says the opposite of what is meant, and one bullet describes fixes to code that never shipped; fold those into the feature bullet.
Vendor name, and the claim is not true yet: no shared fixture pins the metadata bound. Say Shared fixtures pin the existing { verdict, receipt } response shape, namespaced extensions and duplicate rejection and add the bound cases, or leave the bound out of the sentence.
Thanks Liam. This is a well built prototype, and the envelope keeps Verdict closed as promised. I ran the spec text, the Rust core, all five bindings, the fixture and the docs through a full review with an adversarial pass on the untrusted path. Request changes for the items below. Inline comments carry the detail and the exact fix.
Blocking:
1. Decide the proposal before the spec text lands. P-005 is Draft and still lists receipt vs metadata, the verdict-only envelope and the 64 KiB bound as open, while §5.5 lands MUST text and public SDK types in five languages. Either record the decision in this PR and set P-005 to Decided, or hold the spec section and SDK surface until it is decided. I lean to recording the decision here so the stack ships together. Mohammad has the final say on the shape.
2. Receipt and extensions are rewritten, not passed through. Integers above 2^53 and exponent literals come back changed after the host re-serialises, so a provider signature over a receipt will not verify. The repo already has the bigint_json rule in canonical; the new gate must apply it. Inline on response.rs.
3. The response gate and the strict Verdict gate disagree on the same bare Verdict. Unknown members and duplicate keys pass validate_verdict and fail normalize_interceptor_response. Pick one behaviour for both. Inline on response.rs.
4. Spec text gaps: no reserved reason covers a malformed envelope; the duplicate-member rule uses an undefined term and omits the text-path caveat; §5.5 needs a Draft marker and the new section label is not defined anywhere. Inline on the spec.
5. Fixture gaps: no case for the 64 KiB bound although the CHANGELOG says there is; duplicates only tested at the root; no nested Verdict that fails a semantic §5 rule; no non-object verdict. Inline on the fixture.
6. sdk/python/python/agent_hooks/_core.pyi was not updated. Add def normalize_interceptor_response(response_json: str, /) -> str: ... after validate_verdict. mypy fails on response.py without it.
7. Product names. The fixture case azure_style_receipt, CHANGELOG line 15, P-005 line 303 and the PR body name a vendor. Rename the case to provider_receipt and say "an existing { verdict, receipt } wrapper". Product names stay out of the spec, fixtures and docs.
8. README and CHANGELOG present the envelope as shipped. Say it is proposed under P-005 (Draft) and may change.
9. Commit hygiene. Retitle the PR as a conventional commit (feat(spec): ...), and drop the Co-authored-by and Copilot-Session trailers from the three commits. The squash copies them otherwise.
Non-blocking, worth doing in the same pass:
from_wire(&Value) has no depth bound; a deep receipt aborts the process. Call check_depth first.validate_verdict_members is a second hand-kept copy of the Verdict member set. Fold it into verdict::from_wire so the two gates share one validator.agent_hooks, ctk) should be addressed for response extensions. "A transport that declares the envelope form" needs a definition. §5 intro and §1.1 still say an interceptor MUST return a Verdict with no cross-reference. The spec should state that the envelope rides on the spec wire version.receipt: null differently from the other SDKs. Go decodes with json.Number while the rest of the Go SDK does not. Rust alone exposes an always-envelope serializer. Python raises a private exception type from the response parser.ah_validate_verdict.CI is green at c567d0b. Once the blocking items are in I will re-run the review and approve.
Re-reviewed at 31f190e against the 16 asks. Thanks Liam, this is thorough.
Addressed: every spec text ask (reserved reason, duplicate rule, section label and Draft marker, 64 KiB sum and its relation to the evidence cap, version model, transport definition, cross-references, reserved namespaces, host handling of receipt and extensions); every core ask (bigint and exponent literals rejected so receipts survive re-serialisation, one shared validator for both gates, depth bound, bounded error detail, size bound before cloning); every fixture and SDK ask (the new cases, HARNESS.md, the Python stub, TypeScript null handling, Go decoding, the exported Python exception); the vendor name, the README and CHANGELOG wording, the commit subjects and trailers.
Accepted as is: the Rust-only always-envelope serializer stays, with the reason you gave.
One item is open and it is the maintainer's, not yours: P-005 is still Draft while §5.5, the schema and the SDK surface land in this PR marked as proposed. The request-changes stays until Mohammad records the decision (set P-005 to Decided and keep the text, or hold the section and SDK surface until then). Once he does, this is an approve from my side with no further asks.
Liam, thanks for the thorough update. All the review asks are closed and the implementation is in good shape. One design change before I decide P-005.
Drop receipt and keep extensions as the only carrier. A receipt is provider data, so it belongs under the provider's namespace: extensions.<provider>.receipt. Everything the proposal says about receipts already holds for extensions: opaque, re-serialised as I-JSON, never interpreted, the shared 64 KiB bound, no effect on enforcement, and signing over a provider-defined canonical form. The namespace rule also gives us two things receipt does not: two providers in one hosted stack cannot collide, and a reader can always tell who produced a field.
What we give up is small. A generic client has to know the provider's namespace to find a receipt, and the service that already emits { verdict, receipt } renames one member. Neither is a spec concern.
So the envelope becomes { "verdict": ..., "extensions": { "<ns>": ... } } with a closed root of two members. The receipt section of P-005 turns into guidance for providers on carrying a receipt under their namespace, and the schema, fixture cases and the five SDK types lose the receipt member. Keep the other four choices as proposed: an envelope with only verdict is valid, the 64 KiB bound on canonical extensions, bare Verdict when there are no extensions, I-JSON values with unsafe integer literals rejected.
With that change I will record P-005 as decided on this PR and we land the spec text, schema and SDKs together. The branch also needs a rebase; main moved under README and CHANGELOG this morning.
One housekeeping note: P-005 is already taken by #104 (retractability as a declared capability, opened October 1). Please renumber this proposal to P-006 in the next push: the file name, the Status line references, and the mentions in the spec section, schema description, README and CHANGELOG.
Checked 165a818 against the direction above. The design is done: the root is verdict and extensions, receipts live under the provider's namespace, the 64 KiB bound is over the canonical extensions object, the fixture pins the limit, the legacy root receipt is refused, all five SDK types match, and P-006 is the number everywhere. CI is green.
Decision recorded here: P-006 is decided as of 2026-10-15 with option D and the choices listed in the proposal, with extensions as the only carrier.
One more push and I approve:
Not blocking, your call: the parser checks the namespace grammar but does not refuse the reserved namespaces (acs, ctk, agent_hooks); the spec phrases the reservation as a provider obligation. If you prefer the parser to enforce it, add the check beside the grammar test with a fixture case per reserved name, in all five SDKs, in this PR or a follow-up.
Checked d38ddf4. The Status line reads Decided 2026-10-15, the Draft and proposed banners in the spec, both schema descriptions, the reserved-reasons cause text, README, CHANGELOG, HARNESS and the proposal now say adopted, and the branch is one commit rebased on main with your signoff only. The content diff against 165a818 is text only. CI is green.
Approving. I squash-merge now with a hand-written message; this lands in 0.1.0-beta.3. Thanks for carrying it through, Liam.
MohammadHaroonAbuomar
liamcrumm
What this proposes
Hosted interceptors often return provider data alongside a control decision. P-006 proposes a separate transport envelope without opening canonical
Verdict:The root is closed to
verdictand optionalextensions. Receipts belong underextensions.<provider>.receipt; a dedicated rootreceiptis rejected. All five SDK parsers accept bare Verdicts and envelopes. Only the nested Verdict affects enforcement; in-process signatures, composition and records remain unchanged.P-006 remains Draft pending the maintainer's formal decision. The October 15 review direction is implemented, but the proposal, spec section and SDK surface remain explicitly proposed/prototype until that decision is recorded.
Review fixes
68826589e3019cf88ea04b3f3b237fbcd8bb6926without rewriting PR historyNormal serialization prefers a bare Verdict when extensions are absent or empty. Rust's explicit
to_envelope_valueremains the shared FFI normalizer's always-envelope representation.Local validation
At
165a818ac8cbfed1e18c797370be72607341ad93:CI must be checked on this head; local results do not imply hosted checks are green. Whole-package mypy also reports two existing errors in unchanged
composition.py; the response module passes its focused check. No review replies, reviews or thread resolutions were posted. The existing non-draft state and target branch are unchanged.