Repository navigation
fix: Refresh generated models that changed outside code generation - #6024
Merged
FXschwartz merged 4 commits intoNov 25, 2026
Merged
FXschwartz merged 4 commits into
FXschwartz merged 4 commits into
Conversation
FXschwartz
requested changes
Nov 24, 2026
FXschwartz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for tracking this one down @BiAksoy! Fixing it where the context gets refreshed rather than in the watch loops makes sense to me. A few questions before this goes in:
…dels The files of a pull can reach the watcher in a run before the model files they come with, and that run analyzes endpoints and future calls against the generated models too. Stamps stay the record's identity because the seeding and these runs have no file content at hand.
FXschwartz
approved these changes
Nov 25, 2026
FXschwartz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the quick turnaround @BiAksoy! This all looks good to me now.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #6023.
When a pull or branch switch brings a model change together with its regenerated code,
serverpod startandserverpod generate --watchkeep analyzing the old generated model. An endpoint that uses the change then fails analysis ("The named parameter 'tag' isn't defined") and drops out of the generated code, on every generation until the command is restarted.Since #5825, generation refreshes the analysis context with the model files it writes, and it does not write a file whose content is already on disk. After such a pull the regenerated model on disk already matches what generation produces, so it is not written and the context keeps the version it read before the pull. Models whose generated file imports
protocol.dartare not affected, because refreshing theprotocol.dartstub evicts them; leaf models are.Analyzersnow records theFileStamp(modification time and size, the same identity the generation staleness check uses) of each generated server model file as the analysis context last got it. After generating the project's models,performGeneraterefreshes the written files plus every file whose stamp differs from the record, and records the stamps once the refresh has gone through. Runs that do not generate models check the stamps of the server model files already in the record and refresh those that changed. The record is seeded around the firstupdate, where the context makes its first reads of generated files: a file in the server's or a shared model package's generated directory with the same stamp before and after that update is taken as read, or still to be read, in that state. Seeding is best effort; if a directory cannot be listed, the first model generation refreshes every model file instead. The client package is left out, since the server's analysis context does not read it.stampAllingeneration_staleness.dartis made public for this.The fix is in the analyzers rather than in the watch loops, so it covers both commands, the full generation that
retryStartruns on already used analyzers, and a pull whose files reach the watcher over several runs.Why stamps and not content hashes: the seeding and the runs that do not generate models have no file content at hand, and reading it there would mean reading every generated file at start-up and every model file on each endpoint edit. Without seeding, the first model generation would refresh every model file: about +900 ms on the first YAML edit of each watch session and +500 ms on every one-shot regenerate of the large benchmark project. A pull or checkout that rewrites a file gives it a new stamp, and a file whose stamp changes without its content changing is only refreshed once more than needed.
What it does not cover:
serverpod generateon a half-written tree would.Tests:
test/integration/generate/externally_regenerated_model_test.dartgenerates a project with one set of analyzers, primes a second set on it (asserverpod starton an up-to-date project), regenerates with a new field using a third set (the other checkout), adds an endpoint that uses the field, and then generates with the primed set, incrementally and as a full run. A third group runs the endpoint alone first, as when it reaches the watcher before the model file; it also fails when the seeding is turned off. All six tests fail onmainand pass with this change. Also checked end to end in a freshserverpod createproject withgit merge --ff-onlyunder bothserverpod startandserverpod generate --watch. The fulltools/serverpod_clisuite passes locally except three tests inmcp_command_integration_test.dart, which fail the same way onmainon this machine, and one timing-dependent test insdk_resolver_test.dartthat passed on every rerun.Performance,
dart run docs/process/generator_performance/compare.dart --baseline=b1dc2ee9a --repeats=3, macOS on an 18-core machine: no row shows a consistent difference; medians are within about 6 % in either direction, which is the spread between runs of the same baseline. For example, "First run on the up-to-date large project" (analysis, including the seeding) 10300 ms baseline and 10200 ms with this change; "Edit a YAML model in the large project" generation 6300 and 6400 ms; one-shot "Regenerate the large project after an edit" 15703 and 15296 ms.The check in runs that do not generate models, measured against the first version of this PR (
--baseline=c10ce1169 --repeats=3): "Edit an endpoint in the large project" 3444 ms before and 3422 ms after, the two future call edits 40 to 55 ms slower (wall clock medians). Rows that never reach this code move by as much in both directions: saving an unchanged plain Dart file, which does not generate, was 88 ms slower in one row and 50 ms faster in another. After the review changes, the generator suites (test/integration/generate/,test/generator/,test/commands/start/,test/analyzer/) pass, 4771 tests.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.dart run melos run changelog_add), or this change does not need one.Breaking changes
None.