Skip to content

fix(cli): don't stop build daemons of other Jaspr processes, and stop serve when its daemon exits - #998

Merged
schultek merged 8 commits into
schultek:mainfrom
lewinpauli:fix/build-kills-serve-daemon
Nov 18, 2026
Merged

schultek merged 8 commits into
schultek:mainfrom
lewinpauli:fix/build-kills-serve-daemon

Conversation

@lewinpauli

@lewinpauli lewinpauli commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #997

Running jaspr build while jaspr serve runs in the same directory killed the serve's build daemon (OptionsSkew → stopDaemon(workingDirectory)). jaspr serve didn't notice and kept answering every request with an empty 503. This is a regression from the CLI refactor in #928. In 0.23.5, jaspr build just returned 1.

This PR has two fixes:

1. Only stop build daemons this process started

  • Adds isDaemonRunning(workingDirectory) in dev/util.dart. It probes the port from the daemon's port file with Socket.connect on loopback, so a leftover port file doesn't count, and a missing or failing lsof/netstat doesn't make a running daemon look absent.
  • ClientRunner.build() and ClientRunner.start() check this before connecting and remember it as ownsDaemon. stopDaemon is only called for a daemon this process started: on a failed connect, on cancel, in the guard, in cleanUp() and in shutDown(). A daemon shared with another process stops on its own once its last client disconnects (_removeChannel in build_daemon), so nothing is left running.
  • startBuildDaemon now also reports foreignDaemon when connecting fails with OptionsSkew or VersionSkew. In that case the daemon is never stopped, even if it was still starting up (no port file yet) when ownership was checked.
  • This also covers jaspr serve. Its guard runs on every exit, so a second jaspr serve with different options that fails with OptionsSkew killed the other daemon in the same way.

2. Stop jaspr serve with an error when the build daemon exits unexpectedly

  • ClientRunner now also listens to client.finished. If the connection closes without a ShutdownNotification and without shutDown() having been called, it logs The build daemon exited unexpectedly. Please restart Jaspr. (critical) and shuts down with exit code 1. Before, serve kept proxying to a backend that no longer existed, and ProxyHelper only logged the connection error at verbose level.
  • DevWorkflow.start() also stops waiting for the initial build when clientRunner.done completes, so serve exits with 1 when the daemon goes away during the initial build, instead of waiting forever.
  • The guard of ClientRunner.start() now shuts the runner down first. Before, on a failed initial build or Ctrl+C it stopped the daemon before shutDown() ran, and the closing connection would have been reported as an unexpected exit. The second guard that only called shutDown() is removed, since the first one covers it.

Tests:

  • daemon_process_test.dart: isDaemonRunning with a listening port, without a port file and with a leftover port file.
  • client_runner_test.dart: ClientRunner.build() runs in an empty temp directory whose port file points to a separate process standing in for the daemon of a running jaspr serve. Connecting fails there, which takes the same client == null path as OptionsSkew. The test checks that the build returns 1 and that the other process keeps listening and keeps its port file. It uses real processes because the fakes connect through connectUnchecked, where startBuildDaemon never returns null. This test fails without fix 1.
  • serve_command_test.dart: the fake build daemon closes the connection without a notification. Serve must log the critical message and exit with 1. This test fails without fix 2.
  • serve_command_test.dart: the daemon disconnects before the first build result. Serve must log the critical message and exit with 1. Without the change in DevWorkflow.start() the test times out.
  • serve_command_test.dart: the initial build fails and serve stops through the guards, while stopping the daemon closes its connection, as a killed daemon process would. No unexpected exit may be reported. This test fails without the guard change in fix 2.
  • No dedicated test for the OptionsSkew/VersionSkew path: a real skew needs a full package with build_runner and compiled builders, which felt too slow and flaky for CI.

The failing Test CLI jobs (cnen, cspn, smpn, snpn, vnen) fail on main as well (e.g. run 43451833303): Prebuilt SDK file "dart_sdk.js" does not exist at …/flutter_web_sdk/kernel/ddcLibraryBundle-canvaskit with Flutter 3.50. With fail-fast, whichever fails first cancels the others.

Type of Change

  • 🛠️ Bug fix

Ready Checklist

  • I've read the Contribution Guide.
  • In case this PR changes one of the core packages, I've modified the respective CHANGELOG.md file using
    the semantic_changelog format.
  • I updated/added relevant documentation (doc comments with ///).
  • I added myself to the AUTHORS file (optional, if you want to).

@lewinpauli
lewinpauli requested a review from schultek as a code owner November 13, 2026 20:23
Copilot AI balanced review requested due to automatic review settings November 13, 2026 20:23
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Package Version Report

The following packages have been updated:
jaspr_test : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr_builder : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr_cli : 0.24.0-beta.1 -> 0.24.0-beta.2

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unreliable daemon detection and premature ownership claims can delete or terminate another process’s daemon, while a disconnect during the initial build can leave serve hanging instead of exiting with an error.

3 open issues
What changed in this PR

Addresses the CLI regression from #928 reported in #997: commands could stop another Jaspr process’s build daemon, leaving jaspr serve returning empty 503 responses.

Changes:

  • Adds daemon-liveness checks and ownership-based cleanup.
  • Makes serve report unexpected daemon disconnections and initiate shutdown with exit code 1.
  • Adds regression tests and changelog entries.
File Description
packages/​jaspr/​CHANGELOG.md Documents the daemon lifecycle fixes.
packages/​jaspr_cli/​test/​src/​commands/​serve_command_test.dart Tests unexpected daemon disconnection after startup.
packages/​jaspr_cli/​test/​helpers/​daemon_process_test.dart Tests liveness detection with missing, active, and stale port files.
packages/​jaspr_cli/​lib/​src/​dev/​util.dart Adds the daemon-liveness helper.
packages/​jaspr_cli/​lib/​src/​dev/​client_runner.dart Gates daemon cleanup on ownership and handles unexpected disconnections.

Review effort: Balanced

@lewinpauli

Copy link
Copy Markdown
Contributor Author

The red Test CLI jobs (cnen, cspn, smpn, snpn, vnen) are not caused by this PR. They fail on main too since the CI picked up Flutter 3.50, which moved the precompiled DDC SDK to kernel/ddc/{stable,canary} (#999). The fix is in #1000. Once that is merged, I can rebase this PR so the jobs go green here as well.

@schultek
schultek force-pushed the fix/build-kills-serve-daemon branch from d5d9a45 to 6cd7862 Compare November 18, 2026 11:49
schultek
schultek previously approved these changes Nov 18, 2026

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM, just one nit

Comment thread packages/jaspr/CHANGELOG.md Resolved
@schultek
schultek merged commit 95a4aa9 into schultek:main Nov 18, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants