Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: npm run pregate no longer returns before pregate settles on a group SIGTERM (#12670)

[._.]/ Adam Eivy22ffc3b3e8d3
diff --git a/.gitattributes b/.gitattributes
index a942e83ebd..68c0a51d5b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,6 +1,7 @@
# Pin LF line endings for text files cross-platform
* text=auto eol=lf
*.sh text eol=lf
+*.cmd text eol=crlf
# Binary file declarations
*.png binary
diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md
index 85c8a0e66b..da4ec63507 100644
--- a/docs/CONTRIBUTING.md
+++ b/docs/CONTRIBUTING.md
@@ -129,6 +129,13 @@ same signal. After every stage, on POSIX, pregate also kills anything still
left in that stage's group, with a warning, so no stage's processes run into
the next one or past pregate.
+`npm run pregate` is `exec node scripts/pregate.js`, so no shell wrapper sits
+between npm and pregate: a SIGTERM sent to the whole process group (a CI
+cancel, `kill -TERM -<pgid>`) cannot kill the wrapper and let npm return while
+pregate is still settling its stage. On Windows, where `cmd.exe` has no
+`exec`, the repository-root `exec.cmd` shim (found first in the working
+directory) runs the same command.
+
After the push (and, when you open the pull request yourself, before
`gh pr create`), `node scripts/pregate-attest.js` posts that receipt as a
`pregate` commit status on the pushed head, bound to the validated tree and
diff --git a/exec.cmd b/exec.cmd
new file mode 100644
index 0000000000..dbc7ad84d0
--- /dev/null
+++ b/exec.cmd
@@ -0,0 +1 @@
+@%*
diff --git a/package.json b/package.json
index 14c6fc4184..2d0b68a571 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
"reset:password": "node scripts/reset-password.js",
"update": "node -e \"const{spawnSync:s}=require('child_process');const w=process.platform==='win32';const r=s(w?'powershell':'bash',w?['-NoProfile','-ExecutionPolicy','Bypass','-File','update.ps1']:['update.sh'],{stdio:'inherit'});process.exit(r.status??1)\"",
"test": "npm test --prefix server && npm test --prefix client",
- "pregate": "node scripts/pregate.js",
+ "pregate": "exec node scripts/pregate.js",
"quality:snapshot": "node scripts/publish-quality-snapshot.js",
"scan:hidden-content": "node scripts/scan-diff-hidden-content.js",
"eidoverse:assay": "node scripts/eidoverse-resilience-assay.js",
diff --git a/scripts/pregate.test.js b/scripts/pregate.test.js
index acb9f2302e..e7ff030d56 100644
--- a/scripts/pregate.test.js
+++ b/scripts/pregate.test.js
@@ -161,7 +161,9 @@ describe('pregate hidden-content invocation', () => {
mkdirSync(dirname(join(root, path)), { recursive: true });
copyFileSync(join(REPO_ROOT, path), join(root, path));
}
- write('package.json', '{"type":"module","scripts":{"pregate":"node scripts/pregate.js"}}\n');
+ // The real npm script and its Windows shim, so the harness exercises what `npm run pregate` runs.
+ write('package.json', JSON.stringify({ type: 'module', scripts: { pregate: JSON.parse(readFileSync(join(REPO_ROOT, 'package.json'), 'utf8')).scripts.pregate } }) + '\n');
+ copyFileSync(join(REPO_ROOT, 'exec.cmd'), join(root, 'exec.cmd'));
// The receipt lands under /.cache/, which the real repository ignores too.
write('.gitignore', 'node_modules\n/.cache/\n');
for (const workspace of ['', 'client', 'server', 'autofixer']) {
@@ -335,12 +337,16 @@ describe('pregate hidden-content invocation', () => {
}
});
- // #12641: a Ctrl-C reaches pregate from the terminal group AND from npm's
- // forwarding; the duplicate used to kill pregate before it signalled the
- // stage, orphaning the runner. The fixture stage mirrors run-ci-tests.js: a
+ // #12641/#12670: a Ctrl-C reaches pregate from the terminal group AND from
+ // npm's forwarding; the duplicate used to kill pregate before it signalled the
+ // stage, orphaning the runner. A group SIGTERM also kills the `sh -c` wrapper
+ // npm runs the script under (dash on Linux does not always exec its last
+ // command), and npm exits the moment that wrapper dies. The simulated shell
+ // below never execs on its own, so only the script's own `exec` keeps the
+ // wrapper out of the way. The fixture stage mirrors run-ci-tests.js: a
// launcher that settles its own separately grouped child on a signal, plus
// an in-group descendant that ignores signals and keeps writing.
- it.skipIf(process.platform === 'win32').each(['SIGINT', 'SIGTERM'])('settles every owned stage process before a %s through npm finishes', async (signal) => {
+ it.skipIf(process.platform === 'win32').each(['SIGINT', 'SIGTERM'])('settles every owned stage process before npm exits on a group %s', async (signal) => {
const heartbeat = join(scratch, 'heartbeat');
write('scripts/scan-diff-hidden-content.js', `
import { spawn } from 'child_process';
@@ -363,8 +369,11 @@ describe('pregate hidden-content invocation', () => {
setInterval(() => {}, 1000);
`);
const unrelated = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore', detached: true });
+ const nonExecShell = join(scratch, 'non-exec-shell');
+ writeFileSync(nonExecShell, '#!/bin/sh\nexec /bin/sh "$1" "$2 ; :"\n', { mode: 0o755 });
const npm = spawn('npm', ['run', 'pregate', '--', '--base', base, '--skip-lint'], {
- cwd: root, stdio: ['ignore', 'pipe', 'pipe'], detached: true, env: { ...process.env, FIXTURE_HEARTBEAT: heartbeat },
+ cwd: root, stdio: ['ignore', 'pipe', 'pipe'], detached: true,
+ env: { ...process.env, FIXTURE_HEARTBEAT: heartbeat, npm_config_script_shell: nonExecShell },
});
const alive = (pid) => {
try { process.kill(pid, 0); return true; } catch (error) { return error.code !== 'ESRCH'; }
@@ -389,13 +398,7 @@ describe('pregate hidden-content invocation', () => {
npm.once('error', reject);
npm.once('exit', (status, exitSignal) => resolve({ status, signal: exitSignal }));
});
- // npm's own exit is not the boundary: a SIGTERM to the group kills the
- // `sh -c` wrapper npm runs the script under, and npm then exits at once.
- // The contract is that pregate itself does not finish before its stage
- // group settled, so liveness is checked the moment pregate is gone.
- for (const until = Date.now() + 15_000; alive(pregatePid) && Date.now() < until;) {
- await new Promise((resolve) => setTimeout(resolve, 10));
- }
+ // The boundary is npm's own exit: nothing pregate owns may outlive it.
expect(alive(pregatePid)).toBe(false);
expect(owned).toHaveLength(3);
expect(owned.filter(alive)).toEqual([]);