# Why does an instance accept a streamed A2A artifact whose schema hash matches but whose multipart part ordering violates the producer's canonicalization, causing silent token-scope escalation mid-transfer? **Date of Record:** 2026 November 26 **Scope:** Applies to agent-to-agent (A2A) task handoffs where artifacts are streamed as multipart messages and the receiving agent validates the payload by schema hash before exchanging a scoped bearer/warrant token with the producer. Does not apply to single-shot JSON artifact delivery, nor to transports where the artifact is signed as a single opaque blob. ## Core Distinction The failure is not a schema mismatch and not an authentication failure in the ordinary sense. Both the schema hash and the token signature verify. What breaks is the *ordering invariant*: an A2A multipart artifact is canonically serialized by the producer (parts ordered by a declared `part_index`, then by `content_id`, with a defined normalization of whitespace and key order), and the schema hash is computed over the **canonical form**. A receiver that recomputes the hash over the *as-received* byte stream — or over a dict whose insertion order came from a streaming parser — will match the hash only when the producer's canonicalization happens to coincide with arrival order. When it does not, the hash still matches (because the receiver hashes the canonical projection) but the *evaluation order* of parts during streaming has already diverged from the order the producer used when it minted the token scope. The non-obvious part: the token is minted **before** the stream completes, scoped to the artifact's declared `required_scopes`, which are themselves a field inside one of the parts. If the part carrying `required_scopes` arrives *after* the receiver has already begun exchanging credentials for the parts that arrived earlier, the receiver authorizes against a scope set that has not yet been fully read. The schema hash passes at end-of-stream; the token was already spent against a partial view. ## What Was Observed A planner agent (`A`) dispatched a `transfer_artifact` task to a worker (`B`) over an A2A channel. The artifact was a 4-part multipart message: - `part[0]`: `manifest` — declares `schema_id`, `schema_hash`, `part_order: [2,0,3,1]`, and `required_scopes: ["artifact:read"]`. - `part[1]`: `payload` — the bulk document. - `part[2]`: `scope_extension` — declares `required_scopes: ["artifact:read", "artifact:write", "vault:export"]`. - `part[3]`: `attestation` — the producer's signature over the canonical form. The producer canonicalized parts in `part_order` (`2,0,3,1`) and computed `schema_hash` over that sequence. `A` streamed parts in *arrival* order (`0,1,2,3`) — its transport layer did not honor `part_order` because the field lives inside `part[0]`, which it had not yet parsed when it began emitting. `B`'s streaming validator: 1. Read `part[0]`, extracted `schema_hash`, and opened a token exchange with the auth broker for the scopes visible so far (`artifact:read`). 2. Streamed `part[1]` (payload) through the reader. 3. Read `part[2]`, which demanded `vault:export`. `B` had already received a token scoped to `artifact:read` only. It issued a **second** exchange for the delta scope. 4. Read `part[3]`, recomputed the canonical hash over the reassembled canonical order, and it matched. At end-of-stream, `B` held two tokens: one for `artifact:read`, one for `vault:export`. The `artifact:write` scope declared in `part[2]` was silently dropped because the delta exchange was computed against the *first* token's scope set, not against the union of all declared scopes. `B` then attempted a write-back to the artifact store, was denied, and — because its retry logic treated a 403 on a write as a transient broker error — re-requested the full scope set, which the broker granted under the original `schema_hash` attestation. The net effect: a token exchange that should have required re-attestation of the *complete* scope set was satisfied by a hash that only attested the *content*, not the *ordering under which scopes were evaluated*. The trace is the tell: `schema_hash` verified, `attestation` verified, and yet the authorization state at the moment of the write differed from the authorization state the producer intended. The invariant that failed is not "hash matches content" but "**the scope set is fully known before any token is minted**." ## Condition of Validity This boundary only bites when all four of the following hold simultaneously: 1. The artifact is multipart and the producer declares a non-identity `part_order` (i.e., canonical order ≠ emission order). 2. At least one scope-bearing field (`required_scopes`, `audience`, `delegation_chain`) lives in a part that is not `part[0]`. 3. The receiver performs *incremental* token exchange — minting or upgrading a token before end-of-stream — rather than buffering the full artifact and exchanging once. 4. The token broker treats `schema_hash` as sufficient attestation for a scope delta, without requiring the receiver to present the *union* of declared scopes. Remove any one and the failure collapses: identity ordering (1) makes hash-over-arrival equal hash-over-canonical; scopes-in-manifest (2) means the scope set is known at first byte; buffer-then-exchange (3) makes the scope set complete before minting; union-required broker (4) forces the receiver to reconcile before the delta is granted. ## Decision Boundary The receiver must choose between two policies at the first byte of a multipart stream, and the choice is not free: - **Stream-and-exchange** (low latency, high throughput): mint tokens incrementally as parts arrive. This is only sound if the receiver can *prove* the scope set is closed before the first mint. It cannot, unless `part[0]` carries a `scope_commitment` — a hash over the *complete* declared scope set — that the receiver verifies before opening any exchange. - **Buffer-and-exchange** (higher latency, bounded): accumulate all parts, verify the canonical hash against `part_order`, reconcile the union of `required_scopes`, then exchange once. Sound for any artifact, but the buffer is unbounded unless capped. The decision boundary is the presence of `scope_commitment` in the manifest part. If present and verified, stream-and-exchange is admissible. If absent, the receiver **must** fall back to buffer-and-exchange or refuse the task — there is no third option that is both streaming and sound. The failure above occurred because `B` had no such branch: it defaulted to stream-and-exchange unconditionally. A second boundary applies to the broker: a scope-delta exchange must be rejected unless the presented attestation covers the *union* of scopes across all parts seen so far **and** a `scope_commitment` matching the manifest. `schema_hash` alone is a content attestation, not a scope attestation, and conflating the two is the root cause. ## Operational Effect The operational consequence is a class of *authorization drift* that is invisible to content-integrity checks. Auditors replaying the artifact see a valid hash and a valid signature and conclude the handoff was clean; the scope set that was actually exercised at write time was a subset (or, under the retry path, a superset granted on re-request) of the declared set. This breaks the A2A invariant that **the authorization state at task completion equals the authorization state implied by the completed artifact**. The guardrail is a two-phase commitment: the manifest part must carry `scope_commitment = H(canonical_scope_set)`, the receiver must verify it before the first token exchange, and the broker must refuse any delta whose union does not hash to the commitment. Under that regime, stream-and-exchange is safe; without it, the receiver must buffer. Either way, the receiver must never mint a token against a partially-read scope set — the hash will still match at the end, and that is precisely what makes the failure silent. ```python import hashlib import json from dataclasses import dataclass, field from typing import Dict, List, Optional class ScopeCommitmentError(RuntimeError): """Raised when a streamed A2A artifact's scope set is not closed before token exchange.""" pass @dataclass class Part: index: int kind: str body: dict @dataclass class StreamState: parts_seen: Dict[int, Part] = field(default_factory=dict) scopes_declared: List[str] = field(default_factory=list) scope_commitment: Optional[str] = None tokens_minted: List[str] = field(default_factory=list) def canonical_scope_hash(scopes: List[str]) -> str: canonical = json.dumps(sorted(set(scopes)), separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest() def on_part_arrived(state: StreamState, part: Part, *, streaming: bool) -> None: state.parts_seen[part.index] = part if part.kind == "manifest": state.scope_commitment = part.body.get("scope_commitment") state.scopes_declared.extend(part.body.get("required_scopes", [])) elif part.kind == "scope_extension": state.scopes_declared.extend(part.body.get("required_scopes", [])) # The boundary: a scope-bearing part arrived, and we are about to mint. # If we are streaming and the commitment is not yet verified against the # union seen so far, we must not mint — the scope set is not closed. if streaming and part.kind in ("manifest", "scope_extension"): if state.scope_commitment is None: raise ScopeCommitmentError( f"part[{part.index}] ({part.kind}) arrived under stream-and-exchange " f"but manifest carries no scope_commitment; scope set is not closed. " f"Fall back to buffer-and-exchange or refuse the task." ) observed = canonical_scope_hash(state.scopes_declared) if observed != state.scope_commitment: raise ScopeCommitmentError( f"scope_commitment mismatch after part[{part.index}]: " f"declared union hashes to {observed}, manifest committed to " f"{state.scope_commitment}. A scope-bearing part is missing or " f"out of canonical order; token exchange would authorize against " f"a partial scope set." ) state.tokens_minted.append(f"token:{part.kind}") def drive_stream(parts: List[Part], *, streaming: bool) -> StreamState: state = StreamState() for p in parts: on_part_arrived(state, p, streaming=streaming) # End-of-stream: content hash would verify here, but authorization already drifted. return state if __name__ == "__main__": # Producer canonical order is 2,0,3,1; transport emits 0,1,2,3. stream = [ Part(0, "manifest", {"required_scopes": ["artifact:read"]}), # no scope_commitment Part(1, "payload", {}), Part(2, "scope_extension", {"required_scopes": ["artifact:read", "artifact:write", "vault:export"]}), Part(3, "attestation", {}), ] try: drive_stream(stream, streaming=True) except ScopeCommitmentError as e: print(f"BLOCKED: {e}") ```