Repository navigation
Commit 6294157
fix(cli): a direct os serve --dev compiles the config before its dev artifact door serves it (#26289)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XVivP8oT7gawhLRoP3Mv7si)_
Fixes #26242
Clause-②: no
Metadata-protocol: none
## What was wrong
A host config's dev boot holds two copies of one stack. The config
module, evaluated in the serving process, feeds the AppPlugin wrap, and
provider-bound connectors are materialized from that copy, so it is what
dispatch calls. The compiled `dist/objectstack.json` feeds the dev
artifact door, and its copy is what `/api/v1/meta/connector/NAME`
serves. #26130 (PR #26240) made `os dev` compile before it boots. A
direct `os serve --dev` still composed the door over whatever artifact
was on disk, so an env-derived value differed between the two copies.
Red first on `main` at `81bba6c3` (before #26240) and re-read on this
branch's base `3d50a43b`: `examples/app-showcase`, artifact compiled
with `OS_PORT`/`PORT` unset (all three `baseUrl` values
`http://127.0.0.1:3000`), `OS_PORT=41302`, nothing listening on 3000.
"dispatch" is `POST
/api/v1/automation/showcase_declarative_connector_ping/trigger`.
| boot | `/meta/connector/showcase_status_api` →
`providerConfig.baseUrl` before | after | dispatch |
|---|---|---|---|
| `os serve objectstack.config.ts --dev -p 41302` |
`http://127.0.0.1:3000` | `http://127.0.0.1:41302` | 200, `status: ok`
(reached 41302) both |
| `os serve objectstack.config.ts -p 41302` (production) |
`http://127.0.0.1:41302` | `http://127.0.0.1:41302`, artifact md5
unchanged | 200 both |
| `os dev --no-compile --no-watch -p 41302` | `http://127.0.0.1:3000` |
`http://127.0.0.1:3000` (unchanged, the operator's shortcut) | 200 |
| `os dev --no-watch -p 41302` | (`:41302` since #26240) |
`http://127.0.0.1:41302` | 200 |
| `os serve --dev` with `OS_ARTIFACT_URL=file://…` (pinned) | boots the
pinned artifact | same, no compile line, pinned file md5 unchanged | |
## The fix
Route (b), the one #26240 took: the dev boot compiles the config into
the artifact it is about to serve, in its own environment, so both
copies are one evaluation's answer. Nothing restates which variables a
config reads or in what order.
- `packages/cli/src/utils/dev-compile-at-boot.ts` (new):
`devCompilesAtBoot`, moved verbatim from `commands/dev.ts` so both doors
read the one decision (`dev.ts` imports `serve.ts`, so `serve.ts` cannot
import `dev.ts`). `dev.ts` now imports it; the decision and its `os dev`
behaviour are unchanged. The `#26130` pin's import moves with it.
- `packages/cli/src/commands/serve.ts`: in the dev artifact door's
existing-artifact branch, before the door is constructed, a boot with no
supervising `os dev` (its channel `OS_INTERNAL_ARTIFACT_PATH` unset)
asks `devCompilesAtBoot` and compiles. Under `os dev` the child keeps
its parent's decision, so `os dev --no-compile` still serves the
artifact as built and a default `os dev` does not compile twice. A boot
with no artifact on disk never reaches this branch: no door composes,
the wrap is the one copy, and nothing is compiled (so test fixtures and
fresh checkouts without `dist/` are untouched). A failed compile refuses
the boot with the compile's own output, as under `os dev`. Production
boots never reach the branch (it is inside the `isDev` door block).
- `compileForDevBoot` (same util) spawns `os compile CONFIG --output
ARTIFACT` with the serving process's environment, including the `.env`
files serve loaded, but with `NODE_ENV` put back to its launch value.
`serve --dev` sets `NODE_ENV=development` on itself; if the child
inherited that, it would run under oclif's source loader, which
`child-env-source-loader.pin.test.ts` forbids. The child therefore sees
what `os dev`'s compile child sees.
- Cost: one compile per direct dev boot over an existing artifact. On
the showcase, ready went from 5 s to 8 s.
## Tests
- New
`packages/cli/test/serve-dev-connector-env-parity.integration.test.ts`
(integration tier, built entry, `-p 0`). It uses the #26130 fixture,
copied so neither file's legs move the other's (#26268 is reworking that
file for the port flag). The fixture has one provider-bound connector
whose `baseUrl` is built from `OS_PORT`, a provider factory that records
the materialized `providerConfig`, and a `:3000` artifact rewritten
before each boot. Three legs:
- `os serve --dev`: the served `baseUrl` equals the materialized one and
is not the build-time one.
- `os dev --no-compile`: the served one is still `:3000` and the
artifact's bytes are untouched.
- Production `os serve`: the materialized one is not `:3000` and the
artifact's bytes are untouched.
The verdicts compare the two copies, never a port number, so the file
holds whether or not #26268 has landed. Three runs: `Tests 3 passed (3)`
at 13.6 s, 13.9 s and 13.2 s. The header declares `test-budget: 20`,
from the slowest run x 1.25.
- `dev-connector-env-parity.integration.test.ts` (#26130's file) is
unchanged and green at head. Together with the new file: `Test Files 2
passed (2)`, `Tests 5 passed (5)`.
- Ablation, run once per behaviour through
`scripts/ablation-replace.mjs`. Each leg rebuilt the CLI, and
`ablation-dist-preflight` found the marker in
`packages/cli/dist/commands/serve.js` before the run:
- A: the compile condition was short-circuited to false. Only the `serve
--dev` leg went red, with `expected 'http://127.0.0.1:3000' to be
'http://127.0.0.1:41302'`.
- B: the supervised guard was dropped. Only the `--no-compile` leg went
red, with `expected 'http://127.0.0.1:41302' to be
'http://127.0.0.1:3000'`.
- Both restored with the blob equal to HEAD and `git diff HEAD` empty.
After a rebuild, `preflight --absent` passed for both markers.
- `pnpm --filter @objectstack/cli exec vitest run --project unit` at
`ca2e4216`: `Test Files 334 passed (334)`, `Tests 4878 passed (4878)`.
The later commits change one refusal string and one test header.
- `pnpm --filter @objectstack/cli exec vitest run --project integration`
at `378de620` (the first head; the later diff moves the compile spawn
into the util and splits the pin out): `Test Files 173 passed | 1
skipped (174)`, `Tests 1477 passed | 9 skipped`. This tier was run
because the diff touches the serve boot path, and every direct-dev
fixture that has a `dist/` now compiles at boot.
- `pnpm --filter @objectstack/cli typecheck`: exit 0 at head.
## Gates
Local subset at head `6f7edd28c`: `node scripts/pm/dispatch-gates.mjs
--commands` derived 91 families, and each was run with its exit code
captured before any pipe. `--ran` reconciliation: `91 run, 0
NOT-MEASURED`, all exit 0.
- First sweep, at `ca2e4216`:
- `pnpm check:doc-authoring` went red on a real finding: the compile
refusal's runtime text carried the tracker id. It was stripped
(`751f30aa`) and the gate is green.
- `check-plugin-teardown-shape --self-test` exited 3 on the shallow
clone. After `git fetch origin 621a487` it exited 0 (48 cases).
- `check:dual-build-cjs-loads` exited 3 there, with its prerequisite not
met. It exited 0 on the final sweep.
- `pnpm check:cli-test-child-env`: green with the new census entry, and
its self-test passed 152 cases. The first attempt was refused because
the leg env's spread came after `NODE_ENV`; `NODE_ENV: undefined` now
comes last.
- `eslint --no-inline-config` on the six touched source and test files:
exit 0. `node scripts/check-nul-bytes.mjs`: exit 0.
- CI check-runs: in progress at PR open. The seat reads convergence.
## Acceptance notes
- Open overlap re-measured before opening: #26268 (the `-p` port flag;
it touches `dev.ts`, `serve.ts` and #26130's test file), #26244 and
#26215 (`serve.ts`, other regions). A trial merge of #26268 into this
head is clean. On the merged tree with the CLI rebuilt, both parity
files answer `Tests 6 passed (6)`; there `-p 0` makes the config read
`:0`, and the relative verdicts still hold. Whichever of the two lands
second merges `main`.
- Outside the claim's file surface: none. Docs untouched: no flag or
default changed. The `os serve --dev` bullet in
`content/docs/deployment/cli.mdx` says nothing about the artifact, so it
is not false.
- A non-host config (no plugin instances) on `os serve --dev` never
reaches this door: its standalone stack serves metadata and dispatch
from the same artifact bundle, so the two copies already agree, both at
the build-time value. That is the same posture as `os start --artifact`.
It was observed only, not measured on a fixture, and is not this card.
- `NODE_ENV=development os serve` (no `--dev`) is a dev boot too
(`isDevelopmentBoot`), composes the same door, and so compiles the same
way. `os start` with `NODE_ENV=development` is supervised and does not.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_019rDzaJmEJAYLUNJ4kwG2vN
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6ea429d commit 6294157
7 files changed
Lines changed: 536 additions & 44 deletions
File tree
- .changeset
- packages/cli
- src
- commands
- utils
- test
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | 250 | | |
292 | 251 | | |
293 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
2174 | 2175 | | |
2175 | 2176 | | |
2176 | 2177 | | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
2177 | 2181 | | |
2178 | 2182 | | |
2179 | 2183 | | |
| |||
3512 | 3516 | | |
3513 | 3517 | | |
3514 | 3518 | | |
| 3519 | + | |
| 3520 | + | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
| 3528 | + | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
3515 | 3554 | | |
3516 | 3555 | | |
3517 | 3556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
0 commit comments