Skip to content

bug(server): router-based sellers can't get strict request validation — unknown_fields="reject" rejects adcp_version, and subclass re-validation is skipped behind PlatformRouter/LazyPlatformRouter #1293

Closed

Description

@bokelley

Summary

On 8.0.0 a seller has two ways to reject unknown request fields. Neither works for a seller built on LazyPlatformRouter that serves 3.1+ buyers.

  1. Subclass re-validation is skipped behind routers. _coerce_params_to_platform_type (adcp/decisioning/dispatch.py:1306-1389) re-validates the library request (extra='allow') through a stricter subclass annotation on the platform method. Router delegates are synthesized as async def _delegate(*args, **kwargs) (adcp/decisioning/platform_router.py:596, :1085, :1330). The coercion stops at VAR_POSITIONAL (dispatch.py:1352-1356). The child platform's annotation is never consulted, because the delegate calls the child directly.
  2. ValidationHookConfig(unknown_fields="reject") (Server: add configurable unknown-field policy before tool argument coercion #858) rejects the version envelope. _allowed_top_level_fields (adcp/server/mcp_tools.py:2865-2892) takes the allowed set from the request schema's properties. The bundled 3.1 and 3.2 get-products-request.json don't list adcp_version / adcp_major_version there. Every buyer that negotiates a version is rejected.

Reproduction (adcp 8.0.0)

Router bypass:

import asyncio
import logging
import warnings

warnings.simplefilter("ignore")
logging.disable(logging.CRITICAL)

from pydantic import ConfigDict

from adcp.decisioning import DecisioningCapabilities, DecisioningPlatform, LazyPlatformRouter, SingletonAccounts
from adcp.decisioning.serve import create_adcp_server_from_platform
from adcp.server.base import ToolContext
from adcp.types import GetMediaBuysRequest

CAPS = DecisioningCapabilities(specialisms=["sales-non-guaranteed"], supported_billing=["operator"])
ACCOUNTS = SingletonAccounts(account_id="acct", metadata_factory=lambda: {"tenant_id": "t1"})


class StrictGetMediaBuysRequest(GetMediaBuysRequest):
    model_config = ConfigDict(extra="forbid")


class Seller(DecisioningPlatform):
    capabilities = CAPS
    accounts = ACCOUNTS

    def get_media_buys(self, req: StrictGetMediaBuysRequest, ctx):
        return {"media_buys": [], "received": type(req).__name__}

    def get_products(self, req, ctx): return {"products": []}
    def create_media_buy(self, req, ctx): raise NotImplementedError
    def update_media_buy(self, media_buy_id, patch, ctx): raise NotImplementedError
    def sync_creatives(self, req, ctx): raise NotImplementedError
    def get_media_buy_delivery(self, req, ctx): raise NotImplementedError


router = LazyPlatformRouter(accounts=ACCOUNTS, factory=lambda tenant_id: Seller(), capabilities=CAPS)
direct, _, _ = create_adcp_server_from_platform(Seller())
routed, _, _ = create_adcp_server_from_platform(router)


async def call(label, handler):
    req = GetMediaBuysRequest.model_validate({"nonsense_field": "x"})  # library model: extra='allow'
    try:
        result = await handler.get_media_buys(req, ToolContext())
        print(f"{label}: accepted, platform received {result.get('received')}")
    except Exception as exc:
        print(f"{label}: {exc.code} | {exc}")


async def main():
    await call("direct platform     ", direct)
    await call("LazyPlatformRouter  ", routed)

asyncio.run(main())
direct platform     : INVALID_REQUEST | AdcpError[INVALID_REQUEST / correctable]: Request validation failed for 'get_media_buys': Extra inputs are not permitted (field: 'nonsense_field')
LazyPlatformRouter  : accepted, platform received GetMediaBuysRequest

Unknown-field policy:

import asyncio, warnings, logging
warnings.simplefilter("ignore"); logging.disable(logging.CRITICAL)
from adcp.server import ADCPHandler
from adcp.server.mcp_tools import create_tool_caller
from adcp.validation.client_hooks import ValidationHookConfig

class Seller(ADCPHandler):
    async def get_products(self, params, context=None):
        return {"products": []}

async def main():
    call = create_tool_caller(Seller(), "get_products", validation=ValidationHookConfig(unknown_fields="reject"))
    base = {"buying_mode": "brief", "brief": "video"}
    for env in ({}, {"adcp_version": "3.2"}, {"adcp_major_version": 3}, {"nonsense_field": 1}):
        try:
            await call({**base, **env}); print(env, "-> accepted")
        except Exception as exc:
            e = exc.errors[0]; print(env, "->", e.code, e.field, "|", e.message)
asyncio.run(main())
{} -> accepted
{'adcp_version': '3.2'} -> INVALID_REQUEST adcp_version | Unexpected top-level field 'adcp_version' for get_products
{'adcp_major_version': 3} -> INVALID_REQUEST adcp_major_version | Unexpected top-level field 'adcp_major_version' for get_products
{'nonsense_field': 1} -> INVALID_REQUEST nonsense_field | Unexpected top-level field 'nonsense_field' for get_products

Why an adopter hits this

Embedded Sales Agent serves every tenant through LazyPlatformRouter and rejects unknown fields in dev/CI so contract drift fails loudly. Neither SDK path works, so ESA rebuilds it in a pre-validation hook: _strict_request_fields_by_tool and _with_dev_unknown_field_rejection in core/main.py, about 120 LOC. That includes a hand-kept field list for list_creatives, and its field sets come from ESA's local models, which (unlike the schemas) include adcp_version / adcp_major_version. The rejection is also top-level only. Nested extra='forbid' models and field validators on ESA's request subclasses still never run behind the router. The comment on _delegate_get_products in core/platforms/_delegate.py records why.

Ask

  1. Always allow the protocol envelope (adcp_version, adcp_major_version, and anything else detect_wire_version consumes) in _allowed_top_level_fields, or strip it before the policy runs.
  2. Make router delegates carry the child's annotation: resolve the tenant platform first, then run _coerce_params_to_platform_type against the child method. Or expose a per-router request_models={tool: Model} that the dispatcher re-validates through.

Activity

  1. added
    bugSomething isn't working
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
  2. bokelley commented on Oct 2, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug (two independent defects)
    Bucket(s): handlers, validation (labels not found in repo — noted for label gap)
    Status: ready-to-implement
    Milestone: omitted

    What the experts said:

    • code-reviewer: both bugs are blockers — dispatch bypass must handle both positional and kwarg calling conventions when reconstructing args after coercion; Bug 2 fix should derive the envelope-field allowlist from detect_wire_version's canonical source, not a standalone hardcode.
    • ad-tech-protocol-expert: both bugs are blockers — Bug 1 is a spec violation (SDK's own docstring requires enforcement at the dispatch boundary); Bug 2 breaks mandatory version negotiation for every 3.1+ buyer; recommends verifying whether additional 3.2+ envelope fields (signing nonce, idempotency) share the same gap.

    My take: Both bugs are confirmed, non-breaking correctness fixes. No disagreement between experts, no security surface, and clear reproduction steps make this ready to implement without further clarification.

    Implementation scope:

    • Bug 1 — platform_router.py + dispatch.py: In the synthesized _delegate, after resolving the child platform, extract params from args[0] (positional path) or kwargs (arg-projector path), call _coerce_params_to_platform_type(child_method, params, method_name), then reconstruct args (replace args[0]) or kwargs with the coerced object before forwarding to the child. Both calling conventions must be covered. Key files: src/adcp/decisioning/platform_router.py:596,1085,1330 and src/adcp/decisioning/dispatch.py:1352-1356.
    • Bug 2 — mcp_tools.py: In _allowed_top_level_fields, unconditionally union the known wire-envelope field names (adcp_version, adcp_major_version) into the returned set. Derive this list from adcp.validation.envelope / the canonical source consumed by detect_wire_version rather than hardcoding independently, so future envelope fields are covered automatically. Also verify whether AdCP 3.2+ introduces additional envelope fields (e.g. signing nonce) sharing the same gap. Key file: src/adcp/server/mcp_tools.py:2865-2892.
    • Tests: (a) PlatformRouter/LazyPlatformRouter + strict subclass annotation → INVALID_REQUEST on unknown field, valid request routes normally; (b) ValidationHookConfig(unknown_fields="reject") + request with adcp_version → accepted; adcp_major_version → accepted; genuine unknown field → still rejected; STRIP mode preserves envelope fields.
    • Non-breaking rationale: Bug 1 fix adds enforcement that was always intended (silently-accepted invalid requests become INVALID_REQUEST); Bug 2 fix converts incorrect rejections into correct acceptances. No public API removed or renamed.

    Triaged by Claude Code. Session: https://claude.ai/code/session_01EsqDA1d1kM9ny2RpeTWpzG


    Generated by Claude Code

  3. added and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions