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: reclaim dead-owner roots when an unrelated process row is incomplete (#13301)

[._.]/ Adam Eivy824e3a0a65b1
diff --git a/scripts/lib/testProcessAttribution.js b/scripts/lib/testProcessAttribution.js
index 958c0b0062..5ad0498ee2 100644
--- a/scripts/lib/testProcessAttribution.js
+++ b/scripts/lib/testProcessAttribution.js
@@ -6,14 +6,21 @@ import { fileURLToPath } from 'node:url';
import { readTestProcesses } from './testOwnedProcesses.js';
export const PROCESS_OWNERS_DIR = '.process-owners';
-const repo = fileURLToPath(new URL('../../', import.meta.url));
+// Vitest can load this module from a fixture whose import.meta.url is not a
+// file URL. Suite identity is optional; a missing root must not throw at import.
+const repo = (() => {
+ try {
+ const url = new URL('../../', import.meta.url);
+ return url.protocol === 'file:' ? fileURLToPath(url) : null;
+ } catch { return null; }
+})();
const spawned = channel('child_process');
const limit = 64;
const safeSuite = value => typeof value === 'string' && value.length <= 240
&& /^(?:server|client|scripts|lib|autofixer)\/(?:[\w.-]+\/)*[\w.-]+\.(?:test|spec)\.[cm]?[jt]sx?$/.test(value)
&& !value.split('/').includes('..');
const suiteIdentity = value => {
- if (typeof value !== 'string') return 'unavailable';
+ if (!repo || typeof value !== 'string') return 'unavailable';
const path = relative(repo, value).split(sep).join('/');
return safeSuite(path) ? path : 'unavailable';
};
diff --git a/scripts/lib/vitestStaleRunRoots.js b/scripts/lib/vitestStaleRunRoots.js
index 0c41cdae9b..30b21c2d83 100644
--- a/scripts/lib/vitestStaleRunRoots.js
+++ b/scripts/lib/vitestStaleRunRoots.js
@@ -290,11 +290,13 @@ export function sweepStaleRunRoots(tmpRoot, { prefix = 'pvt-', now = Date.now(),
if (typeof prefix !== 'string' || !/^[a-zA-Z0-9-]+-$/.test(prefix)) {
throw new Error('Owned temp prefix must be a nonempty name ending in a hyphen');
}
- // A dead runner does not prove its children exited. On POSIX, a partial
- // inventory also cannot recover identities whose pending stamp failed.
- // Windows has no process reader or signal-based containment here.
+ // No snapshot at all (reader down, or ancestry rejected) cannot prove a
+ // dead owner's children exited, so POSIX keeps those roots. An unrelated
+ // unreadable row inside an otherwise real snapshot must not do the same:
+ // dead owners are still reclaimed, while pid-less roots wait for a complete
+ // inventory. Preserved children and unsettled pending identities stay either way.
const { inspected, preserved, records } = sweepOrphanedTestProcesses(tmpRoot, { prefix, now, probe, read, terminate });
- if (!inspected && process.platform !== 'win32') return;
+ if (!records && process.platform !== 'win32') return;
let names;
try {
names = readdirSync(tmpRoot);
diff --git a/scripts/testOwnedProcessRecovery.test.js b/scripts/testOwnedProcessRecovery.test.js
index 0e9fc8aa24..fc359b79c3 100644
--- a/scripts/testOwnedProcessRecovery.test.js
+++ b/scripts/testOwnedProcessRecovery.test.js
@@ -101,6 +101,29 @@ describe('test process ownership boundaries', () => {
} finally { rmSync(host, { recursive: true, force: true }); }
});
+ it('reclaims a dead owner when an unrelated process row is incomplete', () => {
+ const host = mkdtempSync(join(tmpdir(), 'recovery-unrelated-'));
+ const dead = join(host, 'pvt-dead');
+ const aged = join(host, 'pvt-aged');
+ const old = new Date(Date.now() - STALE_ROOT_AGE_MS - 60000);
+ try {
+ mkdirSync(dead);
+ writeFileSync(join(dead, '.owner.pid'), '2147483646 0\n');
+ mkdirSync(aged);
+ utimesSync(aged, old, old);
+ sweepStaleRunRoots(host, {
+ read: () => [
+ { pid: process.pid, ppid: process.ppid, args: [], env: {} },
+ { pid: process.ppid, ppid: 1, args: [], env: {} },
+ { pid: 900003, ownershipComplete: false },
+ ],
+ probe: () => false,
+ });
+ expect(existsSync(dead)).toBe(false);
+ expect(existsSync(aged)).toBe(true);
+ } finally { rmSync(host, { recursive: true, force: true }); }
+ });
+
it('retains pending identities through partial inventories until terminal evidence permits root removal', () => {
const host = mkdtempSync(join(tmpdir(), 'recovery-pending-'));
const root = join(host, 'pvt-owned'); mkdirSync(root);