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: keep zombie update PIDs blocked (#5134)
[._.]/ Adam Eivyf9cac1729564
diff --git a/server/lib/detachedSpawn.js b/server/lib/detachedSpawn.jsindex 8553d5766d..b69ecdbdd2 100644--- a/server/lib/detachedSpawn.js+++ b/server/lib/detachedSpawn.js@@ -550,7 +550,19 @@ const readControlFile = (path) => readFile(path, 'utf8').catch((err) => {throw err;});-const processMatches = async (pid, { executable, args }) => {+const processCommandMatches = (command, { executable, args }) => {+ // A zombie still owns its PID, so it cannot be a recycled unrelated process.+ // Keep the control dir blocked until the supervisor writes the exit sentinel;+ // otherwise its late write can land in a newly-truncated control directory.+ if (/(?:^|\s)<(?:defunct|exiting)>(?:\s|$)/.test(command)) return true;+ const actualExecutable = command.split(/\s+/, 1)[0];+ if (basename(actualExecutable) !== basename(executable)) return false;+ if (!Array.isArray(args)) return true;+ const actualArgs = command.slice(actualExecutable.length).trim();+ return actualArgs === args.map(String).join(' ');+};++const processMatches = async (pid, expectedProcess) => {const { stdout } = await execFileAsync('ps', ['-ww', '-p', String(pid), '-o', 'command='], safeChildProcessOptions({ timeout: 5000 })).catch((err) => {@@ -561,13 +573,11 @@ const processMatches = async (pid, { executable, args }) => {});const command = stdout.trim();if (!command) return false;- const actualExecutable = command.split(/\s+/, 1)[0];- if (basename(actualExecutable) !== basename(executable)) return false;- if (!Array.isArray(args)) return true;- const actualArgs = command.slice(actualExecutable.length).trim();- return actualArgs === args.map(String).join(' ');+ return processCommandMatches(command, expectedProcess);};+export const __detachedSpawnTesting = { processCommandMatches };+export async function isDetachedRunning(controlDir, expectedProcess = null) {const pidRaw = await readControlFile(join(controlDir, 'pid'));const pid = Number.parseInt(pidRaw, 10);diff --git a/server/lib/detachedSpawn.test.js b/server/lib/detachedSpawn.test.jsindex 067f0021e8..c87290cffd 100644--- a/server/lib/detachedSpawn.test.js+++ b/server/lib/detachedSpawn.test.js@@ -6,7 +6,7 @@ import { ChildProcess, execFile } from './childProcess.js';import { promisify } from 'util';import { pinPlatform } from './testHelper.js';import { killProcessTree } from './bufferedSpawn.js';-import { spawnDetached, reapDetached, reapAndCleanDetachedDirs, reattachDetached, isReattachable, isDetachedRunning } from './detachedSpawn.js';+import { spawnDetached, reapDetached, reapAndCleanDetachedDirs, reattachDetached, isReattachable, isDetachedRunning, __detachedSpawnTesting } from './detachedSpawn.js';// Only the win32 fallback's kill() reaches killProcessTree, so stubbing it is// inert for every POSIX test here — and it lets the win32 test assert the@@ -480,6 +480,16 @@ describe('isReattachable', () => {});describe('isDetachedRunning', () => {+ it.each(['<defunct>', 'bash <defunct>', '[bash] <defunct>', 'bash <exiting>'])(+ 'keeps a zombie PID blocked until its supervisor writes the exit sentinel: %s',+ (command) => {+ expect(__detachedSpawnTesting.processCommandMatches(command, {+ executable: 'bash',+ args: ['/example/update.sh']+ })).toBe(true);+ }+ );+it.runIf(IS_POSIX)('is true while the recorded child is still alive with no exit sentinel', async () => {const controlDir = await tmpControlDir();const handle = await spawnDetached('sh', ['-c', 'sleep 30'], { controlDir, pollMs: 25 });