Skip to content

fix: skip __origin__ entries during alias expansion to prevent excessive-aliasing#2

Merged
reuvenharrison merged 2 commits intov3from
fix/origin-alias-excessive-aliasing
Mar 30, 2026
Merged

fix: skip __origin__ entries during alias expansion to prevent excessive-aliasing#2
reuvenharrison merged 2 commits intov3from
fix/origin-alias-excessive-aliasing

Conversation

@reuvenharrison
Copy link
Copy Markdown
Collaborator

Follow-up to #1

The previous alias fix (aliasDepth == 0 guard on addOriginInMap/addOriginInSeq) stopped injecting duplicate __origin__ keys during alias expansion. However it introduced a secondary issue.

Problem

When an anchor is first processed, __origin__ metadata entries are appended to each nested mapping node's Content. When an alias expands that anchor, the decoder re-walks the subtree — now correctly skipping new origin injection, but still calling d.unmarshal() on the existing __origin__ entries already present in Content. Each such call happens at aliasDepth > 0, incrementing aliasCount.

For large specs with many aliases (e.g. cardano-wallet's ~1900 aliases) the aliasCount/decodeCount ratio exceeds the threshold and triggers:

yaml: document contains excessive aliasing

Fix

In d.mapping(), skip entries whose key has Line == 0 (i.e. synthesised __origin__ nodes) when inside an alias expansion. This keeps aliasCount proportional to actual YAML data, not injected metadata.

if d.aliasDepth > 0 && isOrigin(n.Content[i]) {
    continue
}

Test

Verified with the cardano-wallet spec (alias.yml, 258KB, ~1900 anchors/aliases) via TestAliasIssue in oasdiff/yaml.

🤖 Generated with Claude Code

reuvenharrison and others added 2 commits March 31, 2026 00:06
…ive-aliasing

The previous alias fix (aliasDepth == 0 guard on addOriginInMap/addOriginInSeq)
stopped injecting duplicate __origin__ keys during alias expansion, but still
allowed the decoder to re-walk existing __origin__ entries that were injected
when the anchor was first processed.

Each such re-walk increments aliasCount (because aliasDepth > 0), and for
large specs with many anchors (e.g. cardano-wallet's 1909 aliases) the
aliasCount/decodeCount ratio exceeds the threshold, triggering "document
contains excessive aliasing".

Fix: in d.mapping(), skip entries whose key has Line == 0 (i.e. synthesised
__origin__ nodes) when inside an alias expansion. This keeps aliasCount
proportional to the actual YAML data, not the injected metadata.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ring alias expansion

Re-enable the aliasDepth guard in mapping() so __origin__ metadata
nodes injected during anchor processing are skipped on each alias
expansion. Without this, every expansion re-decoded those nodes,
inflating aliasCount and spuriously triggering the "excessive aliasing"
check for large specs (5000+ aliases).

Add TestOrigin_ManyAliasesNoExcessiveAliasing with 5000 aliases of a
20-property anchor — a load that reliably fails without the guard and
passes with it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@reuvenharrison reuvenharrison merged commit 164ad42 into v3 Mar 30, 2026
@reuvenharrison reuvenharrison deleted the fix/origin-alias-excessive-aliasing branch March 30, 2026 21:19
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