Skip to content

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

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-model-circular-references
Draft

Detect model spread cycles without over-reporting recursive model-expression aliases#10684
Copilot wants to merge 5 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: c5366f4

@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>
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

2 participants