diff --git a/.changeset/ignore-generated-manifest.md b/.changeset/ignore-generated-manifest.md
new file mode 100644
index 0000000000..d00263a47d
--- /dev/null
+++ b/.changeset/ignore-generated-manifest.md
@@ -0,0 +1,7 @@
+---
+"@workflow/builders": patch
+"@workflow/next": patch
+"@workflow/sveltekit": patch
+---
+
+Write colocated `.gitignore` files for public workflow manifests generated by `WORKFLOW_PUBLIC_MANIFEST=1`
diff --git a/.changeset/lazy-discovery-default.md b/.changeset/lazy-discovery-default.md
new file mode 100644
index 0000000000..9490c888c9
--- /dev/null
+++ b/.changeset/lazy-discovery-default.md
@@ -0,0 +1,10 @@
+---
+'@workflow/next': minor
+---
+
+Change `lazyDiscovery` default to `true` for `withWorkflow`. Workflow
+discovery is now deferred until files are requested instead of scanning
+eagerly at startup on Next.js versions that support deferred entries
+(>= 16.2.0-canary.48). Older versions automatically fall back to eager
+discovery. Pass `workflows: { lazyDiscovery: false }` to opt back into
+eager discovery on supported Next.js versions.
diff --git a/.changeset/queued-for-uses-first-step-started.md b/.changeset/queued-for-uses-first-step-started.md
new file mode 100644
index 0000000000..d469643bf3
--- /dev/null
+++ b/.changeset/queued-for-uses-first-step-started.md
@@ -0,0 +1,5 @@
+---
+"@workflow/web-shared": patch
+---
+
+Fix the "Queued for" duration shown in the events list for retried steps. It now measures from `step_created` to the first `step_started` instead of the last, so the displayed value reflects actual queue time rather than queue time plus all retry waits.
diff --git a/.changeset/upgrading-workflows-cookbook.md b/.changeset/upgrading-workflows-cookbook.md
new file mode 100644
index 0000000000..a845151cc8
--- /dev/null
+++ b/.changeset/upgrading-workflows-cookbook.md
@@ -0,0 +1,2 @@
+---
+---
diff --git a/.changeset/upset-ghosts-rush.md b/.changeset/upset-ghosts-rush.md
new file mode 100644
index 0000000000..864621d664
--- /dev/null
+++ b/.changeset/upset-ghosts-rush.md
@@ -0,0 +1,4 @@
+---
+---
+
+chore(tests): surface HTTP status and elapsed time in abort-fetch e2e diagnostics so flaky failures of `abortFetchInFlightWorkflow` and `abortVoidSleepTimeoutWorkflow` reveal why the slow upstream returned early.
diff --git a/.changeset/wise-frogs-thank.md b/.changeset/wise-frogs-thank.md
new file mode 100644
index 0000000000..4b62fe9ff7
--- /dev/null
+++ b/.changeset/wise-frogs-thank.md
@@ -0,0 +1,5 @@
+---
+"@workflow/web-shared": patch
+---
+
+adjusted spacing on trace viewer and detail pane
diff --git a/docs/app/[lang]/llms.mdx/[[...slug]]/route.ts b/docs/app/[lang]/llms.mdx/[[...slug]]/route.ts
index 3134f7d1f7..dd3abd0c4c 100644
--- a/docs/app/[lang]/llms.mdx/[[...slug]]/route.ts
+++ b/docs/app/[lang]/llms.mdx/[[...slug]]/route.ts
@@ -1,10 +1,12 @@
-import { notFound } from 'next/navigation';
+import { generateNotFoundMarkdown } from '@vercel/agent-readability';
import { rewriteCookbookUrlsInText } from '@/lib/geistdocs/cookbook-source';
import { getLLMText, source } from '@/lib/geistdocs/source';
import { i18n } from '@/lib/geistdocs/i18n';
export const revalidate = false;
+const MARKDOWN_HEADERS = { 'Content-Type': 'text/markdown; charset=utf-8' };
+
export async function GET(
_req: Request,
{ params }: RouteContext<'/[lang]/llms.mdx/[[...slug]]'>
@@ -13,7 +15,11 @@ export async function GET(
const page = source.getPage(slug, lang);
if (!page) {
- notFound();
+ // Status 200 (not 404): agents commonly discard 404 response bodies.
+ const requestedPath = slug?.length ? `/${slug.join('/')}` : '/';
+ return new Response(generateNotFoundMarkdown(requestedPath), {
+ headers: MARKDOWN_HEADERS,
+ });
}
const sitemapPath =
diff --git a/docs/content/docs/v4/cookbook/advanced/meta.json b/docs/content/docs/v4/cookbook/advanced/meta.json
index 1b8ea39d44..48610b096d 100644
--- a/docs/content/docs/v4/cookbook/advanced/meta.json
+++ b/docs/content/docs/v4/cookbook/advanced/meta.json
@@ -3,6 +3,7 @@
"pages": [
"child-workflows",
"distributed-abort-controller",
+ "upgrading-workflows",
"serializable-steps",
"publishing-libraries"
]
diff --git a/docs/content/docs/v4/cookbook/advanced/upgrading-workflows.mdx b/docs/content/docs/v4/cookbook/advanced/upgrading-workflows.mdx
new file mode 100644
index 0000000000..45ffdbff1c
--- /dev/null
+++ b/docs/content/docs/v4/cookbook/advanced/upgrading-workflows.mdx
@@ -0,0 +1,212 @@
+---
+title: Upgrading Workflows
+description: Identify a clean upgrade point in a long-running workflow and spawn a fresh run on the latest deployment carrying state forward.
+type: guide
+summary: 'Identify a clean upgrade point and hand off to a fresh run via `start(self, [state], { deploymentId: "latest" })` — either automatically on every iteration, or on demand via a dedicated upgrade hook.'
+related:
+ - /docs/foundations/versioning
+ - /cookbook/common-patterns/workflow-composition
+ - /docs/api-reference/workflow-api/start
+ - /docs/foundations/hooks
+---
+
+Workflows that block on external events for days, weeks, or months can outlive many deployments. **The key is to identify a clean upgrade point in the workflow** — a moment where it's safe to checkpoint state and start fresh — and then call [`start()`](/docs/api-reference/workflow-api/start) with `deploymentId: "latest"` to spawn a new run carrying that state forward. The current run ends; the next run begins on whatever deployment is live at that moment, so shipped fixes apply immediately without ever migrating an in-flight run.
+
+
+For the underlying model — why runs pin to a deployment by default, how cancel-and-rerun works, and how state crosses the version boundary — see [Versioning](/docs/foundations/versioning). This recipe focuses on event-driven workflows that need to keep advancing across deployments.
+
+
+A clean upgrade point is any spot in the workflow where:
+
+- All in-progress side effects have completed (or aren't needed by the next iteration)
+- The relevant state can be serialized into the workflow's input arguments
+- It's natural for the workflow to "checkpoint" — typically right after handling an external event, completing a batch, or finishing a logical phase
+
+There are two ways to apply this:
+
+1. **Upgrade on every iteration** ([Method 1](#method-1-upgrade-on-every-iteration)). Each run handles a single event and unconditionally hands off to a fresh run on the latest deployment before exiting. Simple — no extra triggers — but every event pays the respawn cost.
+2. **Upgrade on demand via a dedicated hook** ([Method 2](#method-2-upgrade-on-demand-via-a-dedicated-hook)). A single long-lived run handles many events in a loop and only respawns when an `upgradeHook` fires. A separate endpoint resumes that hook from your control plane (e.g. after a deploy). More control and fewer respawns, at the cost of an explicit trigger.
+
+### When to use each
+
+- **Method 1** when iterations are short and frequent, the work is cheap to checkpoint, and you want shipped fixes to apply on the very next event. Long-lived "session" workflows (subscriptions, queues, FSMs) that already process events one at a time fit this naturally.
+- **Method 2** when iterations are infrequent or expensive (you don't want to respawn on every event), or when you need to roll out a fix to a fleet of in-flight runs after a deploy by fanning out to a control-plane endpoint. Also fits when "upgrade" should be an explicit operation rather than a side effect of handling each event.
+
+## Method 1: Upgrade on every iteration
+
+Each run inherits state via its argument, blocks on a hook, processes the resume, then unconditionally hands off to its successor. The `start()` call is wrapped in a `"use step"` function (required) and passes `deploymentId: "latest"` so the new run lands on the freshest code.
+
+```typescript lineNumbers
+import { defineHook, getWorkflowMetadata } from "workflow";
+import { start } from "workflow/api";
+
+declare function processItem(itemId: string): Promise; // @setup
+
+interface QueueState {
+ processed: number;
+ cursor: string | null;
+}
+
+export const nextItemHook = defineHook<{ itemId: string }>();
+
+async function spawnSelfOnLatest(state: QueueState): Promise {
+ "use step"; // [!code highlight]
+
+ // `deploymentId: "latest"` resolves to whichever deployment is current
+ // when this spawn lands — NOT the deployment running this code.
+ const next = await start(longRunningQueue, [state], { // [!code highlight]
+ deploymentId: "latest", // [!code highlight]
+ }); // [!code highlight]
+ return next.runId;
+}
+
+export async function longRunningQueue(
+ state: QueueState = { processed: 0, cursor: null },
+): Promise {
+ "use workflow";
+
+ const { workflowRunId } = getWorkflowMetadata();
+
+ // Block until something fires the hook — could be hours, days, or longer.
+ // Per-run hook tokens (workflowRunId) keep concurrent chains isolated.
+ const { itemId } = await nextItemHook.create({ token: workflowRunId }); // [!code highlight]
+
+ await processItem(itemId);
+
+ // Hand off to a fresh run on the latest deployment. THIS run ends here.
+ await spawnSelfOnLatest({ // [!code highlight]
+ processed: state.processed + 1, // [!code highlight]
+ cursor: itemId, // [!code highlight]
+ }); // [!code highlight]
+}
+```
+
+### Resuming the hook
+
+Any server-side code can resume the currently-active iteration by calling `.resume()` with the run ID:
+
+```typescript
+import { nextItemHook } from "@/workflows/long-running-queue";
+
+export async function POST(req: Request) {
+ const { runId, itemId } = await req.json();
+
+ await nextItemHook.resume(runId, { itemId }); // [!code highlight]
+
+ return Response.json({ success: true });
+}
+```
+
+The caller tracks the active `runId` (e.g. in a database, KV, or returned from the previous iteration) and updates it whenever the chain advances.
+
+## Method 2: Upgrade on demand via a dedicated hook
+
+Use a single long-running workflow that handles events in a loop. Define a second hook — `upgradeHook` — alongside the work hook, and race them. While only the work hook fires, the run keeps handling events on its current deployment. When `upgradeHook` resumes, the workflow captures current state and respawns on the latest deployment, then exits.
+
+```typescript lineNumbers
+import { defineHook, getWorkflowMetadata } from "workflow";
+import { start } from "workflow/api";
+
+declare function processItem(itemId: string): Promise; // @setup
+
+interface QueueState {
+ processed: number;
+ cursor: string | null;
+}
+
+export const nextItemHook = defineHook<{ itemId: string }>();
+export const upgradeHook = defineHook<{ reason?: string }>(); // [!code highlight]
+
+async function spawnSelfOnLatest(state: QueueState): Promise {
+ "use step";
+
+ const next = await start(longRunningQueue, [state], {
+ deploymentId: "latest",
+ });
+ return next.runId;
+}
+
+export async function longRunningQueue(
+ state: QueueState = { processed: 0, cursor: null },
+): Promise {
+ "use workflow";
+
+ const { workflowRunId } = getWorkflowMetadata();
+
+ while (true) {
+ // Race a normal work event against the upgrade signal.
+ const event = await Promise.race([ // [!code highlight]
+ nextItemHook
+ .create({ token: workflowRunId })
+ .then((payload) => ({ kind: "work" as const, payload })),
+ upgradeHook // [!code highlight]
+ .create({ token: workflowRunId }) // [!code highlight]
+ .then(() => ({ kind: "upgrade" as const })), // [!code highlight]
+ ]);
+
+ if (event.kind === "upgrade") { // [!code highlight]
+ // Checkpoint current state and hand off to a fresh run
+ // on whatever deployment is live now. THIS run ends here.
+ await spawnSelfOnLatest(state); // [!code highlight]
+ return; // [!code highlight]
+ }
+
+ await processItem(event.payload.itemId);
+ state = {
+ processed: state.processed + 1,
+ cursor: event.payload.itemId,
+ };
+ }
+}
+```
+
+### Triggering the upgrade
+
+Expose a separate endpoint that resumes `upgradeHook` for a given run. Call it from your deploy pipeline, an admin UI, or a fan-out script that iterates over every active run after shipping a fix.
+
+```typescript
+import { upgradeHook } from "@/workflows/long-running-queue";
+
+export async function POST(req: Request) {
+ const { runId, reason } = await req.json();
+
+ // The workflow exits its loop, captures state, and respawns
+ // on the latest deployment.
+ await upgradeHook.resume(runId, { reason }); // [!code highlight]
+
+ return Response.json({ success: true });
+}
+```
+
+To upgrade a fleet of runs after a deploy, list active runs (e.g. from a tracking store) and call this endpoint for each.
+
+## How it works
+
+1. **`deploymentId: "latest"` is the upgrade knob.** Without it, the spawn pins to the current deployment. With it, the new run resolves to whatever deployment is current when the runtime picks it up — so any shipped fix applies starting from that respawn. Both methods rely on this.
+2. **`start()` from a step.** [`start()`](/docs/api-reference/workflow-api/start) is not allowed directly inside `"use workflow"` functions — wrap it in a `"use step"` helper to keep the spawn deterministic across replays.
+3. **State carries through the function argument.** The accumulating context flows from run N to run N+1 as a serialized argument. No external store is required for the state itself.
+4. **Per-run hook tokens.** Using `workflowRunId` as the hook token scopes each iteration's wait to its own run, so multiple chains can run concurrently without interfering.
+5. **Method 1 vs Method 2 is just where the spawn happens.** In Method 1 every run spawns its successor unconditionally before exiting — there is no long-lived process to migrate. In Method 2 the spawn happens only when the upgrade hook fires; otherwise the loop keeps handling events on the same run.
+
+## Adapting to your use case
+
+- **Combine with a sleep.** Race the hook against `sleep()` so iterations also tick on a timer: `Promise.race([hook, sleep("1d")])` lets the workflow advance even if no external event arrives.
+- **Stateless successors.** If the next iteration doesn't need the previous state (e.g. a pure event router), call `start(longRunningQueue, [], { deploymentId: "latest" })` and skip the argument plumbing.
+- **Persist state externally.** If state needs to be readable from outside the workflow (dashboards, debugging, recovery), write it to a database in a step before spawning the next run.
+- **Track the active runId externally.** Whatever resumes the hook needs to know the current run. Have the spawn step write the new `runId` to a KV/database keyed by a stable session identifier so resumers always look up the latest one.
+
+## Caveats
+
+- **Backward compatibility matters.** Because the next run executes on a different deployment, the workflow's input arguments and return type must remain compatible across deployments. Adding required fields, removing fields, or changing types can cause serialization failures. See the [`deploymentId: "latest"` callout](/docs/api-reference/workflow-api/start#using-deploymentid-latest).
+- **Workflow identity is the function name + file path.** Renaming the function or moving the file across a deployment changes the workflow ID — the next iteration will fail to resolve. Treat the workflow's name and location as stable interfaces.
+- **There is a tiny gap between iterations.** The current run ends as soon as `start()` returns; the next run starts asynchronously. A resume that arrives in that window can fail with "hook not found." Make resumers retry, or have the API persist pending payloads and apply them once the next iteration is ready.
+- **Method 2: track active runs externally.** Because Method 2's runs are long-lived, the set of in-flight runs only changes when one starts, completes, or upgrades. Persist run IDs (and clean them up on completion or upgrade) so a rollout script can fan out reliably. After resuming `upgradeHook`, also update the tracked run ID once the new run reports back, the same way you would in Method 1.
+- **`start()` must be called from a step**, never directly from the workflow body.
+
+## Key APIs
+
+- [`"use workflow"`](/docs/foundations/workflows-and-steps) — marks the orchestrator function
+- [`"use step"`](/docs/foundations/workflows-and-steps) — required wrapper for `start()` calls
+- [`start()`](/docs/api-reference/workflow-api/start) with [`deploymentId: "latest"`](/docs/api-reference/workflow-api/start#using-deploymentid-latest) — spawn the successor on the newest deployment
+- [`defineHook()`](/docs/api-reference/workflow/define-hook) — suspend the workflow until an external event resumes it
+- [`getWorkflowMetadata()`](/docs/api-reference/workflow/get-workflow-metadata) — exposes `workflowRunId` for per-run hook tokens
diff --git a/docs/content/docs/v4/cookbook/index.mdx b/docs/content/docs/v4/cookbook/index.mdx
index 94cb6d9d18..ea1ecbb724 100644
--- a/docs/content/docs/v4/cookbook/index.mdx
+++ b/docs/content/docs/v4/cookbook/index.mdx
@@ -34,5 +34,6 @@ A curated collection of workflow patterns with clean, copy-paste code examples f
- [**Child Workflows**](/cookbook/advanced/child-workflows) — Spawn and orchestrate child workflows from a parent
- [**Distributed Abort Controller**](/cookbook/advanced/distributed-abort-controller) — Build a cross-process abort controller using workflow streams and hooks
+- [**Upgrading Workflows**](/cookbook/advanced/upgrading-workflows) — Identify a clean upgrade point in a long-running workflow and spawn a fresh run on the latest deployment carrying state forward
- [**Serializable Steps**](/cookbook/advanced/serializable-steps) — Wrap non-serializable third-party objects so they cross the workflow boundary
- [**Publishing Libraries**](/cookbook/advanced/publishing-libraries) — Ship npm packages that export reusable workflow functions
diff --git a/docs/content/docs/v5/api-reference/workflow-next/with-workflow.mdx b/docs/content/docs/v5/api-reference/workflow-next/with-workflow.mdx
index 413cb55d00..84562002fa 100644
--- a/docs/content/docs/v5/api-reference/workflow-next/with-workflow.mdx
+++ b/docs/content/docs/v5/api-reference/workflow-next/with-workflow.mdx
@@ -68,7 +68,7 @@ const nextConfig: NextConfig = {};
export default withWorkflow(nextConfig, {
workflows: {
- lazyDiscovery: true,
+ lazyDiscovery: false,
local: {
port: 4000,
},
@@ -79,7 +79,7 @@ export default withWorkflow(nextConfig, {
| Option | Type | Default | Description |
| --- | --- | --- | --- |
-| `workflows.lazyDiscovery` | `boolean` | `false` | When `true`, defers workflow discovery until files are requested instead of scanning eagerly at startup. Useful for large projects where startup time matters. |
+| `workflows.lazyDiscovery` | `boolean` | `true` | Defers workflow discovery until files are requested instead of scanning eagerly at startup. Set to `false` to force eager discovery (scanning the project up front). Requires a Next.js version that supports deferred entries; older versions fall back to eager discovery automatically. |
| `workflows.local.port` | `number` | — | Overrides the `PORT` environment variable for local development. Has no effect when deployed to Vercel. |
| `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
diff --git a/docs/content/docs/v5/cookbook/advanced/meta.json b/docs/content/docs/v5/cookbook/advanced/meta.json
index 3f4a6be9ae..443536ea64 100644
--- a/docs/content/docs/v5/cookbook/advanced/meta.json
+++ b/docs/content/docs/v5/cookbook/advanced/meta.json
@@ -1,4 +1,9 @@
{
"title": "Advanced",
- "pages": ["child-workflows", "serializable-steps", "publishing-libraries"]
+ "pages": [
+ "child-workflows",
+ "upgrading-workflows",
+ "serializable-steps",
+ "publishing-libraries"
+ ]
}
diff --git a/docs/content/docs/v5/cookbook/advanced/upgrading-workflows.mdx b/docs/content/docs/v5/cookbook/advanced/upgrading-workflows.mdx
new file mode 100644
index 0000000000..0b9b556c8e
--- /dev/null
+++ b/docs/content/docs/v5/cookbook/advanced/upgrading-workflows.mdx
@@ -0,0 +1,195 @@
+---
+title: Upgrading Workflows
+description: Identify a clean upgrade point in a long-running workflow and spawn a fresh run on the latest deployment carrying state forward.
+type: guide
+summary: 'Identify a clean upgrade point and hand off to a fresh run via `start(self, [state], { deploymentId: "latest" })` — either automatically on every iteration, or on demand via a dedicated upgrade hook.'
+related:
+ - /docs/foundations/versioning
+ - /cookbook/common-patterns/workflow-composition
+ - /docs/api-reference/workflow-api/start
+ - /docs/foundations/hooks
+---
+
+Workflows that block on external events for days, weeks, or months can outlive many deployments. **The key is to identify a clean upgrade point in the workflow** — a moment where it's safe to checkpoint state and start fresh — and then call [`start()`](/docs/api-reference/workflow-api/start) with `deploymentId: "latest"` to spawn a new run carrying that state forward. The current run ends; the next run begins on whatever deployment is live at that moment, so shipped fixes apply immediately without ever migrating an in-flight run.
+
+
+For the underlying model — why runs pin to a deployment by default, how cancel-and-rerun works, and how state crosses the version boundary — see [Versioning](/docs/foundations/versioning). This recipe focuses on event-driven workflows that need to keep advancing across deployments.
+
+
+A clean upgrade point is any spot in the workflow where:
+
+- All in-progress side effects have completed (or aren't needed by the next iteration)
+- The relevant state can be serialized into the workflow's input arguments
+- It's natural for the workflow to "checkpoint" — typically right after handling an external event, completing a batch, or finishing a logical phase
+
+There are two ways to apply this:
+
+1. **Upgrade on every iteration** ([Method 1](#method-1-upgrade-on-every-iteration)). Each run handles a single event and unconditionally hands off to a fresh run on the latest deployment before exiting. Simple — no extra triggers — but every event pays the respawn cost.
+2. **Upgrade on demand via a dedicated hook** ([Method 2](#method-2-upgrade-on-demand-via-a-dedicated-hook)). A single long-lived run handles many events in a loop and only respawns when an `upgradeHook` fires. A separate endpoint resumes that hook from your control plane (e.g. after a deploy). More control and fewer respawns, at the cost of an explicit trigger.
+
+### When to use each
+
+- **Method 1** when iterations are short and frequent, the work is cheap to checkpoint, and you want shipped fixes to apply on the very next event. Long-lived "session" workflows (subscriptions, queues, FSMs) that already process events one at a time fit this naturally.
+- **Method 2** when iterations are infrequent or expensive (you don't want to respawn on every event), or when you need to roll out a fix to a fleet of in-flight runs after a deploy by fanning out to a control-plane endpoint. Also fits when "upgrade" should be an explicit operation rather than a side effect of handling each event.
+
+## Method 1: Upgrade on every iteration
+
+Each run inherits state via its argument, blocks on a hook, processes the resume, then unconditionally hands off to its successor by calling `start()` directly from the workflow body with `deploymentId: "latest"`.
+
+```typescript lineNumbers
+import { defineHook, getWorkflowMetadata } from "workflow";
+import { start } from "workflow/api";
+
+declare function processItem(itemId: string): Promise; // @setup
+
+interface QueueState {
+ processed: number;
+ cursor: string | null;
+}
+
+export const nextItemHook = defineHook<{ itemId: string }>();
+
+export async function longRunningQueue(
+ state: QueueState = { processed: 0, cursor: null },
+): Promise {
+ "use workflow";
+
+ const { workflowRunId } = getWorkflowMetadata();
+
+ // Block until something fires the hook — could be hours, days, or longer.
+ // Per-run hook tokens (workflowRunId) keep concurrent chains isolated.
+ const { itemId } = await nextItemHook.create({ token: workflowRunId }); // [!code highlight]
+
+ await processItem(itemId);
+
+ // Hand off to a fresh run on the latest deployment. THIS run ends here.
+ // `deploymentId: "latest"` resolves to whichever deployment is current
+ // when this spawn lands — NOT the deployment running this code.
+ await start( // [!code highlight]
+ longRunningQueue, // [!code highlight]
+ [{ processed: state.processed + 1, cursor: itemId }], // [!code highlight]
+ { deploymentId: "latest" }, // [!code highlight]
+ );
+}
+```
+
+### Resuming the hook
+
+Any server-side code can resume the currently-active iteration by calling `.resume()` with the run ID:
+
+```typescript
+import { nextItemHook } from "@/workflows/long-running-queue";
+
+export async function POST(req: Request) {
+ const { runId, itemId } = await req.json();
+
+ await nextItemHook.resume(runId, { itemId }); // [!code highlight]
+
+ return Response.json({ success: true });
+}
+```
+
+The caller tracks the active `runId` (e.g. in a database, KV, or returned from the previous iteration) and updates it whenever the chain advances.
+
+## Method 2: Upgrade on demand via a dedicated hook
+
+Use a single long-running workflow that handles events in a loop. Define a second hook — `upgradeHook` — alongside the work hook, and race them. While only the work hook fires, the run keeps handling events on its current deployment. When `upgradeHook` resumes, the workflow captures current state and respawns on the latest deployment, then exits.
+
+```typescript lineNumbers
+import { defineHook, getWorkflowMetadata } from "workflow";
+import { start } from "workflow/api";
+
+declare function processItem(itemId: string): Promise; // @setup
+
+interface QueueState {
+ processed: number;
+ cursor: string | null;
+}
+
+export const nextItemHook = defineHook<{ itemId: string }>();
+export const upgradeHook = defineHook<{ reason?: string }>(); // [!code highlight]
+
+export async function longRunningQueue(
+ state: QueueState = { processed: 0, cursor: null },
+): Promise {
+ "use workflow";
+
+ const { workflowRunId } = getWorkflowMetadata();
+
+ while (true) {
+ // Race a normal work event against the upgrade signal.
+ const event = await Promise.race([ // [!code highlight]
+ nextItemHook
+ .create({ token: workflowRunId })
+ .then((payload) => ({ kind: "work" as const, payload })),
+ upgradeHook // [!code highlight]
+ .create({ token: workflowRunId }) // [!code highlight]
+ .then(() => ({ kind: "upgrade" as const })), // [!code highlight]
+ ]);
+
+ if (event.kind === "upgrade") { // [!code highlight]
+ // Checkpoint current state and hand off to a fresh run
+ // on whatever deployment is live now. THIS run ends here.
+ await start(longRunningQueue, [state], { // [!code highlight]
+ deploymentId: "latest", // [!code highlight]
+ }); // [!code highlight]
+ return; // [!code highlight]
+ }
+
+ await processItem(event.payload.itemId);
+ state = {
+ processed: state.processed + 1,
+ cursor: event.payload.itemId,
+ };
+ }
+}
+```
+
+### Triggering the upgrade
+
+Expose a separate endpoint that resumes `upgradeHook` for a given run. Call it from your deploy pipeline, an admin UI, or a fan-out script that iterates over every active run after shipping a fix.
+
+```typescript
+import { upgradeHook } from "@/workflows/long-running-queue";
+
+export async function POST(req: Request) {
+ const { runId, reason } = await req.json();
+
+ // The workflow exits its loop, captures state, and respawns
+ // on the latest deployment.
+ await upgradeHook.resume(runId, { reason }); // [!code highlight]
+
+ return Response.json({ success: true });
+}
+```
+
+To upgrade a fleet of runs after a deploy, list active runs (e.g. from a tracking store) and call this endpoint for each.
+
+## How it works
+
+1. **`deploymentId: "latest"` is the upgrade knob.** Without it, the spawn pins to the current deployment. With it, the new run resolves to whatever deployment is current when the runtime picks it up — so any shipped fix applies starting from that respawn. Both methods rely on this.
+2. **`start()` runs directly from the workflow body.** In v5, [`start()`](/docs/api-reference/workflow-api/start) is step-backed, so it can be called from a workflow function and still records a deterministic step boundary in the event log — no manual `"use step"` wrapper is required.
+3. **State carries through the function argument.** The accumulating context flows from run N to run N+1 as a serialized argument. No external store is required for the state itself.
+4. **Per-run hook tokens.** Using `workflowRunId` as the hook token scopes each iteration's wait to its own run, so multiple chains can run concurrently without interfering.
+5. **Method 1 vs Method 2 is just where the spawn happens.** In Method 1 every run spawns its successor unconditionally before exiting — there is no long-lived process to migrate. In Method 2 the spawn happens only when the upgrade hook fires; otherwise the loop keeps handling events on the same run.
+
+## Adapting to your use case
+
+- **Combine with a sleep.** Race the hook against `sleep()` so iterations also tick on a timer: `Promise.race([hook, sleep("1d")])` lets the workflow advance even if no external event arrives.
+- **Stateless successors.** If the next iteration doesn't need the previous state (e.g. a pure event router), call `start(longRunningQueue, [], { deploymentId: "latest" })` and skip the argument plumbing.
+- **Persist state externally.** If state needs to be readable from outside the workflow (dashboards, debugging, recovery), write it to a database in a step before spawning the next run.
+- **Track the active runId externally.** Whatever resumes the hook needs to know the current run. Capture the `runId` returned by `start()` and write it to a KV/database keyed by a stable session identifier (in a step) so resumers always look up the latest one.
+
+## Caveats
+
+- **Backward compatibility matters.** Because the next run executes on a different deployment, the workflow's input arguments and return type must remain compatible across deployments. Adding required fields, removing fields, or changing types can cause serialization failures. See the [`deploymentId: "latest"` callout](/docs/api-reference/workflow-api/start#using-deploymentid-latest).
+- **Workflow identity is the function name + file path.** Renaming the function or moving the file across a deployment changes the workflow ID — the next iteration will fail to resolve. Treat the workflow's name and location as stable interfaces.
+- **There is a tiny gap between iterations.** The current run ends as soon as `start()` returns; the next run starts asynchronously. A resume that arrives in that window can fail with "hook not found." Make resumers retry, or have the API persist pending payloads and apply them once the next iteration is ready.
+- **Method 2: track active runs externally.** Because Method 2's runs are long-lived, the set of in-flight runs only changes when one starts, completes, or upgrades. Persist run IDs (and clean them up on completion or upgrade) so a rollout script can fan out reliably. After resuming `upgradeHook`, also update the tracked run ID once the new run reports back, the same way you would in Method 1.
+
+## Key APIs
+
+- [`"use workflow"`](/docs/foundations/workflows-and-steps) — marks the orchestrator function
+- [`start()`](/docs/api-reference/workflow-api/start) with [`deploymentId: "latest"`](/docs/api-reference/workflow-api/start#using-deploymentid-latest) — spawn the successor on the newest deployment
+- [`defineHook()`](/docs/api-reference/workflow/define-hook) — suspend the workflow until an external event resumes it
+- [`getWorkflowMetadata()`](/docs/api-reference/workflow/get-workflow-metadata) — exposes `workflowRunId` for per-run hook tokens
diff --git a/docs/content/docs/v5/cookbook/index.mdx b/docs/content/docs/v5/cookbook/index.mdx
index 0dc1ce62ab..309f087c21 100644
--- a/docs/content/docs/v5/cookbook/index.mdx
+++ b/docs/content/docs/v5/cookbook/index.mdx
@@ -33,5 +33,6 @@ A curated collection of workflow patterns with clean, copy-paste code examples f
## Advanced
- [**Child Workflows**](/cookbook/advanced/child-workflows) — Spawn and orchestrate child workflows from a parent
+- [**Upgrading Workflows**](/cookbook/advanced/upgrading-workflows) — Identify a clean upgrade point in a long-running workflow and spawn a fresh run on the latest deployment carrying state forward
- [**Serializable Steps**](/cookbook/advanced/serializable-steps) — Wrap non-serializable third-party objects so they cross the workflow boundary
- [**Publishing Libraries**](/cookbook/advanced/publishing-libraries) — Ship npm packages that export reusable workflow functions
diff --git a/docs/lib/ai-agent-detection.ts b/docs/lib/ai-agent-detection.ts
deleted file mode 100644
index e4184e8ecf..0000000000
--- a/docs/lib/ai-agent-detection.ts
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * AI Agent Detection Utility
- *
- * Multi-signal detection for AI agents/bots. Used to serve markdown
- * responses when agents request docs pages.
- *
- * Three detection layers:
- * 1. Known UA patterns (definitive) — curated from https://bots.fyi/?tags=ai_assistant
- * 2. Signature-Agent header (definitive) — catches ChatGPT agent (RFC 9421)
- * 3. Missing browser fingerprint heuristic — catches unknown bots
- *
- * Optimizes for recall over precision: serving markdown to a non-AI bot
- * is low-harm; missing an AI agent means a worse experience.
- *
- * Last reviewed: 2026-03-20 against bots.fyi + official vendor docs
- */
-
-// Layer 1: Known AI agent UA substrings (lowercase).
-const AI_AGENT_UA_PATTERNS = [
- // Anthropic — https://support.claude.com/en/articles/8896518
- 'claudebot',
- 'claude-searchbot',
- 'claude-user',
- 'anthropic-ai',
- 'claude-web',
-
- // OpenAI — https://platform.openai.com/docs/bots
- 'chatgpt',
- 'gptbot',
- 'oai-searchbot',
- 'openai',
-
- // Google AI
- 'gemini',
- 'bard',
- 'google-cloudvertexbot',
- 'google-extended',
-
- // Meta
- 'meta-externalagent',
- 'meta-externalfetcher',
- 'meta-webindexer',
-
- // Search/Research AI
- 'perplexity',
- 'youbot',
- 'you.com',
- 'deepseekbot',
-
- // Coding assistants
- 'cursor',
- 'github-copilot',
- 'codeium',
- 'tabnine',
- 'sourcegraph',
-
- // Other AI agents / data scrapers (low-harm to serve markdown)
- 'cohere-ai',
- 'bytespider',
- 'amazonbot',
- 'ai2bot',
- 'diffbot',
- 'omgili',
- 'omgilibot',
-];
-
-// Layer 2: Known AI service URLs in Signature-Agent header (RFC 9421).
-const SIGNATURE_AGENT_DOMAINS = ['chatgpt.com'];
-
-// Layer 3: Traditional bot exclusion list — bots that should NOT trigger
-// the heuristic layer (they're search engine crawlers, social previews, or
-// monitoring tools, not AI agents).
-const TRADITIONAL_BOT_PATTERNS = [
- 'googlebot',
- 'bingbot',
- 'yandexbot',
- 'baiduspider',
- 'duckduckbot',
- 'slurp',
- 'msnbot',
- 'facebot',
- 'twitterbot',
- 'linkedinbot',
- 'whatsapp',
- 'telegrambot',
- 'pingdom',
- 'uptimerobot',
- 'newrelic',
- 'datadog',
- 'statuspage',
- 'site24x7',
- 'applebot',
-];
-
-// Broad regex for bot-like UA strings (used only in Layer 3 heuristic).
-const BOT_LIKE_REGEX = /bot|agent|fetch|crawl|spider|search/i;
-
-export type DetectionMethod = 'ua-match' | 'signature-agent' | 'heuristic';
-
-export interface DetectionResult {
- detected: boolean;
- method: DetectionMethod | null;
-}
-
-/**
- * Detects AI agents from HTTP request headers.
- *
- * Returns both whether the agent was detected and which signal triggered,
- * so callers can log the detection method for accuracy tracking.
- */
-export function isAIAgent(request: {
- headers: { get(name: string): string | null };
-}): DetectionResult {
- const userAgent = request.headers.get('user-agent');
-
- // Layer 1: Known UA pattern match
- if (userAgent) {
- const lowerUA = userAgent.toLowerCase();
- if (AI_AGENT_UA_PATTERNS.some((pattern) => lowerUA.includes(pattern))) {
- return { detected: true, method: 'ua-match' };
- }
- }
-
- // Layer 2: Signature-Agent header (RFC 9421, used by ChatGPT agent)
- const signatureAgent = request.headers.get('signature-agent');
- if (signatureAgent) {
- const lowerSig = signatureAgent.toLowerCase();
- if (SIGNATURE_AGENT_DOMAINS.some((domain) => lowerSig.includes(domain))) {
- return { detected: true, method: 'signature-agent' };
- }
- }
-
- // Layer 3: Missing browser fingerprint heuristic
- // Real browsers (Chrome 76+, Firefox 90+, Safari 16.4+) send sec-fetch-mode
- // on navigation requests. Its absence signals a programmatic client.
- const secFetchMode = request.headers.get('sec-fetch-mode');
- if (!secFetchMode && userAgent && BOT_LIKE_REGEX.test(userAgent)) {
- const lowerUA = userAgent.toLowerCase();
- const isTraditionalBot = TRADITIONAL_BOT_PATTERNS.some((pattern) =>
- lowerUA.includes(pattern)
- );
- if (!isTraditionalBot) {
- return { detected: true, method: 'heuristic' };
- }
- }
-
- return { detected: false, method: null };
-}
-
-/**
- * Generates a markdown response for AI agents that hit non-existent URLs.
- */
-export function generateAgentNotFoundResponse(requestedPath: string): string {
- return `# Page Not Found
-
-The URL \`${requestedPath}\` does not exist in the documentation.
-
-## How to find the correct page
-
-1. **Browse the sitemap**: [/sitemap.md](/sitemap.md) — A structured index of all pages with URLs, content types, and descriptions
-2. **Browse the full index**: [/llms.txt](/llms.txt) — Complete documentation index
-
-## Tips for requesting documentation
-
-- For markdown responses, append \`.md\` to URLs (e.g., \`/docs/getting-started.md\`)
-- Use \`Accept: text/markdown\` header for content negotiation
-`;
-}
diff --git a/docs/lib/cookbook-tree.ts b/docs/lib/cookbook-tree.ts
index 2189235df8..25e6748bd5 100644
--- a/docs/lib/cookbook-tree.ts
+++ b/docs/lib/cookbook-tree.ts
@@ -56,6 +56,7 @@ export const slugToCategory: Record = {
// Advanced
'child-workflows': 'advanced',
'distributed-abort-controller': 'advanced',
+ 'upgrading-workflows': 'advanced',
'serializable-steps': 'advanced',
'publishing-libraries': 'advanced',
};
@@ -189,6 +190,13 @@ export const recipes: Record = {
category: 'advanced',
skipVersions: ['v5'],
},
+ 'upgrading-workflows': {
+ slug: 'upgrading-workflows',
+ title: 'Upgrading Workflows',
+ description:
+ 'Identify a clean upgrade point in a long-running workflow and spawn a fresh run on the latest deployment carrying state forward.',
+ category: 'advanced',
+ },
'serializable-steps': {
slug: 'serializable-steps',
title: 'Serializable Steps',
diff --git a/docs/package.json b/docs/package.json
index 5310247f99..f4b0ce4a27 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -31,6 +31,7 @@
"@types/node": "catalog:",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
+ "@vercel/agent-readability": "^0.2.1",
"@vercel/analytics": "^1.6.1",
"@vercel/edge-config": "^1.4.0",
"@vercel/speed-insights": "1.3.1",
diff --git a/docs/proxy.ts b/docs/proxy.ts
index b6be88c65d..c26e559e76 100644
--- a/docs/proxy.ts
+++ b/docs/proxy.ts
@@ -1,3 +1,4 @@
+import { isAIAgent } from '@vercel/agent-readability';
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
import {
@@ -5,7 +6,6 @@ import {
type NextRequest,
NextResponse,
} from 'next/server';
-import { isAIAgent } from '@/lib/ai-agent-detection';
import { i18n } from '@/lib/geistdocs/i18n';
import { trackMdRequest } from '@/lib/md-tracking';
@@ -92,22 +92,22 @@ const proxy = (request: NextRequest, context: NextFetchEvent) => {
// so they always get structured content without needing .md URLs or Accept headers
if (isDocsOrCookbookPath(pathname) && !pathname.includes('/llms.mdx/')) {
const agentResult = isAIAgent(request);
- if (agentResult.detected && !isMarkdownPreferred(request)) {
- const result = markdownRewrite;
-
- if (result) {
- context.waitUntil(
- trackMdRequest({
- path: pathname,
- userAgent: request.headers.get('user-agent'),
- referer: request.headers.get('referer'),
- acceptHeader: request.headers.get('accept'),
- requestType: 'agent-rewrite',
- detectionMethod: agentResult.method,
- })
- );
- return NextResponse.rewrite(new URL(result, request.nextUrl));
- }
+ if (
+ agentResult.detected &&
+ !isMarkdownPreferred(request) &&
+ markdownRewrite
+ ) {
+ context.waitUntil(
+ trackMdRequest({
+ path: pathname,
+ userAgent: request.headers.get('user-agent'),
+ referer: request.headers.get('referer'),
+ acceptHeader: request.headers.get('accept'),
+ requestType: 'agent-rewrite',
+ detectionMethod: agentResult.method,
+ })
+ );
+ return NextResponse.rewrite(new URL(markdownRewrite, request.nextUrl));
}
}
diff --git a/packages/builders/src/vercel-build-output-api.ts b/packages/builders/src/vercel-build-output-api.ts
index 91c428255d..03fb55ffdf 100644
--- a/packages/builders/src/vercel-build-output-api.ts
+++ b/packages/builders/src/vercel-build-output-api.ts
@@ -62,6 +62,9 @@ export class VercelBuildOutputAPIBuilder extends BaseBuilder {
'static/.well-known/workflow/v1'
);
await mkdir(staticManifestDir, { recursive: true });
+ if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
+ await writeFile(join(staticManifestDir, '.gitignore'), '*');
+ }
await copyFile(
join(workflowGeneratedDir, 'manifest.json'),
join(staticManifestDir, 'manifest.json')
diff --git a/packages/core/e2e/e2e.test.ts b/packages/core/e2e/e2e.test.ts
index 23021b4107..5f00f28ae1 100644
--- a/packages/core/e2e/e2e.test.ts
+++ b/packages/core/e2e/e2e.test.ts
@@ -3016,11 +3016,16 @@ describe('e2e', () => {
const run = await start(await e2e('abortFetchInFlightWorkflow'), []);
const returnValue = await run.returnValue;
- expect(returnValue.winner).toBe('timeout');
+ // Include the full returnValue (status + elapsedMs from the step) in
+ // the assertion message so a flaky failure surfaces *why* fetch won
+ // the race — e.g. httpbin returning a 5xx in <1s — instead of just
+ // "expected 'fetch' to be 'timeout'".
+ const summary = JSON.stringify(returnValue);
+ expect(returnValue.winner, summary).toBe('timeout');
// The step's catch path returned aborted=true (fetch threw AbortError),
// not the natural-completion path (which would set ok=true,aborted=false).
- expect(returnValue.fetchResult.aborted).toBe(true);
- expect(returnValue.fetchResult.ok).toBe(false);
+ expect(returnValue.fetchResult.aborted, summary).toBe(true);
+ expect(returnValue.fetchResult.ok, summary).toBe(false);
}
);
@@ -3041,8 +3046,12 @@ describe('e2e', () => {
const run = await start(await e2e('abortVoidSleepTimeoutWorkflow'), []);
const returnValue = await run.returnValue;
- expect(returnValue.aborted).toBe(true);
- expect(returnValue.ok).toBe(false);
+ // Same diagnostic treatment as abortFetchInFlightWorkflow: when the
+ // slow upstream returns early the step result includes status and
+ // elapsedMs, which are what we'll need to triage the next flake.
+ const summary = JSON.stringify(returnValue);
+ expect(returnValue.aborted, summary).toBe(true);
+ expect(returnValue.ok, summary).toBe(false);
}
);
diff --git a/packages/core/e2e/local-build.test.ts b/packages/core/e2e/local-build.test.ts
index 5be9d63cf9..f734c32fcc 100644
--- a/packages/core/e2e/local-build.test.ts
+++ b/packages/core/e2e/local-build.test.ts
@@ -96,8 +96,7 @@ const DEFERRED_BUILD_MODE_PROJECTS = new Set([
'nextjs-webpack',
'nextjs-turbopack',
]);
-const DEFERRED_BUILD_UNSUPPORTED_WARNING =
- 'Enabled lazyDiscovery but Next.js version is not compatible';
+const DEFERRED_BUILD_UNSUPPORTED_WARNING = 'lazyDiscovery requires Next.js >=';
const EAGER_DISCOVERY_LOG = 'Discovering workflow directives';
describe.each([
diff --git a/packages/next/src/builder-deferred.ts b/packages/next/src/builder-deferred.ts
index b768c6c271..f4170ca966 100644
--- a/packages/next/src/builder-deferred.ts
+++ b/packages/next/src/builder-deferred.ts
@@ -589,6 +589,12 @@ export async function getNextBuilderDeferred() {
'public/.well-known/workflow/v1'
);
await mkdir(publicManifestDir, { recursive: true });
+ if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
+ await this.writeFileIfChanged(
+ join(publicManifestDir, '.gitignore'),
+ '*'
+ );
+ }
await this.copyFileIfChanged(
manifestFilePath,
join(publicManifestDir, 'manifest.json')
diff --git a/packages/next/src/builder-eager.ts b/packages/next/src/builder-eager.ts
index cfc0ed63f3..93d587d951 100644
--- a/packages/next/src/builder-eager.ts
+++ b/packages/next/src/builder-eager.ts
@@ -79,6 +79,9 @@ export async function getNextBuilderEager() {
'public/.well-known/workflow/v1'
);
await mkdir(publicManifestDir, { recursive: true });
+ if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
+ await writeFile(join(publicManifestDir, '.gitignore'), '*');
+ }
await copyFile(
join(workflowGeneratedDir, 'manifest.json'),
join(publicManifestDir, 'manifest.json')
diff --git a/packages/next/src/builder.ts b/packages/next/src/builder.ts
index 43390403fa..e4a4e9ec56 100644
--- a/packages/next/src/builder.ts
+++ b/packages/next/src/builder.ts
@@ -23,7 +23,7 @@ export function shouldUseDeferredBuilder(nextVersion: string): boolean {
if (flagEnabled && !versionCompatible && !warnedAboutFlagAndVersion) {
warnedAboutFlagAndVersion = true;
console.warn(
- `Enabled lazyDiscovery but Next.js version is not compatible, needs ${DEFERRED_BUILDER_MIN_VERSION} have ${nextVersion}`
+ `lazyDiscovery requires Next.js >= ${DEFERRED_BUILDER_MIN_VERSION} (found ${nextVersion}); falling back to eager workflow discovery.`
);
}
diff --git a/packages/next/src/index.test.ts b/packages/next/src/index.test.ts
index 4a3e0adec0..ed68e38a1e 100644
--- a/packages/next/src/index.test.ts
+++ b/packages/next/src/index.test.ts
@@ -129,6 +129,21 @@ describe('withWorkflow builder config', () => {
});
});
+ it('enables lazyDiscovery by default', async () => {
+ withWorkflow({});
+ expect(process.env.WORKFLOW_NEXT_LAZY_DISCOVERY).toBe('1');
+ });
+
+ it('enables lazyDiscovery when explicitly set to true', async () => {
+ withWorkflow({}, { workflows: { lazyDiscovery: true } });
+ expect(process.env.WORKFLOW_NEXT_LAZY_DISCOVERY).toBe('1');
+ });
+
+ it('disables lazyDiscovery when explicitly set to false', async () => {
+ withWorkflow({}, { workflows: { lazyDiscovery: false } });
+ expect(process.env.WORKFLOW_NEXT_LAZY_DISCOVERY).toBeUndefined();
+ });
+
it('configures diagnostics inside the default Next.js dist dir', async () => {
const config = withWorkflow({});
diff --git a/packages/next/src/index.ts b/packages/next/src/index.ts
index cdb9dbbd47..3efa9a40a5 100644
--- a/packages/next/src/index.ts
+++ b/packages/next/src/index.ts
@@ -341,11 +341,17 @@ export function withWorkflow(
};
} = {}
) {
+ // lazyDiscovery defaults to true; pass `lazyDiscovery: false` to force eager
+ // discovery (scanning the project at startup) instead of deferring workflow
+ // discovery until files are requested. The `WORKFLOW_NEXT_LAZY_DISCOVERY`
+ // environment variable, if set, takes precedence over the option.
const lazyDiscoveryOverride = parseEnvironmentFlag(
process.env.WORKFLOW_NEXT_LAZY_DISCOVERY
);
if (lazyDiscoveryOverride === undefined) {
- if (workflows?.lazyDiscovery) {
+ if (workflows?.lazyDiscovery === false) {
+ delete process.env.WORKFLOW_NEXT_LAZY_DISCOVERY;
+ } else {
process.env.WORKFLOW_NEXT_LAZY_DISCOVERY = '1';
}
} else {
diff --git a/packages/sveltekit/src/builder.ts b/packages/sveltekit/src/builder.ts
index 39afe31d4d..ffb130c32b 100644
--- a/packages/sveltekit/src/builder.ts
+++ b/packages/sveltekit/src/builder.ts
@@ -109,6 +109,9 @@ export const POST = async ({request}) => {
'static/.well-known/workflow/v1'
);
await mkdir(staticManifestDir, { recursive: true });
+ if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
+ await writeFile(join(staticManifestDir, '.gitignore'), '*');
+ }
await copyFile(
join(workflowGeneratedDir, 'manifest.json'),
join(staticManifestDir, 'manifest.json')
diff --git a/packages/web-shared/src/components/event-list-view.tsx b/packages/web-shared/src/components/event-list-view.tsx
index 5415f94778..db83be83f5 100644
--- a/packages/web-shared/src/components/event-list-view.tsx
+++ b/packages/web-shared/src/components/event-list-view.tsx
@@ -142,7 +142,7 @@ function buildNameMaps(
return { correlationNameMap, workflowName };
}
-interface DurationInfo {
+export interface DurationInfo {
/** Time from created → started (ms) */
queued?: number;
/** Time from started → completed/failed/cancelled (ms) */
@@ -154,19 +154,30 @@ interface DurationInfo {
* created ↔ started (queued) and started ↔ completed/failed/cancelled (ran).
* Also computes run-level durations under the key '__run__'.
*/
-function buildDurationMap(events: Event[]): Map {
+export function buildDurationMap(events: Event[]): Map {
+ // Process events in chronological order so the result doesn't depend on
+ // the caller's sort direction. Retried steps emit multiple `step_started`
+ // events for the same correlationId; the queued duration must be measured
+ // against the first one, not the last.
+ const chronological = [...events].sort(
+ (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
+ );
+
const createdTimes = new Map();
+ const firstStartedTimes = new Map();
const startedTimes = new Map();
const durations = new Map();
- for (const event of events) {
+ for (const event of chronological) {
const ts = new Date(event.createdAt).getTime();
const key = event.correlationId ?? '__run__';
const type: string = event.eventType;
// Track created times (first event for each correlation)
if (type === 'step_created' || type === 'run_created') {
- createdTimes.set(key, ts);
+ if (!createdTimes.has(key)) {
+ createdTimes.set(key, ts);
+ }
}
// Track started times & compute queued duration
@@ -176,16 +187,21 @@ function buildDurationMap(events: Event[]): Map {
type === 'workflow_started'
) {
startedTimes.set(key, ts);
- // If no explicit created event was seen, use the started time as created
- if (!createdTimes.has(key)) {
- createdTimes.set(key, ts);
- }
- const createdAt = createdTimes.get(key);
- const info = durations.get(key) ?? {};
- if (createdAt !== undefined) {
- info.queued = ts - createdAt;
+ // The queued duration is anchored on the first start event only —
+ // subsequent step_started events come from retries.
+ if (!firstStartedTimes.has(key)) {
+ firstStartedTimes.set(key, ts);
+ // If no explicit created event was seen, use the started time as created
+ if (!createdTimes.has(key)) {
+ createdTimes.set(key, ts);
+ }
+ const createdAt = createdTimes.get(key);
+ const info = durations.get(key) ?? {};
+ if (createdAt !== undefined) {
+ info.queued = ts - createdAt;
+ }
+ durations.set(key, info);
}
- durations.set(key, info);
}
// Compute ran duration on terminal events
diff --git a/packages/web-shared/src/components/new-trace-viewer/components/copy-button.tsx b/packages/web-shared/src/components/new-trace-viewer/components/copy-button.tsx
index 2b3df3bd9b..59e38159ef 100644
--- a/packages/web-shared/src/components/new-trace-viewer/components/copy-button.tsx
+++ b/packages/web-shared/src/components/new-trace-viewer/components/copy-button.tsx
@@ -31,7 +31,7 @@ export function CopyButton({
type="button"
aria-label={ariaLabel}
className={cn(
- 'cursor-pointer text-gray-800 hover:text-gray-1000 bg-transparent border-none p-1 m-0',
+ 'cursor-pointer text-gray-800 hover:text-gray-1000 bg-transparent border-0 p-1 m-0',
className
)}
onClick={(e) => {
diff --git a/packages/web-shared/src/components/new-trace-viewer/components/event-list.tsx b/packages/web-shared/src/components/new-trace-viewer/components/event-list.tsx
index faf504a1e6..7952baf2b6 100644
--- a/packages/web-shared/src/components/new-trace-viewer/components/event-list.tsx
+++ b/packages/web-shared/src/components/new-trace-viewer/components/event-list.tsx
@@ -68,7 +68,7 @@ const EventRow = ({
onClick={() => onSelectSpan(span.spanId)}
>
-
+
diff --git a/packages/web-shared/src/components/new-trace-viewer/detail-panel.tsx b/packages/web-shared/src/components/new-trace-viewer/detail-panel.tsx
index 64956d78fc..739105742c 100644
--- a/packages/web-shared/src/components/new-trace-viewer/detail-panel.tsx
+++ b/packages/web-shared/src/components/new-trace-viewer/detail-panel.tsx
@@ -29,7 +29,7 @@ export function DetailPanel({