Skip to content

fix: report native binary launch and crash failures - #2116

Open
Emrys1105 wants to merge 12 commits into
mainfrom
fix/2053-no-output-after-install
Open

fix: report native binary launch and crash failures#2116
Emrys1105 wants to merge 12 commits into
mainfrom
fix/2053-no-output-after-install

Conversation

@Emrys1105

@Emrys1105 Emrys1105 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix the npm launcher so native binary launch failures and unexpected crashes produce actionable stderr diagnostics instead of failing silently. Issue #2053 is a Windows report, so this covers the platform's crash path explicitly rather than only POSIX signals.

Changes

  • Report the native binary path and OS error code when the executable cannot be launched, including the missing-binary case after installation.
  • Report the NTSTATUS code when a native binary crashes on Windows (e.g. access violation 0xC0000005, missing DLL). Windows has no POSIX signals, so a crash arrives as a numeric exit status that was previously forwarded silently — exactly the 安装 cli 以及 skill 后, config 和 auth 命令均无输出 #2053 symptom on the reporting platform. STATUS_CONTROL_C_EXIT stays quiet, symmetric with the SIGINT/SIGTERM allowlist.
  • Preserve silent handling for intentional SIGINT and SIGTERM interruption while reporting other termination signals factually (never claiming "failed to launch" — the binary may have run for a while first).
  • Write diagnostics with process.exitCode + a natural return instead of process.exit(), so a diagnostic is not dropped when stderr is a congested pipe (the AI-agent / log-wrapper case this CLI targets).
  • Keep the diagnostics concise: binary path plus the OS error/signal/status, no issue-tracker guidance.
  • Add cross-platform launcher regression tests for exit-code passthrough, signal handling, Windows crash status, stderr-backpressure flush safety, argument secrecy, and launch failures.
  • Run the launcher tests on Windows and include that job in the blocking CI result gate.

Test Plan

  • make unit-test
  • go vet ./...
  • Harness validation: build, vet, unit, and integration checks passed
  • Sandbox E2E passed
  • Acceptance review passed all 5 local fixture scenarios (plus flush-safety and argv-secrecy regressions)
  • Security code review passed with no confirmed vulnerabilities
  • Full CI green on the final commit, including shim-test-windows (the Windows crash-status assertion runs on a real windows-latest runner)

Related Issues

Summary by CodeRabbit

  • Bug Fixes

    • Improved native-command failure handling with clearer diagnostics for launch failures, crashes, and signal termination.
    • Preserved exit codes and output forwarding while ensuring error messages flush reliably.
  • Tests

    • Expanded coverage for invalid binaries, signals, exit codes, output handling, and platform-specific failures.
    • Added Windows CI coverage for command shim tests and included it in overall CI result reporting.
    • Included shim tests in the standard script test suite.

…dows

Canonicalise the sandbox temp root with fs.realpathSync so the launch-failure
assertions survive Windows 8.3 short-name expansion (RUNNER~1), which the new
shim-test-windows CI job would otherwise fail on. Give the cleanup hook a
retry budget to tolerate a transient Windows file lock on the ~80MB fixture
binary. Add a second, pure-ASCII line to the launch-failure diagnostic
pointing users at what to include when reporting. Guard the tracker line,
the new line, and empty stdout in assertLaunchFailure, cover child stderr
passthrough in the success case, and extend ci-workflow.test.sh's full_job
loop to keep shim-test-windows from being silently skipped on PR edits.
Extend argv-containment guard to launch-failure cases in run.test.js by
passing the sentinel token to all three failure scenarios and adding an
assertion that catches future regressions where spawnargs or the error
object itself would leak to stderr.

Extend secrets assertion in ci-workflow.test.sh to the newly added
shim-test-windows job, preventing accidental credential references in the
Windows-specific npm shim test job.
…bytes

