Skip to content

fix: preserve __origin__ sequences in alias-expanded schemas#3

Merged
reuvenharrison merged 2 commits intov3from
fix/origin-alias-preserves-sequences
Mar 31, 2026
Merged

fix: preserve __origin__ sequences in alias-expanded schemas#3
reuvenharrison merged 2 commits intov3from
fix/origin-alias-preserves-sequences

Conversation

@reuvenharrison
Copy link
Copy Markdown
Collaborator

@reuvenharrison reuvenharrison commented Mar 31, 2026

Summary

When origin tracking is enabled and a YAML anchor is referenced via an alias,
the __origin__ metadata injected into the anchor's mapping was being skipped
entirely
during alias expansion. This prevented any consumer of the decoded
data from knowing where the anchor's fields and sequences were defined.

Root cause

PR #2 introduced a guard to skip __origin__ entries during alias expansion,
because re-decoding them through the normal path increments aliasCount
which can spuriously trigger the excessive-aliasing ratio check on large
documents with many aliases.

The guard was correct in intent but too blunt: it silently dropped all origin
metadata from every alias-expanded mapping.

Fix

Instead of skipping __origin__ entries, decode them with aliasDepth
temporarily set to 0 so they don't count toward aliasCount. The
ratio check stays safe, and the origin data (keys, field locations, and
sequence-item locations) is preserved in the decoded output.

Test plan

  • TestOrigin_ManyAliasesNoExcessiveAliasing still passes — 5000 aliases
    of a 20-property anchor no longer trigger "document contains excessive
    aliasing" (aliasCount stays below the threshold because __origin__ decodes
    are excluded from the count)
  • TestOrigin_AliasPreservesSequences (new) — verifies that after alias
    expansion the decoded map contains __origin__ with a populated sequences
    sub-map, confirming that sequence-item location data is preserved

🤖 Generated with Claude Code

reuvenharrison and others added 2 commits March 31, 2026 06:11
Previously, __origin__ entries were skipped entirely during alias
expansion to prevent inflating aliasCount. This stripped origin data
(including sequences.required tracking) from alias-expanded schemas,
causing Origin.Sequences to be nil and breaking source navigation for
changes like response-property-became-optional.

Instead, decode __origin__ entries with aliasDepth temporarily zeroed
so they don't count toward aliasCount — the ratio check stays safe and
origin data is preserved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@reuvenharrison reuvenharrison merged commit 7ce4c46 into v3 Mar 31, 2026
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.

1 participant