The Open Framework for Building Agents
fix(eve): workflow runtime - centralize queue namespace (#259)
Andrew Barbac5071e686943
diff --git a/.changeset/sour-seas-pay.md b/.changeset/sour-seas-pay.mdnew file mode 100644index 000000000..70223bdd5--- /dev/null+++ b/.changeset/sour-seas-pay.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Ensure every eve Workflow runtime entrypoint installs the eve queue namespace through a single guarded boundary.diff --git a/packages/eve/src/execution/delegated-parent-notification.ts b/packages/eve/src/execution/delegated-parent-notification.tsindex 91076cb08..00d7ee63b 100644--- a/packages/eve/src/execution/delegated-parent-notification.ts+++ b/packages/eve/src/execution/delegated-parent-notification.ts@@ -9,6 +9,7 @@ import { ChannelKey } from "#runtime/sessions/runtime-context-keys.js";import { deserializeContext } from "#context/serialize.js";import type { RuntimeSubagentResultActionResult } from "#runtime/actions/types.js";import { SUBAGENT_ADAPTER_KIND } from "#execution/subagent-adapter.js";+import { resumeHook } from "#internal/workflow/runtime.js";/*** Resumes the parent driver's hook with a delegated subagent result.@@ -36,8 +37,6 @@ export async function notifyDelegatedParentStep(input: {return;}- process.env.WORKFLOW_QUEUE_NAMESPACE = "eve";- const { resumeHook } = await import("#compiled/@workflow/core/runtime.js");await resumeHook(parentContinuationToken, {kind: "runtime-action-result",results: [input.result],diff --git a/packages/eve/src/execution/durable-session-store.integration.test.ts b/packages/eve/src/execution/durable-session-store.integration.test.tsindex a35da7dc4..9daf8db46 100644--- a/packages/eve/src/execution/durable-session-store.integration.test.ts+++ b/packages/eve/src/execution/durable-session-store.integration.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { start } from "#compiled/@workflow/core/runtime.js";+import { start } from "#internal/workflow/runtime.js";import { createTestRuntime } from "#internal/testing/app-harness.js";import {diff --git a/packages/eve/src/execution/durable-session-store.ts b/packages/eve/src/execution/durable-session-store.tsindex 8326840b4..62d3dd0e4 100644--- a/packages/eve/src/execution/durable-session-store.ts+++ b/packages/eve/src/execution/durable-session-store.ts@@ -24,6 +24,7 @@ import { migrateDurableSessionSnapshot } from "#execution/durable-session-migratimport { projectToDurableSession } from "#execution/session.js";import type { SandboxState } from "#sandbox/state.js";import type { JsonObject } from "#shared/json.js";+import { getRun } from "#internal/workflow/runtime.js";const EVE_SESSION_STREAM_NAMESPACE = "eve.session";@@ -131,10 +132,6 @@ export async function readDurableSession(state: DurableSessionState): Promise<Dureturn migrateDurableSessionSnapshot(state.snapshot).session;}- // Dynamic import: the workflow runtime is only available inside a- // `"use step"` body, and a static import would pull it into the- // workflow-body bundle.- const { getRun } = await import("#compiled/@workflow/core/runtime.js");const stream = getRun<unknown>(state.sessionId).getReadable<unknown>({namespace: EVE_SESSION_STREAM_NAMESPACE,startIndex: -1,diff --git a/packages/eve/src/execution/subagent-adapter.ts b/packages/eve/src/execution/subagent-adapter.tsindex 3a3efab87..41eb06c42 100644--- a/packages/eve/src/execution/subagent-adapter.ts+++ b/packages/eve/src/execution/subagent-adapter.ts@@ -1,4 +1,4 @@-import { resumeHook } from "#compiled/@workflow/core/runtime.js";+import { resumeHook } from "#internal/workflow/runtime.js";import type { ChannelAdapter } from "#channel/adapter.js";import type { SubagentInputRequestHookPayload } from "#channel/types.js";@@ -108,7 +108,6 @@ async function forwardSubagentInputRequestStep(input: {"use step";try {- process.env.WORKFLOW_QUEUE_NAMESPACE = "eve";await resumeHook(input.parentContinuationToken, input.hookPayload);} catch (error) {const errorId = createErrorId();diff --git a/packages/eve/src/execution/turn-workflow.ts b/packages/eve/src/execution/turn-workflow.tsindex 32ecfcb07..e51e5c2d9 100644--- a/packages/eve/src/execution/turn-workflow.ts+++ b/packages/eve/src/execution/turn-workflow.ts@@ -6,6 +6,7 @@ import {type TurnWorkflowInput,} from "#execution/durable-session-migrations/turn-workflow.js";import { turnStep } from "#execution/workflow-steps.js";+import { resumeHook } from "#internal/workflow/runtime.js";const TASK_MODE_WAIT_ERROR_MESSAGE = "Task mode cannot wait for follow-up input (`next: null`).";@@ -132,7 +133,5 @@ export async function notifyDriverStep(input: {}): Promise<void> {"use step";- process.env.WORKFLOW_QUEUE_NAMESPACE = "eve";- const { resumeHook } = await import("#compiled/@workflow/core/runtime.js");await resumeHook(input.completionToken, input.payload);}diff --git a/packages/eve/src/execution/workflow-entry.integration.test.ts b/packages/eve/src/execution/workflow-entry.integration.test.tsindex f018824c2..eca3d0a54 100644--- a/packages/eve/src/execution/workflow-entry.integration.test.ts+++ b/packages/eve/src/execution/workflow-entry.integration.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { getWorld, resumeHook, start } from "#compiled/@workflow/core/runtime.js";+import { getWorld, resumeHook, start } from "#internal/workflow/runtime.js";import { captureTurnEvents, filterEventsByType } from "#internal/testing/events.js";import { createTestRuntime } from "#internal/testing/app-harness.js";diff --git a/packages/eve/src/execution/workflow-runtime.ts b/packages/eve/src/execution/workflow-runtime.tsindex aff4b77a4..b5cb86fd5 100644--- a/packages/eve/src/execution/workflow-runtime.ts+++ b/packages/eve/src/execution/workflow-runtime.ts@@ -1,6 +1,4 @@import { HookNotFoundError } from "#compiled/@workflow/errors/index.js";-import { getRun, resumeHook, start } from "#compiled/@workflow/core/runtime.js";-import type { Run } from "#compiled/@workflow/core/runtime.js";import type { WorkflowFunction, WorkflowMetadata } from "#compiled/@workflow/core/runtime/start.js";import type {@@ -14,7 +12,7 @@ import type {import { serializeContext } from "#context/serialize.js";import { resolveInstalledPackageInfo } from "#internal/application/package.js";import { createLogger, logError } from "#internal/logging.js";-import { applyEveWorkflowQueueNamespace } from "#internal/workflow/queue-namespace.js";+import { getRun, resumeHook, start, type Run } from "#internal/workflow/runtime.js";import type { HandleMessageStreamEvent } from "#protocol/message.js";import type { RuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";import { getCompiledRuntimeAgentBundle } from "#runtime/sessions/compiled-agent-cache.js";@@ -122,7 +120,6 @@ export function createWorkflowRuntime(config: {},async deliver(input: DeliverInput): Promise<{ sessionId: string }> {- applyEveWorkflowQueueNamespace();const hookPayload: Extract<HookPayload, { kind: "deliver" }> = {auth: input.auth,kind: "deliver",@@ -164,7 +161,6 @@ export async function startWorkflowPreferLatest<TArgs extends unknown[], TResultworkflow: WorkflowFunction<TArgs, TResult> | WorkflowMetadata,args: TArgs,): Promise<Run<unknown> | Run<TResult>> {- applyEveWorkflowQueueNamespace();if (!shouldRouteToLatestDeployment()) {return await start(workflow, args);}diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.tsindex 9db9389cb..891cef670 100644--- a/packages/eve/src/execution/workflow-steps.ts+++ b/packages/eve/src/execution/workflow-steps.ts@@ -62,6 +62,7 @@ import { buildTurnAttributes, readRootSessionId } from "#execution/eve-workflow-import { setEveAttributes } from "#runtime/attributes/emit.js";import { turnWorkflow } from "#execution/turn-workflow.js";import { createWorkflowRuntime, startWorkflowPreferLatest } from "#execution/workflow-runtime.js";+import { resumeHook } from "#internal/workflow/runtime.js";/*** Result of one durable harness step, consumed by the turn workflow.@@ -635,9 +636,6 @@ export async function routeProxiedDeliverStep(input: {state: durableSession.state,});- const { resumeHook } = await import("#compiled/@workflow/core/runtime.js");- process.env.WORKFLOW_QUEUE_NAMESPACE = "eve";-for (const forChild of routed.forChildren) {await resumeHook(forChild.childContinuationToken, {auth: input.auth,diff --git a/packages/eve/src/internal/application/package.test.ts b/packages/eve/src/internal/application/package.test.tsindex 8805b3386..747b4b322 100644--- a/packages/eve/src/internal/application/package.test.ts+++ b/packages/eve/src/internal/application/package.test.ts@@ -6,7 +6,7 @@ describe("resolveWorkflowModulePath", () => {it("resolves historical workflow specifiers to narrowed runtime modules", () => {expect(resolveWorkflowModulePath("workflow")).toMatch(/\/src\/internal\/workflow\/index\.ts$/);expect(resolveWorkflowModulePath("workflow/api")).toMatch(- /\/\.generated\/compiled\/@workflow\/core\/runtime\.js$/,+ /\/src\/internal\/workflow\/runtime\.ts$/,);expect(resolveWorkflowModulePath("workflow/internal/builtins")).toMatch(/\/src\/internal\/workflow\/builtins\.ts$/,@@ -14,5 +14,8 @@ describe("resolveWorkflowModulePath", () => {expect(resolveWorkflowModulePath("workflow/internal/private")).toMatch(/\/\.generated\/compiled\/@workflow\/core\/private\.js$/,);+ expect(resolveWorkflowModulePath("workflow/runtime")).toMatch(+ /\/src\/internal\/workflow\/runtime\.ts$/,+ );});});diff --git a/packages/eve/src/internal/application/package.ts b/packages/eve/src/internal/application/package.tsindex b7fb34c01..c245e00bc 100644--- a/packages/eve/src/internal/application/package.ts+++ b/packages/eve/src/internal/application/package.ts@@ -10,10 +10,8 @@ let cachedPackageInfo: InstalledPackageInfo | undefined;// deployments can still report package metadata without resolving package.json.const BUNDLED_FALLBACK_PACKAGE_VERSION: string = "__EVE_PACKAGE_VERSION__";const WORKFLOW_MODULE_ALIASES = {- "workflow/api": "src/compiled/@workflow/core/runtime.js","workflow/errors": "src/compiled/@workflow/errors/index.js","workflow/internal/private": "src/compiled/@workflow/core/private.js",- "workflow/runtime": "src/compiled/@workflow/core/runtime.js",} as const;function resolveFallbackPackageVersion(): string {@@ -263,6 +261,10 @@ export function resolveWorkflowModulePath(specifier: string): string {return resolvePackageSourceFilePath("src/internal/workflow/index.ts");}+ if (specifier === "workflow/api" || specifier === "workflow/runtime") {+ return resolvePackageSourceFilePath("src/internal/workflow/runtime.ts");+ }+if (specifier === "workflow/internal/builtins") {return resolvePackageSourceFilePath("src/internal/workflow/builtins.ts");}diff --git a/packages/eve/src/internal/testing/app-harness.integration.test.ts b/packages/eve/src/internal/testing/app-harness.integration.test.tsindex 42a3f0500..d2e4bdb6e 100644--- a/packages/eve/src/internal/testing/app-harness.integration.test.ts+++ b/packages/eve/src/internal/testing/app-harness.integration.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { start } from "#compiled/@workflow/core/runtime.js";+import { start } from "#internal/workflow/runtime.js";import { workflowEntry } from "#execution/workflow-entry.js";import { createBundledRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";diff --git a/packages/eve/src/internal/testing/workflow-test-helpers.ts b/packages/eve/src/internal/testing/workflow-test-helpers.tsindex 56cee320f..74e2d39dd 100644--- a/packages/eve/src/internal/testing/workflow-test-helpers.ts+++ b/packages/eve/src/internal/testing/workflow-test-helpers.ts@@ -1,4 +1,4 @@-import { getWorld } from "#compiled/@workflow/core/runtime.js";+import { getWorld } from "#internal/workflow/runtime.js";interface WorkflowRunLike {readonly runId: string;diff --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 f07658e51..9120d666e 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@@ -1,9 +1,11 @@-import { mkdtemp, readFile, rm, stat } from "node:fs/promises";+import { mkdtemp, readFile, readdir, rm, stat } from "node:fs/promises";import { tmpdir } from "node:os";import { dirname, join } from "node:path";import { describe, expect, it } from "vitest";-import { atomicWriteFile } from "./builder-support.js";+import { resolvePackageRoot, resolveWorkflowModulePath } from "#internal/application/package.js";++import { atomicWriteFile, bundleFinalWorkflowOutput } from "./builder-support.js";describe("atomicWriteFile", () => {it("writes the requested contents to the target path", async () => {@@ -30,7 +32,7 @@ describe("atomicWriteFile", () => {expect(await readFile(target, "utf8")).toBe("second");- const entries = await import("node:fs/promises").then((fs) => fs.readdir(dir));+ const entries = await readdir(dir);const tmpLeftovers = entries.filter((name) => name.startsWith("output.txt.tmp-"));expect(tmpLeftovers).toEqual([]);} finally {@@ -93,3 +95,27 @@ describe("atomicWriteFile", () => {},);});++describe("bundleFinalWorkflowOutput", () => {+ it("writes the intermediate wrapper against the namespaced eve Workflow runtime facade", async () => {+ const dir = await mkdtemp(join(tmpdir(), "eve-workflow-runtime-facade-"));+ const target = join(dir, "workflows.mjs");++ try {+ await bundleFinalWorkflowOutput({+ bundleFinalOutput: false,+ code: "globalThis.__private_workflows = new Map();",+ format: "esm",+ outfile: target,+ workingDir: resolvePackageRoot(),+ });++ const source = await readFile(target, "utf8");+ const runtimePath = resolveWorkflowModulePath("workflow/runtime").replaceAll("\\", "/");+ expect(source).toContain(`from ${JSON.stringify(runtimePath)}`);+ 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 c0038211e..b113d67b3 100644--- a/packages/eve/src/internal/workflow-bundle/builder-support.ts+++ b/packages/eve/src/internal/workflow-bundle/builder-support.ts@@ -387,9 +387,10 @@ export async function bundleFinalWorkflowOutput(input: {workingDir: string;}): Promise<void> {const workflowBundleCode = input.code.endsWith("\n") ? input.code : `${input.code}\n`;+ const workflowRuntimePath = resolveWorkflowModulePath("workflow/runtime").replaceAll("\\", "/");const workflowFunctionCode = `// biome-ignore-all lint: generated file/* eslint-disable */-import { workflowEntrypoint } from 'workflow/runtime';+import { workflowEntrypoint } from ${JSON.stringify(workflowRuntimePath)};const workflowCode = \`${workflowBundleCode.replace(/[\\`$]/g, "\\$&")}\`;diff --git a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.tsindex a60cca58f..df74c797a 100644--- a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts+++ b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts@@ -434,14 +434,12 @@ describe("WorkflowBundleBuilder", () => {expect(flowConfig.environment).toEqual({EVE_EXISTING_FLAG: "kept",NODE_OPTIONS: "--experimental-require-module",- WORKFLOW_QUEUE_NAMESPACE: "eve",});- expect(- await readFile(- join(outputDir, "functions", ".well-known", "workflow", "v1", "flow.func", "index.js"),- "utf8",- ),- ).toContain("/.well-known/workflow/v1/flow");+ const generatedFlowFunctionSource = await readFile(+ join(outputDir, "functions", ".well-known", "workflow", "v1", "flow.func", "index.js"),+ "utf8",+ );+ expect(generatedFlowFunctionSource).toContain("/.well-known/workflow/v1/flow");expect(await readFile(join(diff --git a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.tsindex ddba4be8f..59ca5d4d3 100644--- a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts+++ b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts@@ -279,7 +279,6 @@ describe("emitBundledWorkflowFunctionDirectory", () => {expect(config.supportsResponseStreaming).toBe(true);expect(config.environment).toEqual({NODE_OPTIONS: "--experimental-require-module",- WORKFLOW_QUEUE_NAMESPACE: "eve",});});diff --git a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.tsindex 597e90101..8e2220e17 100644--- a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts+++ b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts@@ -23,10 +23,6 @@ import {isEveVercelFunctionPath,normalizeEveVercelRoutes,} from "#internal/workflow-bundle/eve-service-route-output.js";-import {- EVE_WORKFLOW_QUEUE_NAMESPACE,- WORKFLOW_QUEUE_NAMESPACE_ENV,-} from "#internal/workflow/queue-namespace.js";// just-bash and microsandbox are optional peer dependencies (the// opt-in local sandbox engines) loaded lazily from the application's@@ -61,7 +57,6 @@ export function createWorkflowFunctionEnvironment(environment?: unknown): Record}nextEnvironment.NODE_OPTIONS = WORKFLOW_FUNCTION_NODE_OPTIONS;- nextEnvironment[WORKFLOW_QUEUE_NAMESPACE_ENV] = EVE_WORKFLOW_QUEUE_NAMESPACE;return nextEnvironment;}diff --git a/packages/eve/src/internal/workflow/configure-world.ts b/packages/eve/src/internal/workflow/configure-world.tsindex 547bb7283..1b9fc7680 100644--- a/packages/eve/src/internal/workflow/configure-world.ts+++ b/packages/eve/src/internal/workflow/configure-world.ts@@ -1,5 +1,5 @@-import { setWorld } from "#compiled/@workflow/core/runtime.js";import type { World } from "#compiled/@workflow/world/index.js";+import { setWorld } from "#internal/workflow/runtime.js";export interface ConfiguredWorkflowWorldModule {readonly [name: string]: unknown;diff --git a/packages/eve/src/internal/workflow/queue-namespace.test.ts b/packages/eve/src/internal/workflow/queue-namespace.test.tsnew file mode 100644index 000000000..095081baf--- /dev/null+++ b/packages/eve/src/internal/workflow/queue-namespace.test.ts@@ -0,0 +1,12 @@+import { describe, expect, it } from "vitest";++import {+ EVE_WORKFLOW_QUEUE_NAMESPACE,+ 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);+ });+});diff --git a/packages/eve/src/internal/workflow/queue-namespace.ts b/packages/eve/src/internal/workflow/queue-namespace.tsindex 3103d2388..3412c87c3 100644--- a/packages/eve/src/internal/workflow/queue-namespace.ts+++ b/packages/eve/src/internal/workflow/queue-namespace.ts@@ -3,6 +3,4 @@ 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}*`;-export function applyEveWorkflowQueueNamespace(): void {- process.env[WORKFLOW_QUEUE_NAMESPACE_ENV] = EVE_WORKFLOW_QUEUE_NAMESPACE;-}+process.env[WORKFLOW_QUEUE_NAMESPACE_ENV] = EVE_WORKFLOW_QUEUE_NAMESPACE;diff --git a/packages/eve/src/internal/workflow/runtime.ts b/packages/eve/src/internal/workflow/runtime.tsnew file mode 100644index 000000000..de4308d86--- /dev/null+++ b/packages/eve/src/internal/workflow/runtime.ts@@ -0,0 +1,9 @@+import "#internal/workflow/queue-namespace.js";+import * as workflowRuntime from "#compiled/@workflow/core/runtime.js";++export * from "#compiled/@workflow/core/runtime.js";++/** Installs a World across source and vendored Workflow package identities. */+export function setWorld(world: unknown): void {+ workflowRuntime.setWorld(world as Parameters<typeof workflowRuntime.setWorld>[0]);+}diff --git a/packages/eve/src/runtime/connections/callback-route.ts b/packages/eve/src/runtime/connections/callback-route.tsindex a268e72b4..d98fbf520 100644--- a/packages/eve/src/runtime/connections/callback-route.ts+++ b/packages/eve/src/runtime/connections/callback-route.ts@@ -22,9 +22,7 @@* internet.*/-import { resumeHook } from "#compiled/@workflow/core/runtime.js";--import { applyEveWorkflowQueueNamespace } from "#internal/workflow/queue-namespace.js";+import { resumeHook } from "#internal/workflow/runtime.js";import { EVE_CONNECTION_CALLBACK_ROUTE_PATTERN } from "#protocol/routes.js";import type { ChannelMethod, RouteContext } from "#public/definitions/channel.js";import type { ResolvedChannelDefinition } from "#runtime/types.js";@@ -114,7 +112,6 @@ export async function handleConnectionCallbackRequest(// this hook upfront (before any turns run) so it always exists// when the callback arrives.try {- applyEveWorkflowQueueNamespace();await resumeHook(token, {kind: "deliver" as const,payloads: [{ authorizationCallback: { connectionName: name, callback } }],diff --git a/packages/eve/src/runtime/session-callback-route.ts b/packages/eve/src/runtime/session-callback-route.tsindex 243df88cd..f7bc7fa18 100644--- a/packages/eve/src/runtime/session-callback-route.ts+++ b/packages/eve/src/runtime/session-callback-route.ts@@ -1,6 +1,4 @@-import { resumeHook } from "#compiled/@workflow/core/runtime.js";--import { applyEveWorkflowQueueNamespace } from "#internal/workflow/queue-namespace.js";+import { resumeHook } from "#internal/workflow/runtime.js";import { EVE_CALLBACK_ROUTE_PATTERN } from "#protocol/routes.js";import type { ChannelMethod, RouteContext } from "#public/definitions/channel.js";import type { ResolvedChannelDefinition } from "#runtime/types.js";@@ -74,7 +72,6 @@ export async function handleSessionCallbackRequest(}try {- applyEveWorkflowQueueNamespace();await resumeHook(token, {kind: "runtime-action-result",results: [result],diff --git a/packages/eve/test/setup/workflow-setup.ts b/packages/eve/test/setup/workflow-setup.tsindex 428e56e1f..753f464e7 100644--- a/packages/eve/test/setup/workflow-setup.ts+++ b/packages/eve/test/setup/workflow-setup.ts@@ -1,16 +1,13 @@import { join } from "node:path";import { pathToFileURL } from "node:url";-import { setWorld } from "@workflow/core/runtime";import { createLocalWorld } from "@workflow/world-local";import { afterAll } from "vitest";import { resolvePackageRoot } from "#internal/application/package.js";import { resolveWorkflowTestOutputDirectory } from "#internal/testing/workflow-vitest-plugin.js";-import {- applyEveWorkflowQueueNamespace,- EVE_WORKFLOW_QUEUE_PREFIX,-} from "#internal/workflow/queue-namespace.js";+import { EVE_WORKFLOW_QUEUE_PREFIX } from "#internal/workflow/queue-namespace.js";+import { setWorld } from "#internal/workflow/runtime.js";const packageRoot = resolvePackageRoot();const outDir = resolveWorkflowTestOutputDirectory(packageRoot);@@ -22,7 +19,6 @@ const world = createLocalWorld({await world.start?.();await world.clear();-applyEveWorkflowQueueNamespace();world.registerHandler(EVE_WORKFLOW_QUEUE_PREFIX, createLazyHandler(join(outDir, "workflows.mjs")));setWorld(world);diff --git a/scripts/guard-invariants.mjs b/scripts/guard-invariants.mjsindex 1804136df..763aeade8 100644--- a/scripts/guard-invariants.mjs+++ b/scripts/guard-invariants.mjs@@ -77,6 +77,10 @@* ISO `last_updated` date. Research documents are implementation* plans attached to tracked GitHub work, not an unowned parallel* 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.** Baselines for rules with pre-existing violations live in* `guard-invariants-baseline.json`. Counts and allowlists in that file@@ -164,6 +168,7 @@ function isTsLike(relPath) {* rule26: Violation[];* rule27: Violation[];* rule28: Violation[];+ * rule33: Violation[];* symlinks: string[];* }} state*/@@ -190,6 +195,7 @@ async function scanRepo(state) {checkRule26(posix, lines, state.rule26);checkRule27(posix, lines, state.rule27);checkRule28(posix, lines, state.rule28);+ checkRule33(posix, lines, state.rule33);}}@@ -243,6 +249,46 @@ function checkRule15(posix, lines, violations) {});}+// ---------- Rule 33: namespaced Workflow runtime boundary ----------++const RAW_WORKFLOW_RUNTIME_SPECIFIER_RE =+ /["'](?:#compiled\/@workflow\/core\/runtime(?:\.js|\/[^"']+\.js)|@workflow\/core\/runtime(?:\/[^"']+)?|workflow\/(?:api|runtime))["']/;+const WORKFLOW_QUEUE_NAMESPACE_WRITE_RE =+ /process\.env(?:\.WORKFLOW_QUEUE_NAMESPACE|\[\s*(?:WORKFLOW_QUEUE_NAMESPACE_ENV|["']WORKFLOW_QUEUE_NAMESPACE["'])\s*\])\s*=/;+const WORKFLOW_RUNTIME_FACADES = new Set(["packages/eve/src/internal/workflow/runtime.ts"]);+const WORKFLOW_QUEUE_NAMESPACE_MODULE = "packages/eve/src/internal/workflow/queue-namespace.ts";++/**+ * @param {string} posix+ * @param {string[]} lines+ * @param {Violation[]} violations+ */+function checkRule33(posix, lines, violations) {+ lines.forEach((line, idx) => {+ const isTypeOnlyImport = /^\s*(?:import|export)\s+type\b/.test(line);+ const isRuntimeImport =+ /^(?:import|export)\b|^}\s*from\b|\b(?:import|require)\s*\(/.test(line.trimStart()) &&+ RAW_WORKFLOW_RUNTIME_SPECIFIER_RE.test(line);+ if (!WORKFLOW_RUNTIME_FACADES.has(posix) && !isTypeOnlyImport && isRuntimeImport) {+ violations.push({+ 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.`,+ });+ }++ if (posix !== WORKFLOW_QUEUE_NAMESPACE_MODULE && WORKFLOW_QUEUE_NAMESPACE_WRITE_RE.test(line)) {+ violations.push({+ 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.`,+ });+ }+ });+}+// ---------- Rule 19: AsyncLocalStorage instances ----------const NEW_ALS_RE = /new\s+AsyncLocalStorage\s*[<(]/;@@ -928,6 +974,7 @@ async function main() {rule26: /** @type {Violation[]} */ ([]),rule27: /** @type {Violation[]} */ ([]),rule28: /** @type {Violation[]} */ ([]),+ rule33: /** @type {Violation[]} */ ([]),symlinks: /** @type {string[]} */ ([]),};@@ -1010,6 +1057,9 @@ async function main() {// Rule 32violations.push(...(await checkRule32ResearchFrontmatter()));+ // Rule 33+ violations.push(...state.rule33);+if (violations.length === 0) {process.stdout.write("[eve:guard:invariants] ok — all mechanical lints passed.\n");return;