Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agent-relay/sandbox",
"version": "0.1.9",
"version": "0.1.10",
"description": "Provider-agnostic sandbox runtimes and orchestration for agent workloads.",
"license": "Apache-2.0",
"type": "module",
Expand Down
19 changes: 19 additions & 0 deletions src/orchestrator.start-mount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ function recordingRuntime() {
* their first real page — see AgentWorkforce/sandbox-router#11.
*/
describe("startMount initial-sync idle budget", () => {
it("finishes the one-shot initial sync before starting the daemon", async () => {
const { orchestrator, commands } = recordingRuntime();
await orchestrator.startMount({ id: "sbx" }, MOUNT);

const initialSyncIndex = commands.findIndex((command) =>
command.includes("relayfile-initial-sync-exit:"),
);
const daemonIndex = commands.findIndex((command) =>
command.includes("nohup relayfile-mount"),
);

assert.notEqual(initialSyncIndex, -1, "initial sync was never launched");
assert.notEqual(daemonIndex, -1, "daemon was never started");
assert.ok(
initialSyncIndex < daemonIndex,
"daemon must not hold the mount lease while one-shot initial sync runs",
);
});

it("defaults to 90s, matching relayfile's own bootstrap idle timeout", async () => {
const { orchestrator, commands } = recordingRuntime();
await orchestrator.startMount({ id: "sbx" }, MOUNT);
Expand Down
27 changes: 15 additions & 12 deletions src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,13 @@ export class SandboxOrchestrator<Handle> {
const initialSyncIdleTimeoutSeconds = relayfileBootstrapIdleTimeoutSeconds(
idleTimeoutMs / 1000,
);
const start = await this.runtime.runScript(handle, {
command: withRelayfileBootstrapIdleTimeout(
buildRelayfileMountStartShell(config),
initialSyncIdleTimeoutSeconds,
),
cwd,
});
if (start.exitCode !== 0) {
throw new Error(`Failed to start relayfile mount: ${start.output}`);
}

// The initial sync can outlive any single exec (Daytona's proxy read
// timeout is ~120s and callers wrap execs in client-side fail-fasts), so
// it runs detached in the sandbox — keeping the in-sandbox idle watchdog
// — while we poll its exit sentinel with short, idempotent execs.
// — while we poll its exit sentinel with short, idempotent execs. Complete
// it before starting the daemon: both commands acquire the same per-root
// mount lease, and the exit sentinel is written only after the one-shot
// supervisor has exited and released that lease.
const initialSyncRun = { runId: relayfileInitialSyncRunId() };
const launch = await this.runtime.runScript(handle, {
command: withRelayfileBootstrapIdleTimeout(
Expand Down Expand Up @@ -294,6 +286,17 @@ export class SandboxOrchestrator<Handle> {
await sleepMs(pollIntervalMs);
}

const start = await this.runtime.runScript(handle, {
command: withRelayfileBootstrapIdleTimeout(
buildRelayfileMountStartShell(config),
initialSyncIdleTimeoutSeconds,
),
cwd,
});
if (start.exitCode !== 0) {
throw new Error(`Failed to start relayfile mount: ${start.output}`);
}

const pid = start.output.trim().split(/\s+/).at(-1);
return pid ? { pid } : {};
}
Expand Down
Loading