Skip to content

The canonical format helpers compare three of the four parameters a format reference declares #1517

Closed

Description

@KonstantinMirin

core/format-id.json declares four parameters beyond the (agent_url, id) identity —
width, height, duration_ms, pixel_ratio. Three helpers in
adcp/canonical_formats/compat_helpers.py each name three of them in a hand-written tuple
and so never look at pixel_ratio:

site line consequence
format_is_supported for field in ("width", "height", "duration_ms") a product that requires 2x accepts a creative that claims no density, and accepts one that claims a conflicting density
formats_are_equivalent same tuple two references that explicitly disagree about density compare equal
_upgrade_legacy_format_id rebuilds the reference from four named keys the legacy-size upgrade silently discards the pixel_ratio it was handed

Measured

adcp at d5195a952:

from adcp.canonical_formats import (
    format_is_supported, formats_are_equivalent, upgrade_legacy_format_id,
)
from adcp.types.legacy import LegacyFormatId as FormatId

a = "https://creative.adcontextprotocol.org"
base = dict(agent_url=a, id="display_image", width=300, height=250)

sup2x = FormatId(**base, pixel_ratio=2)
req1x = FormatId(**base)                 # states no pixel_ratio
req3x = FormatId(**base, pixel_ratio=3)  # states a conflicting one

format_is_supported(req1x, sup2x)      # -> True   expected False
format_is_supported(req3x, sup2x)      # -> True   expected False
formats_are_equivalent(req3x, sup2x)   # -> True   expected False

legacy = FormatId(agent_url=a, id="display_300x250", width=300, height=250, pixel_ratio=2)
upgrade_legacy_format_id(legacy).pixel_ratio   # -> None   expected 2.0

Why these are wrong

core/format-id.json on pixel_ratio:

Required intrinsic-pixel density for a parameterized visual format, expressed as
intrinsic pixels per logical pixel. Requires width and height. Example:
{id: "display_image", width: 300, height: 250, pixel_ratio: 2} identifies a 300×250
logical render supplied by a 600×500 image. Omit for the backward-compatible 1x variant.

So a seller publishing pixel_ratio: 2 is stating a requirement, and the omitted form is
not "unspecified" — it is the 1x variant. format_is_supported accepting req1x for
sup2x therefore delivers a 1x asset into a 2x slot. The directional rule the function
already implements correctly for the other three parameters — if the supported side fixes a
parameter, the request must state and match it — simply never runs for this one.

The req3x/sup2x pair is the sharper case: both sides declare a density, they
conflict, and both helpers still say yes.

Relationship to #1364

#1364 was a different defect in format_is_supported (it refused the
FormatReferenceStructuredObject that generated model fields carry) and its fix landed on
2026-10-04. These gaps survived that fix untouched: the input coercion changed, the
comparison body did not. So this is not a duplicate of it, and the function's test file does
not yet grade the fourth parameter.

The fix is to derive the parameter set, not to append a fourth name

The set is exactly set(LegacyFormatId.model_fields) - {"agent_url", "id"}. This matters
beyond style, and there is direct evidence for it: an independent server-side implementation
of the same comparison hit the identical bug, and the comment on its fix reads —

A hand-written list here is the defect that dropped pixel_ratio: three of the four
parameters were copied by name, so a creative synced with a pixel ratio came back as a
different format than the buyer sent.

Two implementations, one hand-written list each, the same parameter missing from both. A
derived set means the next parameter added to core/format-id.json is compared without
anyone remembering to name it; a fourth literal just resets the clock.

One deliberate exception stays per-field, because the schema makes it one: pixel_ratio is
the only parameter whose absence carries a value (the 1x variant). An omitted width
means "template, unparameterized"; an omitted density means 1x. So a product fixed at 2x
must refuse a silent request, while one fixed at 1x must still serve it — the mirror-image
false rejection that a plain None-is-a-mismatch rule would introduce.

Also noted, not included

_looks_like_legacy_format_tuple in adcp/types/canonical_creative.py carries the same
three-name list as a key-subset test:

"format" in title or keys <= {"agent_url", "id", "width", "height", "duration_ms"}

A node carrying pixel_ratio fails that subset test, so sanitize_canonical_schema leaves
agent_url in properties and required for it. It is left alone here because its only
caller is pydantic schema generation, where the node always carries a class-name title
containing "format" and the first branch matches — so I could not demonstrate a reachable
consequence, only a latent inconsistency. Worth a separate look rather than a speculative
patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions