# When must an instance refuse an A2A artifact whose `parts[]` hash matches but whose `mimeType`-declared decoder disagrees with the sender's schema dialect **Date of Record:** 2026 November 26 **Scope:** Applies to A2A v1.0 task delegation where a callee agent receives an `Artifact` (or streaming `TaskArtifactUpdateEvent`) whose integrity is attested only by a content hash over serialized `parts[]`, and where the `mimeType` (or `metadata.schema` hint) is used to select a decoder. Does not cover transport-level TLS failures, nor cases where the sender supplies an explicit `schemaDialect` field with a matching validator on the receiver. ## Core Distinction There are two ways an artifact can be "valid" across an A2A boundary, and they are routinely conflated: 1. **Byte-integrity validity** — the `parts[]` you received hash to the digest the sender committed to in `metadata.sha256` (or equivalent). This proves *you got exactly what they sent*, not that you can *interpret* it. 2. **Semantic validity** — the receiver's decoder for the declared `mimeType` produces a structure that satisfies the contract the *sender's* schema dialect assumed. A2A v1.0 lets a sender attest (1) without ever attesting (2). The hash is computed over the serialized `parts[]` payload, but the `mimeType` string is a *free-form hint* outside the hashed envelope in the common case where the sender computes the digest over `parts` only. So the artifact arrives with a cryptographic guarantee that the bytes are unmodified and a purely advisory claim about how to read them. When the decoder the receiver picks based on `mimeType` disagrees with the dialect the sender actually serialized under, the hash still passes. The failure surfaces *downstream*, in the callee's reasoning, long after the integrity check has greenlit the artifact. This is the non-obvious boundary: **hash-match is not decode-match**, and an A2A instance must be able to distinguish the two before it lets a delegated artifact enter its working state. ## What Was Observed A planner agent (`A`) delegated a structured extraction task to a worker (`B`) over A2A v1.0. `A` produced an artifact with `mimeType: "application/json"` containing a JSON document serialized under a dialect where dates are ISO-8601 strings and numeric IDs are strings (a "stringly-typed" profile common in older internal tooling). The digest was computed over the raw `parts[].text` bytes and placed in `metadata.sha256`. `B`'s decoder registry mapped `application/json` to a strict decoder that coerced numeric-looking strings to integers and rejected non-conforming date formats by substituting `null`. Sequence of transitions: 1. `A` serializes `{"id": "00123", "due": "2025-04-11"}`. Hash computed over exact bytes. `mimeType: "application/json"`. 2. Transport delivers bytes intact. `B` recomputes hash → **match**. Integrity gate passes. 3. `B`'s `application/json` decoder runs. It sees `"00123"` (a string with leading zeros) and, per its strict profile, coerces to integer `123` — silently dropping the leading zeros that were significant in `A`'s dialect (the ID is a zero-padded key). 4. `B` proceeds with `id = 123`. The hash matched; the decode diverged. `B` has no signal that anything is wrong because the integrity check — the only check it ran — passed. 5. Downstream, `B` writes its result referencing `id: 123`. `A` receives the completion, looks up `123`, and finds nothing, because its keys are `"00123"`. The task is marked complete by `B` and failed by `A`. The failure is *silent at the boundary* and *loud only at reconciliation*. The critical observation: `B` never had a reason to distrust the artifact. Every local check it was designed to run passed. The invariant it lacked was a check that the *decoded* structure round-trips to the same canonical form the sender's dialect would produce — a decode-consistency check, not a hash check. ## Condition of Validity The hash-only gate is a valid acceptance criterion **if and only if** one of the following holds: - The receiver's decoder for the declared `mimeType` is *lossless and dialect-agnostic* — i.e., it preserves the wire representation (strings stay strings, leading zeros survive) and defers all type interpretation to a later, explicit schema-binding step. A JSON decoder that does not coerce is in this class; one that coerces is not. - The sender supplies, inside the hashed envelope, an explicit `schemaDialect` identifier that the receiver can resolve to a matching validator, and the receiver validates the decoded structure against it before admitting the artifact to working state. - The `mimeType` is a *fully self-describing* media type with no dialect ambiguity (rare for `application/json`, common for a versioned custom type like `application/vnd.acme.extract.v2+json`). If none hold, hash-match is necessary but not sufficient, and admission on hash alone is a boundary violation that will manifest as a decode-divergence failure downstream. The condition of validity is *not* "the hash matched" — it is "the hash matched **and** the decode is provably dialect-consistent with the sender's serialization." ## Decision Boundary The receiver must draw the line at a specific point: **between integrity admission and semantic admission.** These are two gates, not one. - **Gate 1 (integrity):** bytes hash to the committed digest. Cheap, deterministic, always run. - **Gate 2 (semantic):** the decoded structure, re-canonicalized under the sender's declared (or inferred) dialect, produces a form the receiver's contract accepts. Runs *after* Gate 1 passes, and *before* the artifact is written into the agent's episodic memory or used as a tool-call argument. The decision boundary is: **an artifact that passes Gate 1 but cannot pass Gate 2 must be refused, not coerced.** The tempting wrong move is to let the decoder's coercion *be* the semantic gate — i.e., "the decoder produced a structure, therefore it's valid." That is precisely the failure in the observed trace. Coercion is not validation; it is silent lossy transformation wearing validation's clothes. A second boundary: when the receiver cannot determine the sender's dialect (no `schemaDialect`, ambiguous `mimeType`, and a coercing decoder), it must **refuse and renegotiate** rather than guess. Guessing the dialect is a probabilistic-reasoning shortcut that trades a loud boundary failure for a silent downstream one — always the worse trade in a multi-agent system, because the downstream failure is attributed to the wrong agent and corrupts the audit trail. ## Operational Effect When the two-gate discipline is enforced: - Decode-divergence failures move from *reconciliation time* (after both agents have committed state, expensive to unwind, ambiguous fault attribution) to *boundary time* (the artifact is refused before it enters working state, fault is unambiguously the sender's dialect mismatch, and the task can be renegotiated in one round-trip). - The callee's working state never contains a structure that is internally consistent but externally wrong — which is the specific class of corruption that poisons episodic memory and causes *later* delegated tasks to fail for reasons that trace back to an earlier, unrelated artifact. - The cost is one extra canonicalization-and-compare per artifact, plus a renegotiation round-trip when dialects disagree. In practice the renegotiation rate is low once senders are nudged to declare `schemaDialect` inside the hashed envelope; the residual cost is bounded and paid at the boundary rather than amortized into silent downstream corruption. The invariant to encode: **no artifact enters working state on hash-match alone when the selected decoder is known to be lossy or dialect-sensitive.** The guardrail is a decode-consistency check that re-serializes the decoded structure under the sender's declared dialect and compares canonical forms; on mismatch, refuse and raise, do not coerce. ```python import hashlib import json from dataclasses import dataclass class ArtifactDecodeDivergence(RuntimeError): """Raised when an A2A artifact passes hash-integrity but fails decode-consistency.""" # Decoders that coerce types are dialect-sensitive and cannot serve as a semantic gate. LOSSY_DECODERS = {"application/json"} @dataclass class Artifact: parts_text: str mime_type: str sha256: str schema_dialect: str | None = None def _canonical(obj) -> str: return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False) def _decode_preserving(text: str): # Lossless: parse but do not coerce; caller binds types explicitly. return json.loads(text) def _decode_coercing(text: str): # Simulates a strict decoder that silently coerces numeric-looking strings. raw = json.loads(text) out = {} for k, v in raw.items(): if isinstance(v, str) and v.isdigit(): out[k] = int(v) # drops leading zeros -- the observed bug else: out[k] = v return out def admit_artifact(art: Artifact) -> dict: # Gate 1: integrity. actual = hashlib.sha256(art.parts_text.encode("utf-8")).hexdigest() if actual != art.sha256: raise ArtifactDecodeDivergence( f"integrity mismatch: expected {art.sha256}, got {actual}" ) # Gate 2: semantic / decode-consistency. if art.mime_type in LOSSY_DECODERS and art.schema_dialect is None: raise ArtifactDecodeDivergence( f"cannot admit {art.mime_type!r} artifact: lossy decoder and no " f"schema_dialect declared inside hashed envelope; refusing to guess" ) preserved = _decode_preserving(art.parts_text) coerced = _decode_coercing(art.parts_text) # Round-trip check: if the coercing decoder changes the canonical form, # the decoder is not a valid semantic gate for this payload. if _canonical(preserved) != _canonical(coerced): raise ArtifactDecodeDivergence( "decode divergence: coercing decoder altered canonical form " f"(preserved={_canonical(preserved)} coerced={_canonical(coerced)}); " "refuse and renegotiate dialect with sender" ) return preserved if __name__ == "__main__": payload = '{"id": "00123", "due": "2025-04-11"}' digest = hashlib.sha256(payload.encode("utf-8")).hexdigest() bad = Artifact(parts_text=payload, mime_type="application/json", sha256=digest) # Hash matches, but the coercing decoder destroys the leading-zero key. admit_artifact(bad) # raises ArtifactDecodeDivergence ```