Repository navigation
test(cli): production-posture spawns take a kernel-assigned port; a pin holds every bin/run.js spawner to it - #24337
Conversation
) reservePort()/randomPort() release the port before the spawn binds it; a production-posture child (bin/run.js, no --dev, NODE_ENV not development) refuses to auto-shift, so a port taken inside that gap was a red -- the hourly full run went red on start-mcp-stdio-early-initialize that way. Add KERNEL_ASSIGNED_PORT ('0') and readKernelAssignedPort() to the shared harness and move every production-posture spawn site onto them; ports a test must know before the spawn and that the child must not bind are held with holdPort() for the whole boot. The reservePort()/randomPort() docblocks now say which columns may still draw. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
A vitest pin under packages/cli/test reads every source there with the TypeScript AST: a file whose code names the built entry (bin/run.js, the only entry that can produce a production-posture child) may call reservePort()/randomPort() only as often as its OUTSIDE_THE_PRODUCTION_COLUMN ledger entry allows -- zero without one. The ledger holds the four files that spawn the built entry in development posture only, each with its reason. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
…serveport-production-spawn
…ocblocks (#24295) Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
…#24295) check:cli-test-child-env rule 3 resolves a built-entry child's NODE_ENV through one same-file hop; splitting the boot into a second function made every leg of serve-node-env-production-default unreadable to it. The held ports are released on both the boot-failure and the probe path instead. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckNothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs. What this run could not see
Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): |
席位核对 — REWORK (patch round 1)
Accepted as it stands:
Owed in this PR: the pin's population misses a spelling of the production entry that the tree already uses.
Settled, no action:
Generated by Claude Code |
…ments (#24295) The census admitted a file only when a code string ended with bin/run.js, so join(PACKAGE_ROOT, 'bin', 'run.js') -- the spelling published-entry-stderr-error-listener.test.ts uses -- left that file outside the pin's population, where a production spawn on a released port would not have turned the pin red. A call's string-literal arguments are now also read as path segments in order; a directory held in a variable is named as still unseen. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
席位核对ACCEPT ·
Generated by Claude Code |
Fixes #24295
Clause-②: no
Basis for the Clause-② line: every changed file is under
packages/cli/test/**, the CLI's test harness.@objectstack/clipublishesdist,README.mdandCHANGELOG.md(itsfiles[]). Measured after the build: the new symbols (KERNEL_ASSIGNED_PORT,readKernelAssignedPort,OUTSIDE_THE_PRODUCTION_COLUMN) occur in 0 of those files. The positive controlchildPortEnv, which comes fromsrc/, occurs in 2. Nothing published moves, so this PR carries theskip-changesetlabel and no changeset. This repo refuses a new empty-frontmatter changeset (scripts/check-empty-changeset.mjs, rule 1), so an empty changeset was not an option.What changed
test/helpers/serve-process.ts):KERNEL_ASSIGNED_PORT('0') andreadKernelAssignedPort(output, what).--port 0. Its own kernel picks the port when it binds, so no released number sits in a gap.readKernelAssignedPortreturns anErrorfor three cases: no banner, an unreadableAPI:row, orlocalhost:0announced.holdPort()held for the whole boot, so the child never binds it.test/released-port-production-spawn.pin.test.ts. It is a unit-tier vitest test, not a gate script or CI step..tsfile underpackages/cli/testwith the TypeScript AST.bin/run.jsmay callreservePort()/randomPort()only as often as itsOUTSIDE_THE_PRODUCTION_COLUMNentry allows. With no entry, the allowance is zero.resolve(HERE, '../bin/run.js'). The other is the entry spelled as path segments inside one call:join(PACKAGE_ROOT, 'bin', 'run.js'). For the second, the call's string-literal arguments are split on/and read in order, and the entry's segments must all appear among them, in that order.bin/run.jsis the only entry that can produce a production-posture child:bin/run-dev.jssetsNODE_ENV=developmentunconditionally before argv is parsed.bin/run.jsfiles whose every spawn is development posture, each with its reason and its exact draw count.reservePort()/randomPort()docblocks no longer say the race is unclosed. They now say it is closed for the production column, and they name the two uses that may still draw: the development column and instruments.portContentionError()now says it is not for a kernel-assigned child. Converted sites stopped calling it, because its "host race, not a verdict" message would hide a real defect there.boundPortFromBanner()'s docblock now points at the pin.Measured before choosing the mechanism
Built CLI, worktree on
83048c686. The harness held a port with a live listener for the HELD legs.bin/run.js serve -p HELD(production)Port 40349 is already in usebin/run.js serve -p 0(production)API:port 34647,GET /api/v1/healthon it: 200bin/run.js serve,OS_PORT=0bin/run.js serve,PORT=0bin/run.js start -p HELD(production)Port 40349 is already in usebin/run.js start -p 0(production)bin/run.js serve -p 0 --devbin/run.js serve -p HELD --devrun-dev.js serve -p HELD(therunServe()shape)run-dev.js start -p HELD(thepackage-install-local-*shape)M9 and M10 confirm that every tsx child is in the development column, including an
os startwhoseservechild inheritsNODE_ENV=development.The enumeration — all 46 test files that draw from the helper (on
83048c686)start-mcp-stdio-early-initialize.integrationos start) + a--devminting bootKERNEL_ASSIGNED_PORT; the mint reads its port back for HTTPstart-stdio-stdout-purity.integrationos start) + a--devminting bootKERNEL_ASSIGNED_PORTserve-mcp-stdio-early-initialize.integrationserve+ a--devminting bootKERNEL_ASSIGNED_PORTdev-standalone-self-heal.integrationserveleg + twoos devlegs through one boot helperKERNEL_ASSIGNED_PORTserve-datasource-mapping-before-sync.integrationserveKERNEL_ASSIGNED_PORTserve-no-storage-boot-guard.integrationserve(and a--devcontrol through the same boot)KERNEL_ASSIGNED_PORTserve-ready-degraded-boot.e2eserveKERNEL_ASSIGNED_PORTserve-node-env-production-default.e2eserve(unset andtestlegs; thedevelopmentleg shares the boot)baseUrland the probed Origin are two ports this file holds; the server takesKERNEL_ASSIGNED_PORTand is read backstart-port-banner-agreement.e2eos start, legs 1–2OS_PORT(it must lose) and passes--port 0(it must win); leg 2 exportsOS_PORT=0. Both compare the bound port withserve's built-in default 3000, and leg 1 also with the held port. Leg 3 already usedholdPort()dev-boot-output-order.integrationos devunder a pty) viabin/run.jsserve-mcp-capability-collision.e2eserve --dev) viabin/run.jsserve-mcp-stdio-answers.e2eserve --dev) viabin/run.jsserve-stdio-stdout-purity.e2eserve --dev) viabin/run.jsartifact-flag-precedence.integration,package-install-local-{boot-steps,handlers,hooks,jobs,jobs-pull,jobs-shared-name,uninstall-cleanups}.integration,package-restart-acceptance.integration,serve-app-anchored-optional-import.e2e,serve-app-runtime-hooks.e2e,serve-boot-diagnostics-noise-budget.e2e,serve-boot-diagnostics.e2e,serve-cluster-driver-diagnosis.e2e,serve-config-boot-flat-docs.integration,serve-config-boot-residual.integration,serve-host-config-metadata-door.integration,serve-migrate-exit-schema-parity.integration,serve-no-artifact.e2e,serve-organization-record-page.e2e,serve-organizations-host-resolution.e2e,serve-organizations-mount-failure.e2e,serve-package-declared-capabilities.test,serve-package-registry-always-on.e2e,serve-port-drift-notice.e2e,serve-port-readback.e2e,serve-process-child-env.e2e,serve-publishes-bound-port.e2e,serve-runtime-assets-branding-warning.e2e,serve-view-container-read.integration,start-signal-forwarding.e2e(31 files)bin/run-dev.jspinsNODE_ENV=development)serve-port-bind-probe.testserve-probe-child-attribution.testreservePort()as a port nothing listens on; spawns a driver script, not the CLIThe PM's read was 29 test files calling
portContentionError(, as the production column. Classified:start-port-banner-agreementnever called it.bin/run.js --dev.Reverse verification and ablation (one-time, not kept)
Each mutation went through
scripts/ablation-replace.mjsin WRAP mode. Every restore ended with blob == HEAD and an emptygit diff HEAD.start-mcp-stdio-early-initialize,[CLI, 'start', '-p', KERNEL_ASSIGNED_PORT, …]was changed torandomPort().Tests 1 failed | 3 passed (4).start-mcp-stdio-early-initialize.integration.test.ts: 1 released-port draw(s) (line 287), ledger allows 0.os startleg was spawned on a port the test holds.AssertionError: initialize was never answered — os start exited 1 before answering — ✗ Port 44877 is already in use.const SCRATCH_PORT = randomPort();added besidepublished-entry-stderr-error-listener.test.ts'sjoin(PACKAGE_ROOT, 'bin', 'run.js'). That file names the entry only in segments.Tests 1 failed | 3 passed (4)—published-entry-stderr-error-listener.test.ts: 1 released-port draw(s) (line 82), ledger allows 0.the built entry spelled in path segments: population: expected false to be true) and the live-tree check (published-entry-stderr-error-listener.test.ts spells bin/run.js in segments but is not in the population).start-port-banner-agreementcan fail. Dropping--port 0givesos start exited 1 before its banner. ✗ Port 38959 is already in use.: the child took the heldOS_PORT. Leg 2's counterpart (unsetOS_PORT⇒ the child binds 3000) was not run, because it would bind 3000 on a container wherePORT=3000is the shared frontend-debug backend.Tests
Patch round 1, on
31f3f6444:released-port-production-spawn.pin4/4published-entry-stderr-error-listener6/6published-entry-stderr-nonblocking.e2e5/5 (nightly tier)The files below are byte-identical between
7c29ce54aand31f3f6444; their readings are from7c29ce54a, and CI'sTest Core1–6/6 passed on that head.Queue tier (
vitest run --maxWorkers=2), 18/18:released-port-production-spawn.pin4/4 (projectunit)start-mcp-stdio-early-initialize1/1start-stdio-stdout-purity1/1serve-mcp-stdio-early-initialize1/1dev-standalone-self-heal4/4serve-datasource-mapping-before-sync2/2serve-no-storage-boot-guard5/5Nightly tier (
OS_TEST_TIERS=nightly), 8/8:serve-node-env-production-default3/3. The unset leg answers403 INVALID_ORIGIN, and thedevelopment/testlegs pass the origin, on the same held-port fixture.serve-ready-degraded-boot2/2start-port-banner-agreement3/3Also run on
31f3f6444:pnpm --filter @objectstack/cli typecheck: exit 0. The test layer holds its existing 3-file / 28-error ledger.tsc --listFiles -p tsconfig.test.jsonputs all 11 changed files in the program with 0 errors.pnpm exec eslint --no-inline-configover the 11 changed files: exit 0.Gates (local subset, head
31f3f6444)node scripts/pm/dispatch-gates.mjs --commands(no paths) derives 52 commands from the 11-path change set against merge base1ef0ee89d. Changed lines: 860 (+667 / -193).--ranwith exit codes recorded reports52 derived, 52 run, 0 NOT-MEASURED, 0 UNRUN.pnpm check:cli-test-child-envwas red on an intermediate head. It caught the probe split described in the acceptance notes, fixed in7c29ce54a.pnpm check:dual-build-cjs-loadsrefused withPREREQUISITE NOT MET(exit 3) until the whole repo was built. After the build it reads exit 0.pnpm lintand the full CI farm are CI's, read from this PR's check-runs.The 52 derived commands, all exit 0:
Acceptance notes
os startbound it); 46 test files share the draw #24295's family; cli test harness: reservePort()'s close-to-spawn race reached main — the hourly full run went red on start-mcp-stdio-early-initialize (port 45195 taken beforeos startbound it); 46 test files share the draw #24295 keeps the production column.serve-port-readback.e2e's held-port leg already pins thatrunServe()rejects a drifted boot withPORT DRIFT.os devboots converted here sit inside files that also hold a production spawn, through the same boot code.serve-node-env-production-default's fixturebaseUrlis now a held port, not the server's own port. Its three legs still split 403 / not-403 on one fixture. The probed Origin is now guaranteed distinct from both thebaseUrland the bound port, where it used to beport + 1.check:cli-test-child-envrule 3 resolves a built-entry child'sNODE_ENVthrough exactly one same-file hop. Splitting that probe into a second function made it red. The spawn stays in the function theitblocks call, and a comment there says why.dist/run directly — or with its directory held in a variable before the file name is joined on (join(BIN_DIR, 'run.js'));Generated by Claude Code