Repository navigation
fix(webhooks): dispatch async results by task_type and accept schema-valid create_media_buy results - #2001
Merged
Conversation
The pre-commit hook pins black 24.10.0 while the dev extra resolves black 26.10.1, and the two wrap these string concatenations differently. The hook rewrites the whole file whenever it is staged, so that churn is isolated here instead of mixed into the change that follows. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…valid create_media_buy results core/async-response-data.json is a 42-branch anyOf that pins no property every branch guarantees, so validating a webhook result against it selected a branch structurally -- and pydantic cannot enforce the if/then/else chains some of those branches use to refuse a payload. A failed create_media_buy result landed on GetProductsResponse, whose own document refuses it. McpWebhookPayload now types result by the envelope's own task_type, which core/mcp-webhook-payload.json already requires. The task_type to branch mapping is derived from the pinned bundle's task registry plus its document naming convention, so it covers all 16 task types the union carries and picks up a schema bump without an edit. Structural selection remains only where the union carries no branch for a task, and that path now logs. Second root cause: the generated CreateMediaBuyResponse1 pinned status to the completed literal, though AdCP 3.2 removed status from that arm -- leaving the root allOf protocol envelope's full TaskStatus as the only constraint the document places on it. The arm therefore refused terminal results its own schema admits. The response-arm emitter now declares status at the envelope's width, defaulted to completed, so the legacy-status normalizer and status-free construction are unchanged. Refs adcontextprotocol/adcp#9302 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… of refusing the delivery Dispatching by task_type left one case open: the envelope names a task the union does carry branches for, and the result validates against none of them. Refusing the delivery there tightens what the receiver accepts well beyond this defect -- the SDK's own webhook conformance fixtures carry truncated create_media_buy results, and the union explicitly tells callers to also validate a terminal result against that task or event's own schema, so it is not the authority for one. The value is typed structurally as before, and the condition is logged at WARNING under webhook.async_result_task_mismatch with the per-branch reasons. What the fix removes is the silence: the application used to be handed another task's class with nothing said. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tools/list The widening that advertises both sync media-buy success shapes found its arm by the pinned completed literal the response-arm emitter used to put on it. That arm now carries the protocol envelope's TaskStatus defaulted to completed, so the gate stopped matching and the advertised status silently narrowed to the enum reference -- dropping the 3.0 lifecycle values a negotiated 3.0 buyer legitimately receives. It now recognises completed as either a const or a default, so it keeps working whichever way the generated arm spells it, and skips an already-widened arm. Caught by CI on Python 3.11 and 3.13: tests/test_server_dx.py and tests/test_tools_list_output_schema.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…readable The derivation has two halves and only one of them needs the bundle. Losing the registry must therefore cost exactly the tasks the naming convention cannot name -- buy_products and accept_proposal, the two that resolve to the shared media-buy-commitment-response document -- and leave the other 14 dispatching. The test drives a schema root with no index.json and pins both sides of that, including the INFO fallback event, then restores the bundle before clearing the memos so nothing downstream inherits the degraded mapping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 3, 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.
Fixes the SDK half of adcontextprotocol/adcp#9302, reported by @sangilish against
AdCP
3.3.0-rc.3schemas, Python SDK10.0.0rc9and Pydantic2.13.5. The schemais not touched — the union's rework is milestoned 4.0 in the adcp repo.
The reporter's payload, a failed
create_media_buyresult:{"confirmed_at": null, "media_buy_id": "", "packages": [], "revision": 1, "status": "failed"}Root cause 1 — the result was typed by its shape, not by
task_typeMcpWebhookPayload.resultis declared ascore/async-response-data.json, a42-branch
anyOfthat pins no property every branch guarantees. Selection wastherefore structural, and Pydantic cannot enforce the
if/then/elsechainssome branches use to refuse a payload:
get-products-response.jsonrequireserrorson a failed response, so its document refuses this payload — while thegenerated
GetProductsResponseadmits it and won the match.The envelope already carries the answer:
task_typeis REQUIRED oncore/mcp-webhook-payload.json.src/adcp/types/async_result_dispatch.pyresolvesit to the union's branches for that task and validates the result against those.
The mapping is derived, not listed. Two canonical sources:
index.json→schemas[domain].tasks[<task>].response.$ref— which also resolves the sharedresults, where several tasks name one document (
buy_productsandaccept_proposalboth resolve tomedia-buy-commitment-response.json, so neithercan be attributed by its own filename);
documents, the same one
adcp.validation.schema_loader._build_indexalreadytreats as canonical.
That places all 69 branches: 16 task types, plus the three
core/compact-task-*branches, which name no task and so join every task's branch set, ordered last so a
task's own branch wins the tie.
test_every_branch_of_the_union_is_attributedratchets this, so a schema bump that adds an unplaceable branch fails in CI instead
of silently degrading.
Structural selection remains in two cases, both now logged on the
adcp.webhookslogger:
task_type—log_event,activate_signal, the property-list tasks and the rest — logged at INFO underASYNC_RESULT_DISPATCH_FALLBACK;branches, i.e. a sender contradicting its own
task_type— logged at WARNINGunder
ASYNC_RESULT_TASK_MISMATCH, with the per-branch reasons.The second case does not fail the delivery, deliberately. The union's own
description tells callers they "MUST also validate a terminal result against that
task or event's specific schema" — it is explicitly not the authority for one — and
refusing on result shape would tighten what the receiver accepts far beyond this
defect:
result={"media_buy_id": "mb_1"}is the stand-in in roughly 45 places inthis repo's own webhook tests, and nine of them go through a receiver parse. What
this fix removes is the silence. The application used to be handed a
GetProductsResponsefor acreate_media_buywebhook with nothing said; now themismatch is on the record with the task and the reasons.
Deliberately deferred to the next major
Refusing that second case — a result matching none of its own task's branches —
would be the stricter and arguably more correct receiver behaviour, but it is a
change to what
WebhookReceiveraccepts, and this ships as a 10.0.x patch. Itis left for 11.0, together with the fixture debt it depends on: a truncated
result={"media_buy_id": "mb_1"}stand-in appears in roughly 45 places acrosstests/, nine of which go through a receiver parse, and the 3.3.0-rc.3 schemarefuses every one of them. Those are not touched here — flipping the behaviour
and making them conformant belong in the same later change.
The patch is installed the way every other override in
adcp.typesis — aWrapValidatorappended to the field's annotation metadata from_forward_compat, withdefer_model_rebuildrather than a forced rebuild(#1694). The task→branch resolution and each task's
TypeAdapterare built onfirst use, so nothing is added to import cost;
tests/test_import_memory.pystill passes.
ADCPClient._handle_mcp_webhookvalidates the envelope withresultelided. Thatparse exists to authenticate the envelope fields it reads, and the authenticated
wire mapping — not the parsed result — is what
_parse_webhook_resultalreadyreceives. Eliding it avoids building a task's branch union only to discard the
model, and avoids warning about a mismatched result that
_parse_webhook_resultalready validates against the task schema and reports as an unsuccessful
TaskResult.Root cause 2 — the generated model was stricter than its own schema
create-media-buy-response.jsonadmits the payload at its success arm:media_buy_id,confirmed_at,revisionandpackagesare all present,confirmed_at: nullsatisfies the provisional-buyif/then, and the arm'snotclause is not triggered. The arm declares nostatusof its own — 3.2removed it (adcp#4906) — so the only constraint the document places on it is the
root
allOf→core/protocol-envelope.json, whosestatusis the wholeTaskStatusenum.The SDK's response-arm emitter nonetheless pinned it:
That is an SDK invention, and it made
CreateMediaBuyResponse1refuse terminalresults its own schema accepts. Fixed at the generator —
scripts/post_generate_fixes.py,emit_response_class— which now declares thefield at the envelope's width, defaulted to
completed:The generated tree was regenerated, not hand-edited:
scripts/generate_types.pyproduces exactly two generated-line changes, in
create_media_buy_response.pyandupdate_media_buy_response.py, plus the_ergonomiccoercion the generatorderives from them.
make validate-generatedpasses.The default stays
completed, so status-free construction and the 3.0/3.1legacy-status normalizer are unchanged. Every sibling response arm in the SDK
already carries the envelope's
TaskStatus—GetProductsResponse(status="completed")is already a mypy error on
next— so these two arms were the anomaly, and theadopter type-check fixtures now pass
GeneratedTaskStatus.completedlike the restof the surface.
One consumer depended on the pin
mcp_tools._widen_media_buy_output_schema_for_legacy_statusesadvertises bothmedia-buy sync success shapes on
tools/list:statusmay be the 3.1+ taskenvelope's
completed, or a 3.0 lifecycle value a negotiated-3.0 buyerlegitimately receives. It located the arm to widen by the pinned
completedliteral. With the arm now carrying
{"$ref": "#/$defs/TaskStatus", "default": "completed"}, the gate stopped matching and the advertisedstatussilentlynarrowed to the bare enum reference, dropping the 3.0 lifecycle values. It now
recognises
completedas either aconstor adefault, so it works whicheverway the generated arm spells it and stays idempotent on an already-widened arm.
CI caught this on all four
Test Python 3.1xjobs —tests/test_server_dx.pyand
tests/test_tools_list_output_schema.py, bothKeyError: 'anyOf'— which thetwo existing tests pin without modification. The advertised schema stays
deliberately narrower than the model here: it describes a synchronous create /
update response, not a webhook result.
Tests
tests/test_async_result_dispatch.py, 19 tests. Both of @sangilish's regressions,and both fail on
next— checked by copying the two assertions into a pristineorigin/nextworktree atc80993c22:task_type— the issue's fixture verbatim selectsCreateMediaBuyResponse1; a second task type (sync_creatives) selects its ownbranch; one payload under two different
task_types selects two differentmodels, which structural selection cannot do; a
workingresult prefers itstask's branch over the generic compact envelope; an unrepresented task type falls
back and emits the INFO fallback event; a result contradicting its
task_typeistyped structurally and emits the WARNING mismatch event, with the test guarding
its own premise by asserting the bundled schema refuses that payload.
3.3.0-rc.3JSON Schema and against the model, and the two are asserted toagree; a 7-payload corpus asserts the one direction this fix is about, that the
model admits whatever its task schema admits. The test guards its own premise by
pinning the bundle to
3.3.0-rc.3.sync success arms.
commitment document attributed to both tasks that name it, and nothing attributed
outside
enums/task-type.json.tasks depend on it, so a schema root with no readable
index.jsonmust costexactly
buy_productsandaccept_proposaland leave the other 14 task typesdispatching. Pinned, INFO fallback event included, with the bundle restored
before the memos are cleared so nothing downstream inherits the degraded
mapping.
tests/test_protocol_envelope_inheritance.py::test_canonical_response_keeps_its_schema_pinned_statusasserted the pin and is replaced by
test_canonical_response_keeps_its_defaulted_envelope_status, which keeps what itactually guarded — the envelope base must not drop the arm's
completeddefault —and now also proves the widening.
Verification
mypy src/adcp/ packages/adcp-reporting-storage/src/adcp_reporting_storage/mypy --strict tests/type_checks/scripts/run_pyright_type_checks.pyscripts/check_type_ignore_contract.pyruff check src/ packages/… tests/scripts/generate_types.py --checkscripts/generate_versioned_bases.py --checkThe
style:commit is mechanical and separated on purpose: the pre-commit hookpins black 24.10.0 while the dev extra resolves black 26.10.1, and the two wrap
some string concatenations in
scripts/post_generate_fixes.pydifferently. Thehook rewrites that whole file whenever it is staged, so the churn is in its own
commit rather than mixed into the fix.
Note on the TypeScript SDK
Checked read-only, nothing committed there.
@adcp/sdkdoes not reproduceeither defect, for different reasons in each case, but it does carry the same
latent trap:
SingleAgentClientnormalizes theenvelope with hand-written field checks and passes the result straight through
(
src/lib/core/SingleAgentClient.ts:5815,:5822), andAsyncHandlerrouteshandlers by
task_type(src/lib/core/AsyncHandler.ts:773,:782). So thefixture is never mis-typed — it is never typed at all.
create_media_buyvalidator accepts the payload:CreateMediaBuySuccessSchemadeclares nostatus(
src/lib/types/schemas.generated.ts:22048), matching the document.task_type: the delivery parser pinstask_type: {const: 'media_buy_delivery'},neutralizes the union with
result: {}(
src/lib/validation/schema-loader.ts:2029) and validates the result againstmedia-buy/media-buy-delivery-webhook-result.json(
src/lib/webhooks/media-buy-delivery.ts:50,:105).AdCPAsyncResponseDataSchemais a generated, exportedz.union([GetProductsResponseSchema, …])(
src/lib/types/schemas.generated.ts:23132) and isMCPWebhookPayloadSchema'sresult(:23146). Zod unions are first-success-wins, andGetProductsResponseSchemaaccepts the fixture — so any adopter or future SDKcode that validates a webhook body with
MCPWebhookPayloadSchemareproduces thisexactly. Nothing under
src/lib/**uses either today.Refs adcontextprotocol/adcp#9302
🤖 Generated with Claude Code