Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): prune lazy preparation from production bundles (#3654)

OwenKephartd2ed49eadb0a
diff --git a/.changeset/prune-lazy-prewarm-production.md b/.changeset/prune-lazy-prewarm-production.md
new file mode 100644
index 000000000..19cc3a35b
--- /dev/null
+++ b/.changeset/prune-lazy-prewarm-production.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Exclude lazy development sandbox preparation and its transitive dependencies from every production server bundle, including self-hosted builds without a Vercel preset.
diff --git a/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts b/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts
index 1f79b1e56..12031e41f 100644
--- a/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts
+++ b/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts
@@ -813,6 +813,28 @@ describe("application Nitro creation", () => {
);
});
+ it("prunes lazy development preparation only from production builds", async () => {
+ const productionNitroStub = createNitroStub();
+ const devNitroStub = createNitroStub({ dev: true });
+ createNitroMock.mockResolvedValueOnce(productionNitroStub.nitro);
+ createNitroMock.mockResolvedValueOnce(devNitroStub.nitro);
+
+ const { createDevelopmentApplicationNitro, createProductionApplicationNitro } =
+ await import("#internal/nitro/host/create-application-nitro.js");
+ const productionHost = await createPreparedHost();
+ await createProductionApplicationNitro(productionHost, createProductionOptions(productionHost));
+ await createDevelopmentApplicationNitro(await createPreparedHost());
+
+ const productionPlugins = createNitroMock.mock.calls[0]?.[0].rollupConfig.plugins;
+ const developmentPlugins = createNitroMock.mock.calls[1]?.[0].rollupConfig.plugins;
+ expect(productionPlugins.map((plugin: { name: string }) => plugin.name)).toContain(
+ "eve-hosted-development-runtime-prune",
+ );
+ expect(developmentPlugins.map((plugin: { name: string }) => plugin.name)).not.toContain(
+ "eve-hosted-development-runtime-prune",
+ );
+ });
+
it("includes the sandbox shutdown plugin only for production builds", async () => {
const productionNitroStub = createNitroStub();
const devNitroStub = createNitroStub();
diff --git a/packages/eve/src/internal/nitro/host/create-application-nitro.ts b/packages/eve/src/internal/nitro/host/create-application-nitro.ts
index f6ae709f6..95f995eb3 100644
--- a/packages/eve/src/internal/nitro/host/create-application-nitro.ts
+++ b/packages/eve/src/internal/nitro/host/create-application-nitro.ts
@@ -555,8 +555,9 @@ function patchWorkflowTransformExcludePath(nitro: Nitro, workflowBuildDir: strin
function createApplicationNitroBundlerConfiguration(
preparedHost: PreparedApplicationHost,
- preset: "vercel" | undefined,
+ options: { readonly development: boolean; readonly preset: "vercel" | undefined },
) {
+ const { preset } = options;
const configuredBackendNames = collectConfiguredSandboxProviderNames(
preparedHost.compileResult.manifest,
);
@@ -592,7 +593,7 @@ function createApplicationNitroBundlerConfiguration(
...preparedHost.compileResult.manifest.subagents.map((subagent) => subagent.agent),
].flatMap((node) => node.extensionMounts);
const nitroBundlerPlugins = [
- preset === "vercel" ? createDevelopmentRuntimePrunePlugin() : null,
+ options.development ? null : createDevelopmentRuntimePrunePlugin(),
compiledSandboxProviderPrunePlugin,
createOptionalEngineDependencyPlugin(unconfiguredOptionalEnginePackages),
createExtensionExternalDependencyPlugin(extensionMounts),
@@ -704,7 +705,10 @@ export async function createDevelopmentApplicationNitro(
preparedHost: PreparedDevelopmentApplicationHost,
): Promise<Nitro> {
const nitroBuildDir = preparedHost.workspace.nitroBuildDir;
- const bundler = createApplicationNitroBundlerConfiguration(preparedHost, undefined);
+ const bundler = createApplicationNitroBundlerConfiguration(preparedHost, {
+ development: true,
+ preset: undefined,
+ });
const plugins = createApplicationNitroPlugins(preparedHost);
if (preparedHost.compiledArtifacts.instrumentationPluginPath === undefined) {
plugins.unshift(
@@ -778,7 +782,10 @@ export async function createProductionApplicationNitro(
options: ProductionApplicationNitroOptions,
): Promise<Nitro> {
const preset = resolveProductionNitroPreset();
- const bundler = createApplicationNitroBundlerConfiguration(preparedHost, preset);
+ const bundler = createApplicationNitroBundlerConfiguration(preparedHost, {
+ development: false,
+ preset,
+ });
const nitroPlugins = createApplicationNitroPlugins(preparedHost);
nitroPlugins.push(
resolvePackageSourceFilePath("src/internal/nitro/host/sandbox-shutdown-plugin.ts"),
diff --git a/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts b/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts
index fa61fb177..66e571316 100644
--- a/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts
+++ b/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts
@@ -814,52 +814,63 @@ describe("app runtime dependency tracing", () => {
expect(serverModuleSource).toContain("URL must start with https://");
}, 30_000);
- it("does not bundle local-only runtime infrastructure into hosted Vercel output", async () => {
- vi.stubEnv("VERCEL", "1");
- vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");
+ it.each([
+ { name: "hosted Vercel", vercel: true },
+ { name: "self-hosted production", vercel: false },
+ ])(
+ "does not bundle local-only runtime infrastructure into $name output",
+ async ({ vercel }) => {
+ if (vercel) {
+ vi.stubEnv("VERCEL", "1");
+ vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");
+ }
- const appRoot = await createScratchDirectory("eve-app-hosted-no-dev-runtime-build-");
+ const appRoot = await createScratchDirectory(
+ `eve-app-${vercel ? "hosted" : "self-hosted"}-no-dev-runtime-build-`,
+ );
- await mkdir(join(appRoot, "agent"), {
- recursive: true,
- });
- await writeFile(
- join(appRoot, "package.json"),
- `${JSON.stringify(
- {
- name: "hosted-no-dev-runtime-build-test",
- private: true,
- type: "module",
- },
- null,
- 2,
- )}\n`,
- );
- await writeFile(
- join(appRoot, "agent", "agent.ts"),
- ["export default {", ' model: "openai/gpt-5.4-mini",', "};", ""].join("\n"),
- );
- await writeFile(
- join(appRoot, "agent", "instructions.md"),
- "Verify deployed runtime contents.\n",
- );
+ await mkdir(join(appRoot, "agent"), {
+ recursive: true,
+ });
+ await writeFile(
+ join(appRoot, "package.json"),
+ `${JSON.stringify(
+ {
+ name: "hosted-no-dev-runtime-build-test",
+ private: true,
+ type: "module",
+ },
+ null,
+ 2,
+ )}\n`,
+ );
+ await writeFile(
+ join(appRoot, "agent", "agent.ts"),
+ ["export default {", ' model: "openai/gpt-5.4-mini",', "};", ""].join("\n"),
+ );
+ await writeFile(
+ join(appRoot, "agent", "instructions.md"),
+ "Verify deployed runtime contents.\n",
+ );
- const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);
- const vercelFunctionsSource = await readJavaScriptModulesRecursively(
- join(outputDir, "functions"),
- );
-
- expect(vercelFunctionsSource).not.toContain("dev-authored-source-watcher");
- expect(vercelFunctionsSource).not.toContain("chokidar");
- expect(vercelFunctionsSource).not.toContain("[eve:dev]");
- expect(vercelFunctionsSource).not.toContain("rollup:reload");
- // The world-local canary is its log prefix, not names other packages
- // legitimately mention without bundling world-local code: the
- // semantic-error catalog embeds error-class names like
- // `DataDirAccessError`, and @workflow/core's runtime world factory
- // (stubbed out at vendor time) names `WORKFLOW_LOCAL_DATA_DIR`.
- expect(vercelFunctionsSource).not.toContain("[world-local]");
- }, 30_000);
+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);
+ const runtimeSource = await readJavaScriptModulesRecursively(
+ join(outputDir, vercel ? "functions" : "server"),
+ );
+
+ expect(runtimeSource).not.toContain("dev-authored-source-watcher");
+ expect(runtimeSource).not.toContain("chokidar");
+ expect(runtimeSource).not.toContain("[eve:dev]");
+ expect(runtimeSource).not.toContain("rollup:reload");
+ // The world-local canary is its log prefix, not names other packages
+ // legitimately mention without bundling world-local code: the
+ // semantic-error catalog embeds error-class names like
+ // `DataDirAccessError`, and @workflow/core's runtime world factory
+ // (stubbed out at vendor time) names `WORKFLOW_LOCAL_DATA_DIR`.
+ if (vercel) expect(runtimeSource).not.toContain("[world-local]");
+ },
+ 30_000,
+ );
it("loads instrumentation runtime dependencies from hosted Vercel output", async () => {
vi.stubEnv("VERCEL", "1");