libuv's execvp falls back to /bin/sh on ENOEXEC, so a chmod-755 zero-byte
file is not a launch failure on Linux: /bin/sh runs it as an empty script
and exits 0, letting the old "zero-byte binary" case pass locally on
macOS (real ENOEXEC) while silently masking the same case in CI. Use a
directory at the bin path on POSIX instead, which reliably reports
EACCES on both macOS and Linux, including as root. win32 keeps its
zero-byte .exe fixture, where CreateProcess genuinely fails to launch
it. Also skip the existing chmod-000 EACCES case under root, since
mode 0000 does not deny exec for uid 0.
@Emrys1105 Emrys1105 added the bugfix Bug fixes label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d18e6d7b-3f4f-4804-a876-d871112da7cf

📥 Commits

Reviewing files that changed from the base of the PR and between a1d1a7d and cd93dd6.

📒 Files selected for processing (2)
  • scripts/run.js
  • scripts/run.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/run.js

📝 Walkthrough

Walkthrough

The shim runner now handles native launch failures, signals, and Windows NTSTATUS crashes with bounded diagnostics. A cross-platform test suite covers these cases. Local tests and Windows CI run the suite and include its status in workflow results.

Changes

Shim diagnostics and CI coverage

Layer / File(s) Summary
Native launch error handling
scripts/run.js
run.js distinguishes launch failures, signals, numeric exit statuses, and Windows NTSTATUS crashes. It sets deferred exit codes and limits diagnostic output.
Shim diagnostic test coverage
scripts/run.test.js, Makefile
The test suite covers launch failures, output and status forwarding, signals, Windows crashes, argument isolation, and stderr backpressure. script-test includes the suite.
Windows CI integration
.github/workflows/ci.yml, scripts/ci-workflow.test.sh
Adds the Windows shim test job, includes it in results aggregation and failure detection, and validates its runner, Node version, command, dependencies, and secret usage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI
  participant ShimTests
  participant ShimRunner
  participant NativeBinary
  CI->>ShimTests: Run scripts/run.test.js
  ShimTests->>ShimRunner: Invoke shim with fixture and sentinel arguments
  ShimRunner->>NativeBinary: Execute native binary
  NativeBinary-->>ShimRunner: Return status, signal, or launch error
  ShimRunner-->>ShimTests: Emit bounded diagnostics and exit status
  ShimTests-->>CI: Report test result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: reporting native binary launch and crash failures.
Description check ✅ Passed The description covers the summary, changes, completed test plan, and related issue with sufficient detail.
Linked Issues check ✅ Passed The changes address issue #2053 by exposing native launcher failures and crash diagnostics that can explain missing command output.
Out of Scope Changes check ✅ Passed The Windows CI job, regression tests, and workflow validation directly support the launcher diagnostics fix and are in scope.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2053-no-output-after-install

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.5)
scripts/run.js

File contains syntax errors that prevent linting: Line 102: Illegal return statement outside of a function; Line 120: Illegal return statement outside of a function


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
.github/workflows/ci.yml (1)

146-157: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add timeout-minutes to the new blocking job.

This job is now in the results FAILED loop, and it spawns child processes that can hang on Windows (locked node.exe copy, endpoint-protection prompts). Without a job timeout it falls back to the 360-minute default while blocking the merge gate.

♻️ Proposed tweak
   shim-test-windows:
     needs: fast-gate
     runs-on: windows-latest
+    timeout-minutes: 15
     steps:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 146 - 157, Add a finite
timeout-minutes setting to the blocking shim-test-windows job so hung Windows
child processes cannot block the merge gate for the default duration; keep the
existing needs, runner, and test steps unchanged.
scripts/run.js (1)

79-90: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Consider 128 + signal exit codes for signal-terminated children.

Both branches exit 1, so a Ctrl+C during auth login is indistinguishable from a generic failure for callers (shell loops, CI wrappers, trap handlers) that rely on the conventional 130/143. The tests pin 1, so this is a deliberate contract — worth confirming it's the intended one before it becomes user-visible behavior.

