Skip to content

fix(cli): os start leaves no process of its group behind on SIGTERM - #34518

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-f16pke
Nov 17, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-f16pke

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Fixes #34337

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么: objectstack start 收到 SIGTERM 退出时,它的进程组里不再残留进程。serve 载入 objectstack.config.ts 后立即关掉打包器 esbuild 的常驻服务进程。
  • 为什么改: 这个 esbuild 服务进程要等 serve 退出后才走,所以 start 退出那一刻它还在。容器运行时、systemd、多副本演练这类监管者读到「已停」时,组里其实还有进程。
  • 风险与回滚: 低。只在 serve 用配置文件启动时,于启动阶段多一次 esbuild stop();之后再有 esbuild 调用会自动重开服务。回滚即撤本 PR。
  • 先看: packages/cli/src/utils/config.ts(stopConfigBundler 与原因)、packages/cli/src/commands/serve.ts(唯一调用点)、packages/cli/test/start-sigterm-process-group.integration.test.ts;scripts/check-cli-test-child-env.mjs 的名单因新测试加一项(21→22)。
  • 两分钟验证: pnpm --filter @objectstack/cli build && cd packages/cli && npx vitest run --project integration test/start-sigterm-process-group.integration.test.ts,预期 1 passed。
  • 需要你做的: 无,席位落地。

What changes

os start already forwards SIGTERM to its serve child and exits with the child's code once the child has exited (ServeRestartCoordinator, #21114). The process the card's drill found alive is the child of serve, not serve itself.

On a config project, serve bundles objectstack.config.ts through bundle-require, which runs esbuild's async API. esbuild serves that API from a long-lived esbuild --service child process, and that child leaves only when it reads end-of-file on its stdin, a moment after its parent has exited. So when start exited, the bundler service was still in its process group.

serve now calls esbuild's stop() right after the config module loads (stopConfigBundler in utils/config.ts, one call site in commands/serve.ts). The service exits at boot while serve is alive to reap it, so the group a SIGTERM later finds is start and serve only. Boots with --artifact/--artifact-fallback or --prebuilt never start the bundler and skip the call. bundle-require takes esbuild as a peer dependency, so it runs the copy this package declares, which is the instance stopped.

The premise was re-measured on origin/main e8cba8f before the change (built entry, SIGTERM to the start pid alone):

Shape start exit group members alive at the exit 2 s later
config project, before code 0 at +66 ms 1: [esbuild] (child of serve, reparented) 0
config project, after (3 runs) code 0 at +84 / +62 / +74 ms 0 0
--artifact project, before code 0 at +62 ms 0 0

