The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop-core): a pre-exec child of the backend is not a second backend
teknium120300f0d475d
diff --git a/apps/desktop/e2e/core/boot-lifecycle.spec.ts b/apps/desktop/e2e/core/boot-lifecycle.spec.tsindex f6c641c61de..5b1c23dcb78 100644--- a/apps/desktop/e2e/core/boot-lifecycle.spec.ts+++ b/apps/desktop/e2e/core/boot-lifecycle.spec.ts@@ -42,6 +42,7 @@ const nonce = Math.random().slice(2, 8).replace(/[^a-z0-9]/g, 'x').padEnd(4, 'q')+const U = (n: number) => `U${n}-${nonce}`const A = (n: number) => `A${n}-${nonce}`const TOOL_TAG = `core-orphan-${nonce}`@@ -79,15 +80,29 @@ test('boot handshake, supervised respawn, and zero orphans on quit', async () =>const ws = recordWebSockets(page)let closed = false- // Background census: every backend pid ever observed.- const seenBackends = new Set<number>()+ // Background census: every backend pid ever observed, with its parent,+ // command line and lifetime so an unexpected extra pid explains itself.+ const seen = new Map<number, { ppid: number; cmdline: string; first: number; last: number; samples: number }>()+ const t0 = Date.now()const census = setInterval(() => {+ const now = Date.now() - t0+for (const proc of backendProcesses(sandbox)) {- seenBackends.add(proc.pid)+ const entry = seen.get(proc.pid)++ if (entry) {+ entry.last = now+ entry.samples+++ } else {+ seen.set(proc.pid, { ppid: proc.ppid, cmdline: proc.cmdline.slice(0, 200), first: now, last: now, samples: 1 })+ }}}, 100)+ const describeSeen = () =>+ JSON.stringify([...seen].map(([pid, e]) => ({ pid, ...e, electronPid: app.process().pid })))+const finished = (marker: string, step = 0) =>expect.poll(() => provider.completions.some(c => c.marker === marker && c.step === step && c.finished), {@@ -110,7 +125,7 @@ test('boot handshake, supervised respawn, and zero orphans on quit', async () =>session.sessionId = await currentSessionId(page)session.expectUserMarkers.push(U(1))await assertTranscriptOracle(page, ws, provider, session, 'boot first turn')- expect(seenBackends.size, `backend pids seen during boot: ${[...seenBackends]}`).toBe(1)+ expect(seen.size, `backend pids seen during boot: ${describeSeen()}`).toBe(1)})await test.step('kill -9 backend: exactly one supervised respawn, app serves again', async () => {@@ -139,7 +154,7 @@ test('boot handshake, supervised respawn, and zero orphans on quit', async () =>expect(alive.length, `live backends after recovery: ${JSON.stringify(alive)}`).toBe(1)// Initial + exactly one replacement, ever — a crash loop or a racing// second spawn would add pids here even if they died again.- expect(seenBackends.size, `backend pids ever seen: ${[...seenBackends]}`).toBe(2)+ expect(seen.size, `backend pids ever seen: ${describeSeen()}`).toBe(2)})await test.step('quit mid-turn with a running tool child: zero processes remain', async () => {diff --git a/apps/desktop/e2e/core/harness.ts b/apps/desktop/e2e/core/harness.tsindex a1e24a34a3e..9dfe9c3f1e1 100644--- a/apps/desktop/e2e/core/harness.ts+++ b/apps/desktop/e2e/core/harness.ts@@ -157,10 +157,12 @@ export async function launchCoreApp(env: Record<string, string>): Promise<{ app:// Keep the main process's stdout/stderr (backend supervisor lines included)// so a boot that never becomes interactive fails with its own story.const lines: string[] = []+const collect = (chunk: Buffer) => {lines.push(...chunk.toString('utf8').split('\n').filter(Boolean))lines.splice(0, Math.max(0, lines.length - 200))}+app.process().stdout?.on('data', collect)app.process().stderr?.on('data', collect)APP_LOGS.set(app, lines)@@ -228,11 +230,25 @@ export function sandboxProcesses(sandbox: CoreSandbox): ProcInfo[] {return out}-/** The `hermes serve` backend(s) spawned for this sandbox. */+/**+ * The `hermes serve` backend(s) spawned for this sandbox.+ *+ * A child of the backend still shows the backend's argv and environ between+ * fork and exec, and the backend forks ~40 probes per boot (git, ps,+ * ldconfig/gcc, pip): a 100 ms sampler catches one in that window every few+ * boots. Such a child is not a second backend, so a serve process whose parent+ * is itself a serve process is excluded. A real second spawn has the+ * supervisor (Electron main) as its parent, and a pre-exec child orphaned by a+ * dead backend is reparented away and still counted.+ */export function backendProcesses(sandbox: CoreSandbox): ProcInfo[] {- return sandboxProcesses(sandbox).filter(+ const serve = sandboxProcesses(sandbox).filter(proc => / serve( |$)/.test(proc.cmdline) && !/electron/i.test(proc.cmdline.split(' ')[0]))++ const pids = new Set(serve.map(proc => proc.pid))++ return serve.filter(proc => !pids.has(proc.ppid))}// ─── WebSocket recorder ─────────────────────────────────────────────────