Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions services/runner/src/engines/sandbox_agent/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ function credEnv(creds: MountCredentials): Record<string, string> {
return env;
}

function waitForExitOrDelay(exited: Promise<void>, ms: number): Promise<void> {
return new Promise((resolve) => {
const timeout = setTimeout(resolve, ms);
void exited.then(() => {
clearTimeout(timeout);
resolve();
});
});
}

export async function waitForLocalMount(
isAlive: () => Promise<boolean>,
hasExited: () => boolean,
exited: Promise<void>,
attempts = 30,
delayMs = 500,
): Promise<boolean> {
for (let i = 0; i < attempts; i++) {
if (hasExited()) return false;
if (await isAlive()) return true;
if (hasExited()) return false;
await waitForExitOrDelay(exited, delayMs);
}
return false;
}

/**
* True only when `cwd` is a mountpoint AND the FUSE backend still serves I/O.
*
Expand Down Expand Up @@ -358,10 +384,11 @@ export async function mountStorage(
child.unref();
// Poll up to ~15s for the mountpoint to serve I/O; geesefs logs "successfully mounted"
// within ~1s normally. Resolve as soon as it's alive; the caller re-verifies after.
for (let i = 0; i < 30; i++) {
if (await isMounted(cwd, () => {})) break;
await new Promise((r) => setTimeout(r, 500));
}
await waitForLocalMount(
() => isMounted(cwd, () => {}),
() => processExited,
exited,
);
return {
stop: async () => {
const waitForExit = async (): Promise<boolean> => {
Expand Down
30 changes: 30 additions & 0 deletions services/runner/tests/unit/sandbox-agent-mount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
mountStorage,
unmountStorage,
mountpointFailureState,
waitForLocalMount,
discoverTunnelEndpoint,
mountStorageRemote,
harnessSessionMounts,
Expand Down Expand Up @@ -244,6 +245,35 @@ function notMountedThenAlive(): (cwd: string) => Promise<boolean> {
};
}

describe("waitForLocalMount", () => {
it("stops polling when geesefs exits before the mount is alive", async () => {
let probes = 0;
let exited = false;
let resolveExit!: () => void;
const exitPromise = new Promise<void>((resolve) => {
resolveExit = () => {
exited = true;
resolve();
};
});

const ok = await waitForLocalMount(
async () => {
probes += 1;
resolveExit();
return false;
},
() => exited,
exitPromise,
30,
1_000,
);

assert.equal(ok, false);
assert.equal(probes, 1);
});
});

describe("mountStorage", () => {
it("builds the geesefs command with creds in env, not argv", async () => {
let seenArgs: string[] = [];
Expand Down
Loading