♻️ Optional: forward conventional signal exit codes
     if (e.signal) {
+      const codes = { SIGINT: 130, SIGTERM: 143, SIGKILL: 137 };
+      const status = codes[e.signal] || 1;
       if (e.signal === "SIGINT" || e.signal === "SIGTERM") {
-        process.exit(1);
+        process.exit(status);
       }
       console.error(
         `\nlark-cli: the native binary was terminated by signal ${e.signal}.\n` +
         `  path:  ${bin}\n\n` +
         `Report this error at https://github.com/larksuite/cli/issues\n` +
         `Please include the path and signal shown above.\n`
       );
-      process.exit(1);
+      process.exit(status);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/run.js` around lines 79 - 90, Update the signal-handling branches in
the child-process error flow to exit with the conventional 128 plus the
terminating signal’s numeric value, including SIGINT and SIGTERM, instead of
always exiting with 1. Preserve the existing diagnostic output for non-interrupt
signals and update the associated tests to assert the new exit-code contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 146-157: Add a finite timeout-minutes setting to the blocking
shim-test-windows job so hung Windows child processes cannot block the merge
gate for the default duration; keep the existing needs, runner, and test steps
unchanged.

In `@scripts/run.js`:
- Around line 79-90: Update the signal-handling branches in the child-process
error flow to exit with the conventional 128 plus the terminating signal’s
numeric value, including SIGINT and SIGTERM, instead of always exiting with 1.
Preserve the existing diagnostic output for non-interrupt signals and update the
associated tests to assert the new exit-code contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: edab3e3a-944f-4a2f-bdae-8dae23b2d6a0

📥 Commits

Reviewing files that changed from the base of the PR and between a575a8b and 7614fa0.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • Makefile
  • scripts/ci-workflow.test.sh
  • scripts/run.js
  • scripts/run.test.js

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@5ed41d67641ec6ec251c6f1b3ed267e3405bc419

🧩 Skill update

npx skills add larksuite/cli#fix/2053-no-output-after-install -y -g

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.55%. Comparing base (427cbd6) to head (5ed41d6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2116   +/-   ##
=======================================
  Coverage   75.55%   75.55%           
=======================================
  Files         931      931           
  Lines       99362    99362           
=======================================
  Hits        75077    75077           
  Misses      18549    18549           
  Partials     5736     5736           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ckpressure

Address external review of PR #2116: a crashing native binary on Windows
(no POSIX signals) was silently forwarded as a numeric exit status instead
of being reported as a crash, and the shim's diagnostic writes could be
dropped entirely if process.exit() ran before an async pipe write to a
congested stderr had flushed. Also tightens two test comments that
overgeneralized Linux-specific and argv-leak-vector behavior to POSIX, adds
regression coverage for both fixes, and closes a gap in the CI gate
assertions that only checked the FAILED loop, not the results job's needs:
array.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/run.test.js (1)

440-441: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use execFileSync for the pgrep call.

shim.pid is a number, so there is no injection risk here. execFileSync avoids the shell and clears the OpenGrep finding.

♻️ Proposed change
-            const out = execSync(`pgrep -P ${shim.pid}`).toString().trim();
+            const out = execFileSync("pgrep", ["-P", String(shim.pid)])
+              .toString()
+              .trim();

Update the import at Line 9 accordingly:

-const { spawnSync, spawn, execSync } = require("child_process");
+const { spawnSync, spawn, execFileSync } = require("child_process");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/run.test.js` around lines 440 - 441, Replace the shell-based execSync
invocation in the fixture PID lookup with execFileSync, passing pgrep and its
arguments separately, and update the corresponding import so the call avoids
shell execution while preserving the existing output parsing and fixturePid
behavior.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/run.test.js`:
- Around line 420-451: Add an immediate cleanup hook after spawning the shim in
the Promise around the test fixture, ensuring the shim is terminated on every
resolve, reject, or timeout path. Update the existing closed/error handling and
the fixture PID failure branches in the shim lifecycle logic so cleanup runs
before rejection and prevents blocked child processes from leaking.

---

Nitpick comments:
In `@scripts/run.test.js`:
- Around line 440-441: Replace the shell-based execSync invocation in the
fixture PID lookup with execFileSync, passing pgrep and its arguments
separately, and update the corresponding import so the call avoids shell
execution while preserving the existing output parsing and fixturePid behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 36cdcf7e-a1aa-4823-821c-f85f94fdf35d

📥 Commits

Reviewing files that changed from the base of the PR and between a1de702 and a1d1a7d.

📒 Files selected for processing (3)
  • scripts/ci-workflow.test.sh
  • scripts/run.js
  • scripts/run.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/ci-workflow.test.sh

Comment thread scripts/run.test.js
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Quality Summary

CI did not complete successfully. Use the failed check links below to decide whether this PR needs a code change or a rerun.

Failed checks

@liangshuo-1 liangshuo-1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:Request changes。当前实现明显改善了诊断,但还不能保证“无 silent bad case / 无兼容性变化”。

必须修复

  1. Linux 上空/纯空白可执行文件仍会静默 exit 0scripts/run.test.js:164-177, scripts/run.js:68
    新测试明确知道 glibc/libuv 会在 ENOEXEC 后交给 /bin/sh,却改用目录 fixture 绕开了这个真实 bad case。实测将 bin/lark-cli 设为 0755 的 0-byte 文件后,当前 HEAD 返回 status=0, stdout=0B, stderr=0B,原生二进制根本没有运行,完全复现 #2053 的症状。install.jscopyFileSync(dest) 也不是原子替换,中断后留下空/残缺目标文件并非不可达。建议在执行前校验至少 isFile + size > 0(最好校验平台 magic),并将安装复制改为临时文件 + rename;测试应直接钉住 0-byte Linux case,而不是规避它。

  2. Windows crash 的原始 NTSTATUS 被改写为 1,属于不必要的退出码 breaking changescripts/run.js:101, scripts/run.test.js:316
    base 会 process.exit(e.status),当前分支对 0xC0000005 打印诊断后改成 1。依赖 %ERRORLEVEL% / NTSTATUS 的 wrapper 将失去原始失败类型;这也与 PR 声明的 exit-status passthrough 不一致。可用 process.exitCode = e.status; return 同时保证 stderr flush 和原始状态透传,并把 Windows 断言改为精确状态值。

  3. Windows crash 判定只覆盖 0xC0000000+,仍会让真实 crash 静默scripts/run.js:92-104
    STATUS_BREAKPOINT (0x80000003)STATUS_FATAL_APP_EXIT (0x40000015) 等进程终止状态会直接走 silent passthrough;mock 路由验证当前两者均无诊断。因此“unexpected crashes”并未完整覆盖。请按 lark-cli 的小整数退出码契约补全异常状态分类,并在真实 Windows job 中覆盖 0x400000150x800000030xC0000005,同时补 0xC000013A 必须保持 quiet 的负向测试。

  4. auto-install 失败诊断仍可能被同一种 stderr backpressure 吞掉scripts/run.js:57-64
    这里仍是 console.error(...) 后立即 process.exit(1)。我用同样的满管道 fixture 实测当前 HEAD 为 code=1, captured=0B, diagnostic=false;改成 process.exitCode = 1; return 后诊断稳定保留。#2053 的 blocked-postinstall 场景正会进入 auto-install 路径,不能只修后面的 native-exec catch。

CI / 测试建议

  • shim-test-windows 是 blocking job 且内部有无 timeout 的同步子进程,建议加 timeout-minutes: 10~15,避免异常时按默认 360 分钟阻塞 results gate。
  • Windows job 当前直接执行 node scripts/run.test.js,未覆盖 issue 截图中的真实 npm-generated .cmd + blocked postinstall 链路;关闭 #2053 前建议增加一个本地 fixture package 的 Windows npm shim E2E。

验证结果:make script-test 160 tests 通过;macOS 相关测试通过;Linux backpressure 连跑 20/20,通过 mutation 可证明旧实现必失败;Node 16 runtime case 通过;PR 的真实 windows-latest shim job 通过。当前 e2e-live/results 失败与 base 427cbd6 上相同(contact fixture 无用户),不是本 PR 引入,但在重新跑绿前仍不应合并。

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

Labels

bugfix Bug fixes size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

安装 cli 以及 skill 后, config 和 auth 命令均无输出

2 participants