Fix UpdateMetadata serializer to allow null values (per-key removal)#22
Merged
Conversation
The UpdateMetadata type is `Record<string, MetadataValue | null>` (null on a
key removes it), but the serializer wrapped the value in a non-nullable
`MetadataValue` schema. At runtime `jsonOrThrow({ key: null })` therefore
threw — null could never be sent, so per-key metadata removal via
`inboxes.update` was impossible despite compiling.
Wrap the record value in `.nullable()` so null short-circuits through
serialization. This also aligns the runtime schema with the declared
`Schema<UpdateMetadata.Raw, UpdateMetadata>` type (Raw already includes
`| null`).
Root cause is upstream: fern-typescript-node-sdk@3.60.0 honors `nullable<T>`
in the type layer but drops `.nullable()` in the serialization layer for
record/map values. This is a manual edit to the generated file pending a
generator fix; it will need re-applying after the next `fern generate` unless
the generator is upgraded.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add the hand-patched serializer to .fernignore so Fern regeneration does not overwrite the null-value fix (per-key removal). Co-Authored-By: Claude Opus 4.8 <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.
Problem
inboxes.updateis documented to remove a metadata key by sending it with anullvalue ({ metadata: { key: null } }). As of 0.5.6 the type allows this —UpdateMetadata = Record<string, MetadataValue | null>— but the serializer does not:MetadataValueisundiscriminatedUnion([string, number, boolean])with no null member, andrecord()applies it to every value with no null handling. So at runtime:Per-key removal compiles but throws before the request is sent — null can never reach the API. (Whole-object clear
metadata: nullwas unaffected, sinceoptional().json()already passes null through; only the per-key value case was broken.)Fix
Wrap the record value schema in
.nullable()so null short-circuits through serialization:Verified:
This also makes the runtime schema match the declared
Schema<UpdateMetadata.Raw, AgentMail.inboxes.UpdateMetadata>annotation (.Rawalready includes| null).tsc --project ./tsconfig.cjs.json --noEmitpasses.Root cause / follow-up
This is an upstream codegen bug:
fern-typescript-node-sdk@3.60.0honorsnullable<T>in the type layer but drops.nullable()in the serialization layer for record/map values (.nullable()is emitted nowhere in the generated serialization despite the def usingnullable<>).This PR is a manual edit to a generated file as an interim fix — it will be overwritten on the next
fern generateunless the generator is upgraded. Reported to the Fern team separately; the durable fix is a generator bump.🤖 Generated with Claude Code