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.8",
"version": "0.1.9",
"description": "Provider-agnostic sandbox runtimes and orchestration for agent workloads.",
"license": "Apache-2.0",
"type": "module",
Expand Down
70 changes: 70 additions & 0 deletions src/orchestrator.flush-mount.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { strict as assert } from "node:assert";
import { describe, it } from "node:test";

import {
SandboxOrchestrator,
type SandboxRunScriptOptions,
} from "./orchestrator.js";

function recordingOrchestrator(): {
orchestrator: SandboxOrchestrator<string>;
calls: SandboxRunScriptOptions[];
} {
const calls: SandboxRunScriptOptions[] = [];
return {
calls,
orchestrator: new SandboxOrchestrator<string>({
runScript: async (_handle, options) => {
calls.push(options);
return { output: "", exitCode: 0 };
},
}),
};
}

describe("flushMount exact-root timeout budget", () => {
it("keeps the pathless mount at one default allowance", async () => {
const { orchestrator, calls } = recordingOrchestrator();

await orchestrator.flushMount("sandbox-1", {
baseUrl: "https://relayfile.example",
workspaceId: "rw_abc12345",
localDir: "/home/daytona/workspace",
stateDir: "/home/daytona/.relayfile-mount-state",
token: "relay_pa_test",
});

assert.equal(calls.length, 1);
assert.equal(calls[0]?.timeoutMs, 120_000);
});

it("budgets the default allowance for every sequential exact root", async () => {
const { orchestrator, calls } = recordingOrchestrator();

const config = {
baseUrl: "https://relayfile.example",
workspaceId: "rw_abc12345",
localDir: "/home/daytona/workspace",
stateDir: "/home/daytona/.relayfile-mount-state",
token: "relay_pa_test",
paths: [
"/slack/channels/C123/**",
"/github/repos/acme/cloud/**",
"/linear/issues/TEAM/**",
],
};
await orchestrator.flushMount("sandbox-1", config);

assert.equal(calls.length, 1);
assert.equal(calls[0]?.timeoutMs, 360_000);

await orchestrator.flushMount("sandbox-1", config, { timeoutMs: 9_000 });

assert.equal(calls.length, 2);
assert.equal(
calls[1]?.timeoutMs,
9_000,
"an explicit whole-operation timeout must remain authoritative",
);
});
});
9 changes: 8 additions & 1 deletion src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export type StartMountOptions = {

export type FlushMountOptions = {
cwd?: string;
/**
* Optional whole-operation runtime timeout. When omitted, the default
* allowance scales by the number of sequential exact-layout commands.
*/
timeoutMs?: number;
};

Expand Down Expand Up @@ -299,10 +303,13 @@ export class SandboxOrchestrator<Handle> {
config: RelayfileMountShellOptions,
options: FlushMountOptions = {},
): Promise<void> {
const exactLayout = resolveRelayfileMountExactLayout(config);
const defaultTimeoutMs = 120_000
* Math.max(1, exactLayout.mountLocalDirs.length);
const result = await this.runtime.runScript(handle, {
command: buildRelayfileMountFlushShell(config),
cwd: options.cwd,
timeoutMs: options.timeoutMs ?? 120_000,
timeoutMs: options.timeoutMs ?? defaultTimeoutMs,
});
if (result.exitCode !== 0) {
throw new Error(`Failed to flush relayfile mount: ${result.output}`);
Expand Down
Loading