Skip to content

fix(bundled): add x-adcp-hoist to data-provider-signal-selector to fix codegen discriminator fabrication - #4867

Merged
bokelley merged 1 commit into
mainfrom
claude/issue-4859-bundled-schema-dedup-hoist
May 20, 2026
Merged

bokelley merged 1 commit into
mainfrom
claude/issue-4859-bundled-schema-dedup-hoist

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Adds "x-adcp-hoist": true to data-provider-signal-selector.json so the bundler deduplicates it via root $defs instead of inlining it N times
  • Adds a regression test covering the discriminated oneOf dedup case (the exact pattern that triggered the bug)
  • Adds a patch changeset

Problem

In 3.1.0-beta.x, tasks-get-response.json gained a result field referencing async-response-data.json — a union of all task response schemas. When bundled, data-provider-signal-selector.json (a 3-branch discriminated oneOf with selection_type values all, by_id, by_tag) appeared twice in the same bundled file. datamodel-code-generator 0.56.1 fabricated a Literal['reuse'] discriminator value, raising:

TypeError: Value 'reuse' for discriminator 'selection_type' mapped to multiple choices

This blocked the entire Python SDK from importing.

Fix

Mark the schema x-adcp-hoist: true. The bundler's existing hoistMarkedSchemas() function moves it to root $defs.DataProviderSignalSelector and replaces all inline occurrences with {"$ref": "#/$defs/DataProviderSignalSelector"}. The directive is stripped from bundled output — wire contract is unchanged.

Verified: DataProviderSignalSelector appears once in $defs with discriminator + oneOf intact and x-adcp-hoist absent.

Test plan

  • npm run build:schemas — 0 failures, 83 schemas bundled
  • npm run test:build-schemas-hoist-marked — 15/15 pass (14 existing + 1 new regression test)
  • Protocol expert review — confirmed semantically equivalent under JSON Schema draft-07; no wire contract change
  • Code reviewer — approved; no blockers

Fixes #4859

https://claude.ai/code/session_01KTXLjR1c5tGKPZQpSE8T4H


Generated by Claude Code

…x codegen discriminator fabrication

data-provider-signal-selector.json appeared twice in the same bundled
tasks-get-response.json after 3.1.0-beta.x added the result field (a union
of all task response schemas). datamodel-code-generator fabricated a
Literal['reuse'] discriminator value when the same discriminated oneOf was
inlined twice, raising TypeError at import time and blocking the Python SDK.

Mark the schema x-adcp-hoist:true so hoistMarkedSchemas() collapses both
copies to a single $defs entry, replacing inline occurrences with $refs.
The directive is stripped from bundled output; wire contract is unchanged.

Adds a regression test covering the discriminated oneOf dedup case.

Closes #4859

https://claude.ai/code/session_01KTXLjR1c5tGKPZQpSE8T4H
@bokelley
bokelley marked this pull request as ready for review May 20, 2026 18:05

@aao-release-bot aao-release-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Real fix, narrow surface. Uses an existing build-time mechanism (hoistMarkedSchemas) instead of inventing a new one, and keeps the bundled wire contract identical.

Things I checked

  • Schema edit at static/schemas/source/core/data-provider-signal-selector.json:6 — single new key, no change to discriminator, oneOf, or the three selection_type branches.
  • Bundler strip is real: scripts/build-schemas.cjs:1473 strips the marker on the canonical $defs entry, and the final stripStrayMarkers sweep at :1515-1523 recursively deletes any survivors. The existing test at :280-301 already asserts x-adcp-hoist is absent from emitted output.
  • Fingerprint at scripts/build-schemas.cjs:1381 canonicalizes by recursive key-sort, so structurally equivalent inline copies collapse to one $defs.DataProviderSignalSelector. Same-title-different-shape is a hard error at :1450 — fail-closed beats fail-open.
  • Regression test at tests/build-schemas-hoist-marked.test.cjs:303-346 reproduces the duplicated discriminated-oneOf pattern (first_use, second_use), asserts both collapse to a single $ref, asserts the discriminator survives, and asserts the marker is stripped. Right shape.
  • Changeset type patch matches wire impact — JSON Schema semantics on the bundled artifact are identical (inline → $ref to $defs), no field renames/additions/removals on the wire.
  • No docs drift risk: data-provider-signal-selector has no page under docs/reference/** or mintlify-docs/reference/**; it's an internal building block referenced from product.json:152 and pulled through async-response-data.json's task-response union — exactly the fan-out path the changeset describes.
  • ad-tech-protocol-expert: sound. Wire contract equivalent. x-adcp-hoist is established namespace (one of two x-adcp-* extension keys in use), not invented.
  • code-reviewer: ready to push, no blockers.
  • CI: TypeScript Build, Server integration tests, changeset check, CodeQL, Semgrep — all green.

Follow-ups (non-blocking — file as issues)

  • Other discriminated-oneOf schemas in static/schemas/source/core/ (audience-selector, signal-targeting, publisher-property-selector, creative-asset, creative-manifest) share the same shape and are a latent class of this bug if they ever land in a multiplied fan-out path. Worth a one-shot audit that counts inline duplication in static/schemas/dist/ for each discriminated oneOf and flags any ≥2 without x-adcp-hoist.
  • Consider a bundler-side warning when a discriminated oneOf is inlined ≥2 times without the marker — catches the rest of the class before it ships as a codegen TypeError.
  • Changeset body cites issue #4859 in prose but doesn't cross-link it. Test comment at tests/build-schemas-hoist-marked.test.cjs:303 does. Non-blocking.

LGTM. Follow-ups noted below.

@bokelley
bokelley merged commit 079c25c into main May 20, 2026
15 checks passed
@bokelley
bokelley deleted the claude/issue-4859-bundled-schema-dedup-hoist branch May 20, 2026 18:37
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.

3.1.0-beta.1 bundled mega-schemas fully inline duplicated structures, breaking downstream codegens

2 participants