test(node-sdk): stop comparing killed-task exitCode across engines - #2857
test(node-sdk): stop comparing killed-task exitCode across engines#2857rajathpi wants to merge 3 commits into
Conversation
Stopping a background task signals the whole process group, and the shell settles two ways depending on which group member observes the SIGTERM first: reaped by the signal itself (exit code null, mapped to -1 by both engines) or outliving its child and exiting 128+15 (143). Both engines map the raw exit payload identically, so each lands on its own side of that OS race and the lifecycle parity test fails whenever the two runs disagree. Project exitCode away for killed tasks only, and assert instead that each engine still settles on a concrete numeric code. Completed and failed tasks keep comparing exitCode in full.
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@chatgpt-codex-connector review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@liruifengv could you please take a look when you have time 😄 |
Related Issue
No existing issue — the problem is explained below. (Searched open issues and PRs for this flake first; nothing covers it.)
Problem
pnpm testintermittently fails the background-task lifecycle parity test:This is a flaky test, not an engine divergence. The killed-task step stops
sh -c "echo bg-out; sleep 30", and stopping signals the whole process group (process.kill(-pid, 'SIGTERM')— v1packages/kaos/src/local.ts, v2packages/agent-core-v2/src/os/backends/node-local/hostProcessService.ts). The shell then settles one of two ways depending on which group member observes the SIGTERM first:exitfires withcode=null, signal=SIGTERM, which both backends map through the samecode ?? -1to-1;sleepand exits with the shell's 128+15 convention →code=143, signal=null→143.Both backends'
child.on('exit')handlers are line-for-line identical, and so is the settle logic in v1ProcessBackgroundTaskand v2ProcessTask— so a143can only come from the shell itself. I reproduced the race outside the engines with a barespawnof the same command (detached, group-SIGTERM after 60ms, 40 trials): 38xcode=null signal=SIGTERM, 2xcode=143 signal=nullon an idle machine. Each engine independently lands on either side of that coin flip, and the parity comparison fails whenever they disagree.What changed
Test-only, one file (
packages/node-sdk/test/v1-v2-parity.test.ts):projectBackgroundTask()now deletesexitCodeonly whenstatus === 'killed', with a comment explaining the OS race. Completed and failed tasks keep comparingexitCodein full — the drain-mode test'sexitCode: 0assertion is deliberately untouched.KNOWN_DIFFS.listBackgroundTasksdoc comment is updated to match (that block documents every projected-away field and why).numberexit code. Not asserting-1 | 143specifically, because those values are POSIX-specific and the suite also runs on Windows.This follows the file's existing pattern:
KNOWN_DIFFSprojections remove per-run nondeterminism (pids, timestamps, task-id suffixes) while call-site assertions pin the invariants that do hold. An engine-side fix was considered — mapping signal deaths to128+Nwould make the reported code deterministic here — but that changes the SDK-visibleexitCodefor every signal-killed task on both engines, which is a behavior change deserving its own discussion, and the engines already agree exactly on how they map the exit payload today, so there is no cross-engine bug for this parity test to catch.Verification:
pnpm vitest run packages/node-sdk/test/v1-v2-parity.test.ts→ 84 passed, several consecutive runs.exitCode: 143vs-1, the fixed projection passes; with the new projection line disabled, it fails with exactly the original error signature.pnpm lint→ 0 errors, warning count identical tomain.tsc --noEmiton@moonshot-ai/kimi-code-sdkpasses.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.