Skip to content

fix(plugin-sdk): API diff fails under load and on macOS temporary checkouts - #164466

Merged
steipete merged 2 commits into
mainfrom
fix/plugin-sdk-api-diff-native-child
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/plugin-sdk-api-diff-native-child

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: pnpm plugin-sdk:api:diff fails with Managed command exited while its process group remained active and produces no report when the host is under heavy load, and on macOS it cannot render any revision at all.

User Impact

Maintainers can run the released Plugin SDK comparison locally (including on macOS) and under load, and a genuine render failure now reports its real compiler diagnostics instead of an orphaned-process error. No product or public API behavior changes.

Why This Change Was Made

There were two defects, and the first was hiding the second.

The orphaned compiler. Native declaration emission runs in a managed subprocess that must leave no process-group member behind when it exits (requireProcessTreeExit, no grace period on POSIX). The TypeScript native API's close() only ends the compiler's stdin and drops its process handle; it never waits for exit. On success that was fine, because Node's event loop keeps running until the ref'd tsgo child exits. On failure, though, the subprocess let the error escape as an uncaught top-level rejection, so Node exited immediately while tsgo was still finishing its stdin-EOF shutdown. The managed runner then saw the live group, SIGKILLed it, and reported the orphan, discarding the real error. A loaded host just widens that race. The subprocess now reports the failure and sets process.exitCode, so the event loop drains and joins the compiler on the failure path exactly as it already did on success. The process-group check stays strict.

The real failure underneath (macOS). With the orphan fixed, every macOS run surfaced thousands of TS6059: File '/var/folders/…/src/plugin-sdk/…' is not under 'rootDir' '/private/var/folders/…'. Since #158674, emission sets rootDir to the realpath of the checkout, but the renderer passed root file names derived from the unresolved repoRoot. The diff renders revisions under os.tmpdir(), which is the /var → /private/var symlink alias on macOS. renderPluginSdkApiBaseline now canonicalizes repoRoot once when rendering starts. The existing tests never caught this because the shared temp-dir helper already canonicalizes os.tmpdir().

Evidence

All runs were on macOS (32 cores) at load averages between 50 and 97, with other agents' renders running concurrently.

  • Live tool, before: pnpm run plugin-sdk:api:diff -- --base v2026.9.8 --head HEAD started both renders, then failed with Managed command exited while its process group remained active and no report, matching the reported failure.
  • Live tool, orphan fix only: the same command now failed with the real error, TS6059 … is not under 'rootDir' for every SDK source, after 259 s.
  • Live tool, both fixes: exit 0 after 1,419 s, with renders taking 861 s and 936 s. It produced a report with 1 entrypoint added, 8 removed, and 2,219 export changes (acknowledgement digest 2dfbd058).
  • New test/scripts/native-declaration-subprocess.test.ts: a deterministic delay hook (a preload wraps the spawned tsc so its process exits 500 ms after the real compiler, as a loaded host can impose) drives a real declaration failure (TS4094) through emitNativeDeclarationsInSubprocess. Before the fix it fails with the orphan error; after the fix it passes 3/3 and asserts the compiler process exited before the subprocess settled. It is skipped on Windows, which has no managed tree join for this subprocess. pnpm test test/scripts/native-declaration-subprocess.test.ts --maxWorkers=1: 1 test, 2.3–4.0 s wall (about 1.4 s in the test).
  • New case in src/plugin-sdk/api-baseline.test.ts (renders a fixture through a symlinked alias): before the fix it fails with the same TS6059; after the fix it passes, taking 2.6 s.
  • Affected files in full: src/plugin-sdk/api-baseline.test.ts 30/30 (80 s under load, mostly existing renders); test/scripts/native-declaration-boundary.test.ts 15 passed, 3 platform-skipped.
  • node scripts/check-changed.mjs --base <branch point>: passed, all 50 lanes (typecheck core/tests/extensions/scripts/test root, lint, dead-export scan, ratchets and guards), in 1,347 s. An earlier attempt stopped in extension typecheck on an unrelated qa-lab import because the gateway worktree profile does not link that package's workspace dependencies; running the full profile's pnpm install --frozen-lockfile fixed the environment, with no code change.
  • Independent Codex review of the diff (P0–P2): no actionable findings.

Stored Data

None. The V8-serialized result.bin in the native declaration subprocess is a per-call hand-off file in a private mkdtemp directory: the same build writes and reads it, then deletes it. This PR does not change its format, and nothing persists across versions, so no migration or upgrade proof applies.

…ailures

The native declaration subprocess let an emission failure escape as an
uncaught top-level rejection. Node then exited immediately, while the
TypeScript native API's close() had only ended the compiler's stdin, so
tsgo was still shutting down inside the managed process group. Under load
the managed runner reported "Managed command exited while its process
group remained active" and the real failure was lost.

Report the failure through process.exitCode instead, so the event loop
drains and joins the compiler exactly as the success path already does.
Native declaration emission sets rootDir to the realpath of the checkout,
but the renderer derived its root file names from the unresolved repoRoot.
The API diff renders revisions under os.tmpdir(), which is a symlinked
alias on macOS (/var -> /private/var), so every source landed outside
rootDir and the render failed with TS6059. Canonicalize repoRoot once when
rendering starts.
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Oct 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 5:27 PM ET / 21:27 UTC (Revision 2).

ClawSweeper review

What this changes

The PR preserves compiler diagnostics while compiler shutdown completes and canonicalizes checkout paths so Plugin SDK API comparisons work through macOS temporary-directory aliases.

Merge readiness

⛔ Blocked before merge - 1 item remains

The PR remains useful and has no blocking correctness findings. The earlier migration-proof blocker is resolved by source inspection: the subprocess hand-off is temporary and its format is unchanged.

Priority: P2
Reviewed head: 0676a1f45ead558896160437f686cccfa38fb577

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant real-run evidence, regression coverage, and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured macOS run exercises the real API-diff entrypoint through the changed renderer and managed compiler worker, showing failure before and a completed comparison after both repairs. Focused regressions additionally cover delayed compiler shutdown and symlinked roots. The unchanged per-call hand-off format creates no stored-data upgrade requirement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured macOS run exercises the real API-diff entrypoint through the changed renderer and managed compiler worker, showing failure before and a completed comparison after both repairs. Focused regressions additionally cover delayed compiler shutdown and symlinked roots. The unchanged per-call hand-off format creates no stored-data upgrade requirement.
Evidence reviewed 9 items Pinned introduced changes: The merge-base-to-head delta contains only the compiler failure handler, checkout-root normalization, and their two regression tests.
Compiler lifecycle repair: The worker catches emission failures, prints the original error, and sets exitCode instead of allowing a top-level rejection to terminate Node. The caller retains strict POSIX process-tree verification and rejects nonzero exits.
Pinned compiler dependency contract: The target emitter imports typescript/unstable/async, establishing the dependency signal. Registry metadata identifies TypeScript 7.1.0-dev.20260920.1 and gitHead f29aeb9f825d96feea27841f3f7342dbf0df68a8. Its published package/dist/api/async/client.js spawns a referenced child and close() ends stdin without awaiting child exit, confirming the lifecycle premise. This is package evidence, not a claimed repository source coordinate.
Findings None None.
Security None None.

How this fits together

Plugin SDK API comparison tooling compiles selected repository revisions and compares their public declarations. Its renderer uses a managed compiler subprocess and passes the resulting API surfaces to the comparison report.

flowchart TD
  A[Selected repository revisions] --> B[Temporary checkouts]
  B --> C[Canonical checkout paths]
  C --> D[Managed declaration compiler]
  D --> E{Compilation result}
  E -->|Success| F[API comparison report]
  E -->|Failure| G[Joined shutdown and diagnostics]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +3, Tests +87, Other +7. Total +97 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 2 88 1 +87
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 9 2 +7
Total 4 101 4 +97

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: scripts/lib/native-declaration-subprocess.mts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep one canonical renderer and strict compiler-process ownership while returning useful diagnostics on failure.

Do we have a high-confidence way to reproduce the issue?

Yes: current source exposes the mismatched canonical root and premature failure exit, and the captured body records the real macOS command failing before the repairs. This review did not execute that command.

Is this the best way to solve the issue?

Yes: the patch fixes both defects at their existing owners while preserving process-tree checks, declaration validation, and public SDK contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f1239520835.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs maintainer API-comparison tooling failures with a bounded impact on development and release validation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured macOS run exercises the real API-diff entrypoint through the changed renderer and managed compiler worker, showing failure before and a completed comparison after both repairs. Focused regressions additionally cover delayed compiler shutdown and symlinked roots. The unchanged per-call hand-off format creates no stored-data upgrade requirement.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured macOS run exercises the real API-diff entrypoint through the changed renderer and managed compiler worker, showing failure before and a completed comparison after both repairs. Focused regressions additionally cover delayed compiler shutdown and symlinked roots. The unchanged per-call hand-off format creates no stored-data upgrade requirement.

Evidence

What I checked:

  • Pinned introduced changes: The merge-base-to-head delta contains only the compiler failure handler, checkout-root normalization, and their two regression tests. (0676a1f45ead)
  • Compiler lifecycle repair: The worker catches emission failures, prints the original error, and sets exitCode instead of allowing a top-level rejection to terminate Node. The caller retains strict POSIX process-tree verification and rejects nonzero exits. (scripts/lib/native-declaration-subprocess.mts:133, 0676a1f45ead)
  • Pinned compiler dependency contract: The target emitter imports typescript/unstable/async, establishing the dependency signal. Registry metadata identifies TypeScript 7.1.0-dev.20260920.1 and gitHead f29aeb9f825d96feea27841f3f7342dbf0df68a8. Its published package/dist/api/async/client.js spawns a referenced child and close() ends stdin without awaiting child exit, confirming the lifecycle premise. This is package evidence, not a claimed repository source coordinate. (f29aeb9f825d)
  • Canonical path consistency: The renderer now canonicalizes repoRoot before constructing source filenames. The emitter already sets rootDir from realpath(options.cwd), and the API-diff entrypoint creates revision checkouts beneath os.tmpdir(); the change aligns those paths without adding a parallel rendering path. (src/plugin-sdk/api-baseline.ts:412, 0676a1f45ead)
  • Real after-fix behavior: The captured PR body reports the actual plugin-sdk:api:diff command on macOS under load: before-fix orphan failure, compiler diagnostics after the lifecycle fix alone, and successful comparison after both fixes. The final run exited zero after 1,419 seconds and produced the report with acknowledgement digest 2dfbd058. Reported failing-before/passing-after regressions supplement this real entrypoint evidence. (0676a1f45ead)
  • No stored-data contract change: result.bin is written inside a fresh per-call temporary directory, read by the same invocation, and removed after joined completion. Neither serialization nor validation changes. The previous review's migration request therefore does not apply. (scripts/lib/native-declaration-subprocess.mts:80, 0676a1f45ead)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-03T18:59:32.208Z sha 0676a1f :: blocked before merge. :: none

@steipete
steipete merged commit 7b9615f into main Oct 3, 2026
137 checks passed
@steipete
steipete deleted the fix/plugin-sdk-api-diff-native-child branch October 3, 2026 22:00
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 3, 2026
Bring in the SDK API diff tooling fix from #164466. Preserve the involvement delta unchanged. Fresh P2 autoreview is scoped clean, and all 12 focused Gateway and worker involvement tests pass on the merged candidate.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…ckouts (openclaw#164466)

* fix(scripts): join the native compiler before reporting declaration failures

The native declaration subprocess let an emission failure escape as an
uncaught top-level rejection. Node then exited immediately, while the
TypeScript native API's close() had only ended the compiler's stdin, so
tsgo was still shutting down inside the managed process group. Under load
the managed runner reported "Managed command exited while its process
group remained active" and the real failure was lost.

Report the failure through process.exitCode instead, so the event loop
drains and joins the compiler exactly as the success path already does.

* fix(plugin-sdk): render API surfaces from canonical checkout roots

Native declaration emission sets rootDir to the realpath of the checkout,
but the renderer derived its root file names from the unresolved repoRoot.
The API diff renders revisions under os.tmpdir(), which is a symlinked
alias on macOS (/var -> /private/var), so every source landed outside
rootDir and the render failed with TS6059. Canonicalize repoRoot once when
rendering starts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant