Skip to content

Friendlier context-violation errors + Ansi renderer#1831

Closed
pranaygp wants to merge 2 commits intomainfrom
pranaygp/friendlier-errors-phase-1
Closed

Friendlier context-violation errors + Ansi renderer#1831
pranaygp wants to merge 2 commits intomainfrom
pranaygp/friendlier-errors-phase-1

Conversation

@pranaygp
Copy link
Copy Markdown
Contributor

@pranaygp pranaygp commented Apr 23, 2026

Summary

Phase 1 + 2 of the friendlier-errors stack. Picks up where #706 (@Schniz, stalled) left off.

  • @workflow/errors — new Ansi rendering helpers (frame, hint, note, help, code, inline) for composing terminal-friendly, box-drawn error messages. Chalk auto-detects TTY and falls back to plain text (CI, Datadog).
  • @workflow/core — four context-violation error classes applied to all 12 user-facing throw sites:
    • NotInWorkflowContextError (e.g. createHook(), sleep())
    • NotInStepContextError (e.g. getStepMetadata())
    • NotInWorkflowOrStepContextError (e.g. getWorkflowMetadata(), getWritable())
    • UnavailableInWorkflowContextError (e.g. resumeHook(), defineHook().resume()) — names the active workflow.

Example rendering:

`createHook()` can only be called inside a workflow function
╰▶ note: Read more about createHook(): https://workflow-sdk.dev/docs/api-reference/workflow/create-hook

Note

The rendered framing in this PR is later polished in PR #1849 (drop functionName leak, simplify note: Read more about…docs:, and redirect the stack trace to user code). Verify the phase-1 behavior here; the polished form lands in the followups PR.

Manual test plan

All tests below use workbench/nextjs-turbopack — start with cd workbench/nextjs-turbopack && pnpm dev and visit http://localhost:3000. Watch the terminal running pnpm dev for rendered errors.

A convenient smoke route that exercises most throw sites — drop this at workbench/nextjs-turbopack/app/api/friendlier-errors-smoke/route.ts:

import { NextResponse } from 'next/server';
import { createHook, sleep, getStepMetadata, getWorkflowMetadata } from 'workflow';

export async function GET(req: Request) {
  const which = new URL(req.url).searchParams.get('which');
  try {
    if (which === 'createHook') createHook();
    if (which === 'sleep') await sleep('1s');
    if (which === 'getStepMetadata') getStepMetadata();
    if (which === 'getWorkflowMetadata') getWorkflowMetadata();
    return NextResponse.json({ ok: true });
  } catch (err) {
    console.error(err);
    return NextResponse.json(
      { name: (err as Error).name, message: (err as Error).message, stack: (err as Error).stack },
      { status: 500 }
    );
  }
}
  • createHook() outside workflow — hit ?which=createHook. Expect a box-drawn frame (╭─ … ╰─) with title `createHook()` can only be called inside a workflow function and a note: Read more about createHook(): https://…/workflow/create-hook inside.
  • sleep() outside workflow — hit ?which=sleep. Same framing, docs URL ends in .../workflow/sleep.
  • getStepMetadata() in a workflow function (not a step) — add to a "use workflow" file:
    export async function broken() {
      'use workflow';
      const meta = getStepMetadata(); // should throw
    }
    Expect title: "can only be called inside a step function".
  • getWorkflowMetadata() in application code — hit ?which=getWorkflowMetadata. Expect "workflow or step function".
  • resumeHook() inside a workflow — call resumeHook(token, payload) from inside a "use workflow" function. Expect:
    • Title: `resumeHook()` cannot be called from a workflow context.
    • Three body lines: the determinism explanation; this call was made from the workflow//./src/workflows/example.ts//myWorkflow workflow context. (with the workflow/ prefix dimmed); and the docs URL.
  • TTY detection — run the rendered error in a real terminal and confirm the blue docs URL / bold code backticks show; pipe through | cat and confirm ANSI escape bytes are stripped (chalk auto-detect).

Unit tests

  • pnpm --filter @workflow/errors test (10 new Ansi tests)
  • pnpm --filter @workflow/core test (5 new context-error tests)

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

