Skip to content

test(cli): production-posture spawns take a kernel-assigned port; a pin holds every bin/run.js spawner to it - #24337

Merged
objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/issue-24295-reserveport-production-spawn
Oct 18, 2026
Merged

objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/issue-24295-reserveport-production-spawn

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24295

Clause-②: no

Basis for the Clause-② line: every changed file is under packages/cli/test/**, the CLI's test harness. @objectstack/cli publishes dist, README.md and CHANGELOG.md (its files[]). Measured after the build: the new symbols (KERNEL_ASSIGNED_PORT, readKernelAssignedPort, OUTSIDE_THE_PRODUCTION_COLUMN) occur in 0 of those files. The positive control childPortEnv, which comes from src/, occurs in 2. Nothing published moves, so this PR carries the skip-changeset label 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

  • The closed mechanism (test/helpers/serve-process.ts): KERNEL_ASSIGNED_PORT ('0') and readKernelAssignedPort(output, what).
    • A production-posture spawn passes --port 0. Its own kernel picks the port when it binds, so no released number sits in a gap.
    • The test reads the bound port back from the banner tail.
    • readKernelAssignedPort returns an Error for three cases: no banner, an unreadable API: row, or localhost:0 announced.
  • Every production-posture spawn site now uses that mechanism (9 files). Two sites needed a number before the spawn (A3). For them, the number the test needs is a holdPort() held for the whole boot, so the child never binds it.
  • The enumeration pin, test/released-port-production-spawn.pin.test.ts. It is a unit-tier vitest test, not a gate script or CI step.
    • It reads every .ts file under packages/cli/test with the TypeScript AST.
    • A file whose code names the built entry bin/run.js may call reservePort()/randomPort() only as often as its OUTSIDE_THE_PRODUCTION_COLUMN entry allows. With no entry, the allowance is zero.
    • "Names" covers both spellings this directory uses (patch round 1). One is a string that ends with the entry: 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.js is the only entry that can produce a production-posture child: bin/run-dev.js sets NODE_ENV=development unconditionally before argv is parsed.
    • The ledger holds the four bin/run.js files whose every spawn is development posture, each with its reason and its exact draw count.
  • Docblocks. The 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.
    • The stale "the ONLY file in the loud row" count in 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.

leg spawn result
M1 bin/run.js serve -p HELD (production) exit 1, Port 40349 is already in use
M2 bin/run.js serve -p 0 (production) banner API: port 34647, GET /api/v1/health on it: 200
M3 bin/run.js serve, OS_PORT=0 banner port 43365, health 200
M4 bin/run.js serve, PORT=0 banner port 35705, health 200
M5 bin/run.js start -p HELD (production) exit 1, Port 40349 is already in use
M6 bin/run.js start -p 0 (production) banner port 33721, health 200
M7 bin/run.js serve -p 0 --dev banner port 42681, health 200
M8 bin/run.js serve -p HELD --dev green boot on 40350 (drift)
M9 tsx run-dev.js serve -p HELD (the runServe() shape) green boot on HELD+1 (drift)
M10 tsx run-dev.js start -p HELD (the package-install-local-* shape) green boot on HELD+1 (drift)

M9 and M10 confirm that every tsx child is in the development column, including an os start whose serve child inherits NODE_ENV=development.

The enumeration — all 46 test files that draw from the helper (on 83048c686)

file column mechanism, or why it still draws
start-mcp-stdio-early-initialize.integration production (os start) + a --dev minting boot both on KERNEL_ASSIGNED_PORT; the mint reads its port back for HTTP
start-stdio-stdout-purity.integration production (os start) + a --dev minting boot both on KERNEL_ASSIGNED_PORT
serve-mcp-stdio-early-initialize.integration production serve + a --dev minting boot both on KERNEL_ASSIGNED_PORT
dev-standalone-self-heal.integration production serve leg + two os dev legs through one boot helper all three on KERNEL_ASSIGNED_PORT
serve-datasource-mapping-before-sync.integration production serve KERNEL_ASSIGNED_PORT
serve-no-storage-boot-guard.integration production serve (and a --dev control through the same boot) KERNEL_ASSIGNED_PORT
serve-ready-degraded-boot.e2e production serve KERNEL_ASSIGNED_PORT
serve-node-env-production-default.e2e production serve (unset and test legs; the development leg shares the boot) A3: the fixture's baseUrl and the probed Origin are two ports this file holds; the server takes KERNEL_ASSIGNED_PORT and is read back
start-port-banner-agreement.e2e production os start, legs 1–2 A3: leg 1 holds the exported OS_PORT (it must lose) and passes --port 0 (it must win); leg 2 exports OS_PORT=0. Both compare the bound port with serve's built-in default 3000, and leg 1 also with the held port. Leg 3 already used holdPort()
dev-boot-output-order.integration development (os dev under a pty) via bin/run.js ledger: reads no port, so a lost race is an unobserved auto-shift
serve-mcp-capability-collision.e2e development (serve --dev) via bin/run.js ledger: a lost race drifts, and the file's own drift check reds it
serve-mcp-stdio-answers.e2e development (serve --dev) via bin/run.js ledger: same
serve-stdio-stdout-purity.e2e development (serve --dev) via bin/run.js ledger: same
artifact-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) development: tsx entry (bin/run-dev.js pins NODE_ENV=development) not converted, outside this card's column and outside the pin's population. See the acceptance notes
serve-port-bind-probe.test instrument: measures the draw itself, spawns no CLI draws by design
serve-probe-child-attribution.test instrument: reservePort() as a port nothing listens on; spawns a driver script, not the CLI draws by design

The PM's read was 29 test files calling portContentionError(, as the production column. Classified:

  • 8 are production posture: the first 8 rows. start-port-banner-agreement never called it.
  • 3 spawn bin/run.js --dev.
  • 17 spawn a tsx (development) child, where a lost race drifts instead of exiting.
  • 1 is the bind-probe instrument.

Reverse verification and ablation (one-time, not kept)

Each mutation went through scripts/ablation-replace.mjs in WRAP mode. Every restore ended with blob == HEAD and an empty git diff HEAD.

  • The pin turns red on a reverted site. In start-mcp-stdio-early-initialize, [CLI, 'start', '-p', KERNEL_ASSIGNED_PORT, …] was changed to randomPort().
    • Result: Tests 1 failed | 3 passed (4).
    • The failure names the site: start-mcp-stdio-early-initialize.integration.test.ts: 1 released-port draw(s) (line 287), ledger allows 0.
  • The lost race, forced (A5), reproduces the hourly-run red deterministically. The same os start leg was spawned on a port the test holds.
    • Result: AssertionError: initialize was never answered — os start exited 1 before answering — ✗ Port 44877 is already in use.
    • That is the shape the hourly run recorded on port 45195.
    • On the converted site the child is handed no number, so this hostile condition has nothing to act on. The converted file passes (see Tests).
  • Patch round 1 — the pin sees the segment spelling.
    • Mutation: a scratch const SCRATCH_PORT = randomPort(); added beside published-entry-stderr-error-listener.test.ts's join(PACKAGE_ROOT, 'bin', 'run.js'). That file names the entry only in segments.
    • Result: Tests 1 failed | 3 passed (4) — published-entry-stderr-error-listener.test.ts: 1 released-port draw(s) (line 82), ledger allows 0.
    • The first attempt was a no-op: its replacement still contained the anchor text, so the tool refused before running anything. The anchor was changed and the run repeated.
    • Removing the segment reading turns two of the pin's own checks red: the fixture battery (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).
  • The leg-1 assertion of start-port-banner-agreement can fail. Dropping --port 0 gives os start exited 1 before its banner. ✗ Port 38959 is already in use.: the child took the held OS_PORT. Leg 2's counterpart (unset OS_PORT ⇒ the child binds 3000) was not run, because it would bind 3000 on a container where PORT=3000 is the shared frontend-debug backend.

Tests

Patch round 1, on 31f3f6444:

  • released-port-production-spawn.pin 4/4
  • published-entry-stderr-error-listener 6/6
  • published-entry-stderr-nonblocking.e2e 5/5 (nightly tier)

The files below are byte-identical between 7c29ce54a and 31f3f6444; their readings are from 7c29ce54a, and CI's Test Core 1–6/6 passed on that head.

Queue tier (vitest run --maxWorkers=2), 18/18:

  • released-port-production-spawn.pin 4/4 (project unit)
  • start-mcp-stdio-early-initialize 1/1
  • start-stdio-stdout-purity 1/1
  • serve-mcp-stdio-early-initialize 1/1
  • dev-standalone-self-heal 4/4
  • serve-datasource-mapping-before-sync 2/2
  • serve-no-storage-boot-guard 5/5

Nightly tier (OS_TEST_TIERS=nightly), 8/8:

  • serve-node-env-production-default 3/3. The unset leg answers 403 INVALID_ORIGIN, and the development/test legs pass the origin, on the same held-port fixture.
  • serve-ready-degraded-boot 2/2
  • start-port-banner-agreement 3/3

Also 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.json puts all 11 changed files in the program with 0 errors.
  • pnpm exec eslint --no-inline-config over the 11 changed files: exit 0.

Gates (local subset, head 31f3f6444)

  • Derived list. node scripts/pm/dispatch-gates.mjs --commands (no paths) derives 52 commands from the 11-path change set against merge base 1ef0ee89d. Changed lines: 860 (+667 / -193).
  • Every command exited 0. Each exit code was captured before any pipe.
  • Reconciled. --ran with exit codes recorded reports 52 derived, 52 run, 0 NOT-MEASURED, 0 UNRUN.
  • Two reds on the first pass, both resolved (the original round; the round-1 run had none):
    • pnpm check:cli-test-child-env was red on an intermediate head. It caught the probe split described in the acceptance notes, fixed in 7c29ce54a.
    • pnpm check:dual-build-cjs-loads refused with PREREQUISITE NOT MET (exit 3) until the whole repo was built. After the build it reads exit 0.
  • The repo-wide pnpm lint and the full CI farm are CI's, read from this PR's check-runs.

The 52 derived commands, all exit 0:

node scripts/check-ci-filter-parity.mjs
node scripts/check-closing-keyword-parity.mjs
node scripts/check-closing-keyword-parity.mjs --self-test
node scripts/check-comment-mask-adoption.mjs
node scripts/check-comment-mask-adoption.mjs --self-test
node scripts/check-comment-mask-corpus.mjs
node scripts/check-dts-emitted.mjs --self-test
node scripts/check-issue-citations.mjs
node scripts/check-keyed-text-bounds.mjs
node scripts/check-keyed-text-bounds.mjs --self-test
node scripts/check-platform-object-tenancy-census.mjs
node scripts/check-platform-object-tenancy-census.mjs --self-test
node scripts/check-plugin-teardown-shape.mjs
node scripts/check-plugin-teardown-shape.mjs --self-test
node scripts/check-position-name-fold-loaders.mjs
node scripts/check-position-name-fold-loaders.mjs --self-test
node scripts/check-registry-log-declared.mjs
node scripts/check-registry-log-declared.mjs --self-test
node scripts/check-rest-log-spy-declared.mjs
node scripts/check-rest-log-spy-declared.mjs --self-test
node scripts/check-system-context-census.mjs
node scripts/check-system-context-census.mjs --self-test
node scripts/check-undeclared-dep-imports.mjs
node scripts/check-undeclared-dep-imports.mjs --self-test
node scripts/docs-audit/check-affected-docs.mjs
node scripts/docs-audit/check-drift-comment.mjs
pnpm check:cli-test-child-env
pnpm check:cross-package-test-inputs
pnpm check:doc-authoring
pnpm check:driver-memory-census
pnpm check:dts-closure
pnpm check:dual-build-cjs-loads
pnpm check:engine-double-contract
pnpm check:gitlink-declared
pnpm check:issue-citations
pnpm check:lean-entry-closure
pnpm check:logger-receiver-detach
pnpm check:nul-bytes
pnpm check:objectql-double-limit
pnpm check:org-identifier
pnpm check:page-declaration-shape
pnpm check:published-files
pnpm check:query-options-erasure
pnpm check:refd-timer-probe
pnpm check:slot-lookup
pnpm check:sourcemap-no-sources-content
pnpm check:test-source-alias
pnpm check:tier-file-adoption
pnpm check:type-check-coverage
pnpm check:type-check-debt
pnpm check:watch-hint-literal
pnpm check:where-matcher

Acceptance notes


Generated by Claude Code

)

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>
…#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>
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing 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): node scripts/docs-audit/affected-docs.mjs --json 51ad8e4fba87d730688a822849c107c9358c7cf0 → packageMentionDocs.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

席位核对 — REWORK (patch round 1)

domain:cli seat 1 (seat post #6024) · zhuangjianguo · session session_01SYEJqDL3NXxrJRBVqaMu9T · 2026-10-18T13:57Z · on head 7c29ce54a · #24295 (claim 6249651480, report 6250714154). This is the seat's own review at the default tier (Clause-②: no, test harness only, not governed), read against GitHub, not the report.

Accepted as it stands:

  • The production column is the 9 files that spawn bin/run.js without --dev. Each now spawns on KERNEL_ASSIGNED_PORT and reads the bound port back with readKernelAssignedPort().
  • The two sites that need the number before the spawn (serve-node-env-production-default, start-port-banner-agreement) hold it with holdPort() for the whole boot.
  • The reservePort() / randomPort() docblocks no longer call the race unclosed for production.
  • The A5 ablation reproduced the hourly red deterministically: Port 44877 is already in use.
  • The widening into the development spawns of the same files is declared.
  • skip-changeset is the repo's route for a test-only PR.
  • Re-read here: artifact-flag-precedence.integration.test.ts and serve-organizations-host-resolution.e2e.test.ts draw, but spawn the tsx entry (TSX + CLI, runServe), so they are in the development column.

Owed in this PR: the pin's population misses a spelling of the production entry that the tree already uses.

  • The census admits a file when some string in its code ends with bin/run.js.
  • Two files reach the same entry through path segments: published-entry-stderr-error-listener.test.ts:82 and published-entry-stderr-nonblocking.e2e.test.ts:66 both write const RUN_JS = join(PACKAGE_ROOT, 'bin', 'run.js').
  • Neither draws a port today. A production spawn on a released port added to either would not turn the pin red, so the card's second Done-when ("the pin turns red when a production-mode spawn draws a released port") is not held for them.
  • Ask: the census also admits a file whose code builds the entry from segments, at least a 'run.js' string literal preceded by 'bin' in the same call's arguments. Prove it with the one-time ablation: a scratch released draw in one of the two files turns the pin red, then is restored.
  • The docblock's "does not see" item 2 then names only the other spellings (a packed tarball's bin, dist/ run directly).

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>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

席位核对

ACCEPT · domain:cli seat 1 (seat post #6024) · zhuangjianguo · session session_01SYEJqDL3NXxrJRBVqaMu9T · 2026-10-18T14:36Z · on head 31f3f6444 · #24295 (claim 6249651480, reports 6250714154 and round 1's on the card). This is the seat's own review at the default tier (Clause-②: no, test harness only), read against GitHub, not the report.

  1. Shape: draft against main. The first line is Fixes #24295, with no other closing keyword, and Clause-②: no is line-initial and bare. Assignee zhuangjianguo. 11 files, +667 / −193. skip-changeset: packages/cli/test/** ships in no package's files[]. Not governed, under 3,000.
  2. Premise, measured: the hourly red was reproduced deterministically: a held port gave os start "Port 44877 is already in use" and "initialize was never answered". --port 0 on the built CLI binds a non-zero, published port for serve, start, serve --dev, OS_PORT=0 and PORT=0, and /api/v1/health answers 200 on it.
  3. The closure:
    • The production column is the 9 files that spawn bin/run.js without --dev. They spawn on KERNEL_ASSIGNED_PORT and read the bound port back with readKernelAssignedPort().
    • The two sites that need the number before the spawn hold it with holdPort() for the whole boot.
    • The reservePort() / randomPort() docblocks now say what may still draw.
  4. The pin (round 1, 6250765412, read on the diff 7c29ce54a..31f3f6444, one file):
    • The census admits a file that spells the entry in one string, or in one call's string-literal arguments read as ordered path segments (join(PACKAGE_ROOT, 'bin', 'run.js')).
    • Fixtures show the source entry's segments and segments split across two calls are not admitted. Live controls show both published-entry-* files are in the population.
    • Ablations: a scratch released draw in published-entry-stderr-error-listener.test.ts gives "1 released-port draw(s) (line 82), ledger allows 0". Deleting the segment reading reds 2 cases.
    • The four ledger entries carry their reasons and exact draw counts.
  5. Gates: 52 derived commands exit 0, with 0 NOT-MEASURED, and eslint exits 0. CI on 7c29ce54a completed with no failure, Test Core 1–6 included. CI on this head is running at this stamp. ⛔ Not ready until every check on the head is green.
  6. Deviations accepted:
    • the segment reading is a superset of the review's floor, and it over-approximates only toward a red;
    • the docblock names a third unseen spelling (a directory held in a variable);
    • the declared development spawns in the same files;
    • one main merge in round 0.
  7. Out of scope: the development column (31 tsx files and the 4 ledgered files) is filed as cli test harness: the development column still draws a released port — a lost race drifts the child and portDriftError() reds a correct tree (35 files; #24295 closed the production column) #24342; the PR's Acceptance notes point to it.
  8. Landing: ready plus auto-merge through the queue once every check on the current head is success or a roster skip. 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 before os start bound it); 46 test files share the draw #24295 closes on Fixes.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

2 participants