Skip to content

fix: Compile file changes that arrived with a failed code generation - #5858

Merged
marcelomendoncasoares merged 2 commits into
serverpod:mainfrom
BiAksoy:fix/watch-compile-after-failed-generation
Oct 22, 2026
Merged

marcelomendoncasoares merged 2 commits into
serverpod:mainfrom
BiAksoy:fix/watch-compile-after-failed-generation

Conversation

@BiAksoy

@BiAksoy BiAksoy commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Under serverpod start, WatchSession._handleFileChange returns as soon as code generation fails. The changed files of that batch are handed to the incremental compiler further down, so they never reach it, and nothing records them. The next cycle invalidates only its own files, and the Frontend Server keeps the previous content of the earlier ones until each is saved again. Depending on the files, the server reloads and keeps running old code, or fails to compile a tree that dart analyze accepts.

The session already carries paths over when a compile is rejected, through _pendingPaths and _pendingPackageConfig. This PR uses the same mechanism for a failed generation: the batch's source files, the generated files the watcher reported, and the files the failed generation wrote are added to _pendingPaths, so the next compile invalidates them. A package_config.json change in that batch is carried the same way, and the native-assets builder is reset as the skipped compile would have done, so the build hooks see the new package layout.

With the steps from #5857, calling greeting.hello after the syntax error is fixed:

Before:

"message":"Hello Bob"

After:

"message":"Hi Bob"

On 99c3387, where this branch started, the merge case from the issue also compiles again once the conflict is resolved. On current main that case still fails at that point, for a separate reason tracked in #5882: since #5825 the cycle after the conflict runs generation, and that generation deletes the model files the failed cycle wrote. The steps above are not affected.

Tests cover a failed generation followed by a successful cycle (the earlier source, watched generated and written generated files are compiled with it), a package_config.json change in a failed cycle (invalidated on the next compile), and the same with a native-assets builder (package discovery is reset before the next hook run). The three tests fail on main.

Not changed here: a failed generation still writes the generated files without the endpoint whose file had the error. Whether the next cycle generates again was changed by #5825, which has since been merged; with it the generated files recover once the error is fixed. This branch is up to date with main (60a7176 merged in), and the tests pass.

Fixes #5857.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

None.

Under `serverpod start`, a failed code generation returned before the batch's
changed files reached the incremental compiler, and nothing recorded them. The
Frontend Server kept their previous content until each file was saved again.

Carry them over through the pending paths a rejected compile already uses.
@BiAksoy

BiAksoy commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

The two failing jobs look unrelated to this change.

@BiAksoy

BiAksoy commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@Crazelu @marcelomendoncasoares since you both worked on #5825: I merged current main into this branch; the change applies as it was and the tests pass. While re-checking the merge case from #5857 I found a separate generator problem that shows up there since #5825, filed as #5882, and updated the description to match.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix, @BiAksoy! LGTM! 🚀

@marcelomendoncasoares
marcelomendoncasoares merged commit 9217d4c into serverpod:main Oct 22, 2026
483 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serverpod start: Dart files changed together with a failed code generation are never compiled

2 participants