The Open Framework for Building Agents
fix(eve): write dynamic skill files to the sandbox concurrently (#4767)
Matan Kushnerafa774187774
diff --git a/.changeset/concurrent-skill-file-writes.md b/.changeset/concurrent-skill-file-writes.mdnew file mode 100644index 000000000..6850be4f9--- /dev/null+++ b/.changeset/concurrent-skill-file-writes.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Sync dynamic skill files to the sandbox about 7× faster by writing them concurrently.diff --git a/packages/eve/src/shared/skill-package.test.ts b/packages/eve/src/shared/skill-package.test.tsindex 2e127b694..0b9c33938 100644--- a/packages/eve/src/shared/skill-package.test.ts+++ b/packages/eve/src/shared/skill-package.test.ts@@ -94,6 +94,30 @@ describe("writeSkillPackageToSandbox", () => {);});+ it("writes several files at once, but not all of them", async () => {+ let inFlight = 0;+ let maxInFlight = 0;+ const session = {+ ...mockSandbox().session,+ async writeBinaryFile() {+ maxInFlight = Math.max(maxInFlight, ++inFlight);+ await Promise.resolve();+ inFlight -= 1;+ },+ };+ const skill = normalizeSkillPackage({+ name: "tenant",+ description: "Tenant-specific procedures.",+ markdown: "Follow tenant policy.",+ files: Object.fromEntries(Array.from({ length: 40 }, (_, i) => [`references/${i}.md`, ""])),+ });++ await writeSkillPackageToSandbox({ sandbox: session, skill });++ expect(maxInFlight).toBeGreaterThan(1);+ expect(maxInFlight).toBeLessThan(skill.files.length);+ });+it("falls back to the legacy workspace skill directory when HOME is unavailable", async () => {const sandbox = mockSandbox();const skill = normalizeSkillPackage({diff --git a/packages/eve/src/shared/skill-package.ts b/packages/eve/src/shared/skill-package.tsindex dfcdb9e31..6e976c4db 100644--- a/packages/eve/src/shared/skill-package.ts+++ b/packages/eve/src/shared/skill-package.ts@@ -3,10 +3,18 @@ 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 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;@@ -95,7 +103,7 @@ export async function writeSkillPackageToSandbox(input: {readonly sandbox: SandboxSession;readonly skill: MaterializableSkillPackage;}): Promise<void> {- for (const file of input.skill.files) {+ await mapWithConcurrency(input.skill.files, SANDBOX_WRITE_CONCURRENCY, async (file) => {await input.sandbox.writeBinaryFile({content: file.content,path: await resolveSandboxSkillWritePath({@@ -104,7 +112,7 @@ export async function writeSkillPackageToSandbox(input: {sandbox: input.sandbox,}),});- }+ });}/**