Skip to content

fix(validation): strip null on optional v2.x envelope fields before Ajv (#1149) - #1158

Merged
bokelley merged 4 commits into
mainfrom
claude/issue-1149-v2-5-envelope-null-tolerance
May 1, 2026
Merged

bokelley merged 4 commits into
mainfrom
claude/issue-1149-v2-5-envelope-null-tolerance

Conversation

@bokelley

@bokelley bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor

Closes #1149

Summary

After #1137 pinned validateResponseSchema to the detected server version, v2.5 sellers (Pydantic-origin) that emit errors: null, context: null, or ext: null began failing response validation with spurious type errors (/errors: must be array; /context: must be object; /ext: must be object). The v2.5 schemas declare these as type: 'array' / type: 'object' without a null union, but the Pydantic convention is "present-as-null = absent."

The fix adds a stripEnvelopeNulls() pre-processing step inside validateResponse that removes top-level optional fields whose value is null but whose declared schema type is not nullable — before handing the payload to Ajv. Gated to v2.x bundles via parseAdcpMajorVersion(version) === 2; v3 is unaffected (in v3, errors is required on failure branches and must not be silently dropped).

What was tested

  • npm run format:check — ✅ passes
  • npx tsc --project tsconfig.lib.json — ✅ pre-existing TS2688/TS5107 only (confirmed identical on main)
  • node --test test/validation-oneof-cascade.test.js test/validation-enum-enrichment.test.js test/lib/schema-validation.test.js — ✅ 44 fail / 10 pass (identical baseline on main; zero regressions)
  • node --test test/lib/v2-5-envelope-null-stripping.test.js — ✅ skips gracefully when v2.5 bundle not cached (same skip pattern as existing test/lib/post-adapter-v2-5-validation.test.js); CI runs sync-schemas:all so the v2.5 suite runs in full there

Pre-PR review

  • code-reviewer: approved — logic is correct, Ajv 8 doesn't mutate input (confirmed removeAdditional/useDefaults/coerceTypes absent), required guard prevents stripping legitimately required fields, top-level-only scope is correct for envelope fields; nit on startsWith('v2') gate addressed via parseAdcpMajorVersion
  • ad-tech-protocol-expert: approved — null-as-absent is de-facto Pydantic behavior not documented in v2.5 spec (SDK-side fix is the correct track, not schema patching); v2-gate is required and is present; patch bump correct; selectResponseVariant(payload) call ordering is safe (runs on original payload before normalizedPayload is computed)

Known scope boundary (not a blocker for this PR)

The protocol expert noted validateRequest has no equivalent null-strip for outgoing v2.x requests. The issue is scoped to response validation (the reproduction is a buyer receiving a v2.5 seller response). Buyers control their own request payloads and the validateOutgoingRequest path defaults to warn mode, so this is a separate follow-up concern. Filed as a note here for the next sweep.

Nits (surfaced, not fixed):

  • Test 'null on field not declared in schema properties' only asserts doesNotThrow; a deeper assertion on outcome.valid would be tighter.
  • v3 bypass test verifies validator still rejects a bad payload but doesn't directly assert errors: null remains in the Ajv input.

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 1150 →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

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


Generated by Claude Code

v2.5 sellers (Pydantic-origin) emit errors/context/ext as null instead
of omitting them. The v2.5 schemas declare these as type:array/object
without a null union, so Ajv spuriously rejects them post-#1137's
version-pinned validator.

Adds stripEnvelopeNulls() that removes top-level optional fields with
null values and non-nullable declared types before the Ajv pass. Gated
to v2.x bundles via parseAdcpMajorVersion() — v3 errors is required on
failure branches and must not be silently stripped.

Closes #1149

https://claude.ai/code/session_01H9wytvzmHPVPdCPUYZVCte
bokelley and others added 2 commits May 1, 2026 10:22
minimalGetProductsResponse needs delivery_measurement (top-level required)
and is_fixed: true on the cpm pricing option (const discriminator) for the
v2.5 schema to pass without stripping. Verified against upstream schemas
in adcontextprotocol/[email protected] dist/schemas/2.5.3/.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Admin merge rationale

Same `Test & Build` failures as every recent main run: `storyboard adcp#3083` + `a2a_context_continuity`. Both pre-existing, tracked at #1178. All other CI lanes pass.

@bokelley
bokelley merged commit f397f9e into main May 1, 2026
9 of 10 checks passed
@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Acknowledged — pre-existing storyboard adcp#3083 + a2a_context_continuity failures tracked at #1178. No action needed here.


Generated by Claude Code

@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Noted — tracking at #1178. Nothing to do here.


Generated by Claude Code

@bokelley

bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Acknowledged — #1178 noted as the tracking issue for the validateRequest follow-up.


Generated by Claude Code


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.

v2.5 response validator rejects null envelope fields (errors / context / ext) instead of treating as absent

2 participants