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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: flush cancelled-pregate output before the self-signal (#12641)
[._.]/ Adam Eivye8ffad9a7e6a
diff --git a/scripts/pregate.js b/scripts/pregate.jsindex 9083f428ab..e57ee7d321 100644--- a/scripts/pregate.js+++ b/scripts/pregate.js@@ -750,17 +750,17 @@ async function main() {finishedAt: new Date().toISOString(),});writePregateReport(REPO_ROOT, report);+ // Synchronous: a piped stderr is written asynchronously, and the self-signal+ // below would drop these lines before they flush.if (tree !== null && !report.treeStable) {- console.warn(`⚠️ The working tree changed while pregate ran (${tree.slice(0, 12)} → ${treeAfterRun?.slice(0, 12) ?? 'unhashable'}); the receipt covers the tree it started with.`);+ writeSync(2, `⚠️ The working tree changed while pregate ran (${tree.slice(0, 12)} → ${treeAfterRun?.slice(0, 12) ?? 'unhashable'}); the receipt covers the tree it started with.\n`);}+ if (failure) writeSync(2, `${failure}\n📄 Receipt: ${PREGATE_REPORT_PATH}\n`);+ else if (owner.signal) writeSync(2, `⚠️ Received ${owner.signal} after every stage passed; the receipt records that completed run.\n`);owner.release();- if (failure) {- console.error(failure);- console.error(`📄 Receipt: ${PREGATE_REPORT_PATH}`);- }// Every owned group has settled and the receipt is written; end the way the- // caller's signal asked. A signal after the last stage leaves its truthful receipt.+ // caller's signal asked.if (owner.signal) process.kill(process.pid, owner.signal);if (failure) process.exit(exitCode);diff --git a/scripts/pregate.test.js b/scripts/pregate.test.jsindex 9a461aa603..2ff21a5f30 100644--- a/scripts/pregate.test.js+++ b/scripts/pregate.test.js@@ -344,6 +344,7 @@ describe('pregate hidden-content invocation', () => {const heartbeat = join(scratch, 'heartbeat');write('scripts/scan-diff-hidden-content.js', `import { spawn } from 'child_process';+ import { existsSync } from 'fs';const straggler = spawn(process.execPath, ['-e', "process.on('SIGINT', () => {}); process.on('SIGTERM', () => {});"+ " setInterval(() => require('fs').appendFileSync(process.env.FIXTURE_HEARTBEAT, '.'), 10);"], { stdio: 'ignore' });const launched = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore', detached: true });@@ -353,7 +354,12 @@ describe('pregate hidden-content invocation', () => {};process.on('SIGINT', settle);process.on('SIGTERM', settle);- setTimeout(() => console.log('fixture-stage-ready ' + JSON.stringify([process.pid, straggler.pid, launched.pid])), 200);+ // Ready only once the straggler is provably writing.+ const ready = setInterval(() => {+ if (!existsSync(process.env.FIXTURE_HEARTBEAT)) return;+ clearInterval(ready);+ console.log('fixture-stage-ready ' + JSON.stringify([process.pid, straggler.pid, launched.pid]));+ }, 10);setInterval(() => {}, 1000);`);const unrelated = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore', detached: true });@@ -377,13 +383,16 @@ describe('pregate hidden-content invocation', () => {}});try {- // `exit`, not `close`: a surviving descendant would hold the pipes open.+ const closed = new Promise((resolve) => npm.once('close', resolve));const result = await new Promise((resolve, reject) => {npm.once('error', reject);npm.once('exit', (status, exitSignal) => resolve({ status, signal: exitSignal }));});+ // Liveness at `exit` is the contract. Output is read after `close`, which+ // a surviving descendant holding the pipes would delay, hence the bound.expect(owned).toHaveLength(3);expect(owned.filter(alive)).toEqual([]);+ await Promise.race([closed, new Promise((resolve) => setTimeout(resolve, 5000))]);expect(result.status === null ? result.signal : result.status).not.toBe(0);expect(stderr).toMatch(new RegExp(`stage="hidden-content scan" owner_pid=\\d+ child_pid=${owned[0]} received_signal=${signal}`));expect(stderr).toContain(`stage="hidden-content scan" cancelled by ${signal}; its process group has exited.`);