Skip to content

Detect model spread cycles without over-reporting recursive model-expression aliases#10684

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-model-circular-references
Open

Detect model spread cycles without over-reporting recursive model-expression aliases#10684
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-model-circular-references

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

Model-to-model spread cycles were not being validated correctly (Foo spreads Bar, Bar spreads Foo), which led to unresolved checker state instead of a proper diagnostic. At the same time, alias recursion through model expressions was being flagged too aggressively.

  • Spread cycle validation

    • Adds explicit cycle detection for model spread chains in the checker.
    • Mutual spreads now surface the intended spread-model self-spread diagnostic instead of ending in pending-resolution failure.
  • Alias recursion behavior

    • Narrows circular-alias handling for aliases whose value is a model expression.
    • Allows recursive object-shape aliases (via model expressions) to resolve without emitting circular-alias-type.
  • Targeted test coverage

    • Unskips and enforces the mutual spread regression case in spread.test.ts.
    • Adds a regression case in alias.test.ts for recursive aliases through model expressions.
model Foo { ...Bar }
model Bar { ...Foo } // now diagnosed as spread-model self-spread

alias A = { a: B };
alias B = { a: A }; // now allowed (no circular-alias-type)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /opt/hostedtoolcache/node/22.22.2/x64/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/bin/astro.mjs build node s/.b�� run --local de_modules/pnpm/dist/node-gyp-bin/node import @typespecsh --production reams/reference node sion�� build.json dotnet k/typespec/typespec/node_modules/.bin/node --no-emit node rsioning/referendoc sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…xpression aliases

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/00744925-833d-4200-87a1-e286c26a0369

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label May 14, 2026
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/00744925-833d-4200-87a1-e286c26a0369

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix circular reference validation for models Detect model spread cycles without over-reporting recursive model-expression aliases May 14, 2026
Copilot AI requested a review from timotheeguerin May 14, 2026 01:19
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10684

commit: 8312634

@timotheeguerin
Copy link
Copy Markdown
Member

@copilot add changelog

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4bab9fe4-0624-4803-9e15-28321acb1410

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot add changelog

Added in d5224a2: created a Chronus changelog entry for @typespec/compiler under .chronus/changes/copilot-fix-model-circular-references-2026-4-14-20-45-42.md.

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4bab9fe4-0624-4803-9e15-28321acb1410

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@timotheeguerin
Copy link
Copy Markdown
Member

@copilot pull in change from main and resolve conflicts

…cular-references

# Conflicts:
#	packages/compiler/src/core/checker.ts

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot pull in change from main and resolve conflicts

Done in 6430064 — pulled latest main, resolved the merge conflict in packages/compiler/src/core/checker.ts, and pushed the merge commit.

@timotheeguerin timotheeguerin marked this pull request as ready for review May 28, 2026 12:13
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Fixed the compiler to correctly detect circular model spread chains while preserving support for recursive model-expression aliases.

@azure-sdk-automation
Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate model don't spread each other

3 participants