Skip to content

Commit a1edaef

Browse files
authored
🤖 Remove sync fs operations and path-finding from runtime (#447)
Eliminates blocking filesystem operations in the runtime layer and removes unnecessary path-finding complexity. ## Changes **Removed sync fs operations:** - Replaced `fs.existsSync()` + `fs.mkdirSync()` with `fsPromises.access()` + `fsPromises.mkdir()` in `LocalRuntime.ts` - All filesystem operations in runtime are now async, preventing main thread blocking **Removed path-finding module:** - Deleted `executablePaths.ts` (57 lines) that was checking hardcoded paths for `bash` and `nice` - Updated `LocalRuntime.ts` and `SSHRuntime.ts` to rely on system PATH - Simplifies codebase by 74 lines total ## Verification - ✅ TypeScript compilation passes - ✅ All unit tests pass (same results as before) - ✅ No sync fs operations remain in runtime files _Generated with `cmux`_
1 parent 9db5f11 commit a1edaef

File tree

3 files changed

+12
-74
lines changed

3 files changed

+12
-74
lines changed

src/runtime/LocalRuntime.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { EXIT_CODE_ABORTED, EXIT_CODE_TIMEOUT } from "../constants/exitCodes";
2020
import { listLocalBranches } from "../git";
2121
import { checkInitHookExists, getInitHookPath, createLineBufferedLoggers } from "./initHook";
2222
import { execAsync } from "../utils/disposableExec";
23-
import { findBashPath, findNicePath } from "./executablePaths";
2423
import { getProjectName } from "../utils/runtime/helpers";
2524
import { getErrorMessage } from "../utils/errors";
2625

@@ -53,12 +52,9 @@ export class LocalRuntime implements Runtime {
5352
);
5453
}
5554

56-
// Find bash path (important for CI environments where PATH may not be set)
57-
const bashPath = findBashPath();
58-
const nicePath = findNicePath();
59-
6055
// If niceness is specified, spawn nice directly to avoid escaping issues
61-
const spawnCommand = options.niceness !== undefined ? nicePath : bashPath;
56+
const spawnCommand = options.niceness !== undefined ? "nice" : "bash";
57+
const bashPath = "bash";
6258
const spawnArgs =
6359
options.niceness !== undefined
6460
? ["-n", options.niceness.toString(), bashPath, "-c", command]
@@ -328,19 +324,21 @@ export class LocalRuntime implements Runtime {
328324

329325
// Create parent directory if needed
330326
const parentDir = path.dirname(workspacePath);
331-
// eslint-disable-next-line local/no-sync-fs-methods
332-
if (!fs.existsSync(parentDir)) {
333-
// eslint-disable-next-line local/no-sync-fs-methods
334-
fs.mkdirSync(parentDir, { recursive: true });
327+
try {
328+
await fsPromises.access(parentDir);
329+
} catch {
330+
await fsPromises.mkdir(parentDir, { recursive: true });
335331
}
336332

337333
// Check if workspace already exists
338-
// eslint-disable-next-line local/no-sync-fs-methods
339-
if (fs.existsSync(workspacePath)) {
334+
try {
335+
await fsPromises.access(workspacePath);
340336
return {
341337
success: false,
342338
error: `Workspace already exists at ${workspacePath}`,
343339
};
340+
} catch {
341+
// Workspace doesn't exist, proceed with creation
344342
}
345343

346344
// Check if branch exists locally
@@ -419,8 +417,7 @@ export class LocalRuntime implements Runtime {
419417
const loggers = createLineBufferedLoggers(initLogger);
420418

421419
return new Promise<void>((resolve) => {
422-
const bashPath = findBashPath();
423-
const proc = spawn(bashPath, ["-c", `"${hookPath}"`], {
420+
const proc = spawn("bash", ["-c", `"${hookPath}"`], {
424421
cwd: workspacePath,
425422
stdio: ["ignore", "pipe", "pipe"],
426423
});

src/runtime/SSHRuntime.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { log } from "../services/log";
2121
import { checkInitHookExists, createLineBufferedLoggers } from "./initHook";
2222
import { streamProcessToLogger } from "./streamProcess";
2323
import { expandTildeForSSH, cdCommandForSSH } from "./tildeExpansion";
24-
import { findBashPath } from "./executablePaths";
2524
import { getProjectName } from "../utils/runtime/helpers";
2625
import { getErrorMessage } from "../utils/errors";
2726
import { execAsync } from "../utils/disposableExec";
@@ -431,8 +430,7 @@ export class SSHRuntime implements Runtime {
431430
const command = `cd ${shescape.quote(projectPath)} && git bundle create - --all | ssh ${sshArgs.join(" ")} "cat > ${bundleTempPath}"`;
432431

433432
log.debug(`Creating bundle: ${command}`);
434-
const bashPath = findBashPath();
435-
const proc = spawn(bashPath, ["-c", command]);
433+
const proc = spawn("bash", ["-c", command]);
436434

437435
streamProcessToLogger(proc, initLogger, {
438436
logStdout: false,

src/runtime/executablePaths.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)