Tests

  • New packages/cli/test/start-sigterm-process-group.integration.test.ts (integration tier: spawns the built bin/run.js). It boots start on a defineStack config project in its own process group, checks that the probe sees start and serve in the group (positive control), sends SIGTERM to the start pid alone, and reads kill(-pgid, 0) in the exit handler: it must answer ESRCH, and the exit code must be 0 (the child's).
  • Ablation: with the stopConfigBundler() call removed and the CLI rebuilt (grep -c stopConfigBundler dist/commands/serve.js = 0), the pin is red: expected [ '8309 8270 [esbuild] <defunct>' ] to deeply equal [] and kill(-pgid, 0) still found a member of the start process group at its exit. Restored and rebuilt: 1 passed.
  • The source entry (bin/run-dev.js under tsx) is not used by the pin: tsx's own esbuild service is a child of the start parent there and would be read as this defect.

No existing test was changed. One gate's census changed with it: scripts/check-cli-test-child-env.mjs pins the exact set of test files that spawn the built entrypoint, and the new pin joins that set (twenty-one files become twenty-two), with an entry saying why it spawns the built entry. The gate's self-test and scan both pass at the head.

Acceptance notes

  • Card item 3 (document the behaviour if intended) does not apply: the behaviour was not intended and is fixed.

Verification

Gate readings are in the os-dev report on the card.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp

On a config project, `serve` bundles objectstack.config.ts with esbuild,
whose async API runs in a long-lived `esbuild --service` child that leaves
only after its caller has exited. When `start` exited on SIGTERM (after its
serve child, with its code), that service was still in start's process
group. `serve` now stops the bundler service once the config module has
loaded, so the service exits while `serve` can still reap it.

Pinned by test/start-sigterm-process-group.integration.test.ts on the built
entry: kill(-pgid, 0) at start's exit answers ESRCH; with the stop removed
the esbuild service is read in the group and the pin is red.

Claude-Session: https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp
Co-authored-by: Claude <noreply@anthropic.com>
…s-group pin

check-cli-test-child-env pins the exact set of test files that spawn
bin/run.js. The new start-sigterm-process-group pin spawns the built entry
on purpose (the source entry runs under tsx, whose own esbuild service would
be read as the defect), so it joins the set with its reason.

Claude-Session: https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

1 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: os serve (command, 50 pages)
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 37 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 0c7869c03c9c6ff3a38bd6b09206edeee0184769 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 1957932ffa4995ea67e2449c0a45440f9455ab56 — the merge of head 0fb55f6ec76cb38958d4128803e81729e815613f into base 0c7869c03c9c6ff3a38bd6b09206edeee0184769, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 1957932ffa4995ea67e2449c0a45440f9455ab56 && git checkout 1957932ffa4995ea67e2449c0a45440f9455ab56
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0c7869c03c9c6ff3a38bd6b09206edeee0184769 0fb55f6ec76cb38958d4128803e81729e815613f && git checkout -B drift-repro 0c7869c03c9c6ff3a38bd6b09206edeee0184769 && git merge --no-ff 0fb55f6ec76cb38958d4128803e81729e815613f

node scripts/docs-audit/affected-docs.mjs --json 0c7869c03c9c6ff3a38bd6b09206edeee0184769

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp

Final head for review: 0fb55f6ec76cb38958d4128803e81729e815613f. Local: all 92 derived gates exit 0 at this head, dispatch-gates --ran 92 run, 0 NOT-MEASURED (os-dev-report 6933008861 on #34337, record /mnt/project-files/objectstack-seat2/34337-gates-ran.txt); the new pin passes on the rebuilt CLI at this head. CI at this head: 51 check runs, 35 success, 16 skipped, 0 failed. Clause-② no, no contract surface; L1 owed (over 50 lines), L2 not owed.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmQVWXw7KT8ThxT4CBy

席位核对

L1 verdict: ACCEPT · PR #34518 · card #34337 · first review · read 2026-11-17T00:14Z

Head-sha: 0fb55f6ec76cb38958d4128803e81729e815613f (the head named in final-head comment 6933458294)

Read from GitHub at this head (get_files, diff, check-runs), not from the report.

Checklist

  • Shape: draft, base main. The body opens with the attribution lines, then Fixes #34337. The card's item 3 (document the behaviour if it was intended) is answered in the body as not applicable, so Fixes is right. No other card number sits next to a closing verb.
  • Scope: 5 files: cli/src/utils/config.ts (stopConfigBundler), cli/src/commands/serve.ts (its one call site), the new integration pin, scripts/check-cli-test-child-env.mjs, and a root changeset. The gate file's change is only the census row its own self-test requires for a new built-entry spawner (21 → 22), with the reason written beside it. No content/docs/releases/.
  • Changeset: root, patch for @objectstack/cli (published). I checked each sentence against the diff:
    • "serve now stops the esbuild service as soon as the config module has loaded, at boot" matches await stopConfigBundler() right after bundleConfigModule resolves.
    • "Boots from --artifact or --prebuilt never started the service and are unchanged" matches the guard !useArtifactFallback && !flags.prebuilt, which mirrors the two branches above it that do not bundle.
    • "forward the signal … and exit with the child's code, as before" holds: start is not touched.
  • Tests: start-sigterm-process-group.integration.test.ts spawns the built bin/run.js detached on a defineStack project. It has a positive control (the probe sees start and serve in the group before the signal), sends SIGTERM to the start pid alone, and asserts kill(-pgid, 0) answers ESRCH in the exit handler, with exit code 0. The recorded ablation (call removed, CLI rebuilt, grep -c = 0 in dist) goes red with the [esbuild] <defunct> row named; restored and rebuilt, it passes. The integration tier is CI-mandatory (packages/cli/vitest.config.ts).
  • Gates: 51 check-runs on this head, all completed: 35 success, 16 skipped, 0 failed. Lint & Repo Gates success, TypeScript Type Check success, Test Core success, Check Changeset success.

Spot checks (mine)

  1. Nothing else in serve uses esbuild after boot: at this head, serve.ts's only esbuild path is the one bundleConfigModule call, and it is awaited before stop(), so no in-flight build is cut. loadConfig is imported but not called there. A later esbuild call in the same process would start a fresh service; stop() does not disable esbuild.
  2. Same instance: bundle-require (^5.1.0) takes esbuild as a peer, and @objectstack/cli declares esbuild ^0.28.2, so the dynamic import('esbuild') resolves the copy the bundler ran. The built-entry pin is the measured proof of that on this workspace.
  3. The premise table in the body was measured on origin/main before the change. The --artifact row is already clean there, which agrees with the guard skipping those boots.

L2 owed: no. None of the four contract faces is touched: Clause-②: no, no narrowing, no packages/spec/src/** path, no governed rule text (scripts/*.mjs is not on the governed register).

Landing tier: check-governed-merges.mjs --pr 34518 reports NOT governed, +260/−2 = 262 lines ≤ 3000. Ordinary queue landing by the area at this head.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp

Landing · Head-sha: 0fb55f6 · ACCEPT → comment 6933488940

Probe Reading
check-governed-merges --pr 34518 NOT governed; +260/−2 = 262 lines ≤ 3000
check-runs at this head 51 runs: 35 success, 16 skipped, 0 failed; K = 7

State: ready for review and auto-merge enabled; #34337 closes with the merge (Fixes).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 17, 2026 00:16
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit d4c0c12 Nov 17, 2026
52 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-f16pke branch November 17, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objectstack start exits on SIGTERM before its serve child stops (measured twice; reopens the premise of #32149)

2 participants