The Open Framework for Building Agents
fix(eve): workflow - scope queues per agent (#338)
Andrew Barba2e00da7b86b0
diff --git a/.changeset/unique-agent-workflow-queues.md b/.changeset/unique-agent-workflow-queues.mdnew file mode 100644index 000000000..f57f34520--- /dev/null+++ b/.changeset/unique-agent-workflow-queues.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Scope workflow queue prefixes to each eve agent so multiple uniquely named agents can deploy in the same project without consuming one another's workflow messages.diff --git a/packages/eve/src/internal/application/compiled-artifacts.test.ts b/packages/eve/src/internal/application/compiled-artifacts.test.tsindex ca4968ca6..1def18309 100644--- a/packages/eve/src/internal/application/compiled-artifacts.test.ts+++ b/packages/eve/src/internal/application/compiled-artifacts.test.ts@@ -58,6 +58,7 @@ describe("createCompiledArtifactsBootstrapSource", () => {});expect(source).toContain('import * as workflowWorldModule from "@acme/eve-world";');+ expect(source).toContain('installEveWorkflowQueueNamespace("app");');expect(source).toContain('await installConfiguredWorkflowWorld({ module: workflowWorldModule, packageName: "@acme/eve-world" });',);diff --git a/packages/eve/src/internal/application/compiled-artifacts.ts b/packages/eve/src/internal/application/compiled-artifacts.tsindex e3bd0f966..925f40686 100644--- a/packages/eve/src/internal/application/compiled-artifacts.ts+++ b/packages/eve/src/internal/application/compiled-artifacts.ts@@ -110,6 +110,7 @@ export async function createCompiledArtifactsBootstrapSource(input: {moduleMapPath: string;}): Promise<string> {const workflowWorld = input.compileResult.manifest.config.experimental?.workflow?.world;+ const agentName = input.compileResult.manifest.config.name;const moduleMapSource = stripCompiledModuleMapExports(createCompiledModuleMapSource({importSpecifierStyle: "absolute",@@ -121,8 +122,11 @@ export async function createCompiledArtifactsBootstrapSource(input: {return ["// Generated by eve. Do not edit by hand.",`import { installBundledCompiledArtifacts } from ${stringifyEsmImportSpecifier(input.installModulePath)};`,+ `import { installEveWorkflowQueueNamespace } from ${stringifyEsmImportSpecifier(resolvePackageSourceFilePath("src/internal/workflow/queue-namespace.ts"))};`,...createWorkflowWorldBootstrapImports(workflowWorld),"",+ `installEveWorkflowQueueNamespace(${JSON.stringify(agentName)});`,+ "",moduleMapSource,"",`const metadata = ${JSON.stringify(input.metadata, null, 2)};`,diff --git a/packages/eve/src/internal/nitro/host/build-application.ts b/packages/eve/src/internal/nitro/host/build-application.tsindex 9b422e972..43bd5c41a 100644--- a/packages/eve/src/internal/nitro/host/build-application.ts+++ b/packages/eve/src/internal/nitro/host/build-application.ts@@ -173,6 +173,7 @@ async function readVercelServerRuntime(outputDir: string): Promise<string | unde}async function emitVercelWorkflowFunctions(input: {+ agentName: string;appRoot: string;compiledArtifactsBootstrapPath: string;flowNitroOutputDir: string;@@ -180,6 +181,7 @@ async function emitVercelWorkflowFunctions(input: {workflowBuildDir: string;}): Promise<void> {const builder = new WorkflowBundleBuilder({+ agentName: input.agentName,appRoot: input.appRoot,compiledArtifactsBootstrapPath: input.compiledArtifactsBootstrapPath,outDir: input.workflowBuildDir,@@ -265,6 +267,7 @@ export async function buildApplication(rootDir: string): Promise<string> {});const flowNitroOutputDir = await buildVercelNitroSurface(preparedHost, "flow");await emitVercelWorkflowFunctions({+ agentName: preparedHost.compileResult.manifest.config.name,appRoot: preparedHost.appRoot,compiledArtifactsBootstrapPath: preparedHost.compiledArtifacts.bootstrapPath,flowNitroOutputDir,diff --git a/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts b/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.tsindex 0b60b2917..4376e9477 100644--- a/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts+++ b/packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts@@ -25,6 +25,7 @@ interface PreparedApplicationHostStub {manifest: {channels: [];config: {+ name: string;experimental?: { workflow?: { world?: string } };};};@@ -108,7 +109,12 @@ function createNitroStub(}function createPreparedHost(- input: { appRoot?: string; workflowWorld?: string; workflowBuildDir?: string } = {},+ input: {+ agentName?: string;+ appRoot?: string;+ workflowWorld?: string;+ workflowBuildDir?: string;+ } = {},): PreparedApplicationHost {const appRoot = input.appRoot ?? "G:\\projects\\test-eve";@@ -119,8 +125,11 @@ function createPreparedHost(channels: [],config:input.workflowWorld === undefined- ? {}- : { experimental: { workflow: { world: input.workflowWorld } } },+ ? { name: input.agentName ?? "test-agent" }+ : {+ name: input.agentName ?? "test-agent",+ experimental: { workflow: { world: input.workflowWorld } },+ },},project: {agentRoot: `${appRoot}\\agent`,@@ -245,7 +254,7 @@ describe("configureNitroRoutes", () => {"const __eveWorkflowWorld = await __eveGetWorkflowWorld();",);expect(workflowHandlerSource).toContain(- '__eveWorkflowWorld.registerHandler("__eve_wkf_workflow_", POST);',+ '__eveWorkflowWorld.registerHandler("__eve746573742d6167656e74_wkf_workflow_", POST);',);expect(readWriteFileSourceMatching("/workflow/steps-handler.mjs")).toBeUndefined();});@@ -369,7 +378,7 @@ describe("configureNitroRoutes", () => {"const __eveWorkflowWorld = await __eveGetWorkflowWorld();",);expect(workflowHandlerSource).toContain(- '__eveWorkflowWorld.registerHandler("__eve_wkf_workflow_", POST);',+ '__eveWorkflowWorld.registerHandler("__eve746573742d6167656e74_wkf_workflow_", POST);',);expect(readWriteFileSourceMatching("/workflow/steps-handler.mjs")).toBeUndefined();});diff --git a/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts b/packages/eve/src/internal/nitro/host/configure-nitro-routes.tsindex 4c4a82dcb..86311928b 100644--- a/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts+++ b/packages/eve/src/internal/nitro/host/configure-nitro-routes.ts@@ -24,7 +24,7 @@ import {createNitroArtifactsConfig,type NitroArtifactsConfigInput,} from "#internal/nitro/host/artifacts-config.js";-import { EVE_WORKFLOW_QUEUE_PREFIX } from "#internal/workflow/queue-namespace.js";+import { deriveEveWorkflowQueuePrefix } from "#internal/workflow/queue-namespace.js";import {computeChannelRouteRegistrations,registerChannelVirtualHandlers,@@ -269,6 +269,7 @@ export async function configureNitroRoutes(if (includesWorkflowBundles(input.surface)) {const packageRoot = resolvePackageRoot();const builder = new WorkflowBundleBuilder({+ agentName: preparedHost.compileResult.manifest.config.name,appRoot: preparedHost.appRoot,compiledArtifactsBootstrapPath: preparedHost.compiledArtifacts.bootstrapPath,outDir: preparedHost.workflowBuildDir,@@ -421,7 +422,14 @@ export async function configureNitroRoutes(nitro.options.dev || (!isVercelBuildEnvironment() && hasConfiguredWorkflowWorld);const directHandlerEntries: WorkflowDirectHandlerEntry[] =localWorldDrivesQueue && workflowBundlePath !== undefined- ? [{ bundlePath: workflowBundlePath, queuePrefix: EVE_WORKFLOW_QUEUE_PREFIX }]+ ? [+ {+ bundlePath: workflowBundlePath,+ queuePrefix: deriveEveWorkflowQueuePrefix(+ preparedHost.compileResult.manifest.config.name,+ ),+ },+ ]: [];// Generated handlers will JSON-stringify this at write-time, so we hand them// an ESM-safe specifier (Windows drive paths get converted to file://) butdiff --git a/packages/eve/src/internal/workflow-bundle/builder-support.integration.test.ts b/packages/eve/src/internal/workflow-bundle/builder-support.integration.test.tsindex 9120d666e..36ec9ca75 100644--- a/packages/eve/src/internal/workflow-bundle/builder-support.integration.test.ts+++ b/packages/eve/src/internal/workflow-bundle/builder-support.integration.test.ts@@ -107,12 +107,14 @@ describe("bundleFinalWorkflowOutput", () => {code: "globalThis.__private_workflows = new Map();",format: "esm",outfile: target,+ queueNamespace: "evetest",workingDir: resolvePackageRoot(),});const source = await readFile(target, "utf8");const runtimePath = resolveWorkflowModulePath("workflow/runtime").replaceAll("\\", "/");expect(source).toContain(`from ${JSON.stringify(runtimePath)}`);+ expect(source).toContain('workflowEntrypoint(workflowCode, { namespace: "evetest" })');expect(source).not.toContain('from "workflow/runtime"');} finally {await rm(dir, { recursive: true, force: true });diff --git a/packages/eve/src/internal/workflow-bundle/builder-support.ts b/packages/eve/src/internal/workflow-bundle/builder-support.tsindex b113d67b3..5f31eff64 100644--- a/packages/eve/src/internal/workflow-bundle/builder-support.ts+++ b/packages/eve/src/internal/workflow-bundle/builder-support.ts@@ -13,10 +13,20 @@ import {getImportPath,type WorkflowManifest,} from "#internal/workflow-bundle/workflow-builders.js";-import { EVE_WORKFLOW_QUEUE_NAMESPACE } from "#internal/workflow/queue-namespace.js";import { WORKFLOW_STEP_EXTERNAL_PACKAGES } from "#internal/workflow-bundle/vercel-workflow-output.js";export const WORKFLOW_VIRTUAL_ENTRY_ID = "\0eve-workflow-entry";++export interface WorkflowBundleBuilderOptions {+ agentName: string;+ appRoot: string;+ compiledArtifactsBootstrapPath: string;+ outDir: string;+ rootDir: string;+ watch: boolean;+ /** Test-harness-only: also scans `src/internal/testing/`. */+ includeTestFixtures?: boolean;+}const PSEUDO_PACKAGES = new Set(["server-only","client-only",@@ -384,6 +394,7 @@ export async function bundleFinalWorkflowOutput(input: {code: string;format: "cjs" | "esm";outfile: string;+ queueNamespace: string;workingDir: string;}): Promise<void> {const workflowBundleCode = input.code.endsWith("\n") ? input.code : `${input.code}\n`;@@ -394,7 +405,7 @@ import { workflowEntrypoint } from ${JSON.stringify(workflowRuntimePath)};const workflowCode = \`${workflowBundleCode.replace(/[\\`$]/g, "\\$&")}\`;-export const POST = workflowEntrypoint(workflowCode, { namespace: ${JSON.stringify(EVE_WORKFLOW_QUEUE_NAMESPACE)} });`;+export const POST = workflowEntrypoint(workflowCode, { namespace: ${JSON.stringify(input.queueNamespace)} });`;if (!input.bundleFinalOutput) {await writeWorkflowBundleAtomically(input.outfile, workflowFunctionCode);diff --git a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.tsindex df74c797a..a4c81bb10 100644--- a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts+++ b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts@@ -93,6 +93,7 @@ describe("WorkflowBundleBuilder", () => {const appRoot = "/tmp/eve-app";const rootDir = resolvePackageRoot();const builder = new InspectableWorkflowBundleBuilder({+ agentName: "test-agent",appRoot,compiledArtifactsBootstrapPath: "/tmp/compiled-artifacts-bootstrap.js",outDir: "/tmp/eve-workflows",@@ -134,6 +135,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new StepEntryOnlyWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,@@ -201,6 +203,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new StepEntryOnlyWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,@@ -251,7 +254,7 @@ describe("WorkflowBundleBuilder", () => {"",`const workflowCode = \`${workflowBundleCode.replace(/[\\`$]/g, "\\$&")}\`;`,"",- 'export const POST = workflowEntrypoint(workflowCode, { namespace: "eve" });',+ 'export const POST = workflowEntrypoint(workflowCode, { namespace: "eve746573742d6167656e74" });',"",].join("\n"),);@@ -283,6 +286,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new TemplateLiteralWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,@@ -405,6 +409,7 @@ describe("WorkflowBundleBuilder", () => {]);const builder = new BuildTrackingWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: "/tmp/eve-app",compiledArtifactsBootstrapPath: "/tmp/compiled-artifacts-bootstrap.js",outDir,@@ -473,7 +478,7 @@ describe("WorkflowBundleBuilder", () => {),"utf8",),- ).resolves.toContain('"__eve_wkf_workflow_*"');+ ).resolves.toContain('"__eve746573742d6167656e74_wkf_workflow_*"');await expect(readFile(join(@@ -570,6 +575,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new FixtureWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,@@ -625,6 +631,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new FixtureWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,@@ -692,6 +699,7 @@ describe("WorkflowBundleBuilder", () => {const builder = new FixtureWorkflowBundleBuilder({+ agentName: "test-agent",appRoot: tempRoot,compiledArtifactsBootstrapPath,outDir,diff --git a/packages/eve/src/internal/workflow-bundle/builder.ts b/packages/eve/src/internal/workflow-bundle/builder.tsindex 06e3fb8f7..e22636b02 100644--- a/packages/eve/src/internal/workflow-bundle/builder.ts+++ b/packages/eve/src/internal/workflow-bundle/builder.ts@@ -26,6 +26,7 @@ import {createWorkflowVirtualEntryPlugin,WORKFLOW_VIRTUAL_ENTRY_ID,type WorkflowBundleBuilderConfig,+ type WorkflowBundleBuilderOptions,type WorkflowBundleCreateWorkflowsBundleOptions,type WorkflowBundleCreateWorkflowsBundleResult,type WorkflowBundleDiscoveredEntries,@@ -44,18 +45,20 @@ import {} from "#internal/workflow-bundle/vercel-workflow-output.js";import {detectWorkflowPatterns,- WORKFLOW_QUEUE_TRIGGER,+ createEveWorkflowQueueTrigger,type WorkflowManifest,} from "#internal/workflow-bundle/workflow-builders.js";-import { EVE_WORKFLOW_QUEUE_NAMESPACE } from "#internal/workflow/queue-namespace.js";+import { deriveEveWorkflowQueueNamespace } from "#internal/workflow/queue-namespace.js";// Serialize same-output builds so parallel Vercel surfaces never read// `workflows.mjs` between the workflow wrapper write and literal rewrite pass.const workflowBundleBuildLocks = new Map<string, Promise<void>>();export class WorkflowBundleBuilder {+ readonly #agentName: string;readonly #compiledArtifactsBootstrapPath: string;readonly #outDir: string;+ readonly #queueNamespace: string;protected readonly config: WorkflowBundleBuilderConfig;readonly #discoveredEntries = new WeakMap<readonly string[], WorkflowBundleDiscoveredEntries>();@@ -74,8 +77,10 @@ export class WorkflowBundleBuilder {workingDir: options.rootDir,};+ this.#agentName = options.agentName;this.#compiledArtifactsBootstrapPath = options.compiledArtifactsBootstrapPath;this.#outDir = options.outDir;+ this.#queueNamespace = deriveEveWorkflowQueueNamespace(options.agentName);}async build(@@ -144,7 +149,7 @@ export class WorkflowBundleBuilder {await addStepRegistrationsImport(workflowsOutfile, stepsOutfile);await rewriteWorkflowRuntimeImports(workflowsOutfile);- await rewriteWorkflowCodeLiteral(workflowsOutfile);+ await rewriteWorkflowCodeLiteral(workflowsOutfile, this.#queueNamespace);const nitroWorkflowOutfile = options.nitroWorkflowOutfile;@@ -154,7 +159,7 @@ export class WorkflowBundleBuilder {if (nitroStepOutfile !== undefined) {await addStepRegistrationsImport(nitroWorkflowOutfile, nitroStepOutfile);await rewriteWorkflowRuntimeImports(nitroWorkflowOutfile);- await rewriteWorkflowCodeLiteral(nitroWorkflowOutfile);+ await rewriteWorkflowCodeLiteral(nitroWorkflowOutfile, this.#queueNamespace);}}@@ -318,6 +323,7 @@ export class WorkflowBundleBuilder {code: interimBundle.code,format,outfile,+ queueNamespace: this.#queueNamespace,workingDir: this.config.workingDir,});@@ -329,6 +335,7 @@ export class WorkflowBundleBuilder {code: interimBundleResult,format,outfile,+ queueNamespace: this.#queueNamespace,workingDir: this.config.workingDir,});},@@ -409,7 +416,7 @@ export class WorkflowBundleBuilder {await Promise.all([this.#patchVercelFunctionConfig(stagedFlowFunctionDir, {- experimentalTriggers: Array.from([WORKFLOW_QUEUE_TRIGGER]),+ experimentalTriggers: [createEveWorkflowQueueTrigger(this.#agentName)],maxDuration: "max",runtime: options.runtime ?? null,shouldAddHelpers: false,@@ -561,7 +568,7 @@ async function rewriteWorkflowRuntimeImports(filePath: string): Promise<void> {}}-async function rewriteWorkflowCodeLiteral(filePath: string): Promise<void> {+async function rewriteWorkflowCodeLiteral(filePath: string, queueNamespace: string): Promise<void> {const source = await readTextFileIfPresent(filePath);if (source === null) {@@ -569,7 +576,7 @@ async function rewriteWorkflowCodeLiteral(filePath: string): Promise<void> {}const declarationPrefix = "const workflowCode = ";- const declarationSuffix = `;\n\nexport const POST = workflowEntrypoint(workflowCode, { namespace: ${JSON.stringify(EVE_WORKFLOW_QUEUE_NAMESPACE)} });`;+ const declarationSuffix = `;\n\nexport const POST = workflowEntrypoint(workflowCode, { namespace: ${JSON.stringify(queueNamespace)} });`;const expressionStart = source.indexOf(declarationPrefix);const expressionEnd = source.lastIndexOf(declarationSuffix);@@ -687,13 +694,3 @@ async function mirrorFileBypassingUnlink(sourcePath: string, targetPath: string)await atomicWriteFile(targetPath, sourceContents);}--interface WorkflowBundleBuilderOptions {- appRoot: string;- compiledArtifactsBootstrapPath: string;- outDir: string;- rootDir: string;- watch: boolean;- /** Test-harness-only: also scans `src/internal/testing/`. */- includeTestFixtures?: boolean;-}diff --git a/packages/eve/src/internal/workflow-bundle/workflow-builders.ts b/packages/eve/src/internal/workflow-bundle/workflow-builders.tsindex dc87d84c8..2fff154f5 100644--- a/packages/eve/src/internal/workflow-bundle/workflow-builders.ts+++ b/packages/eve/src/internal/workflow-bundle/workflow-builders.ts@@ -4,7 +4,7 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";import { STABLE_WORKFLOW_NAMES } from "#execution/workflow-runtime.js";import { EVE_PACKAGE_NAME } from "#internal/package-name.js";-import { EVE_WORKFLOW_QUEUE_TOPIC } from "#internal/workflow/queue-namespace.js";+import { deriveEveWorkflowQueueTopic } from "#internal/workflow/queue-namespace.js";import { transformWorkflowDirectives } from "./workflow-transformer.js";@@ -32,13 +32,15 @@ export type WorkflowManifest = {};};-export const WORKFLOW_QUEUE_TRIGGER = {- type: "queue/v2beta",- topic: EVE_WORKFLOW_QUEUE_TOPIC,- consumer: "default",- retryAfterSeconds: 5,- initialDelaySeconds: 0,-} as const;+export function createEveWorkflowQueueTrigger(agentName: string) {+ return {+ type: "queue/v2beta" as const,+ topic: deriveEveWorkflowQueueTopic(agentName),+ consumer: "default",+ retryAfterSeconds: 5,+ initialDelaySeconds: 0,+ };+}type PackageInfo = {dir: string;diff --git a/packages/eve/src/internal/workflow/queue-namespace.test.ts b/packages/eve/src/internal/workflow/queue-namespace.test.tsindex 095081baf..b75a12a73 100644--- a/packages/eve/src/internal/workflow/queue-namespace.test.ts+++ b/packages/eve/src/internal/workflow/queue-namespace.test.ts@@ -1,12 +1,41 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {- EVE_WORKFLOW_QUEUE_NAMESPACE,+ deriveEveWorkflowQueueNamespace,+ deriveEveWorkflowQueuePrefix,+ deriveEveWorkflowQueueTopic,+ installEveWorkflowQueueNamespace,WORKFLOW_QUEUE_NAMESPACE_ENV,} from "#internal/workflow/queue-namespace.js";describe("workflow queue namespace", () => {- it("installs the eve namespace when the module loads", () => {- expect(process.env[WORKFLOW_QUEUE_NAMESPACE_ENV]).toBe(EVE_WORKFLOW_QUEUE_NAMESPACE);+ it("derives a valid, collision-free namespace from the agent name", () => {+ expect(deriveEveWorkflowQueueNamespace("weather-agent")).toBe("eve776561746865722d6167656e74");+ expect(deriveEveWorkflowQueueNamespace("weatheragent")).not.toBe(+ deriveEveWorkflowQueueNamespace("weather-agent"),+ );+ expect(deriveEveWorkflowQueueNamespace("weather-agent")).toMatch(/^[a-z][a-z0-9]*$/);+ });++ it("derives the workflow queue prefix and topic from the same namespace", () => {+ expect(deriveEveWorkflowQueuePrefix("weather-agent")).toBe(+ "__eve776561746865722d6167656e74_wkf_workflow_",+ );+ expect(deriveEveWorkflowQueueTopic("weather-agent")).toBe(+ "__eve776561746865722d6167656e74_wkf_workflow_*",+ );+ });++ it("installs the derived namespace for Workflow runtime operations", () => {+ vi.stubEnv(WORKFLOW_QUEUE_NAMESPACE_ENV, "previous");++ try {+ expect(installEveWorkflowQueueNamespace("weather-agent")).toBe(+ "eve776561746865722d6167656e74",+ );+ expect(process.env[WORKFLOW_QUEUE_NAMESPACE_ENV]).toBe("eve776561746865722d6167656e74");+ } finally {+ vi.unstubAllEnvs();+ }});});diff --git a/packages/eve/src/internal/workflow/queue-namespace.ts b/packages/eve/src/internal/workflow/queue-namespace.tsindex 3412c87c3..8a660ec8a 100644--- a/packages/eve/src/internal/workflow/queue-namespace.ts+++ b/packages/eve/src/internal/workflow/queue-namespace.ts@@ -1,6 +1,27 @@-export const EVE_WORKFLOW_QUEUE_NAMESPACE = "eve";export const WORKFLOW_QUEUE_NAMESPACE_ENV = "WORKFLOW_QUEUE_NAMESPACE";-export const EVE_WORKFLOW_QUEUE_PREFIX = `__${EVE_WORKFLOW_QUEUE_NAMESPACE}_wkf_workflow_`;-export const EVE_WORKFLOW_QUEUE_TOPIC = `${EVE_WORKFLOW_QUEUE_PREFIX}*`;-process.env[WORKFLOW_QUEUE_NAMESPACE_ENV] = EVE_WORKFLOW_QUEUE_NAMESPACE;+/** Derives a stable Workflow queue namespace from an eve agent's unique name. */+export function deriveEveWorkflowQueueNamespace(agentName: string): string {+ const encodedAgentName = Array.from(new TextEncoder().encode(agentName), (byte) =>+ byte.toString(16).padStart(2, "0"),+ ).join("");++ return `eve${encodedAgentName}`;+}++/** Derives the queue prefix consumed by an eve agent's workflow handler. */+export function deriveEveWorkflowQueuePrefix(agentName: string): string {+ return `__${deriveEveWorkflowQueueNamespace(agentName)}_wkf_workflow_`;+}++/** Derives the queue topic registered for an eve agent's workflow handler. */+export function deriveEveWorkflowQueueTopic(agentName: string): string {+ return `${deriveEveWorkflowQueuePrefix(agentName)}*`;+}++/** Installs the agent-scoped namespace used by Workflow runtime operations. */+export function installEveWorkflowQueueNamespace(agentName: string): string {+ const namespace = deriveEveWorkflowQueueNamespace(agentName);+ process.env[WORKFLOW_QUEUE_NAMESPACE_ENV] = namespace;+ return namespace;+}diff --git a/packages/eve/src/internal/workflow/runtime.ts b/packages/eve/src/internal/workflow/runtime.tsindex c3bd15ded..649eb02d7 100644--- a/packages/eve/src/internal/workflow/runtime.ts+++ b/packages/eve/src/internal/workflow/runtime.ts@@ -1,4 +1,3 @@-import "#internal/workflow/queue-namespace.js";import * as workflowRuntime from "#compiled/@workflow/core/runtime.js";export * from "#compiled/@workflow/core/runtime.js";diff --git a/packages/eve/test/setup/workflow-global-setup.ts b/packages/eve/test/setup/workflow-global-setup.tsindex 41d2d33e6..98de74b9f 100644--- a/packages/eve/test/setup/workflow-global-setup.ts+++ b/packages/eve/test/setup/workflow-global-setup.ts@@ -17,6 +17,9 @@ import {type WorkflowBundleDiscoveredEntries,} from "#internal/workflow-bundle/builder-support.js";import { detectWorkflowPatterns } from "#internal/workflow-bundle/workflow-builders.js";+import { installEveWorkflowQueueNamespace } from "#internal/workflow/queue-namespace.js";++export const WORKFLOW_TEST_AGENT_NAME = "eve-test";export default async function setupWorkflowTests(): Promise<void> {const packageRoot = resolvePackageRoot();@@ -24,8 +27,10 @@ export default async function setupWorkflowTests(): Promise<void> {const compiledArtifactsBootstrapPath = resolvePackageSourceFilePath("test/setup/compiled-artifacts-bootstrap.mjs",);+ installEveWorkflowQueueNamespace(WORKFLOW_TEST_AGENT_NAME);const builder = new WorkflowBundleBuilder({+ agentName: WORKFLOW_TEST_AGENT_NAME,appRoot: packageRoot,compiledArtifactsBootstrapPath,includeTestFixtures: true,diff --git a/packages/eve/test/setup/workflow-setup.ts b/packages/eve/test/setup/workflow-setup.tsindex 753f464e7..c2667f48e 100644--- a/packages/eve/test/setup/workflow-setup.ts+++ b/packages/eve/test/setup/workflow-setup.ts@@ -6,12 +6,18 @@ import { afterAll } from "vitest";import { resolvePackageRoot } from "#internal/application/package.js";import { resolveWorkflowTestOutputDirectory } from "#internal/testing/workflow-vitest-plugin.js";-import { EVE_WORKFLOW_QUEUE_PREFIX } from "#internal/workflow/queue-namespace.js";+import {+ deriveEveWorkflowQueuePrefix,+ installEveWorkflowQueueNamespace,+} from "#internal/workflow/queue-namespace.js";import { setWorld } from "#internal/workflow/runtime.js";+import { WORKFLOW_TEST_AGENT_NAME } from "./workflow-global-setup.js";+const packageRoot = resolvePackageRoot();const outDir = resolveWorkflowTestOutputDirectory(packageRoot);const poolId = process.env.VITEST_POOL_ID ?? "0";+installEveWorkflowQueueNamespace(WORKFLOW_TEST_AGENT_NAME);const world = createLocalWorld({dataDir: join(packageRoot, ".workflow-data"),tag: `vitest-${poolId}`,@@ -19,7 +25,10 @@ const world = createLocalWorld({await world.start?.();await world.clear();-world.registerHandler(EVE_WORKFLOW_QUEUE_PREFIX, createLazyHandler(join(outDir, "workflows.mjs")));+world.registerHandler(+ deriveEveWorkflowQueuePrefix(WORKFLOW_TEST_AGENT_NAME),+ createLazyHandler(join(outDir, "workflows.mjs")),+);setWorld(world);afterAll(async () => {diff --git a/scripts/guard-invariants.mjs b/scripts/guard-invariants.mjsindex 763aeade8..e45a875cf 100644--- a/scripts/guard-invariants.mjs+++ b/scripts/guard-invariants.mjs@@ -79,8 +79,8 @@* backlog.* rule 33 — Workflow runtime imports and queue-namespace environment writes* must go through the `src/internal/workflow/runtime.ts` facade and- * `queue-namespace.ts`. This guarantees every queue-producing- * Workflow API observes eve's namespace before it can run.+ * `queue-namespace.ts`. The generated agent bootstrap installs the+ * agent-scoped namespace before queue-producing APIs can run.** Baselines for rules with pre-existing violations live in* `guard-invariants-baseline.json`. Counts and allowlists in that file@@ -274,7 +274,7 @@ function checkRule33(posix, lines, violations) {rule: 33,file: posix,line: idx + 1,- message: `imports the raw Workflow runtime. Import from "#internal/workflow/runtime.js" so eve's queue namespace is installed before any queue-producing API runs.`,+ message: `imports the raw Workflow runtime. Import from "#internal/workflow/runtime.js" to preserve eve's single Workflow runtime package identity.`,});}@@ -283,7 +283,7 @@ function checkRule33(posix, lines, violations) {rule: 33,file: posix,line: idx + 1,- message: `writes WORKFLOW_QUEUE_NAMESPACE outside the canonical namespace module. Remove the write; importing "#internal/workflow/runtime.js" installs the namespace once.`,+ message: `writes WORKFLOW_QUEUE_NAMESPACE outside the canonical namespace module. Use installEveWorkflowQueueNamespace() so every queue surface derives the same agent-scoped value.`,});}});