Repository navigation
fix(validation): strip null on optional v2.x envelope fields before Ajv (#1149) - #1158
Merged
Merged
Conversation
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
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]>
Contributor
Author
Admin merge rationaleSame `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. |
Contributor
Author
|
Acknowledged — pre-existing Generated by Claude Code |
Contributor
Author
|
Noted — tracking at #1178. Nothing to do here. Generated by Claude Code |
Contributor
Author
|
Acknowledged — #1178 noted as the tracking issue for the Generated by Claude Code Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1149
Summary
After #1137 pinned
validateResponseSchemato the detected server version, v2.5 sellers (Pydantic-origin) that emiterrors: null,context: null, orext: nullbegan 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 astype: 'array'/type: 'object'without a null union, but the Pydantic convention is "present-as-null = absent."The fix adds a
stripEnvelopeNulls()pre-processing step insidevalidateResponsethat removes top-level optional fields whose value isnullbut whose declared schema type is not nullable — before handing the payload to Ajv. Gated to v2.x bundles viaparseAdcpMajorVersion(version) === 2; v3 is unaffected (in v3,errorsis required on failure branches and must not be silently dropped).What was tested
npm run format:check— ✅ passesnpx tsc --project tsconfig.lib.json— ✅ pre-existingTS2688/TS5107only (confirmed identical onmain)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 onmain; 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 existingtest/lib/post-adapter-v2-5-validation.test.js); CI runssync-schemas:allso the v2.5 suite runs in full therePre-PR review
removeAdditional/useDefaults/coerceTypesabsent),requiredguard prevents stripping legitimately required fields, top-level-only scope is correct for envelope fields; nit onstartsWith('v2')gate addressed viaparseAdcpMajorVersionselectResponseVariant(payload)call ordering is safe (runs on original payload beforenormalizedPayloadis computed)Known scope boundary (not a blocker for this PR)
The protocol expert noted
validateRequesthas 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 thevalidateOutgoingRequestpath defaults towarnmode, so this is a separate follow-up concern. Filed as a note here for the next sweep.Nits (surfaced, not fixed):
'null on field not declared in schema properties'only assertsdoesNotThrow; a deeper assertion onoutcome.validwould be tighter.errors: nullremains in the Ajv input.Session: https://claude.ai/code/session_01H9wytvzmHPVPdCPUYZVCte
Generated by Claude Code