fix(decoders): MsgspecDecoder.can_decode rejects nested CustomType (0.9.1)#43
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…itive Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
list[PUser], dict[str, PUser], and other containers parameterized by a pydantic BaseModel (any CustomType-falling element) were wrongly accepted because can_decode inspected only the top-level type_info node. They now route to MissingDecoderError before a request is sent. Closes the High finding in planning/audit/2026-06-12-delta-audit.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A msgspec-only client asked for list[_PydanticUser] now raises MissingDecoderError without sending a request. Sync + async twins. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Two linked deliverables from a post-0.9.0 review pass:
planning/audit/2026-06-12-delta-audit.md) of everything changed since0.8.6, run via a single-chunk find→verify→synthesize workflow. 14 confirmed findings (2 high, 1 medium, 3 low, 8 nit).MsgspecDecoder.can_decodeno longer falsely claims parameterized containers of pydantic models.The bug
can_decodeinspected only the top-levelmsgspec.inspect.type_infonode. Forlist[PUser](aListTypewhoseitem_typeis aCustomType), the guard passed, msgspec built a decoder via itsCustomTypefallback, andcan_decodereturnedTrue. TheMissingDecoderErrorpre-flight was bypassed, a real request was sent, anddecodethen failed withDecodeError— cached per-instance, so every later request of that shape repeated the wasted round-trip. Masked under the pydantic-first default; only bit msgspec-only configs.The fix
A recursive
_contains_custom_typewalker rejects when aCustomTypeappears anywhere in the type tree — coveringlist/dict/set/tuple/Optional/Unionand arbitrary nesting via generic introspection. It stops atStruct/dataclass field boundaries automatically (those exposeField, notType), so valid targets likelist[SomeStruct]stay accepted and self-referential structs can't loop. No public-API orResponseDecoderprotocol change.Ships as 0.9.1 (release notes drafted in
planning/releases/0.9.1.md; tagging is a separate manual step).Test Plan
just lintclean (ruff format + check + ty)just test— 501 passed, 100% coveragelist[PUser],dict[str, PUser],dict[PUser, str],PUser | None,tuple[PUser, int],list[list[PUser]],set[PUser]) + acceptance (list[Struct],dict[str, int], scalars) setsMissingDecoderErrorforlist[PUser]with the transport handler asserted never invoked🤖 Generated with Claude Code