Title: feat(server): ship built-in spec_compat_hooks() for pre-v3 / pre-4.4 buyer compatibility · Issue #646 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: feat(server): ship built-in spec_compat_hooks() for pre-v3 / pre-4.4 buyer compatibility · Issue #646 · adcontextprotocol/adcp-client-python
X Title: feat(server): ship built-in spec_compat_hooks() for pre-v3 / pre-4.4 buyer compatibility · Issue #646 · adcontextprotocol/adcp-client-python
Description: Problem adcp 5.0 (PR #629, closes #614) shipped serve(pre_validation_hooks=...) — the mechanism is great, but every Python adopter that accepts pre-v3 / pre-4.4 buyers needs the same handful of spec-mandated default + shape-migration hoo...
Open Graph Description: Problem adcp 5.0 (PR #629, closes #614) shipped serve(pre_validation_hooks=...) — the mechanism is great, but every Python adopter that accepts pre-v3 / pre-4.4 buyers needs the same handful of spe...
X Description: Problem adcp 5.0 (PR #629, closes #614) shipped serve(pre_validation_hooks=...) — the mechanism is great, but every Python adopter that accepts pre-v3 / pre-4.4 buyers needs the same handful of spe...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/646
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(server): ship built-in spec_compat_hooks() for pre-v3 / pre-4.4 buyer compatibility","articleBody":"## Problem\n\nadcp 5.0 (PR #629, closes #614) shipped `serve(pre_validation_hooks=...)` — the mechanism is great, but every Python adopter that accepts pre-v3 / pre-4.4 buyers needs the same handful of spec-mandated default + shape-migration hooks. Each adopter writes (and maintains) the same code.\n\nIn [bokelley/salesagent](https://github.com/bokelley/salesagent) we just migrated our 273-LOC `SpecDefaultsMiddleware` to ~150 LOC of `pre_validation_hooks`. Looking at what we wrote, **none of it is salesagent-specific** — every line is a universal compatibility shim:\n\n| Hook | What it does | Why universal |\n|---|---|---|\n| `get_products.buying_mode='brief'` | Default the field when omitted | Spec says: *\"Sellers receiving requests from pre-v3 clients without buying_mode SHOULD default to 'brief'.\"* Every seller, by the spec text. |\n| `sync_creatives.creatives[*].format_id` string → `{agent_url, id}` | Wrap bare string format_id as the structured 4.4 reference | adcp 4.4 changed format_id from string to structured. Pre-4.4 buyers send a string; any seller accepting them needs the same wrap. The default `agent_url` is the canonical `https://creative.adcontextprotocol.org/` registry. |\n| `sync_creatives.creatives[*].assets[*].asset_type` inference | Infer the missing `asset_type` from the asset key (`image`/`video`/...) or from `content`/`url`/`width+height` presence | adcp 4.4 added explicit `asset_type` to make `AssetVariant` discriminated; pre-4.4 buyers used the key as the implicit type. Universal compat. |\n| `sync_creatives.creatives[*].assets[*]` image → url demote | When `asset_type='image'` but `width`/`height` missing, demote to `url` variant | The strict 4.4 image variant requires dims; pre-4.4 buyers frequently send image-shaped URLs without them. Universal compat. |\n\nWe're carrying this code as if it were adopter logic. It's not — it's the SDK's compat layer for migrating buyers across spec major versions.\n\n## Proposed shape\n\nShip a built-in `spec_compat_hooks()` (or similarly named) in `adcp.server` that adopters can wire into `pre_validation_hooks`:\n\n```python\nfrom adcp.server import spec_compat_hooks, serve\n\n# Standalone:\nserve(router, pre_validation_hooks=spec_compat_hooks())\n\n# Combined with adopter-specific hooks:\nserve(router, pre_validation_hooks={\n **spec_compat_hooks(),\n \"create_media_buy\": my_custom_hook,\n})\n\n# Selective opt-out:\nserve(router, pre_validation_hooks=spec_compat_hooks(exclude={\"sync_creatives\"}))\n```\n\nOpt-in by design — adopters who want strict-4.4 rejection of pre-v3 / pre-4.4 buyers leave it off. Adopters who accept the long tail of legacy clients (most production sellers) wire it once and forget about it.\n\n## What's in / out of scope\n\n**In:** The four hooks above. Each maps to a spec versioning event (pre-v3 `buying_mode`, pre-4.4 `format_id` shape, pre-4.4 `asset_type` discriminator, pre-4.4 image dim requirement).\n\n**Out:** Adopter-specific defaulting (e.g. salesagent's removed `account: auth-chain` placeholder — that was an adopter bug, not a spec migration). Adopters write those themselves via the same `pre_validation_hooks` mechanism, layered on top.\n\n## Why this matters beyond us\n\nThese hooks are *exactly* the kind of glue every adopter has to write when migrating from a pre-4.4 SDK to a 5.0 SDK. Shipping them in the SDK:\n\n1. Saves each adopter ~150 LOC of mechanical-but-spec-sensitive code.\n2. Centralises the canonical agent_url (`https://creative.adcontextprotocol.org/`), the asset-type inference table, the image-dim demotion rule — adopters who roll their own will silently diverge.\n3. Provides a single PR target when the spec adds the next pre-major-version compat shim (adcp 6.0 → 7.0 someday) instead of every adopter re-discovering it.\n\n## Source\n\nOur [core/spec_default_hooks.py](https://github.com/bokelley/salesagent/blob/main/core/spec_default_hooks.py) is what we just wrote — happy to send the contents as a starter PR if there's interest in shipping it directly. The file is intentionally pure-Python (no transport / framework deps) so dropping it into `adcp.server` should be drop-in.\n\n## Related\n\n- #614 / PR #629 — the `pre_validation_hooks` mechanism this builds on.\n- #623 — closed, established the spec-correctness boundary: `account` and `idempotency_key` are unconditionally required (NOT spec-migration defaults; adopters must enforce them). This issue stays on the right side of that boundary — only proposing hooks for fields the spec explicitly marks as defaultable or as shape-migration cases.\n","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-05-11T06:17:22Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/646"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1bf1ad66-906e-c0fc-1d65-73734cb1da21 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9A6:3D97C8:26371B9:32E14F4:6B01A521 |
| html-safe-nonce | d0e75d7c3acf6e0c8ca55fd6d6ae56f32ba7a6de20cb323a6736c6c7aa724f59 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUE2OjNEOTdDODoyNjM3MUI5OjMyRTE0RjQ6NkIwMUE1MjEiLCJ2aXNpdG9yX2lkIjoiNzAxODE4MjExMjAwNDEyMTg4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0b4ed0726b20c5dec8036b69cebe3043c818af869903c33505bafec47ad8de57 |
| hovercard-subject-tag | issue:4418498421 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/646/issue_layout |
| twitter:image | https://opengraph.githubassets.com/780b547a0cf55ced3121796621bbbb98f802ce2783f26190e71cef3c3b8edce0/adcontextprotocol/adcp-client-python/issues/646 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/780b547a0cf55ced3121796621bbbb98f802ce2783f26190e71cef3c3b8edce0/adcontextprotocol/adcp-client-python/issues/646 |
| og:image:alt | Problem adcp 5.0 (PR #629, closes #614) shipped serve(pre_validation_hooks=...) — the mechanism is great, but every Python adopter that accepts pre-v3 / pre-4.4 buyers needs the same handful of spe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bokelley |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width