Skip to content

Commit 36fc938

Browse files
hotlongclaude
andauthored
fix(cli): dev restarts the serve child after each rebuild — no more silent artifact/server divergence (#5148) (#6150)
The dev watcher rebuilt dist/objectstack.json and printed "server will auto-reload", but the running serve child only partially receives a rebuilt artifact: MetadataPlugin's artifact watcher re-ingests the registry, syncs DDL + seeds for NEW objects and broadcasts the SSE HMR event, while hook bodies and already-registered view metadata from the compiled bundle are applied at boot only. #5148 measured both staying stale — every dev edit/verify loop could produce a false conclusion in either direction. Boot-time load is the one path that applies the whole artifact, so dev now supervises its serve child nodemon-style via ServeRestartCoordinator (packages/cli/src/utils/dev-restart.ts): - after each successful rebuild: SIGTERM the child (kernel shuts down gracefully), spawn a replacement on exit; requests during teardown coalesce; SIGKILL escalation after 8s; a failed respawn is loud and exits dev; parent SIGINT/SIGTERM is forwarded and a process-exit hook guarantees no orphaned server. - --no-restart keeps the rebuild-only behavior but says on EVERY rebuild that the running server keeps the build it booted with; the watch banner states the active mode instead of implying hot reload. - startup variant (#5148 comment 2026-08-05): when objectstack.config.ts / src/** are newer than the artifact at boot, warn loudly (newest source + remedy) without gating the boot. The staleness walk shares the watcher's ignore list so both judge the same source surface. Seams unit-tested (22 cases): staleness assessment on real tmpdirs, coordinator state machine with a fake child (restart sequencing, coalescing, self-exit follow, shutdown-beats-respawn, force-kill, spawn failure, orphan guard, late exit events). Claude-Session: https://claude.ai/code/session_015a5qkLzpGXhLL2F5gvJ7dD Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4576a22 commit 36fc938

5 files changed

Lines changed: 907 additions & 80 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
"@objectstack/cli": patch
3+
---
4+
5+
fix(cli): `objectstack dev` restarts the server after each rebuild — the running server can no longer silently disagree with `dist/objectstack.json` (#5148)
6+
7+
The dev watcher rebuilt `dist/objectstack.json` on every source change and
8+
printed `✓ recompiled — server will auto-reload`, but the running serve child
9+
only **partially** received the rebuilt artifact: MetadataPlugin's own
10+
artifact watcher re-ingests the metadata registry, syncs DDL + seeds for
11+
newly-appearing objects and broadcasts the SSE HMR event — while hook bodies
12+
and already-registered view metadata from the compiled bundle are applied at
13+
**boot only**. #5148 measured both staying stale: the old hook kept executing
14+
and `/api/v1/meta/views` kept serving the old view after a confirmed on-disk
15+
rebuild, with no error and no warning. That made every dev edit/verify loop
16+
capable of a false conclusion in either direction ("my fix doesn't work" /
17+
"this code isn't load-bearing").
18+
19+
`objectstack dev` now supervises its serve child nodemon-style:
20+
21+
- **Auto-restart (default-on).** After a rebuild lands on disk, the serve
22+
child is SIGTERMed (the kernel shuts down gracefully), and a replacement is
23+
spawned once it exits — boot-time load is the one path that applies the
24+
whole artifact. Restarts coalesce (rapid saves produce one restart), a
25+
child that ignores SIGTERM is force-killed after 8s, a replacement that
26+
fails to come up is loud and exits dev, and parent SIGINT/SIGTERM is
27+
forwarded to the child so no orphan server outlives dev.
28+
- **`--no-restart` opt-out.** The watcher then only rebuilds the artifact —
29+
and every rebuild now says explicitly that the running server keeps the
30+
build it booted with. The watch banner states the active mode instead of
31+
implying a hot reload the runtime only partially performs.
32+
- **Boot-time staleness warning (#5148 startup variant).** When
33+
`objectstack.config.ts` / `src/**` are newer than the artifact at boot
34+
(edited while the server was down), dev warns loudly that the boot serves
35+
the stale build, names the newest source file and the remedy
36+
(`objectstack build`, `--compile`, or save a watched file). The boot is
37+
never gated — the silence is removed, not the start.

content/docs/getting-started/your-first-project.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Postgres / MySQL / MongoDB for production — [no code changes](/docs/data-model
179179
## 3. Run it
180180

181181
```bash
182-
npm run dev # objectstack dev — hot reload
182+
npm run dev # objectstack dev — rebuild + server restart on change
183183
```
184184

185185
Or with the visual Console (data browser, metadata explorer, API docs):

0 commit comments

Comments
 (0)