Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): remove dynamic skill files only on withdrawal, and batch their writes (#5193)

Andrew Barba3c25e62dd7d8
diff --git a/.changeset/dynamic-skills-write-only.md b/.changeset/dynamic-skills-write-only.md
new file mode 100644
index 000000000..b6afca3fa
--- /dev/null
+++ b/.changeset/dynamic-skills-write-only.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+A dynamic skill that stops returning `files` but is still returned now keeps the files already written to the sandbox, so files the sandbox provides another way, such as from its snapshot, stay in place. If you dropped `files` to take files away from some callers, stop returning the skill for them instead: a skill the resolver stops returning still has its files removed. On Vercel Sandbox, eve now writes a dynamic skill's files in one batch, with one path lookup and one upload instead of two round trips per file.
diff --git a/docs/guides/dynamic-capabilities.md b/docs/guides/dynamic-capabilities.md
index 7c71ad0ed..07dcfbb93 100644
--- a/docs/guides/dynamic-capabilities.md
+++ b/docs/guides/dynamic-capabilities.md
@@ -448,7 +448,7 @@ Skills follow the same naming rule as tools: a single `defineSkill(...)` is name
A dynamic skill with `deferred: true` is left out of the dynamic skill announcement and isn't named in context. The model finds it with `eve__search` and loads it with `eve__skill({ name })`, like a static deferred skill. When it overrides a static skill that isn't deferred, the system prompt still lists the static skill's description, and loading returns the dynamic body.
-A dynamic skill that returns only `markdown` never starts a sandbox: eve keeps its instructions in session state and returns them when the model loads the skill. When the skill also returns `files`, eve writes the package to the sandbox skill root when the resolver first returns it, and again only when its contents change or the session gets a new sandbox. A changed package replaces the previous directory, so files omitted from the new result are removed.
+A dynamic skill that returns only `markdown` never starts a sandbox: eve keeps its instructions in session state and returns them when the model loads the skill. When the skill also returns `files`, eve writes the package to the sandbox skill root when the resolver first returns it, and again only when its contents change or the session gets a new sandbox. A changed package replaces the previous directory, so files omitted from the new result are removed, and a skill the resolver stops returning has its files removed. A skill that keeps its name but stops returning `files` keeps the files already written, since the sandbox may provide them another way, such as from its snapshot. Keep content meant for only some callers in `markdown`, or stop returning the skill for the others.
## Dynamic instructions
diff --git a/packages/eve/src/context/dynamic-skill-lifecycle.test.ts b/packages/eve/src/context/dynamic-skill-lifecycle.test.ts
index 7db06729b..a0c9e6bed 100644
--- a/packages/eve/src/context/dynamic-skill-lifecycle.test.ts
+++ b/packages/eve/src/context/dynamic-skill-lifecycle.test.ts
@@ -370,22 +370,48 @@ describe("dynamic skill supporting files", () => {
expect(sandbox.writes).toHaveLength(6);
});
- it("removes files when a package is withdrawn or loses its supporting files", async () => {
+ it("removes files when a package is withdrawn", async () => {
const { ctx, sandbox } = createCtx();
let result: SkillPackageDefinition | null = makeSkill("Policy", "# Policy", { "a.md": "A" });
const resolver = createResolver("policy", () => result);
await dispatch(ctx, resolver);
- result = makeSkill("Policy", "# Inline policy");
+ result = null;
await dispatch(ctx, resolver);
expect(sandbox.removedPaths).toEqual([`${SKILL_ROOT}/policy`, `${SKILL_ROOT}/policy`]);
expect(sandbox.files.has(`${SKILL_ROOT}/policy/a.md`)).toBe(false);
expect(ctx.get(DynamicSkillSandboxKey)).toEqual({});
+ });
+
+ it("keeps files when a package loses its supporting files", async () => {
+ const { ctx, get, sandbox } = createCtx();
+ let result = makeSkill("Policy", "# Policy", { "a.md": "A" });
+ const resolver = createResolver("policy", () => result);
+
+ await dispatch(ctx, resolver);
+ result = makeSkill("Policy", "# Inline policy");
+ await dispatch(ctx, resolver);
+
+ expect(get).toHaveBeenCalledOnce();
+ expect(sandbox.removedPaths).toEqual([`${SKILL_ROOT}/policy`]);
+ expect(sandbox.files.get(`${SKILL_ROOT}/policy/a.md`)).toBe("A");
+ });
+ it("removes kept files when a package that lost its supporting files is withdrawn", async () => {
+ const { ctx, sandbox } = createCtx();
+ let result: SkillPackageDefinition | null = makeSkill("Policy", "# Policy", { "a.md": "A" });
+ const resolver = createResolver("policy", () => result);
+
+ await dispatch(ctx, resolver);
+ result = makeSkill("Policy", "# Inline policy");
+ await dispatch(ctx, resolver);
result = null;
await dispatch(ctx, resolver);
- expect(sandbox.removedPaths).toHaveLength(2);
+
+ expect(sandbox.removedPaths).toEqual([`${SKILL_ROOT}/policy`, `${SKILL_ROOT}/policy`]);
+ expect(sandbox.files.has(`${SKILL_ROOT}/policy/a.md`)).toBe(false);
+ expect(ctx.get(DynamicSkillSandboxKey)).toEqual({});
});
it("does not remove withdrawn files from a sandbox that never received them", async () => {
diff --git a/packages/eve/src/context/dynamic-skill-lifecycle.ts b/packages/eve/src/context/dynamic-skill-lifecycle.ts
index 91c8e6427..e3f1a1cff 100644
--- a/packages/eve/src/context/dynamic-skill-lifecycle.ts
+++ b/packages/eve/src/context/dynamic-skill-lifecycle.ts
@@ -94,21 +94,30 @@ function sandboxIdentity(state: SandboxState): string | null {
* Writes only packages with supporting files. Markdown-only skills are served
* from durable context, so they never need a sandbox. A package is skipped when
* its revision is unchanged and was written to the same persisted sandbox.
+ *
+ * Files are removed only when the session no longer has a dynamic skill by that
+ * name. A skill that stops returning supporting files keeps them, since the
+ * sandbox may already provide them, for example from its snapshot.
*/
async function syncDynamicSkillFiles(input: {
readonly ctx: ContextContainer;
+ /** Every dynamic skill the session keeps, with or without supporting files. */
+ readonly kept: ReadonlySet<string>;
readonly previous: ReadonlyMap<string, string>;
readonly next: ReadonlyMap<string, SandboxSkillPackage>;
}): Promise<void> {
- const { ctx, previous, next } = input;
- if (previous.size === 0 && next.size === 0) return;
+ const { ctx, kept, previous, next } = input;
+ // The written record, not the manifest, finds withdrawn files: a skill that
+ // went markdown-only has no revision left, but its files are still there.
+ const written = ctx.get(DynamicSkillSandboxKey) ?? {};
+ const withdrawn = Object.keys(written).filter((name) => !kept.has(name));
+ if (withdrawn.length === 0 && next.size === 0) return;
const access = ctx.require(SandboxKey);
- const written = ctx.get(DynamicSkillSandboxKey) ?? {};
const identity = sandboxIdentity(await access.captureState());
const isWritten = (name: string) => identity !== null && written[name] === identity;
- const stale = [...previous.keys()].filter((name) => !next.has(name) && isWritten(name));
+ const stale = withdrawn.filter(isWritten);
const pending = [...next.values()].filter(
({ revision, skill }) => previous.get(skill.name) !== revision || !isWritten(skill.name),
);
@@ -119,9 +128,7 @@ async function syncDynamicSkillFiles(input: {
// Forget touched packages first so a failed write is never skipped later.
const nextWritten = { ...written };
- for (const name of previous.keys()) {
- if (!next.has(name)) delete nextWritten[name];
- }
+ for (const name of withdrawn) delete nextWritten[name];
for (const { skill } of pending) delete nextWritten[skill.name];
ctx.set(DynamicSkillSandboxKey, { ...nextWritten });
@@ -243,7 +250,7 @@ export async function dispatchDynamicSkillEvent(input: {
}
}
- await syncDynamicSkillFiles({ ctx, next, previous });
+ await syncDynamicSkillFiles({ ctx, kept: new Set(dynamicSkillOwners.keys()), next, previous });
ctx.set(DynamicSkillManifestKey, newManifest);
}
diff --git a/packages/eve/src/execution/sandbox/abort-bound-session.test.ts b/packages/eve/src/execution/sandbox/abort-bound-session.test.ts
index c555d2154..1f0bd05d5 100644
--- a/packages/eve/src/execution/sandbox/abort-bound-session.test.ts
+++ b/packages/eve/src/execution/sandbox/abort-bound-session.test.ts
@@ -6,7 +6,9 @@ import type {
SandboxCommandResult,
SandboxProcess,
SandboxSession,
+ SandboxWriteFilesOptions,
} from "#shared/sandbox-session.js";
+import { SANDBOX_WRITE_FILES, writeSandboxFiles } from "#shared/sandbox-write-files.js";
import { bindSandboxAbortSignal } from "#execution/sandbox/abort-bound-session.js";
interface RecordedCall {
@@ -91,6 +93,23 @@ describe("bindSandboxAbortSignal", () => {
expect(new Set(calls.map((call) => call.abortSignal)).size).toBe(calls.length);
});
+ it("injects the bound signal into a provider's batch write", async () => {
+ const calls: RecordedCall[] = [];
+ const session = Object.assign(createRecordingSession(calls), {
+ [SANDBOX_WRITE_FILES]: async (options: SandboxWriteFilesOptions) => {
+ calls.push({ abortSignal: options.abortSignal, method: "writeFiles" });
+ },
+ });
+ const controller = new AbortController();
+ const bound = bindSandboxAbortSignal(session, controller.signal);
+
+ await writeSandboxFiles(bound, { files: [{ content: new Uint8Array(), path: "a.bin" }] });
+ controller.abort();
+
+ expect(calls.map((call) => call.method)).toEqual(["writeFiles"]);
+ expect(calls[0]?.abortSignal?.aborted).toBe(true);
+ });
+
it("does not accumulate provider listeners on the bound signal", async () => {
const calls: RecordedCall[] = [];
const recordingSession = createRecordingSession(calls);
diff --git a/packages/eve/src/execution/sandbox/abort-bound-session.ts b/packages/eve/src/execution/sandbox/abort-bound-session.ts
index a64958733..b8a4670c3 100644
--- a/packages/eve/src/execution/sandbox/abort-bound-session.ts
+++ b/packages/eve/src/execution/sandbox/abort-bound-session.ts
@@ -8,8 +8,10 @@ import type {
SandboxSpawnOptions,
SandboxWriteBinaryFileOptions,
SandboxWriteFileOptions,
+ SandboxWriteFilesOptions,
SandboxWriteTextFileOptions,
} from "#shared/sandbox-session.js";
+import { getSandboxWriteFiles, SANDBOX_WRITE_FILES } from "#shared/sandbox-write-files.js";
/**
* Returns a sandbox session that applies `abortSignal` to every operation.
@@ -43,6 +45,13 @@ export function bindSandboxAbortSignal<TSession extends SandboxSession>(
removePath: (options: SandboxRemovePathOptions) =>
session.removePath({ ...options, abortSignal: compose(options.abortSignal) }),
} satisfies SandboxSession;
+ const writeFiles = getSandboxWriteFiles(session);
+ if (writeFiles !== undefined) {
+ Object.assign(bound, {
+ [SANDBOX_WRITE_FILES]: (options: SandboxWriteFilesOptions) =>
+ writeFiles({ ...options, abortSignal: compose(options.abortSignal) }),
+ });
+ }
// The spread retains provider-specific lifecycle methods not declared on SandboxSession.
return bound as TSession;
diff --git a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
index ab8ba0461..0ffa00264 100644
--- a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
@@ -3,6 +3,7 @@ import { Readable } from "node:stream";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { SandboxTemplateNotProvisionedError } from "#shared/sandbox-template-error.js";
+import { writeSandboxFiles } from "#shared/sandbox-write-files.js";
import { VERCEL_EVE_SANDBOX_IMAGE } from "#execution/sandbox/bindings/eve-image.js";
import { createVercelSandbox as createVercelImplementation } from "#execution/sandbox/bindings/vercel.js";
import { createSandboxProviderHarness } from "#internal/testing/sandbox-provider-harness.js";
@@ -72,7 +73,13 @@ function createMockSandbox(input: {
command.cmd === "realpath"
? {
...createMockCommandResult(),
- stdout: vi.fn().mockResolvedValue(`${command.args?.at(-1) ?? ""}\n`),
+ // `realpath -m -z -- <paths...>` ends each path with NUL.
+ stdout: vi.fn().mockResolvedValue(
+ (command.args ?? [])
+ .slice(3)
+ .map((path) => `${path}\0`)
+ .join(""),
+ ),
}
: createMockCommandResult(),
),
@@ -455,7 +462,7 @@ describe("createVercelSandbox", () => {
const { handle, sessionSandbox } = await createTestVercelSession();
vi.mocked(sessionSandbox.runCommand).mockResolvedValueOnce({
...createMockCommandResult(),
- stdout: vi.fn().mockResolvedValue("/workspace/repository/agent/instructions.md\n"),
+ stdout: vi.fn().mockResolvedValue("/workspace/repository/agent/instructions.md\0"),
});
await handle.sandbox.writeTextFile({
@@ -464,7 +471,7 @@ describe("createVercelSandbox", () => {
});
expect(sessionSandbox.runCommand).toHaveBeenLastCalledWith({
- args: ["-m", "--", "/source/instructions.md"],
+ args: ["-m", "-z", "--", "/source/instructions.md"],
cmd: "realpath",
signal: undefined,
});
@@ -479,6 +486,38 @@ describe("createVercelSandbox", () => {
);
});
+ it("writes a batch of files with one realpath call and one upload", async () => {
+ const { handle, sessionSandbox } = await createTestVercelSession();
+ vi.mocked(sessionSandbox.runCommand).mockClear();
+
+ await writeSandboxFiles(handle.sandbox, {
+ files: [
+ { content: Buffer.from("A"), path: "/home/agent/.agents/skills/policy/a.md" },
+ { content: Buffer.from("B"), path: "skills/policy/b notes.md " },
+ ],
+ });
+
+ expect(sessionSandbox.runCommand).toHaveBeenCalledOnce();
+ expect(sessionSandbox.runCommand).toHaveBeenCalledWith({
+ args: [
+ "-m",
+ "-z",
+ "--",
+ "/home/agent/.agents/skills/policy/a.md",
+ "/workspace/skills/policy/b notes.md ",
+ ],
+ cmd: "realpath",
+ signal: undefined,
+ });
+ expect(sessionSandbox.writeFiles).toHaveBeenLastCalledWith(
+ [
+ { content: Buffer.from("A"), path: "/home/agent/.agents/skills/policy/a.md" },
+ { content: Buffer.from("B"), path: "/workspace/skills/policy/b notes.md " },
+ ],
+ { signal: undefined },
+ );
+ });
+
it("resolves and writes all seed paths to the sandbox filesystem in one batch", async () => {
const templateSandbox = createMockSandbox({ name: "template" });
const sessionSandbox = createMockSandbox({ name: "session" });
diff --git a/packages/eve/src/execution/sandbox/bindings/vercel.ts b/packages/eve/src/execution/sandbox/bindings/vercel.ts
index c9ca3e7cd..b13bf4aea 100644
--- a/packages/eve/src/execution/sandbox/bindings/vercel.ts
+++ b/packages/eve/src/execution/sandbox/bindings/vercel.ts
@@ -16,6 +16,7 @@ import type {
SandboxSession,
SandboxSpawnOptions,
SandboxWriteFileOptions,
+ SandboxWriteFilesOptions,
} from "#shared/sandbox-session.js";
import {
isSandboxPreparedArtifactRecord,
@@ -656,9 +657,17 @@ function createVercelInternalSandboxSession(sandbox: VercelSandbox): InternalSan
return normalizeVercelReadStream(await sandbox.readFile({ path: options.path }));
},
async writeFile(options: SandboxWriteFileOptions) {
- const bytes = await streamToBuffer(options.content);
- const path = await resolveVercelWritePath(sandbox, options.path, options.abortSignal);
- await sandbox.writeFiles([{ content: bytes, path }], { signal: options.abortSignal });
+ const files = [{ content: await streamToBuffer(options.content), path: options.path }];
+ await sandbox.writeFiles(await resolveVercelWriteFiles(sandbox, files, options.abortSignal), {
+ signal: options.abortSignal,
+ });
+ },
+ async writeFiles(options: SandboxWriteFilesOptions) {
+ if (options.files.length === 0) return;
+ await sandbox.writeFiles(
+ await resolveVercelWriteFiles(sandbox, options.files, options.abortSignal),
+ { signal: options.abortSignal },
+ );
},
async removePath(options: SandboxRemovePathOptions) {
await sandbox.fs.rm(options.path, {
@@ -699,21 +708,39 @@ function resolveVercelSandboxPath(path: string): string {
return `${WORKSPACE_ROOT}/${path}`;
}
-async function resolveVercelWritePath(
+/**
+ * The SDK writes by unpacking a tar archive, which replaces a symlinked
+ * destination instead of writing through it. Resolve every path first, with
+ * one `realpath` call. `-z` ends each path with NUL, so names with whitespace
+ * or newlines come back intact.
+ */
+async function resolveVercelWriteFiles(
sandbox: VercelSandbox,
- path: string,
+ files: SandboxWriteFilesOptions["files"],
signal?: AbortSignal,
-): Promise<string> {
+): Promise<{ content: Uint8Array; path: string }[]> {
const result = await sandbox.runCommand({
- args: ["-m", "--", path],
+ args: ["-m", "-z", "--", ...files.map((file) => file.path)],
cmd: "realpath",
signal,
});
- const resolved = (await result.stdout()).trim();
- if (result.exitCode !== 0 || !resolved.startsWith("/") || resolved.includes("\n")) {
- throw new Error(`Failed to resolve Vercel Sandbox write path: ${path}`);
+ if (result.exitCode !== 0) {
+ const stderr = (await result.stderr()).trim();
+ throw new Error(`Failed to resolve Vercel Sandbox write paths with realpath: ${stderr}`);
+ }
+ const paths = (await result.stdout()).split("\0").slice(0, -1);
+ if (paths.length !== files.length) {
+ throw new Error(
+ `Failed to resolve Vercel Sandbox write paths: realpath printed ${paths.length} paths for ${files.length} files.`,
+ );
}
- return resolved;
+ return files.map((file, index) => {
+ const path = paths[index];
+ if (path === undefined || !path.startsWith("/")) {
+ throw new Error(`Failed to resolve Vercel Sandbox write path: ${file.path}`);
+ }
+ return { content: file.content, path };
+ });
}
/**
diff --git a/packages/eve/src/execution/sandbox/session.ts b/packages/eve/src/execution/sandbox/session.ts
index 3f29a0eb0..c76ff9b61 100644
--- a/packages/eve/src/execution/sandbox/session.ts
+++ b/packages/eve/src/execution/sandbox/session.ts
@@ -14,8 +14,10 @@ import type {
SandboxSpawnOptions,
SandboxWriteBinaryFileOptions,
SandboxWriteFileOptions,
+ SandboxWriteFilesOptions,
SandboxWriteTextFileOptions,
} from "#shared/sandbox-session.js";
+import { SANDBOX_WRITE_FILES } from "#shared/sandbox-write-files.js";
import { bufferToStream, streamToBuffer } from "./stream-utils.js";
export type { InternalSandboxSession };
@@ -125,6 +127,19 @@ export function buildSandboxSession(
});
},
};
+ if (primitives.writeFiles !== undefined) {
+ Object.assign(session, {
+ [SANDBOX_WRITE_FILES]: async (options: SandboxWriteFilesOptions) => {
+ await primitives.writeFiles?.({
+ abortSignal: options.abortSignal,
+ files: options.files.map((file) => ({
+ content: file.content,
+ path: primitives.resolvePath(file.path),
+ })),
+ });
+ },
+ });
+ }
if (setNetworkPolicy === undefined) return session;
return { ...session, setNetworkPolicy } as NetworkPolicySandboxSession;
}
diff --git a/packages/eve/src/shared/sandbox-session.ts b/packages/eve/src/shared/sandbox-session.ts
index 3184e24f4..ec861596b 100644
--- a/packages/eve/src/shared/sandbox-session.ts
+++ b/packages/eve/src/shared/sandbox-session.ts
@@ -62,6 +62,14 @@ export type SandboxWriteBinaryFileOptions = Parameters<AiSdkSandbox["writeBinary
*/
export type SandboxWriteTextFileOptions = Parameters<AiSdkSandbox["writeTextFile"]>[0];
+/**
+ * Options for writing several files from raw bytes in one batch.
+ */
+export interface SandboxWriteFilesOptions {
+ readonly abortSignal?: AbortSignal;
+ readonly files: readonly { readonly content: Uint8Array; readonly path: string }[];
+}
+
/**
* Options for removing a path from a sandbox.
*
@@ -152,4 +160,9 @@ export interface InternalSandboxSession extends Pick<
removePath(options: SandboxRemovePathOptions): Promise<void>;
/** Translates a user-facing path to the provider's native path. */
resolvePath(path: string): string;
+ /**
+ * Writes several already-resolved files in one provider call. Providers that
+ * omit it get one `writeFile` per file.
+ */
+ writeFiles?(options: SandboxWriteFilesOptions): Promise<void>;
}
diff --git a/packages/eve/src/shared/sandbox-write-files.ts b/packages/eve/src/shared/sandbox-write-files.ts
new file mode 100644
index 000000000..42e5ef439
--- /dev/null
+++ b/packages/eve/src/shared/sandbox-write-files.ts
@@ -0,0 +1,41 @@
+import { mapWithConcurrency } from "#shared/map-with-concurrency.js";
+import type { SandboxSession, SandboxWriteFilesOptions } from "#shared/sandbox-session.js";
+
+const FALLBACK_WRITE_CONCURRENCY = 16;
+
+/**
+ * Where `buildSandboxSession` puts a provider's batch write. A symbol keeps it
+ * off the public session type while session wrappers, which spread or proxy
+ * the session, still carry it. A wrapper that changes calls, such as
+ * `bindSandboxAbortSignal`, must wrap it too.
+ */
+export const SANDBOX_WRITE_FILES = Symbol("eve.sandbox.writeFiles");
+
+type SandboxWriteFiles = (options: SandboxWriteFilesOptions) => Promise<void>;
+
+/** The session's batch write, when its provider has one. */
+export function getSandboxWriteFiles(session: SandboxSession): SandboxWriteFiles | undefined {
+ return (session as { readonly [SANDBOX_WRITE_FILES]?: SandboxWriteFiles })[SANDBOX_WRITE_FILES];
+}
+
+/**
+ * Writes `files` in one provider call when the provider supports it, and one
+ * `writeBinaryFile` per file otherwise. Paths resolve like `writeBinaryFile`.
+ */
+export async function writeSandboxFiles(
+ session: SandboxSession,
+ options: SandboxWriteFilesOptions,
+): Promise<void> {
+ const writeFiles = getSandboxWriteFiles(session);
+ if (writeFiles !== undefined) {
+ await writeFiles(options);
+ return;
+ }
+ await mapWithConcurrency(options.files, FALLBACK_WRITE_CONCURRENCY, async (file) => {
+ await session.writeBinaryFile({
+ abortSignal: options.abortSignal,
+ content: file.content,
+ path: file.path,
+ });
+ });
+}
diff --git a/packages/eve/src/shared/skill-package.ts b/packages/eve/src/shared/skill-package.ts
index 6e976c4db..ed3a6caf8 100644
--- a/packages/eve/src/shared/skill-package.ts
+++ b/packages/eve/src/shared/skill-package.ts
@@ -3,18 +3,11 @@ import { createHash } from "node:crypto";
import { mkdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
-import { mapWithConcurrency } from "#shared/map-with-concurrency.js";
import type { SandboxSession } from "#shared/sandbox-session.js";
+import { writeSandboxFiles } from "#shared/sandbox-write-files.js";
import type { NamedSkillDefinition } from "#shared/skill-definition.js";
import { resolveSandboxSkillRoot, resolveSandboxSkillWritePath } from "#shared/skill-paths.js";
-/**
- * Each sandbox write is a remote round trip (Vercel Sandbox also resolves the
- * path with a command first), so writing a package's files one at a time makes
- * a dynamic skill's first sync cost seconds.
- */
-const SANDBOX_WRITE_CONCURRENCY = 16;
-
export interface NormalizedSkillPackageFile {
readonly content: Buffer;
readonly relativePath: string;
@@ -103,16 +96,17 @@ export async function writeSkillPackageToSandbox(input: {
readonly sandbox: SandboxSession;
readonly skill: MaterializableSkillPackage;
}): Promise<void> {
- await mapWithConcurrency(input.skill.files, SANDBOX_WRITE_CONCURRENCY, async (file) => {
- await input.sandbox.writeBinaryFile({
+ const files = await Promise.all(
+ input.skill.files.map(async (file) => ({
content: file.content,
path: await resolveSandboxSkillWritePath({
name: input.skill.name,
relativePath: file.relativePath,
sandbox: input.sandbox,
}),
- });
- });
+ })),
+ );
+ await writeSandboxFiles(input.sandbox, { files });
}
/**