Skip to content

Commit 178c172

Browse files
committed
test(api): run jest with --no-sparkplug to stop Node 24's V8 worker SIGSEGV
The api suite intermittently lost a worker to SIGSEGV, which jest then blamed on whichever file that worker happened to be running — an innocent bystander (env-schema.test.ts in the reported case), which is why solo and full reruns always passed. Root cause is not our code. The macOS crash report for the reported incident survived and correlates to the second (pid 90485, parent 90275, 2026-08-05 00:54:30 JST) with the taxonomy record our own reporter wrote. It shows `KERN_INVALID_ADDRESS at 0x6` with every faulting frame inside node itself: ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers <- InternalFrame::Iterate <- MarkCompactCollector::MarkRoots <- StackGuard::HandleInterrupts <- Builtins_BaselineOutOfLinePrologue. A stack-guard interrupt triggers Mark-Compact GC during a Sparkplug prologue and the half-built frame is walked as a GC root. That is nodejs/node#62393 (V8 13.6), fixed in Node 25.0.0+ and not backported to 24.x as of 24.18.0. Three occurrences are on record here. `--no-sparkplug` removes the baseline-JIT stage the race lives in. It cannot go in NODE_OPTIONS (node rejects it there) and `node_modules/.bin/jest` is a shim that swallows node flags, so the script invokes jest.js through node directly; jest-worker forwards process.execArgv, so workers inherit it. Bypassing the shim also drops the NODE_PATH it exported (pnpm's hidden hoist), which surfaced four dependencies `@crowi/api` used but never declared — a latent bug of its own, invisible to type-check because tsconfig excludes test files. Declared as devDependencies here. Not a retry and not a fallback to --maxWorkers=1: the trigger is removed. Since a probabilistic native crash has no deterministic regression test, verification is (1) all five workers observably carry the flag (checked via ps during a run) with 187 suites / 3045 tests green, and (2) the existing taxonomy pipeline already classifies this signature, so a recurrence would be recorded. Removal condition is documented in jest.config.js. Left alone: `test:server` targets a `lib/` directory that no longer exists, so it matches nothing; deleting it touches turbo.json and the root package.json and is out of scope here. Diagnosis delegated per CLAUDE.md's flake/CI-infra rule. Codex adversarial review: no findings.
1 parent b43b6ef commit 178c172

4 files changed

Lines changed: 93 additions & 47 deletions

File tree

‎packages/api/jest.config.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
// For a detailed explanation regarding each configuration property, visit:
22
// https://jestjs.io/docs/en/configuration.html
3+
//
4+
// ---------------------------------------------------------------------------
5+
// Why `package.json`'s `test` script runs `node --no-sparkplug
6+
// node_modules/jest/bin/jest.js` instead of plain `jest`
7+
// ---------------------------------------------------------------------------
8+
// Node 24.x carries a V8 (13.6) bug: when a stack-guard interrupt triggers a
9+
// Mark-Compact GC during a Sparkplug (baseline JIT) prologue, the
10+
// half-constructed frame is walked as a GC root and a garbage slot value is
11+
// dereferenced — SIGSEGV, `KERN_INVALID_ADDRESS at 0x6`, faulting in
12+
// `ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers` <-
13+
// `InternalFrame::Iterate`. It surfaces here as a jest WORKER dying
14+
// (`A jest worker process was terminated ... signal=SIGSEGV`), which jest
15+
// then attributes to whichever test file that worker happened to be running
16+
// — an innocent bystander, not the trigger. Reproduced three times on this
17+
// codebase (crash reports under ~/Library/Logs/DiagnosticReports).
18+
//
19+
// Upstream: https://github.com/nodejs/node/issues/62393 — fixed in Node
20+
// 25.0.0+, NOT backported to 24.x as of 24.18.0. `--no-sparkplug` removes the
21+
// baseline-JIT stage the race lives in.
22+
//
23+
// The flag cannot go in NODE_OPTIONS (`--no-sparkplug is not allowed in
24+
// NODE_OPTIONS`), and `node_modules/.bin/jest` is a shell shim that swallows
25+
// node flags — hence invoking `jest.js` through node directly. jest-worker
26+
// forwards `process.execArgv` to its children, so all workers inherit it.
27+
//
28+
// REMOVE THIS once the fix reaches our Node floor (a 24.x backport, or
29+
// `engines` moving to >= 25). Verify with the flag dropped before deleting:
30+
// the bug is probabilistic, roughly 0.5 crashes/day under continuous
31+
// parallel use here.
32+
// ---------------------------------------------------------------------------
333

434
module.exports = {
535
// All imported modules in your tests should be mocked automatically

‎packages/api/package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dev": "cd ../../apps/crowi-runner && NODE_ENV=development tsx watch --tsconfig ../../packages/api/tsconfig.json --clear-screen=false --env-file-if-exists=../../.env ../../packages/api/src/app.ts",
4040
"lint": "eslint src/ --ext .ts,.tsx",
4141
"lint:fix": "eslint src/ --ext .ts,.tsx --fix",
42-
"test": "env -u DEBUG TZ=UTC jest --maxWorkers=5 ${CROWI_TEST_JSON_OUTPUT_FILE:+--json --outputFile=$CROWI_TEST_JSON_OUTPUT_FILE}",
42+
"test": "env -u DEBUG TZ=UTC node --no-sparkplug node_modules/jest/bin/jest.js --maxWorkers=5 ${CROWI_TEST_JSON_OUTPUT_FILE:+--json --outputFile=$CROWI_TEST_JSON_OUTPUT_FILE}",
4343
"test:server": "env -u DEBUG jest lib --maxWorkers=5",
4444
"coverage": "npm test -- --coverage",
4545
"build": "tsc && tsc-alias",
@@ -90,6 +90,8 @@
9090
"zod": "catalog:"
9191
},
9292
"devDependencies": {
93+
"@aws-sdk/client-s3": "^3.1060.0",
94+
"@aws-sdk/s3-request-presigner": "^3.1060.0",
9395
"@crowi/plugin-slack": "workspace:*",
9496
"@crowi/tsconfig": "workspace:*",
9597
"@hocuspocus/provider": "^4.0.0",
@@ -110,8 +112,10 @@
110112
"faker": "^4.1.0",
111113
"form-data": "^4.0.6",
112114
"jest": "catalog:",
115+
"jest-environment-node": "catalog:",
113116
"mdast-util-to-hast": "^13.2.1",
114117
"mongodb-memory-server": "^11.2.0",
118+
"nodemailer": "^9.0.1",
115119
"regenerator-runtime": "^0.13.3",
116120
"supertest": "^7.2.2",
117121
"ts-jest": "catalog:",

‎pnpm-lock.yaml‎

Lines changed: 57 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ catalog:
1212
"@types/node": ^24
1313
jest: ^29.7.0
1414
"@types/jest": ^29.5.14
15+
jest-environment-node: ^29.7.0
1516
ts-jest: ^29.3.4
1617
zod: ^4.4.3
1718
"@modelcontextprotocol/sdk": ^1.29.0

0 commit comments

Comments
 (0)