Skip to content

Find a shaped field's Input location on its container, not its val - #466

Open
DZakh wants to merge 12 commits into
mainfrom
claude/schema-failing-cases-u2dnpj-never-field
Open

DZakh wants to merge 12 commits into
mainfrom
claude/schema-failing-cases-u2dnpj-never-field

Conversation

@DZakh

@DZakh DZakh commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Cause

A shaped object's encode finds where each Output field came from by walking the decoded vals and reading each val's expected schema, which is the s.field proxy that carries the location. S.never's decoder ends its val's chain on never_, so nothing after it runs. That replaces the proxy, and the location goes with it.

Fix

The walk now reads the location off the container's own field schema. For every other field that's the same proxy the val carried (checked), and for a never field it's still there.

I tried the obvious alternative and rejected it: keeping the caller's expected schema in the never decoder broke codec-array-never-jsonstring. Ending the chain is deliberate there, since it's what stops a link after never from compiling a conversion for a value that can't exist.

What changes for you

main already fixed the union case (#490). This PR now fixes only a renamed never field:

const schema = S.object((s) => ({ b: s.field("a", S.never) }));
S.encodeOrThrow(schema, { b: 1 });
// main: creation error "Missing input for never at a"
// now:  "Failed at b: Expected never, received 1"

S.union([S.string, S.object((s) => ({ a: s.field("a", S.never) }))]) gives the same answer as on main: parse, decode and encode are all typeof i==="string", and { a: 1 } is rejected with Expected string | { a: never; }, received { a: 1; }.

Impact (bundle vs main)

Gzip bytes: object +18 (13235 to 13253), shape +15, tuple +15, protobuf +21, protobufAny +19, total +21 (73883 to 73904). The benchmark goldens moved by the same amounts. No other export moved.

Decision

  • main's Fix the critical and most important bugs from the FIXME and known-bug triage #490 made a union member with a never field yield to its siblings, so union-never-member.yaml takes main's side and this PR no longer changes it.
  • main listed the remaining fuzzer difference as the limitation union-never-member-yields: the member-by-member reference met the object alone, and its encode refused to compile. With this fix that object compiles and rejects at runtime, so the reference agrees with the union and the gate stopped reaching the entry. The entry is deleted, as the gate requires.

Details

  • Spec: object-field-never-renamed (new). With main's src its encode becomes creationError: "SuryError: Missing input for never at a"; with this branch it reads b back into a and fails with Failed at b: Expected never.
  • Merged origin/main (2ebcac6) as a merge commit. knownBugs.ts, union-never-member.yaml and the generated goldens took main's side and were regenerated after that. The changes in factory.ts/parse.ts merged cleanly.
  • Gates: full pnpm verify passes on ea83f23, every step including the ppx build, e2e, every fuzzer and the protobuf suites.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X9uDwr3yJ2L75BYdetqyE1

Summary by CodeRabbit

  • Bug Fixes
    • Improved parsing, decoding, and encoding for renamed object fields whose schema is never, including when those fields are nested in objects or tuples.
    • Removed a previously tracked limitation related to unions containing never.
  • Performance
    • Bundle-size measurements increased slightly for several library exports.

`S.union([S.string, S.object((s) => ({ a: s.field("a", S.never) }))])` would
not compile an encode ("Missing input for never at a"), and neither would the
object alone, while `S.schema({ a: S.never })` compiles and rejects every
value at runtime, as a schema nothing inhabits should.

A shaped object's encode finds where each Output field came from by walking
the decoded vals and reading each val's expected schema, the `s.field` proxy
that carries the location. `S.never`'s decoder ends its val's chain on
`never_` so nothing after it runs, and that replaces the proxy, location and
all. The walk now reads the location off the container's own field schema,
which is the same proxy for every other field and is still there for this one.

The never field then encodes like the plain object's: it compiles, rejects any
value with "Expected never", and inside a union yields to the string member.

Known bug `union-never-member` is deleted; its spec now encodes "x" (encode is
the same code as parse), and `object-field-never-renamed` pins a renamed never
field, whose encode reads `b` back into `a`. Bundle: `object` +9 gzip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The serializer accumulator now reads source metadata from the schema for each traversed value and passes child schemas during recursion. A new specification covers a renamed object field using S.never. The known-bug entry is removed, and bundle-size measurements are updated.

Changes: Never-valued object fields

Layer / File(s) Summary
Schema-aware serializer traversal
packages/sury/src/factory.ts, packages/sury/src/parse.ts
prepareShapedSerializerAcc reads from and fromFlattened from the supplied schema. Recursive traversal passes the schema for each child value. The never_ comment describes this behavior.
Renamed field specification and measurements
packages/sury/specs/object-field-never-renamed.yaml, packages/sury/scripts/knownBugs.ts, packages/sury/specs/bundleSize.yaml, packages/benchmarks/goldens/*
The new specification covers field a renamed to b with S.never. The matching known-bug entry is removed. Bundle-size measurements increase in the listed specifications and benchmark goldens.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to ea83f

The change addresses metadata lookup for never-valued fields and adds a renamed-field specification. No actionable merge-blocking issue was identified; merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the core fix: a shaped field's Input location is now found on its container rather than on its val. That matches the factory.ts change, which reads from and fromFlattened from the fiel…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the core fix: a shaped field's Input location is now found on its container rather than on its val. That matches the factory.ts change, which reads from and fromFlattened from the field's container schema, and the objective that the encoder reads a field location from the container's field schema instead of the decoded value's schema chain, which S.never terminates. The title is specific and short. It does not mention the benchmark golden or bundle-size updates, the removed KNOWN_BUGS entry, or the new object-field-never-renamed fixture, but those are supporting changes, not the main point.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (4 skipped: 4 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58951b2b-7fe9-4d44-8bff-f445544ab39c
Commits

Reviewing files that changed from the base of the PR and between 2ebcac6 and ea83f23.

Files selected for processing: 7
  • packages/benchmarks/goldens/protobuf.json
  • packages/benchmarks/goldens/schema.json
  • packages/sury/scripts/knownBugs.ts
  • packages/sury/specs/bundleSize.yaml
  • packages/sury/specs/object-field-never-renamed.yaml
  • packages/sury/src/factory.ts
  • packages/sury/src/parse.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@github-actions

Copy link
Copy Markdown

Spec performance

1 slower of 3741 timed targets · 9b78051 vs e84e97a (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
jsonstring-novalidation-format · decode · accepts ×2 +4.9% slower

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.0% · create+compile 3.9% · run 3.4% · scenario 3.0%
new: object-field-never-renamed · encode · rejects
3740 unchanged · 132 constant-schema targets skipped · 40 async examples skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

…-cases-u2dnpj-never-field

# Conflicts:
#	packages/benchmarks/goldens/schema.json
#	packages/sury/specs/bundleSize.yaml
@github-actions

Copy link
Copy Markdown

Spec performance

No significant changes of 3856 timed targets · 06de0ac vs 4a723c8 (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Full report ↗

+% slower than baseline, -% faster · noise floor create 4.1% · create+compile 6.3% · run 3.0% · scenario 3.7%
new: object-field-never-renamed · encode · rejects
3856 unchanged · 132 constant-schema targets skipped · 40 async examples skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

Generated files (bundleSize.yaml, benchmark goldens) regenerated rather
than hand-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@github-actions

Copy link
Copy Markdown

Spec performance

1 slower of 3883 timed targets · 6a565b4 vs b9bf517 (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
fromjsonschema-nested-dialect · create+compile · parse +3.6% slower

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.4% · create+compile 3.1% · run 7.3% · scenario 9.0%
new: object-field-never-renamed · encode · rejects
3882 unchanged · 132 constant-schema targets skipped · 45 async examples skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

No conflicts; every golden regenerates unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
Generated files (bundleSize.yaml, benchmark goldens) regenerated rather
than hand-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@github-actions

Copy link
Copy Markdown

Spec performance

1 faster of 3956 timed targets · 0165901 vs 0491207 (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Faster

target Δ vs baseline
fromjsonschema-open-tuple · parse · accepts ×4 -9.7% faster

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.0% · create+compile 7.1% · run 3.9% · async 3.0% · scenario 4.8%
new: object-field-never-renamed · encode · rejects
3955 unchanged · 132 constant-schema targets skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

claude added 2 commits October 1, 2026 10:16
Generated files (bundleSize.yaml, benchmark goldens) regenerated rather
than hand-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
knownBugs.ts takes main's version less this branch's union-never-member
entry; generated files regenerated rather than hand-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Spec performance

1 slower of 4235 timed targets · 5d0c878 vs 4b9e6fb (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
codec-email-jsonstring · decode · accepts +6.5% slower

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.8% · create+compile 3.0% · run 3.0% · async 3.3% · scenario 11.8%
new: object-field-never-renamed · encode · rejects
4234 unchanged · 132 constant-schema targets skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

Generated files (bundleSize.yaml, benchmark goldens) regenerated rather
than hand-merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Spec performance

1 slower of 4257 timed targets · 8f5492b vs 5522d8f (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
codec-json-union-recursive-union-member · parse · accepts ×3 +18.4% slower

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.0% · create+compile 3.0% · run 4.3% · async 3.0% · scenario 3.0%
new: object-field-never-renamed · encode · rejects
4256 unchanged · 132 constant-schema targets skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

Version bump only; no conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdDnkN38pECC46XqMZbwp8
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Spec performance

1 slower of 4257 timed targets · bda7857 vs 63b73cf (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
codec-json-union-recursive-union-member · parse · accepts ×3 +9.8% slower

Full report ↗

+% slower than baseline, -% faster · noise floor create 3.0% · create+compile 4.9% · run 3.0% · async 3.0% · scenario 14.1%
new: object-field-never-renamed · encode · rejects
4256 unchanged · 132 constant-schema targets skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

Main settled union-never-member its own way (#490), so its spec and the
union-never-member-yields knownBugs entry take main's side. What stays is the
renamed-field fix: S.object(s=>({b: s.field("a", S.never)})) now compiles its
encode and rejects with "Failed at b: Expected never, received 1" instead of
failing at creation with "Missing input for never at a".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X9uDwr3yJ2L75BYdetqyE1
The limitation stood because the union fuzzer's member-by-member reference
met an object with an `S.never` field alone, where its encode refused to
compile. Reading a shaped field's location off its container lets that object
compile and reject at runtime, so the reference agrees with the union and the
gate no longer reaches the entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X9uDwr3yJ2L75BYdetqyE1
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Spec performance

3 slower, 1 faster of 6476 timed targets · ea83f23 vs 2ebcac6 (origin/main)

Not timed

  • could not measure object-field-never-renamed · create+compile · encode: Missing input for never at a

Slower

target Δ vs baseline
codec-json-union-recursive-union-member · parse · accepts ×3 +17.6% slower
recursive-same-name · encode · accepts +6.5% slower
fromjsonschema-object-if-then-undeclared-key · decode · accepts +3.5% slower

Faster

target Δ vs baseline
codec-protobuf-any-one-member · encode · accepts -3.3% faster

Full report ↗

+% slower than baseline, -% faster · noise floor create 4.9% · create+compile 4.5% · run 3.0% · async 3.0% · scenario 3.0%
new: object-field-never-renamed · encode · rejects
6472 unchanged · 134 constant-schema targets skipped · advisory only
node 24.16.0 · linux x64 · 4 cores · 8×2 rounds · 2 screening jobs · confirmed by 2 fresh processes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants