You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/09/04 10:36:12 UTC

(maka) branch diagnose/windows-local-remote-access-ebusy created (now 6540936f8b)

This is an automated email from the ASF dual-hosted git repository.

M4n5ter pushed a change to branch diagnose/windows-local-remote-access-ebusy
in repository https://gitbox.apache.org/repos/asf/maka.git


      at 6540936f8b fix(desktop): stabilize Windows remote access setup

This branch includes the following new commits:

     new 6540936f8b fix(desktop): stabilize Windows remote access setup

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


(maka) 01/01: fix(desktop): stabilize Windows remote access setup

Posted by wy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

M4n5ter pushed a commit to branch diagnose/windows-local-remote-access-ebusy
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 6540936f8b81b127b6258ff332aa91b4b550ca99
Author: M4n5ter <m4...@gmail.com>
AuthorDate: Fri Sep 4 18:35:58 2026 +0800

    fix(desktop): stabilize Windows remote access setup
---
 .../__tests__/runtime-host-local-operator.test.ts  | 69 ++++++++++++++++++++++
 .../src/main/runtime-host-local-operator.ts        | 19 +++++-
 .../cli/src/runtime-host-package-deployment.ts     |  1 +
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/apps/desktop/src/main/__tests__/runtime-host-local-operator.test.ts b/apps/desktop/src/main/__tests__/runtime-host-local-operator.test.ts
index 8b57c82549..5a08954585 100644
--- a/apps/desktop/src/main/__tests__/runtime-host-local-operator.test.ts
+++ b/apps/desktop/src/main/__tests__/runtime-host-local-operator.test.ts
@@ -133,6 +133,75 @@ test('local setup forwards the exact development archive evidence', async (t) =>
   assert.equal(environment?.[RUNTIME_HOST_SETUP_SOURCE_PACKAGE_INTEGRITY_ENV], integrity);
 });
 
+test('local setup scratch cleanup cannot replace its framed outcome', async (t) => {
+  const frames = [
+    {
+      schemaVersion: 1 as const,
+      sequence: 0,
+      kind: 'complete' as const,
+      version: '0.2.0',
+      serviceId: 'b'.repeat(64),
+      deploymentId: '00000000-0000-4000-8000-000000000001',
+      operator: OPERATOR,
+      rootPath: '/tmp/maka/root',
+      rootId: 'a'.repeat(64),
+      endpoint: 'ws://127.0.0.1:7443/runtime-host',
+      credentialId: 'credential-1',
+      credential: 'secret-access-token',
+    },
+    {
+      schemaVersion: 1 as const,
+      sequence: 0,
+      kind: 'error' as const,
+      error: { code: 'setup_failed', message: 'primary setup failure' },
+    },
+  ];
+  let invocation = 0;
+  let cleanupCount = 0;
+  const spawnProcess = (() => {
+    const child = new EventEmitter() as ReturnType<typeof spawn>;
+    const stdout = new PassThrough();
+    const stderr = new PassThrough();
+    const frame = frames[invocation++];
+    Object.assign(child, { pid: 1234, stdout, stderr, kill: () => true });
+    process.nextTick(() => {
+      stdout.end(encodeRuntimeHostSetupFrame(frame));
+      stderr.end();
+      child.emit('close', frame.kind === 'complete' ? 0 : 1, null);
+    });
+    return child;
+  }) as typeof spawn;
+  const operator = createDesktopRuntimeHostLocalOperator({
+    environment: { PATH: process.env.PATH },
+    spawnProcess,
+    removeSetupWorkingDirectory: async (path) => {
+      cleanupCount += 1;
+      await rm(path, { recursive: true, force: true });
+      throw new Error('scratch cleanup failed');
+    },
+  });
+  t.after(() => operator.close());
+  const setup = {
+    setupPackage: { kind: 'npm' as const, specifier: 'maka-agent@0.2.0' },
+    clientDataRoot: '/tmp/maka/client',
+    rootPath: '/tmp/maka/root',
+    principalId: 'desktop-owner:pairing',
+    expectedTarget: {
+      serviceId: 'b'.repeat(64),
+      rootPath: '/tmp/maka/root',
+      rootId: 'a'.repeat(64),
+    },
+  };
+
+  const complete = await operator.runSetup(setup, () => undefined);
+  assert.equal(complete.kind, 'complete');
+  await assert.rejects(
+    operator.runSetup(setup, () => undefined),
+    /primary setup failure/u,
+  );
+  assert.equal(cleanupCount, 2);
+});
+
 test('Windows npm discovery cannot outlive setup cancellation', async (t) => {
   const originalPlatform = process.platform;
   const fixtureRoot = await mkdtemp(join(tmpdir(), 'maka-windows-npm-lookup-'));
diff --git a/apps/desktop/src/main/runtime-host-local-operator.ts b/apps/desktop/src/main/runtime-host-local-operator.ts
index 4b00e73885..1ade55cedc 100644
--- a/apps/desktop/src/main/runtime-host-local-operator.ts
+++ b/apps/desktop/src/main/runtime-host-local-operator.ts
@@ -62,6 +62,8 @@ import {
 const SETUP_TIMEOUT_MS = 10 * 60_000;
 const SETUP_FRAME_PENDING_MAX = 20 * 1024;
 const STDERR_MAX_BYTES = 64 * 1024;
+const SETUP_CLEANUP_MAX_RETRIES = 10;
+const SETUP_CLEANUP_RETRY_DELAY_MS = 100;
 const WINDOWS_NPM_RESOLUTION_SCRIPT = String.raw`
 const { statSync } = require('node:fs');
 const path = require('node:path').win32;
@@ -199,6 +201,7 @@ export function createDesktopRuntimeHostLocalOperator(input: {
   readonly spawnProcess?: typeof spawn;
   readonly setupTimeoutMs?: number;
   readonly terminateProcess?: typeof terminateChildProcessTree;
+  readonly removeSetupWorkingDirectory?: (path: string) => Promise<void>;
 } = {}): {
   runSetup(
     setup: DesktopRuntimeHostLocalSetupInput,
@@ -267,6 +270,15 @@ export function createDesktopRuntimeHostLocalOperator(input: {
   let closed = false;
   const closing = new AbortController();
   const terminate = input.terminateProcess ?? terminateChildProcessTree;
+  const removeSetupWorkingDirectory =
+    input.removeSetupWorkingDirectory ??
+    ((path: string) =>
+      rm(path, {
+        recursive: true,
+        force: true,
+        maxRetries: SETUP_CLEANUP_MAX_RETRIES,
+        retryDelay: SETUP_CLEANUP_RETRY_DELAY_MS,
+      }));
 
   return {
     async runSetup(setup, onProgress) {
@@ -302,7 +314,12 @@ export function createDesktopRuntimeHostLocalOperator(input: {
           active,
         });
       } finally {
-        await rm(workingDirectory, { recursive: true, force: true });
+        try {
+          await removeSetupWorkingDirectory(workingDirectory);
+        } catch {
+          // The private scratch directory is not part of the setup transaction.
+          // Its cleanup must not replace the operator's framed result or error.
+        }
       }
     },
     runPeer(command) {
diff --git a/packages/cli/src/runtime-host-package-deployment.ts b/packages/cli/src/runtime-host-package-deployment.ts
index 18d1968b41..ff2f7a7cf8 100644
--- a/packages/cli/src/runtime-host-package-deployment.ts
+++ b/packages/cli/src/runtime-host-package-deployment.ts
@@ -369,6 +369,7 @@ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
   await rm(path, { recursive: true, force: true, maxRetries: 100, retryDelay: 100 });
 })().catch(() => { process.exitCode = 1; });`;
   const cleanup = spawn(process.execPath, ['-e', script, path, String(process.pid)], {
+    cwd: dirname(process.execPath),
     detached: true,
     stdio: 'ignore',
     windowsHide: true,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org