# PR Phase Summary
1 → this PR (#1831) Phase 1 + 2 Ansi rendering primitives + context-violation errors
2 #1832 Phase 3 Structured logger metadata; folds in #1812
3 #1836 Phase 4 SerializationError at serialization / stream / encryption boundaries
4 #1837 Phase 5 Presentation-only user vs SDK attribution (describeError)
5 #1838 Phase 6 Consistency pass on remaining bare throw new Error(...) sites
6 #1839 Phase 7 foundation Data-driven describeRunError + public subpath
7 #1840 Phase 8 WorkflowBuildError + applications in @workflow/builders
8 #1849 Followups Drop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

Phase 1: Add Ansi rendering helpers (frame, hint, note, help, code, inline)
to @workflow/errors, and a chalk mock for readable snapshot tests.

Phase 2: Add four context-violation error classes to @workflow/core
(NotInWorkflowContextError, NotInStepContextError,
NotInWorkflowOrStepContextError, UnavailableInWorkflowContextError)
and apply them to all twelve user-facing throw sites so errors now
include docs links and a structured "what/why/fix" frame.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: cec8cfe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@workflow/core Patch
@workflow/errors Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
workflow Patch
@workflow/world-testing Patch
@workflow/world-local Patch
@workflow/world-postgres Patch
@workflow/world-vercel Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Nitro 0.035s (-17.6% 🟢) 1.004s (~) 0.968s 10 1.00x
💻 Local Express 0.042s (-5.0%) 1.005s (~) 0.963s 10 1.19x
💻 Local Next.js (Turbopack) 0.047s 1.006s 0.958s 10 1.34x
🐘 Postgres Nitro 0.057s (-40.0% 🟢) 1.009s (-3.3%) 0.952s 10 1.61x
🐘 Postgres Next.js (Turbopack) 0.057s 1.009s 0.952s 10 1.61x
🐘 Postgres Express 0.059s (+1.9%) 1.010s (~) 0.951s 10 1.66x
workflow with 1 step

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Nitro 1.104s (-2.4%) 2.005s (~) 0.901s 10 1.00x
💻 Local Next.js (Turbopack) 1.121s 2.006s 0.885s 10 1.02x
💻 Local Express 1.133s (+0.7%) 2.006s (~) 0.872s 10 1.03x
🐘 Postgres Next.js (Turbopack) 1.140s 2.012s 0.871s 10 1.03x
🐘 Postgres Express 1.142s (~) 2.009s (~) 0.867s 10 1.03x
🐘 Postgres Nitro 1.148s (+0.7%) 2.012s (~) 0.863s 10 1.04x
workflow with 10 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Nitro 10.755s (-1.7%) 11.020s (~) 0.265s 3 1.00x
💻 Local Next.js (Turbopack) 10.795s 11.023s 0.228s 3 1.00x
🐘 Postgres Express 10.856s (-1.0%) 11.019s (~) 0.163s 3 1.01x
🐘 Postgres Nitro 10.866s (~) 11.022s (~) 0.156s 3 1.01x
🐘 Postgres Next.js (Turbopack) 10.881s 11.021s 0.140s 3 1.01x
💻 Local Express 10.946s (~) 11.024s (~) 0.078s 3 1.02x
workflow with 25 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Nitro 14.465s (-4.0%) 15.027s (-6.3% 🟢) 0.562s 4 1.00x
🐘 Postgres Next.js (Turbopack) 14.516s 15.023s 0.507s 4 1.00x
🐘 Postgres Nitro 14.575s (~) 15.025s (~) 0.450s 4 1.01x
🐘 Postgres Express 14.585s (~) 15.025s (~) 0.440s 4 1.01x
💻 Local Next.js (Turbopack) 14.657s 15.031s 0.374s 4 1.01x
💻 Local Express 14.993s (~) 15.280s (+1.7%) 0.286s 4 1.04x
workflow with 50 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 13.854s 14.022s 0.169s 7 1.00x
🐘 Postgres Express 13.926s (-0.6%) 14.021s (-3.9%) 0.096s 7 1.01x
🐘 Postgres Nitro 14.007s (~) 14.596s (+2.0%) 0.589s 7 1.01x
💻 Local Nitro 15.150s (-9.7% 🟢) 16.027s (-5.9% 🟢) 0.877s 6 1.09x
💻 Local Next.js (Turbopack) 16.327s 17.033s 0.706s 6 1.18x
💻 Local Express 16.351s (-1.5%) 17.031s (~) 0.681s 6 1.18x
Promise.all with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 1.256s (~) 2.010s (~) 0.753s 15 1.00x
🐘 Postgres Nitro 1.274s (~) 2.009s (~) 0.735s 15 1.01x
🐘 Postgres Next.js (Turbopack) 1.287s 2.009s 0.721s 15 1.02x
💻 Local Nitro 1.397s (-14.4% 🟢) 2.005s (-3.3%) 0.608s 15 1.11x
💻 Local Express 1.507s (+1.2%) 2.005s (~) 0.498s 15 1.20x
💻 Local Next.js (Turbopack) 1.538s 2.006s 0.468s 15 1.22x
Promise.all with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 2.363s (+0.5%) 3.010s (~) 0.647s 10 1.00x
🐘 Postgres Express 2.373s (+0.5%) 3.008s (~) 0.635s 10 1.00x
💻 Local Nitro 2.388s (-24.0% 🟢) 3.007s (-22.6% 🟢) 0.618s 10 1.01x
🐘 Postgres Next.js (Turbopack) 2.436s 3.011s 0.575s 10 1.03x
💻 Local Next.js (Turbopack) 2.809s 3.453s 0.645s 9 1.19x
💻 Local Express 2.829s (-4.2%) 3.108s (-10.0% 🟢) 0.280s 10 1.20x
Promise.all with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 3.456s (-0.9%) 4.011s (~) 0.555s 8 1.00x
🐘 Postgres Nitro 3.489s (~) 4.011s (~) 0.522s 8 1.01x
🐘 Postgres Next.js (Turbopack) 3.648s 4.011s 0.363s 8 1.06x
💻 Local Nitro 6.341s (-24.1% 🟢) 6.814s (-24.5% 🟢) 0.474s 5 1.83x
💻 Local Express 7.543s (-9.5% 🟢) 8.270s (-8.4% 🟢) 0.728s 4 2.18x
💻 Local Next.js (Turbopack) 8.329s 9.018s 0.689s 4 2.41x
Promise.race with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 1.222s 2.008s 0.785s 15 1.00x
🐘 Postgres Nitro 1.264s (+0.5%) 2.007s (~) 0.743s 15 1.03x
🐘 Postgres Express 1.278s (+1.7%) 2.008s (~) 0.730s 15 1.05x
💻 Local Nitro 1.426s (-23.6% 🟢) 2.005s (-14.3% 🟢) 0.579s 15 1.17x
💻 Local Next.js (Turbopack) 1.505s 2.006s 0.502s 15 1.23x
💻 Local Express 1.648s (-13.0% 🟢) 2.074s (-12.3% 🟢) 0.426s 15 1.35x
Promise.race with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 2.321s (-0.9%) 3.009s (~) 0.688s 10 1.00x
🐘 Postgres Nitro 2.334s (~) 3.007s (~) 0.673s 10 1.01x
🐘 Postgres Next.js (Turbopack) 2.393s 3.010s 0.617s 10 1.03x
💻 Local Nitro 2.448s (-20.1% 🟢) 3.013s (-22.5% 🟢) 0.566s 10 1.05x
💻 Local Next.js (Turbopack) 2.766s 3.453s 0.687s 9 1.19x
💻 Local Express 2.820s (-10.0% 🟢) 3.108s (-17.4% 🟢) 0.288s 10 1.22x
Promise.race with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 3.463s (~) 4.009s (~) 0.546s 8 1.00x
🐘 Postgres Express 3.497s (~) 4.011s (~) 0.514s 8 1.01x
🐘 Postgres Next.js (Turbopack) 3.628s 4.012s 0.384s 8 1.05x
💻 Local Nitro 7.196s (-21.3% 🟢) 7.768s (-22.5% 🟢) 0.572s 4 2.08x
💻 Local Next.js (Turbopack) 7.943s 8.518s 0.575s 4 2.29x
💻 Local Express 8.384s (-4.7%) 9.024s (-2.7%) 0.640s 4 2.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.787s 1.006s 0.219s 60 1.00x
🐘 Postgres Express 0.813s (-3.1%) 1.006s (-1.7%) 0.194s 60 1.03x
🐘 Postgres Nitro 0.824s (~) 1.023s (+1.6%) 0.199s 59 1.05x
💻 Local Next.js (Turbopack) 0.865s 1.022s 0.156s 59 1.10x
💻 Local Nitro 0.887s (-9.6% 🟢) 1.136s (+3.8%) 0.249s 53 1.13x
💻 Local Express 1.014s (+3.1%) 1.610s (+49.7% 🔺) 0.596s 38 1.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 1.918s 2.100s 0.182s 43 1.00x
🐘 Postgres Express 1.921s (-2.8%) 2.123s (-6.0% 🟢) 0.202s 43 1.00x
🐘 Postgres Nitro 1.950s (+1.2%) 2.203s (+4.9%) 0.252s 41 1.02x
💻 Local Next.js (Turbopack) 2.725s 3.008s 0.283s 30 1.42x
💻 Local Nitro 2.802s (-7.7% 🟢) 3.293s (-12.4% 🟢) 0.492s 28 1.46x
💻 Local Express 3.018s (~) 3.508s (-2.2%) 0.490s 26 1.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 3.882s 4.044s 0.162s 30 1.00x
🐘 Postgres Express 3.918s (-1.8%) 4.148s (-5.1% 🟢) 0.230s 29 1.01x
🐘 Postgres Nitro 3.986s (-2.9%) 4.368s (-5.1% 🟢) 0.382s 28 1.03x
💻 Local Nitro 7.905s (-15.0% 🟢) 8.348s (-16.7% 🟢) 0.443s 15 2.04x
💻 Local Next.js (Turbopack) 8.750s 9.017s 0.267s 14 2.25x
💻 Local Express 8.953s (-2.8%) 9.324s (-6.9% 🟢) 0.371s 13 2.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.245s 1.007s 0.762s 60 1.00x
🐘 Postgres Express 0.287s (+1.5%) 1.007s (~) 0.720s 60 1.17x
🐘 Postgres Nitro 0.295s (+4.1%) 1.007s (~) 0.712s 60 1.20x
💻 Local Next.js (Turbopack) 0.559s 1.004s 0.445s 60 2.28x
💻 Local Express 0.578s (+3.1%) 1.004s (~) 0.427s 60 2.36x
💻 Local Nitro 0.583s (-3.6%) 1.095s (+7.2% 🔺) 0.512s 55 2.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.485s 1.006s 0.522s 90 1.00x
🐘 Postgres Express 0.495s (-3.0%) 1.006s (~) 0.512s 90 1.02x
🐘 Postgres Nitro 0.495s (~) 1.007s (~) 0.511s 90 1.02x
💻 Local Nitro 1.983s (-21.9% 🟢) 2.670s (-11.3% 🟢) 0.687s 34 4.09x
💻 Local Express 2.378s (-5.4% 🟢) 3.008s (~) 0.631s 30 4.91x
💻 Local Next.js (Turbopack) 2.593s 3.009s 0.416s 30 5.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.775s 1.015s 0.240s 119 1.00x
🐘 Postgres Express 0.792s (-3.3%) 1.007s (-1.0%) 0.216s 120 1.02x
🐘 Postgres Nitro 0.807s (+2.1%) 1.008s (~) 0.201s 120 1.04x
💻 Local Nitro 8.591s (-23.2% 🟢) 9.093s (-22.0% 🟢) 0.502s 14 11.09x
💻 Local Express 10.460s (-6.5% 🟢) 11.026s (-7.7% 🟢) 0.566s 11 13.50x
💻 Local Next.js (Turbopack) 10.936s 11.483s 0.547s 11 14.11x
Stream Benchmarks (includes TTFB metrics)
workflow with stream

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Next.js (Turbopack) 0.174s 1.003s 0.012s 1.018s 0.844s 10 1.00x
🐘 Postgres Express 0.199s (-3.0%) 0.997s (~) 0.002s (+6.2% 🔺) 1.010s (~) 0.811s 10 1.14x
🐘 Postgres Next.js (Turbopack) 0.199s 1.001s 0.001s 1.011s 0.812s 10 1.14x
💻 Local Express 0.206s (+3.3%) 1.004s (~) 0.010s (-16.5% 🟢) 1.016s (~) 0.810s 10 1.18x
💻 Local Nitro 0.209s (-2.2%) 1.003s (~) 0.008s (-36.8% 🟢) 1.013s (-0.6%) 0.804s 10 1.20x
🐘 Postgres Nitro 0.212s (+3.4%) 0.995s (~) 0.001s (-20.0% 🟢) 1.010s (~) 0.798s 10 1.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.616s 1.009s 0.006s 1.023s 0.407s 59 1.00x
🐘 Postgres Express 0.625s (-0.7%) 1.022s (+1.6%) 0.004s (~) 1.039s (+1.6%) 0.414s 58 1.01x
🐘 Postgres Nitro 0.626s (~) 1.022s (+1.6%) 0.004s (-6.2% 🟢) 1.039s (+1.6%) 0.413s 58 1.02x
💻 Local Nitro 0.749s (-10.7% 🟢) 1.029s (+1.7%) 0.010s (+3.3%) 1.135s (+1.7%) 0.386s 53 1.22x
💻 Local Next.js (Turbopack) 0.888s 1.011s 0.010s 1.229s 0.341s 49 1.44x
💻 Local Express 0.969s (+28.0% 🔺) 1.011s (-1.8%) 0.009s (-1.6%) 1.226s (+17.9% 🔺) 0.257s 49 1.57x
10 parallel streams (1MB each)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.926s 1.092s 0.000s 1.108s 0.182s 55 1.00x
🐘 Postgres Express 0.967s (+0.7%) 1.226s (-4.1%) 0.000s (+43.8% 🔺) 1.257s (-3.8%) 0.290s 48 1.04x
🐘 Postgres Nitro 0.998s (+3.0%) 1.326s (+6.3% 🔺) 0.000s (+60.0% 🔺) 1.341s (+6.6% 🔺) 0.343s 45 1.08x
💻 Local Nitro 1.082s (-11.5% 🟢) 1.780s (-11.9% 🟢) 0.000s (+76.5% 🔺) 1.782s (-11.9% 🟢) 0.700s 34 1.17x
💻 Local Express 1.191s (-2.8%) 2.019s (~) 0.000s (+20.0% 🔺) 2.021s (~) 0.830s 30 1.29x
💻 Local Next.js (Turbopack) 1.288s 2.019s 0.000s 2.022s 0.735s 30 1.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 1.756s (-2.0%) 2.102s (-1.8%) 0.000s (-100.0% 🟢) 2.113s (-2.8%) 0.357s 29 1.00x
🐘 Postgres Express 1.757s (-0.9%) 2.068s (-5.0% 🟢) 0.000s (+Infinity% 🔺) 2.118s (-3.7%) 0.361s 29 1.00x
🐘 Postgres Next.js (Turbopack) 1.869s 2.146s 0.000s 2.152s 0.284s 28 1.06x
💻 Local Nitro 3.126s (-7.7% 🟢) 3.675s (-8.8% 🟢) 0.001s (-0.7%) 3.678s (-8.9% 🟢) 0.551s 17 1.78x
💻 Local Express 3.413s (-1.6%) 4.032s (~) 0.000s (-41.7% 🟢) 4.035s (~) 0.622s 15 1.94x
💻 Local Next.js (Turbopack) 3.681s 4.164s 0.001s 4.168s 0.487s 15 2.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World 🥇 Fastest Framework Wins
💻 Local Nitro 17/21
🐘 Postgres Next.js (Turbopack) 12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework 🥇 Fastest World Wins
Express 🐘 Postgres 19/21
Next.js (Turbopack) 🐘 Postgres 17/21
Nitro 🐘 Postgres 16/21
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)

