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: retry transient failures removing the owned capture browser profile so close only resolves once it is gone (#10181)
Adam Eivy09f0ac776115
diff --git a/server/services/htmlComposition/ownedBrowser.js b/server/services/htmlComposition/ownedBrowser.jsindex bfa4ab39b5..af6776752a 100644--- a/server/services/htmlComposition/ownedBrowser.js+++ b/server/services/htmlComposition/ownedBrowser.js@@ -6,6 +6,21 @@ import { safeChildProcessOptions } from '../../lib/processEnv.js';import { killWithEscalation } from '../../lib/killWithEscalation.js';import { browserExecutablePath } from '../../lib/browserConfig.js';+// Chrome helpers (crashpad, GPU) can still be writing into the profile for a+// moment after the browser's close event, so a recursive rm may lose the race+// with ENOTEMPTY/EBUSY. Retry until the directory is really gone, so a resolved+// close always means the profile no longer exists.+const TRANSIENT_RM = new Set(['ENOTEMPTY', 'EBUSY', 'EPERM', 'EMFILE']);+async function removeProfile(profile, attempts = 20, delayMs = 50) {+ for (let attempt = 1; ; attempt++) {+ try { return await rm(profile, { recursive: true, force: true }); }+ catch (error) {+ if (attempt >= attempts || !TRANSIENT_RM.has(error?.code)) throw error;+ await new Promise(resolve => setTimeout(resolve, delayMs));+ }+ }+}+// Only this child/profile belong to the render. Never discover processes by// name, attach to a user profile, or restart the managed browsing service.export async function launchCompositionBrowser({ signal, startupMs = 20000, shutdownMs = 5000 } = {}) {@@ -50,7 +65,7 @@ export async function launchCompositionBrowser({ signal, startupMs = 20000, shut// Wait for the process and our pipe to close before removing its profile.if (!proc || closed) {proc?.removeListener('error', onError);- await rm(profile, { recursive: true, force: true });+ await removeProfile(profile);}}})();diff --git a/server/services/htmlComposition/ownedBrowser.test.js b/server/services/htmlComposition/ownedBrowser.test.jsindex 56b1305176..0dd1d44db8 100644--- a/server/services/htmlComposition/ownedBrowser.test.js+++ b/server/services/htmlComposition/ownedBrowser.test.js@@ -126,4 +126,12 @@ describe('owned composition capture browser lifecycle', () => {}await expect(access(profile)).rejects.toThrow();});++ it('retries a transient profile removal failure so a resolved close means the profile is gone', async () => {+ const owner = await launchCompositionBrowser();+ vi.mocked(rm).mockRejectedValueOnce(Object.assign(new Error('busy'), { code: 'ENOTEMPTY' }));+ await owner.close();+ expect(rm).toHaveBeenCalledTimes(2);+ await expect(access(profile)).rejects.toThrow();+ });});