Skip to content

fix(types): make account optional in CreateMediaBuyRequest and SyncCreativesRequest - #633

Closed
bokelley wants to merge 2 commits into
mainfrom
claude/issue-623-implicit-account-optional
Closed

bokelley wants to merge 2 commits into
mainfrom
claude/issue-623-implicit-account-optional

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #623

Summary

The typed dispatcher was rejecting valid create_media_buy and sync_creatives requests when the buyer omitted account. Per AdCP 3.0.6+, account is optional when the seller uses implicit or derived resolution mode — account identity is resolved from the verified auth chain instead of the wire field.

Root cause: CreateMediaBuyRequest.account and SyncCreativesRequest.account were defined as required Pydantic fields (no default). Pydantic rejected the request with INVALID_REQUEST before the handler could call AccountStore.resolve, which already accepts ref=None and correctly derives account identity for implicit/derived mode.

Changes:

  • src/adcp/types/generated_poc/media_buy/create_media_buy_request.py: account: AccountReference → account: AccountReference | None = None
  • src/adcp/types/generated_poc/creative/sync_creatives_request.py: same
  • schemas/cache/{media-buy,creative}/ + bundled/ variants: removed account from required[] so generate_types.py regen reproduces the optional field on next stable-tag run
  • tests/test_issue_623_implicit_account_optional.py: 7 regression tests (model-level + wire dispatch for derived mode + explicit-mode fail-closed)
  • tests/test_mcp_schema_drift.py: updated spot-check to assert account is NOT in create_media_buy.required

GetProductsRequest.account was already AccountReference | None = None — this change aligns the other two request types with that existing pattern.

ExplicitAccounts.resolve still raises ACCOUNT_NOT_FOUND when ref=None, preserving fail-closed behavior for explicit-mode adopters without any handler changes.

What was tested

  • ruff check src/ — clean
  • mypy on changed files — no new errors (pre-existing import-not-found for httpx/a2a stubs unrelated)
  • pytest tests/test_issue_623_implicit_account_optional.py — 7/7 passed
  • pytest tests/test_mcp_schema_drift.py — 19/19 passed
  • pytest tests/ --ignore=tests/conformance/signing/ — 3773 passed, 24 skipped, 1 xfailed (pre-existing TLS network test unrelated to this change)

Pre-PR review

  • code-reviewer: approved after 2-round review — both blockers fixed (schema cache required[] + model_construct→model_validate tests); no new blockers
  • ad-tech-protocol-expert: sound — change aligns with GetProductsRequest precedent; AccountStore.resolve(ref=None) contract already correct for implicit/derived; ExplicitAccounts fail-closed path preserved

Nits surfaced (not fixed):

  • lambda account_id: None in _ExplicitModePlatform fixture could be lambda _: None
  • Local from adcp.decisioning.types import AdcpError import inside test function could move to module-level imports
  • test_mcp_schema_drift.py spot-check has no parallel sync_creatives assertion (covered by model-level test instead)
  • idempotency_key description still reads "unique per (seller, request) pair" — with implicit mode the scope is actually (store_qualname, account.id) where account.id is synthesized by the store (pre-existing description, out of this PR's scope)

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01JX6bQ9FK2YxLefGnUSkg6x


Generated by Claude Code

claude added 2 commits May 10, 2026 13:09
…eativesRequest

Per AdCP 3.0.6+, account is optional when the seller uses implicit or
derived resolution mode — identity is resolved from the auth chain
instead of the wire field. The Pydantic models for create_media_buy and
sync_creatives had account as required (no default), causing
INVALID_REQUEST before the handler could resolve identity from auth.

AccountStore.resolve already accepts ref=None; no handler changes needed.
ExplicitAccounts.resolve still raises ACCOUNT_NOT_FOUND when ref=None,
preserving fail-closed behavior for explicit-mode adopters.

Fixes #623

https://claude.ai/code/session_01JX6bQ9FK2YxLefGnUSkg6x
- Remove account from required[] in all four schema cache files so
  generate_types.py regen preserves the optional field
- Replace model_construct tests with model_validate to exercise the
  actual Pydantic validation path (the real failure mode from #623)
- Add ExplicitAccounts wire-dispatch test confirming ACCOUNT_NOT_FOUND
  is returned (not a 500) when account is omitted in explicit mode

https://claude.ai/code/session_01JX6bQ9FK2YxLefGnUSkg6x
@bokelley

Copy link
Copy Markdown
Contributor Author

Closing — the premise of this PR is wrong

After re-deriving the resolution-mode semantics with @bokelley:

  • explicit mode — seller owns the account catalog; supports both account.account_id (seller-assigned) and natural-key (brand+operator → resolve).
  • derived mode — account catalog comes from the decisioning platform (GAM, etc.); buyer addresses by the platform's account_id returned from list_accounts. Natural keys don't apply because the seller doesn't own the mapping — the platform does.

Either way, the buyer must identify which account they're transacting against. There's no resolution mode where the dispatcher should accept create_media_buy / sync_creatives with account omitted — there's no clean way to tell "which advertiser's budget to debit" without an explicit ref.

This PR makes account: AccountReference | None = None, which doesn't model a real spec mode. Closing as won't-merge. The salesagent auth-chain placeholder middleware that motivated #623 is itself hiding a buyer-side protocol violation (buyers should be passing a real account_id they got from list_accounts), and the right fix lives there, not in the SDK types.

See updated discussion on #623.

@bokelley bokelley closed this May 10, 2026
@bokelley

Copy link
Copy Markdown
Contributor Author

Acknowledged. The protocol reasoning is sound — regardless of resolution mode (explicit or derived), the buyer must supply an AccountReference so the dispatcher knows which account to debit. Making the field None-able doesn't correspond to any real spec mode and would silently accept malformed requests.

Closing this draft is the right call. I can't close PRs directly, so a repo member will need to hit the close button. The source issue #623 should be updated to reflect that the fix belongs in the salesagent auth-chain middleware (buyer should pass the account_id returned from list_accounts), not in the SDK field optionality.


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


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed dispatcher rejects valid request when account is omitted on auth-resolved tools

2 participants