📋 View full workflow run


Some benchmark jobs failed:

  • Local: success
  • Postgres: success
  • Vercel: failure

Check the workflow run for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ 💻 Local Development 1052 2 86 1140
✅ 📦 Local Production 1054 0 86 1140
✅ 🐘 Local Postgres 959 0 86 1045
✅ 📋 Other 267 0 18 285
Total 3332 2 276 3610

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack

Details by Category

❌ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-turbopack-stable 95 0 0
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
✅ nuxt-stable 89 0 6
✅ sveltekit-stable 89 0 6
❌ vite-stable 87 2 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-turbopack-stable 95 0 0
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
✅ nuxt-stable 89 0 6
✅ sveltekit-stable 89 0 6
✅ vite-stable 89 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
✅ nuxt-stable 89 0 6
✅ sveltekit-stable 89 0 6
✅ vite-stable 89 0 6
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 89 0 6
✅ e2e-local-postgres-nest-stable 89 0 6
✅ e2e-local-prod-nest-stable 89 0 6

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: failure
  • Local Prod: success
  • Local Postgres: failure
  • Windows: cancelled

Check the workflow run for details.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Apr 24, 2026 1:18am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Apr 24, 2026 1:18am
example-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-astro-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-express-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-fastify-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-hono-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-nitro-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-nuxt-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-sveltekit-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workbench-vite-workflow Ready Ready Preview, Comment Apr 24, 2026 1:18am
workflow-docs Ready Ready Preview, Comment, Open in v0 Apr 24, 2026 1:18am
workflow-swc-playground Ready Ready Preview, Comment Apr 24, 2026 1:18am
workflow-web Ready Ready Preview, Comment Apr 24, 2026 1:18am

