Repository navigation
Conversation
`$.type.clone` copies `derivedModels` as a shallow array, so a mutated base model kept pointing at the *source* derived models. `ModelMutationNode`'s base-model edge already keeps `baseModel` in sync from the derived side; it now also swaps the source derived model for the mutated one in the mutated base's `derivedModels` (appending when absent) and removes it again when the derived node is deleted. The source graph is never touched. `@typespec/graphql`'s `flattenBaseModel` severs `baseModel` on the derived model but left the base's back-reference in place, so a flattened graph still advertised inheritance; it now drops the flattened model from the (mutated) base's `derivedModels` too. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Sep 9, 2026
mauriciogardini
approved these changes
Sep 10, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$.type.clonecopies a model'sderivedModelsas a shallow array, so a mutated base model kept pointing at the source derived models. Nothing in the framework ever rewired that back-reference:ModelMutationNodehas half-edges forbaseModel, properties and indexer, but the derived side of the inheritance link was left alone.Two changes:
@typespec/mutator-framework— the base-model edge already keepsbaseModelin sync from the derived side. It now also swaps the source derived model for the mutated one in the mutated base'sderivedModels(appending when it wasn't listed), and removes it again when the derived node is deleted. Works regardless of mutation order (base first or derived first). The source graph is never touched.@typespec/graphql—flattenBaseModelseversbaseModelon the derived model but left the base's back-reference in place, so a flattened graph still advertised inheritance. It now drops the flattened model from the mutated base'sderivedModels. Only a mutated base is touched; an un-mutated base is the source type.Why
Found while reviewing pinboard's staged mutation pipeline. After several cloning stages,
V5_Animal.derivedModelspointed at a flattened, un-prefixedDoginstance that was not registered anywhere, and downstream code (canonicalizeNestedReferences) grew a by-name repoint pass to paper over it. With this change the pipeline's probe showsderivedModelscorrect after every stage with no repair pass.Not covered here
templateMapper.argshas the same shallow-copy problem and is also never rewired. Separate change.onTailReplaced(base replaced by another model) does not touchderivedModelson the replacement, because the replacement type may be a raw source type.Tests
mutator-framework: 3 new tests inmutation-node/model.test.ts(sync on base mutation, sync when the base mutated before the derived connected, removal on derived deletion). Suite 59/59.graphql: 1 new test intest/mutation-engine/models.test.tsasserting the flattened base has no derived back-reference and the source is untouched. Package suite 369/369.