Repository navigation
build(macos): parallelize native helpers with complete cancellation - #19651
Conversation
|
Warning Review limit reachedNext included review available in 16 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe macOS native build script starts detached concurrent pnpm builds with labeled output. It tracks child processes and waits for both error and close events. It terminates process groups on Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Concurrent macOS native builds may leave sibling build processes running when the parent is interrupted, potentially consuming resources or affecting subsequent builds. This termination behavior should be confirmed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f7a58bfd-c5bf-47aa-bbfa-ac7c077f8706
📒 Files selected for processing (1)
config/scripts/build-native-for-platform.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| child.kill(signal) | ||
| process.kill(process.pid, signal) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 10387
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- changed file ---'
cat -n config/scripts/build-native-for-platform.mjs
printf '%s\n' '--- runtime declarations and relevant references ---'
for f in package.json .nvmrc .node-version; do
if [ -f "$f" ]; then
echo "--- $f ---"
cat -n "$f"
fi
done
rg -n --glob '!node_modules' --glob '!dist' --glob '!build' \
'build-native-for-platform|resolvePnpmCliInvocation|spawnSync|process\.kill|child\.kill|pnpm' \
config package.json .github 2>/dev/null | head -200Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -eu
node --version 2>&1 || true
printf '%s\n' '--- focused source ---'
sed -n '1,120p' config/scripts/build-native-for-platform.mjs
printf '%s\n' '--- package/runtime metadata ---'
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'"(engines|packageManager|volta|node)"|node-version|NODE_VERSION|Node\.js' \
package.json .nvmrc .node-version .tool-versions README.md CONTRIBUTING.md .github 2>/dev/null | head -120Repository: stablyai/orca
Length of output: 11116
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- repository status and diff context ---'
git diff -- config/scripts/build-native-for-platform.mjs
printf '%s\n' '--- all direct callers ---'
rg -n --glob '!node_modules' --glob '!dist' --glob '!build' \
'config/scripts/build-native-for-platform\.mjs|build-native-for-platform' . 2>/dev/null | head -100Repository: stablyai/orca
Length of output: 403
Terminate sibling builds before re-raising a child signal.
When runPnpmScript receives a signaled close event, child.kill(signal) targets the already-closed child, and process.kill(process.pid, signal) terminates only the parent. The other pnpm processes can continue and write artifacts after the build fails. Track the child processes, terminate the siblings, await their cleanup, and then re-raise the signal.
There was a problem hiding this comment.
ℹ️ Minor suggestions only.
Reviewed changes
- Parallel macOS native-module builds —
config/scripts/build-native-for-platform.mjsnow runs the three native-module pnpm scripts (build:computer-macos,build:keyboard-layout-macos,build:notification-status-macos) concurrently viaspawn+Promise.all, aggregating exit codes withMath.max, instead of sequentially viaspawnSync.
The change is sound: the three builds write to distinct output directories and use separate temp dirs (plus computer's own SwiftPM .build), so there's no shared filesystem state, and resolvePnpmCliInvocation() returns shell: false on macOS. A couple of minor nits inline.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Address coderabbit review: concurrent builds kept writing native artifacts after a sibling reported failure. Track spawned children, kill remaining siblings on first nonzero exit, and forward SIGINT/ SIGTERM to all children.
|
Pushed 4776e74 to address the sibling-cleanup concern: spawned children are now tracked, remaining siblings receive SIGTERM as soon as one build exits nonzero (fail fast so no straggler keeps writing native artifacts), and SIGINT/SIGTERM on the parent are forwarded to all children. |
There was a problem hiding this comment.
ℹ️ The new fail-fast logic is correct; one outstanding nit from the prior review is still actionable and now matters even more.
Reviewed changes
- Fail-fast sibling termination — when one native-module build fails,
terminateAllnow sendsSIGTERMto the sibling builds so they stop writing artifacts; the deadchild.kill(signal)from the prior review is gone. - Parent signal handling —
SIGINT/SIGTERMon the parent now terminate any still-running builds via the trackedchildrenset instead of leaving them orphaned.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a29ad1d1-0ac5-4b9b-a73c-30ac6bb023b2
📒 Files selected for processing (1)
config/scripts/build-native-for-platform.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
…ative builds Address second coderabbit round: - Detached process groups + negative-pid kill so SIGTERM reaches swift/ swiftc descendants, not just the direct pnpm child (they could keep writing artifacts after fail-fast) - Signal handlers preserve the received signal (SIGINT no longer becomes SIGTERM for children) and are removed before re-raising, so the parent actually dies instead of looping through terminateAll - runPnpmScript settles only on close, never on error alone, so Promise.all cannot exit while children are still running - Per-module output prefixes ([computer]/[keyboard-layout]/[notification- status]) match what the PR description always claimed; interleaved swiftc errors are now attributable - Windows path untouched (early return before any of this runs) execa/p-limit were considered and rejected: no new runtime deps for a build script, and detached process groups give strictly stronger cleanup than execa's direct-child kill.
|
Pushed a second-round fix addressing all remaining threads (including the ones on 4776e74): Process-group teardown — children now spawn Signal fidelity — Settle-on-close only — Output prefixes — each child's stdout/stderr is piped through a On execa + p-limit: considered and rejected. This is a build script that currently has zero runtime dependencies; the same semantics (fail-fast cancellation, cleanup on parent exit, concurrency) come free here from detached process groups + Promise.all, and negative-pid group kill is stronger than execa's |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c868abd3-e241-4f38-982b-7e6cf37f4846
📒 Files selected for processing (1)
config/scripts/build-native-for-platform.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Important
The process-group teardown itself is correct, but the signal/exit-status logic has two bugs that break the PR's core promise: on a real build failure the script never reaches process.exit(Math.max(...exitCodes)), and on Ctrl-C it does not die with 130. Both are reproducible (details inline).
Reviewed changes
- Process-group teardown — each build now spawns
detached: trueinto its own POSIX process group, andterminateAllnegative-pid-kills the whole group soswift/swiftcdescendants die too, not just thepnpmchild. - Settle-on-close + signal fidelity — build promises resolve only from the child
closeevent; a child that dies by signal attempts to re-raise that signal on the parent. - Per-module output prefixes — stdout/stderr are piped through a
[computer]/[keyboard-layout]/[notification-status]line prefixer, resolving the prior "interleaved logs are unattributable" feedback.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…plit Second-round coderabbit findings on 24392a0: - Registration now uses the memoized handlerFor() instances so removeListener actually removes them (inline arrows were never registered, so the parent looped through terminateAll and hung) - externalSignal is set only by the parent's own signal handlers; a sibling's fail-fast SIGTERM no longer masquerades as an external signal, so settle() resolves Promise.all with the failing module's exit code instead of leaving top-level await unsettled (exit 13) - Also fixes a TDZ crash: handlerFor() was invoked at registration time before the signalHandlers const initialized Verified: sibling fail-fast resolves failer=7 with no survivors; external SIGINT kills children then the parent exits 130; real concurrent macOS build green.
|
All three findings fixed and pushed:
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- External-vs-sibling signal split — introduced
externalSignal, set only by theSIGINT/SIGTERMhandlers, so a sibling killed by fail-fastSIGTERMfalls through toresolve(exitCode)instead of re-raising on the parent;Promise.allnow settles andprocess.exit(Math.max(...exitCodes))is reached. - Memoized handler removal —
SIGINT/SIGTERMare registered viahandlerFor(signal), soremoveListener(received, handlerFor(received))removes the actually-installed reference and the parent re-raise terminates with the original signal (exit 130 on SIGINT).
Both findings from the prior review (removeListener no-op; fail-fast siblings short-circuiting exit-code aggregation) are correctly fixed, and no new issues were introduced.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Wait for cancellation before exiting —
stopBuilds(signal)centralizes idempotent process-group teardown and schedules the 2sSIGKILLescalation only while children remain; afterPromise.allthe parent clears the force timer and signal listeners, then re-raises an external signal or setsprocess.exitCode(natural exit, so drained output is not truncated instead of the previousprocess.exit). - Output-stream failure handling —
process.stdout/process.stderrerrorlisteners markoutputFailed, abort sibling builds, and force exit code 1 even when the error lands after every child has exited;pipePrefixedskips writes to a destroyed target. - Regression suite added — a macOS-gated
build-native-for-platform.test.mjscovering concurrent launch, SIGINT/SIGTERM sibling wait and re-raise, fail-fast on failure, a default-handler child, an ignore-SIGTERM child reaped by the escalation timer, closed stdout/stderr consumers, late output errors, missing commands, descendant reaping, and simulated Linux/Windows entry points.
The two new commits resolve the prior review's remaining concerns cleanly, and the fail-fast/external-signal split and removeListener fixes from 8709e65 still hold. All Pullfrog threads on this PR are resolved.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
I like faster builds. Thanks Will review + merge |
…sure - Bound the per-child close wait: two seconds after a child exits, reap its process group and destroy its pipes so a descendant that inherited stdout/stderr cannot hang `pnpm build:native` forever. - Handle SIGHUP alongside SIGINT/SIGTERM so a terminal hangup reaches the detached compiler sessions instead of orphaning them. - Pause a compiler's output stream when the launcher's stdout/stderr reports backpressure and resume on drain, so prefixed output no longer buffers without bound. - Run build-native-for-platform.test.mjs in the computer-e2e mac-native-owner-smoke PR job and trigger that workflow on launcher changes; the tests are darwin-only and no other PR job runs on macOS. - Report the first failing child's status: re-raise its signal, or use its exit code instead of Math.max over cancelled siblings.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Bounded cancellation waits — a new 2s per-child
closeTimer(armed onexit, cleared onclose) SIGKILLs the child's process group and destroys its stdout/stderr when a descendant keeps the pipes open, soclosestill fires andPromise.allsettles. - First-failure attribution —
firstFailurerecords the code/signal of the child whose failure started cancellation (only while!stopping), so siblings killed by fail-fastSIGTERM/SIGKILLno longer mask it; the final block re-raises that signal, or reports that code instead of the maximum sibling status. - SIGHUP forwarding — the launcher now handles
SIGHUPalongsideSIGINT/SIGTERMvia the memoizedhandlerForand re-raises it after cleanup, so compilers do not outlive a terminal hangup. - Output backpressure —
pipePrefixedpauses the child stream when the parent's stdout/stderr reportswritableNeedDrainand resumes it ondrain/close, bounding the launcher's own output buffer. - macOS CI coverage — the
mac-native-owner-smokejob now runs the darwin-only cancellation suite with--config config/vitest.config.ts, path triggers were extended, and new tests cover first-failure status, signal re-raise, descendant reaping, and backpressure.
I traced the new exit-status paths (non-zero exit, spawn error, signal death, external signal, descendant-held pipes, late output error) and the backpressure/close-timer interaction. Exit status is correct in each, close still fires after the timer destroys a paused stream, and the pause/resume listeners do not leak or double-resume. The pre-existing concern about output that is still buffered when stdout stalls is a deliberate wait-bounding trade-off and does not hide a failure.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… fail on ignored re-raised signal The descendant reap timer started on every child 'exit' and fired even when 'close' was late only because the launcher paused the pipe for its own stdout backpressure, destroying pipes with compiler output still queued. Arm the countdown only while the pipes are actually draining: clear it on 'pause' and re-arm on 'resume' after exit. Write the reap notice to stderr since stdout is the stream that may be blocked. Re-raising a child's fatal signal is a no-op when Node ignores it (SIGPIPE), so set a non-zero exit code first; a failed build no longer exits 0. Tests: stall the launcher's stdout consumer past the reap timeout and assert every kernel-accepted compiler line still arrives; kill the computer build with SIGPIPE and assert the launcher exits 1.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reap timer respects output backpressure —
armReapnow returns without arming the 2s close timer whilechild.stdout/child.stderris paused, and re-arms onresumeonce the child has exited, so compiler output still buffered in the pipe is drained instead of destroyed mid-write. - Nonzero exit when a re-raised signal is ignored — the
firstFailure.signalbranch setsprocess.exitCode = 1beforeprocess.kill, so a build killed by a signal Node ignores (e.g.SIGPIPE) still reports failure rather than exiting 0. - Regression coverage — new
failure-sigpipeandstalled-consumercases plus awaitForhelper; the stall test resumes the consumer past the reap timeout and asserts every line the compiler pushed into the pipe is delivered.
I traced the new pause/exit interaction: a closed consumer routes through pipePrefixed's close handler into resume, the timer re-arms on resume only after exited, and close still clears it. The stalled-consumer assertion is exact, so it would fail if the timer destroyed the pipes while paused. Ran the non-darwin tests locally (27 passed, 21 darwin-gated skipped) and oxlint is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Build Orca’s three independent macOS helpers at the same time. Four fresh-build trials on one Mac averaged 76.712 seconds sequentially and 74.418 seconds concurrently: 2.294 seconds faster, about 3%. Cancellation waits for the other builds to stop before the launcher exits.
What Changed
Why
These helpers have separate build directories and no ordering dependency. Overlapping the work reduces packaging time. Waiting for all close events fixes the original proposal’s early signal exit, which could leave sibling compilers running.
Linked Issue
No linked issue was provided with the original PR.
Visual Proof
N/A — build tooling only; no application UI or interaction change.
Testing
macOS 26.6.2 arm64, Node 26.6.0, Swift 6.3.3; all commands used ORCA_BACKGROUND_LAUNCH=1. No helpers or Electron windows were launched.
Four real builds used the same copied source path, fresh .build directories, and ad-hoc signing:
All builds exited successfully and produced arm64 + x86_64 helpers; the app signature verifies. Keyboard and notification binaries are byte-identical across all four trials. A further concurrent build (75.252 s) was compared against the final sequential build: both architectures’ machine code and linked libraries match, and the complete Swift helper matches after masking only LC_UUID, code-signature bytes, and N_OSO debug-object modification timestamps. This is a modest local result, not a claimed several-minute or all-machine speedup.
pnpm test config/scripts/build-native-for-platform.test.mjs config/scripts/pnpm-cli-invocation.test.mjs src/shared/child-process/child-process-import-boundary.test.ts: 24 tests pass across three files. Coverage includes concurrent launch, SIGINT/SIGTERM, mixed signal handlers, failed builds, ignored cancellation, grandchildren retaining output pipes, missing commands, and simulated Linux/Windows entry points. Restoring the original PR implementation makes both interrupt regressions fail: it exits after only one of three children finishes cleanup.Node typecheck, all three changed-code quality gates, syntax and whitespace checks pass. Native Windows/Linux builds, full application build, and release-identity signing were not run; simulated entry points are not native platform coverage.
AI Disclosure
The original author disclosed Claude assistance. The takeover fixes, tests, and verification were performed with OpenAI Codex assistance.
Review
Cancellation, output completion, artifact equivalence, platform guards, and failure paths were reviewed. This changes only build orchestration; SSH execution, folder workspaces, runtime wire formats, and Git providers are unaffected.
Agent skill upstream boundary
Checklist
Independent review follow-up
Handle stdout/stderr failures through the same compiler cleanup path, skip writes to broken output streams, and return failure even if an output error arrives after every child exits. The published version left two quiet compilers running when its output pipe closed; the fix leaves no survivors. Four added regressions cover both pipes and late errors; all 28 tests across three files and changed-code quality gates pass. Removing immediate failure status makes both late-error cases fail.
Parallel builds can use more CPU/RAM at once; concurrency is bounded to these three independent helpers. The measured ~3% gain applies to
build:nativecallers. Existingbuild:maccommands retain their explicit sequential helper steps. Peak memory across all compiler processes was not measured.