'@workflow/core': patch
'@workflow/errors': patch
---

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change should be terse. 1-2 sentences. not this verbose

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps happening for me as well. We should update AGENTS.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is part of the effort to make @workflow/core context-violation errors more actionable by introducing a structured terminal-friendly renderer in @workflow/errors and new dedicated context error classes in @workflow/core, then applying them across the call sites that throw in the wrong context.

Changes:

  • Add @workflow/errors Ansi helpers (frame, help, hint, note, code, inline) plus tests and a chalk mock for snapshot readability.
  • Introduce new @workflow/core context error classes and replace multiple generic Error throw sites with these structured errors.
  • Add a changeset for publishing @workflow/core + @workflow/errors patches.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.ts Re-exports Ansi from the package entrypoint.
packages/errors/src/ansi.ts New ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.ts Adds unit tests for Ansi rendering behavior.
packages/errors/package.json Adds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.ts Manual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.ts Switches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.ts Adds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.ts Uses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.ts Uses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.ts Uses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.ts Uses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.ts Uses NotInStepContextError when called outside step context.
packages/core/src/sleep.ts Uses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.ts Uses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.ts Uses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.ts New context error classes built on @workflow/errors Ansi framing.
packages/core/src/context-errors.test.ts Adds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.md Documents the patch release for new Ansi helpers + context error classes.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +119 to +131
for (const marker of markers) {
const textLen = marker.endCol - marker.startCol;
const midPoint = Math.floor(textLen / 2);

if (marker.startCol > pos) {
parts.push(' '.repeat(marker.startCol - pos));
pos = marker.startCol;
}
const segment = `${'─'.repeat(midPoint)}┬${'─'.repeat(textLen - midPoint - 1)}`;
const colorFn = marker.color ?? identity;
parts.push(colorFn(segment));
pos += textLen;
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildUnderline() assumes every marker has endCol > startCol. If a caller passes an empty text token (length 0), textLen - midPoint - 1 becomes negative and '─'.repeat(...) will throw. Add a guard (e.g. treat zero-length markers as length 1, or skip underlining + still emit an explanation) to make Ansi.inline robust for edge cases.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cec8cfebuildUnderline now clamps endCol - startCol with Math.max(1, …) so a zero-length marker produces a single-char anchor instead of a negative String.repeat count.

Comment thread packages/core/src/context-errors.ts Outdated

/** Apply dim styling to the `workflow//` / `step//` separators in a name. */
function ansifyName(name: string): string {
return name;
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansifyName() is documented as applying dim styling to the workflow// / step// separators, but it currently returns the input unchanged. Either implement the styling (so the workflow name in UnavailableInWorkflowContextError matches the intent) or remove/adjust the comment + call site to avoid misleading behavior.

Suggested change
return name;
return name
.replaceAll('workflow//', Ansi.dim('workflow//'))
.replaceAll('step//', Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cec8cfeansifyName() now actually applies Ansi.dim to the workflow/ / step/ prefix (added a dim export in packages/errors/src/ansi.ts for this).

Comment thread packages/core/src/context-errors.ts Outdated
Comment on lines +123 to +125
// Keep `getWorkflowMetadata` import live for future use (the error message
// currently reads the symbol directly to avoid a circular throw).
void getWorkflowMetadata;
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing getWorkflowMetadata solely to silence noUnusedLocals via void getWorkflowMetadata; adds a hard dependency and makes the file harder to reason about. If the goal is to avoid a circular dependency, it would be cleaner to remove the unused import entirely (or convert it to a type-only import if you only need types), and restructure shared constants/types into a separate module if needed later.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cec8cfe — the void getWorkflowMetadata; workaround and the value import were removed. context-errors.ts now imports only the WorkflowMetadata type and the WORKFLOW_CONTEXT_SYMBOL, so there's no hard value-level dependency on the metadata module at class-construction time.

Comment on lines +42 to 48
// Avoid importing NotInWorkflowOrStepContextError here — that module
// imports from this file, so bringing it in eagerly would create a
// module-init cycle. The companion step/get-workflow-metadata.ts uses
// the structured class.
throw new Error(
'`getWorkflowMetadata()` can only be called inside a workflow or step function'
);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still throws a plain Error rather than the new structured context-violation error, but the PR description/changeset mention applying the friendlier framing to both getWorkflowMetadata() call sites. If the structured class can’t be imported here due to cycles, consider throwing an Ansi.frame(...) message directly (or moving WORKFLOW_CONTEXT_SYMBOL / types into a shared module) so this path matches the new error format too.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cec8cfegetWorkflowMetadata() now throws with the same Ansi.frame / Ansi.code / Ansi.note framing as the other context errors, instead of a plain Error. Kept it inline rather than importing one of the new classes to avoid a module-init cycle with context-errors.ts.

Comment thread .changeset/friendlier-context-errors.md Outdated
Comment on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changeset frontmatter uses single quotes around package names, but existing changesets in this repo use double quotes (e.g. .changeset/curvy-dingos-cry.md). Please switch to double quotes for consistency and to match the established convention.

Suggested change
'@workflow/core': patch
'@workflow/errors': patch
"@workflow/core": patch
"@workflow/errors": patch

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cec8cfe — single-quoted frontmatter switched to double-quoted to match repo convention.

import type { StructuredError } from '@workflow/world';
import type { StringValue } from 'ms';

export * as Ansi from './ansi.js';
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@workflow/errors is designed to avoid Node.js-only imports for VM/workflow contexts (see the comment below isError), but exporting Ansi from the main entrypoint makes ./ansi (and its chalk dependency) load whenever @workflow/errors is imported. This can increase bundle size and may break workflow/VM bundling if chalk (or its transitive deps) pull in Node built-ins. Consider moving Ansi to a separate subpath export (e.g. @workflow/errors/ansi) or making the renderer implementation dependency-free / lazily loaded so the default entry stays workflow-safe.

Suggested change
export * as Ansi from './ansi.js';
// Do not export `./ansi.js` from the main entrypoint.
// This package is used in workflow/VM contexts that must avoid pulling in
// Node.js-only or heavier optional dependencies through the default module graph.
// Expose ANSI helpers from a separate subpath entry instead.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged — valid concern. I'm going to address this in a followup PR rather than folding it into this 7-PR stack, since:

  1. Moving Ansi to a subpath export (@workflow/errors/ansi) is mechanical but touches every importer; doing it here would force a rebase through phases 3–8 and re-run CI 7 times.
  2. The immediate user-facing VM risk is bounded — context-errors.ts and get-workflow-metadata.ts are the only VM-reachable modules that pull in Ansi today, and they'd still pay the chalk cost after the subpath move (they explicitly use the rendering helpers). The subpath change is really about sparing other @workflow/errors consumers (e.g. code that only wants SerializationError) from the chalk dep.
  3. The followup PR can also audit whether ansi.ts needs chalk at all vs. a lightweight dependency-free renderer, which is the cleaner end state.

Will file the followup and link it back here.

@pranaygp pranaygp closed this Apr 24, 2026
@pranaygp pranaygp reopened this Apr 24, 2026
Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the specific error classes, but unsure about the Ansi stuff. I also don't like errors package depending on chalk. Also, would be nice to have a screenshot of what this looks like in logs for vercel and local CLI dev

import type { StructuredError } from '@workflow/world';
import type { StringValue } from 'ms';

export * as Ansi from './ansi.js';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

- Tighten phase 1 changeset to a single sentence (per pranaygp review) and switch to double-quoted frontmatter (per Copilot + repo convention).
- Implement `ansifyName` to actually apply dim styling to workflow/ / step/ prefixes; add an `Ansi.dim` helper to `@workflow/errors` so callers don't need to import chalk directly.
- Remove the `void getWorkflowMetadata;` workaround in context-errors.ts by dropping the unused value import (we only needed the type and symbol).
- Render the plain-Error throw in `workflow/get-workflow-metadata.ts` with `Ansi.frame` + docs link so the VM path matches the structured-class styling from the sibling step path (still uses a plain Error to avoid the module-init cycle).
- Guard `buildUnderline` against zero-length markers so a stray empty token can't produce a negative `String.repeat` count.
@pranaygp
Copy link
Copy Markdown
Contributor Author

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

@pranaygp pranaygp closed this Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants