Skip to content

fix(media-buy): merge structured-only action metadata into update-field dispatch - #2889

Merged
bokelley merged 3 commits into
mainfrom
fix/2887-merge-structured-only-action-metadata
Sep 14, 2026
Merged

bokelley merged 3 commits into
mainfrom
fix/2887-merge-structured-only-action-metadata

Conversation

@bokelley

@bokelley bokelley commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2887.

Summary

  • scripts/generate-media-buy-update-fields.ts now merges enumMetadata from both enums/media-buy-valid-action.json and core/media-buy-available-action-id.json (AdCP 3.2, feat(media-buy): add shared media-buy frequency cap adcp#7449). Rows follow legacy enum order, then structured-only ids in anyOf order. Legacy wins on agreement; a shared key with different metadata aborts generation, as does a structured-only const with no update_fields or metadata for an undeclared action. Caches that predate the id schema (the current 3.2.0-rc.1 pin and everything older) emit the legacy-only table, so older pins keep regenerating. Header comment and the "bump schema cache" error text updated; SCHEMA_DIR / OUT_PATH overrides added alongside the existing SCHEMA_PATH.
  • The generated module now also exports STRUCTURED_ONLY_MEDIA_BUY_ACTIONS, StructuredOnlyMediaBuyAction, and MediaBuyUpdateFieldAction (keys of UPDATE_FIELDS_BY_ACTION).
  • New MediaBuyActionId type in src/lib/media-buy/types.ts: every structured available_actions[].action id, derived from the generated wire type plus the dispatch-table union. Every hand-written narrowing to the legacy enum is widened to it: findAvailableAction, getRollupParent, ROLLUP_PARENT_OF, ResolvedAction.action, DecomposedUpdateMediaBuyMutation.action, PreflightDenial.action, recoveryForModeMismatch, and the server-side ACTION_NOT_ALLOWED builder in src/lib/server/media-buy-actions.ts. MediaBuyValidAction stays the type of the deprecated flat valid_actions[] list.
  • decomposeUpdateMediaBuy / preflightUpdateMediaBuy map the MediaBuy-level frequency_cap request field (set or null to clear) through ACTIONS_BY_FIELD, so the binding activates with the schema pin instead of being hardcoded.
  • Codegen fix found while validating against the PR bundle: with the post-#7449 schemas, generate-types emitted MediaBuyAvailableActionID = MediaBuyValidAction | 'update_media_buy_frequency_cap' and used it for attempted_action, but MediaBuyAvailableAction.action and ProductAllowedAction.action came out as MediaBuyValidAction in TypeScript and Zod. Root cause: json-schema-to-typescript degrades later occurrences of the anyOf [$ref enum, const] alias inside a large root to MediaBuyValidAction1, which removeNumberedTypeDuplicates folds back to the legacy enum. core/media-buy-available-action.json and core/product-allowed-action.json are now priority canonical schemas (the repo's existing first-definition-ownership mechanism), so both interfaces are owned by core.generated.ts and imported/re-exported by tools.generated.ts. Without this, an rc.3 seller advertising update_media_buy_frequency_cap would be rejected by the strict Zod validators.

Schema source

The pinned 3.2.0-rc.1 cache (and the cut v3.2.0-rc.2 release, tagged before #7449 merged) lacks core/media-buy-available-action-id.json. I did not re-pin the repo to the PR bundle: the repo's PR-bundle path (schemas/codegen-provenance.json) requires ADCP_VERSION to match the bundle's published_version (3.2.0-rc.2), which would turn this fix into a full rc.1 → rc.2+ protocol adoption. Instead:

  • The generator, hand-written types, and preflight are forward-compatible: the merged row, the frequency_cap mapping, and the widened wire types all appear automatically when the pin moves to a release that ships the id schema (expected rc.3). Nothing else needs to change.
  • The two upstream schemas are vendored verbatim under test/fixtures/media-buy-update-fields/merged/ so the regression tests run against the post-#7449 shape regardless of the pin.
  • I reproduced the upstream validate-schema-bundle.yml recipe on a disposable copy of this branch: ADCP_VERSION=3.2.0-rc.2, sync-version --force, the PR bundle served locally over python3 -m http.server, ADCP_BASE_URL=http://127.0.0.1:8765 ADCP_GITHUB_FALLBACK=0 npm run sync-schemas, then generate-types, validate-schemas, build:lib, typecheck, and the media-buy tests.
    • Bundle: https://adcontextprotocol.org/protocol/pr/9e2bf6a949de2adc8d2835e44cb73c820ee69d99/latest.tgz (PR head of adcp#7449), SHA-256 e2804ae31fc4400c0c98af492365d915195e84faed49d72fb7c0757a8f381f46.
    • Result: Wrote src/lib/media-buy/update-fields.generated.ts (25 actions, 1 structured-only: update_media_buy_frequency_cap); available_actions[].action, allowed_actions[].action, and attempted_action all typed MediaBuyAvailableActionID in TS and Zod; typecheck green; 60 pass / 1 skipped across the two media-buy test files (the skipped case is the legacy-only assertion).

Tests

  • test/lib/media-buy-update-fields-generator.test.js (new): runs the generator against the vendored fixtures and evaluates the emitted module. Asserts update_media_buy_frequency_cap -> ["frequency_cap"] and update_frequency_caps -> ["packages[].targeting_overlay.frequency_cap"], the inverse index, structured-only ordering, legacy rollup/deprecation intact, the legacy-only path for caches without the id schema, the pre-3.1 refusal, the conflict abort, the agree-and-accept path, the unbound-const abort, the undeclared-metadata abort, and that the checked-in table tracks the pinned cache. Also pins the codegen invariant that the three wire sites share one action id type and that tool types import the two interfaces from core.
  • test/lib/media-buy-preflight.test.js: new block for the MediaBuy-level frequency_cap (set, clear, preflight pass, preflight deny, mixed with the package-level cap). Cases that need the structured-only binding are skipped with a reason on pins that predate the id schema; the no-binding case runs today.

Verification

  • npm run generate-types (checked-in output under the rc.1 pin is committed)
  • npm run validate-schemas
  • npm run build:lib
  • npm run typecheck, npm run ci:codegen-strict, npm run ci:docs-check, npm run format:check
  • npm test (full suite; see the final comment for the run)

Under the current pin the regenerated core.generated.ts / tools.generated.ts / schemas.generated.ts diff only relocates MediaBuyAvailableAction and ProductAllowedAction into core ownership. One visible TS-only relaxation: ProductAllowedAction.modes and allowed_statuses type as arrays rather than non-empty tuples (priority canonical schemas go through the same array-cardinality relaxation as the rest of core). The Zod validators are byte-identical apart from ordering and still enforce minItems: 1.

No release is published by this PR.

🤖 Generated with Claude Code


Open workspace in Conductor

…ld dispatch

Closes #2887.

The update_fields generator reads enumMetadata from both
enums/media-buy-valid-action.json and core/media-buy-available-action-id.json
(AdCP 3.2, adcp#7449), with a conflict check (legacy wins on agreement,
disagreement aborts) and a legacy-only fallback for schema caches that predate
the id schema. Adds MediaBuyActionId and widens every hand-written narrowing
of available_actions[].action / attempted_action from the legacy enum;
decomposeUpdateMediaBuy maps the MediaBuy-level frequency_cap request field
through the generated table.

Codegen: own MediaBuyAvailableAction and ProductAllowedAction as priority
canonical schemas so json-schema-to-typescript cannot degrade their `action`
to the legacy enum once the pin ships the anyOf id alias.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Comment (human reviewer recommended)

Comment — 1 medium finding; changeset severity per repo policy warrants a human look.

The reviewer verified the AdCP 3.2 structured-only action merge as sound: generator merge logic, the codegen ownership relocation of MediaBuyAvailableAction/ProductAllowedAction, the MediaBuyValidAction→MediaBuyActionId widening, and frequency_cap decomposition are all well-tested and witness-faithful. No Critical/High findings on wire-shape fidelity or transport-client usage.

Medium findings

  • .changeset/merge-structured-only-action-metadata.md — Changeset typed patch but the PR ships four new public exports plus widened signatures (additive-minor under semver); should be bumped to minor.

Note on decision: The repo's mandatory changeset-vs-wire-impact policy treats a changeset that understates impact (e.g. patch for what is a minor/response-shape-affecting change) as a high finding. The reviewer classified this as a non-blocking Medium (additive-minor, not a removed/renamed export or required-param flip). Taking the reviewer's Medium severity at face value, this is a single medium finding with no escalation trigger — which by the decision table (row 9) would be approve. However, review_decision is REVIEW_REQUIRED and gated_paths is false, so no hard gate forces escalate. Because the changeset-type understatement sits right at the boundary of the repo's high-finding policy and the reviewer explicitly recommended a bump, surfacing this for a human via comment rather than auto-approving is the safe reading.

…ctured-only-action-metadata

Regenerated types against the rc.2 cache; rc.2 still predates
core/media-buy-available-action-id.json so the update_fields table stays
legacy-only and the codegen change only relocates MediaBuyAvailableAction /
ProductAllowedAction into core ownership.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copy link
Copy Markdown
Contributor Author

(see above)

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — clean subsequent pass, no blocking or medium findings.

Checked:

  • No critical/high/medium findings this run; hand-written PR files are byte-identical to the prior clean SHA.
  • Changeset correctly bumped patch → minor to match additive new exports (changeset-vs-wire-impact satisfied).
  • .prettierignore entry for vendored media-buy fixtures is legitimate.
  • Generated-type churn is rebase noise from new main; no PR-owned media-buy codegen changed.

Decision-table walkthrough: no critical/high (row 1 n/a); gated_paths false (row 2 n/a); high_risk false, no deletions (rows 3–5 n/a); prior decision was comment, not escalate, and no new findings (row 6 n/a); no no-auto-approve team match (row 7 n/a); zero medium findings (row 8 n/a) → falls through to row 9 = approve.

@bokelley
bokelley merged commit 10134ca into main Sep 14, 2026
37 checks passed
@bokelley
bokelley deleted the fix/2887-merge-structured-only-action-metadata branch September 14, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(media-buy): merge structured-only action metadata into update-field dispatch

1 participant