Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Friendlier context-violation errors + Ansi renderer - #1831

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

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

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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';exportasyncfunctionGET(req: Request){constwhich=newURL(req.url).searchParams.get('which');try{if(which==='createHook')createHook();if(which==='sleep')awaitsleep('1s');if(which==='getStepMetadata')getStepMetadata();if(which==='getWorkflowMetadata')getWorkflowMetadata();returnNextResponse.json({ok: true});}catch(err){console.error(err);returnNextResponse.json({name: (errasError).name,message: (errasError).message,stack: (errasError).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:
    exportasyncfunctionbroken(){'use workflow';constmeta=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:

#PRPhaseSummary
1→ this PR (#1831)Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3#1836Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop 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

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 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
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.035s (-17.6% 🟢)1.004s (~)0.968s101.00x
💻 LocalExpress0.042s (-5.0%)1.005s (~)0.963s101.19x
💻 LocalNext.js (Turbopack)0.047s1.006s0.958s101.34x
🐘 PostgresNitro0.057s (-40.0% 🟢)1.009s (-3.3%)0.952s101.61x
🐘 PostgresNext.js (Turbopack)0.057s1.009s0.952s101.61x
🐘 PostgresExpress0.059s (+1.9%)1.010s (~)0.951s101.66x
workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro1.104s (-2.4%)2.005s (~)0.901s101.00x
💻 LocalNext.js (Turbopack)1.121s2.006s0.885s101.02x
💻 LocalExpress1.133s (+0.7%)2.006s (~)0.872s101.03x
🐘 PostgresNext.js (Turbopack)1.140s2.012s0.871s101.03x
🐘 PostgresExpress1.142s (~)2.009s (~)0.867s101.03x
🐘 PostgresNitro1.148s (+0.7%)2.012s (~)0.863s101.04x
workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro10.755s (-1.7%)11.020s (~)0.265s31.00x
💻 LocalNext.js (Turbopack)10.795s11.023s0.228s31.00x
🐘 PostgresExpress10.856s (-1.0%)11.019s (~)0.163s31.01x
🐘 PostgresNitro10.866s (~)11.022s (~)0.156s31.01x
🐘 PostgresNext.js (Turbopack)10.881s11.021s0.140s31.01x
💻 LocalExpress10.946s (~)11.024s (~)0.078s31.02x
workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro14.465s (-4.0%)15.027s (-6.3% 🟢)0.562s41.00x
🐘 PostgresNext.js (Turbopack)14.516s15.023s0.507s41.00x
🐘 PostgresNitro14.575s (~)15.025s (~)0.450s41.01x
🐘 PostgresExpress14.585s (~)15.025s (~)0.440s41.01x
💻 LocalNext.js (Turbopack)14.657s15.031s0.374s41.01x
💻 LocalExpress14.993s (~)15.280s (+1.7%)0.286s41.04x
workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)13.854s14.022s0.169s71.00x
🐘 PostgresExpress13.926s (-0.6%)14.021s (-3.9%)0.096s71.01x
🐘 PostgresNitro14.007s (~)14.596s (+2.0%)0.589s71.01x
💻 LocalNitro15.150s (-9.7% 🟢)16.027s (-5.9% 🟢)0.877s61.09x
💻 LocalNext.js (Turbopack)16.327s17.033s0.706s61.18x
💻 LocalExpress16.351s (-1.5%)17.031s (~)0.681s61.18x
Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express1.256s (~)2.010s (~)0.753s151.00x
🐘 PostgresNitro1.274s (~)2.009s (~)0.735s151.01x
🐘 PostgresNext.js (Turbopack)1.287s2.009s0.721s151.02x
💻 LocalNitro1.397s (-14.4% 🟢)2.005s (-3.3%)0.608s151.11x
💻 LocalExpress1.507s (+1.2%)2.005s (~)0.498s151.20x
💻 LocalNext.js (Turbopack)1.538s2.006s0.468s151.22x
Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro2.363s (+0.5%)3.010s (~)0.647s101.00x
🐘 PostgresExpress2.373s (+0.5%)3.008s (~)0.635s101.00x
💻 LocalNitro2.388s (-24.0% 🟢)3.007s (-22.6% 🟢)0.618s101.01x
🐘 PostgresNext.js (Turbopack)2.436s3.011s0.575s101.03x
💻 LocalNext.js (Turbopack)2.809s3.453s0.645s91.19x
💻 LocalExpress2.829s (-4.2%)3.108s (-10.0% 🟢)0.280s101.20x
Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.456s (-0.9%)4.011s (~)0.555s81.00x
🐘 PostgresNitro3.489s (~)4.011s (~)0.522s81.01x
🐘 PostgresNext.js (Turbopack)3.648s4.011s0.363s81.06x
💻 LocalNitro6.341s (-24.1% 🟢)6.814s (-24.5% 🟢)0.474s51.83x
💻 LocalExpress7.543s (-9.5% 🟢)8.270s (-8.4% 🟢)0.728s42.18x
💻 LocalNext.js (Turbopack)8.329s9.018s0.689s42.41x
Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.222s2.008s0.785s151.00x
🐘 PostgresNitro1.264s (+0.5%)2.007s (~)0.743s151.03x
🐘 PostgresExpress1.278s (+1.7%)2.008s (~)0.730s151.05x
💻 LocalNitro1.426s (-23.6% 🟢)2.005s (-14.3% 🟢)0.579s151.17x
💻 LocalNext.js (Turbopack)1.505s2.006s0.502s151.23x
💻 LocalExpress1.648s (-13.0% 🟢)2.074s (-12.3% 🟢)0.426s151.35x
Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express2.321s (-0.9%)3.009s (~)0.688s101.00x
🐘 PostgresNitro2.334s (~)3.007s (~)0.673s101.01x
🐘 PostgresNext.js (Turbopack)2.393s3.010s0.617s101.03x
💻 LocalNitro2.448s (-20.1% 🟢)3.013s (-22.5% 🟢)0.566s101.05x
💻 LocalNext.js (Turbopack)2.766s3.453s0.687s91.19x
💻 LocalExpress2.820s (-10.0% 🟢)3.108s (-17.4% 🟢)0.288s101.22x
Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro3.463s (~)4.009s (~)0.546s81.00x
🐘 PostgresExpress3.497s (~)4.011s (~)0.514s81.01x
🐘 PostgresNext.js (Turbopack)3.628s4.012s0.384s81.05x
💻 LocalNitro7.196s (-21.3% 🟢)7.768s (-22.5% 🟢)0.572s42.08x
💻 LocalNext.js (Turbopack)7.943s8.518s0.575s42.29x
💻 LocalExpress8.384s (-4.7%)9.024s (-2.7%)0.640s42.42x
workflow with 10 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.787s1.006s0.219s601.00x
🐘 PostgresExpress0.813s (-3.1%)1.006s (-1.7%)0.194s601.03x
🐘 PostgresNitro0.824s (~)1.023s (+1.6%)0.199s591.05x
💻 LocalNext.js (Turbopack)0.865s1.022s0.156s591.10x
💻 LocalNitro0.887s (-9.6% 🟢)1.136s (+3.8%)0.249s531.13x
💻 LocalExpress1.014s (+3.1%)1.610s (+49.7% 🔺)0.596s381.29x
workflow with 25 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)1.918s2.100s0.182s431.00x
🐘 PostgresExpress1.921s (-2.8%)2.123s (-6.0% 🟢)0.202s431.00x
🐘 PostgresNitro1.950s (+1.2%)2.203s (+4.9%)0.252s411.02x
💻 LocalNext.js (Turbopack)2.725s3.008s0.283s301.42x
💻 LocalNitro2.802s (-7.7% 🟢)3.293s (-12.4% 🟢)0.492s281.46x
💻 LocalExpress3.018s (~)3.508s (-2.2%)0.490s261.57x
workflow with 50 sequential data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)3.882s4.044s0.162s301.00x
🐘 PostgresExpress3.918s (-1.8%)4.148s (-5.1% 🟢)0.230s291.01x
🐘 PostgresNitro3.986s (-2.9%)4.368s (-5.1% 🟢)0.382s281.03x
💻 LocalNitro7.905s (-15.0% 🟢)8.348s (-16.7% 🟢)0.443s152.04x
💻 LocalNext.js (Turbopack)8.750s9.017s0.267s142.25x
💻 LocalExpress8.953s (-2.8%)9.324s (-6.9% 🟢)0.371s132.31x
workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.245s1.007s0.762s601.00x
🐘 PostgresExpress0.287s (+1.5%)1.007s (~)0.720s601.17x
🐘 PostgresNitro0.295s (+4.1%)1.007s (~)0.712s601.20x
💻 LocalNext.js (Turbopack)0.559s1.004s0.445s602.28x
💻 LocalExpress0.578s (+3.1%)1.004s (~)0.427s602.36x
💻 LocalNitro0.583s (-3.6%)1.095s (+7.2% 🔺)0.512s552.38x
workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.485s1.006s0.522s901.00x
🐘 PostgresExpress0.495s (-3.0%)1.006s (~)0.512s901.02x
🐘 PostgresNitro0.495s (~)1.007s (~)0.511s901.02x
💻 LocalNitro1.983s (-21.9% 🟢)2.670s (-11.3% 🟢)0.687s344.09x
💻 LocalExpress2.378s (-5.4% 🟢)3.008s (~)0.631s304.91x
💻 LocalNext.js (Turbopack)2.593s3.009s0.416s305.35x
workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.775s1.015s0.240s1191.00x
🐘 PostgresExpress0.792s (-3.3%)1.007s (-1.0%)0.216s1201.02x
🐘 PostgresNitro0.807s (+2.1%)1.008s (~)0.201s1201.04x
💻 LocalNitro8.591s (-23.2% 🟢)9.093s (-22.0% 🟢)0.502s1411.09x
💻 LocalExpress10.460s (-6.5% 🟢)11.026s (-7.7% 🟢)0.566s1113.50x
💻 LocalNext.js (Turbopack)10.936s11.483s0.547s1114.11x
Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.174s1.003s0.012s1.018s0.844s101.00x
🐘 PostgresExpress0.199s (-3.0%)0.997s (~)0.002s (+6.2% 🔺)1.010s (~)0.811s101.14x
🐘 PostgresNext.js (Turbopack)0.199s1.001s0.001s1.011s0.812s101.14x
💻 LocalExpress0.206s (+3.3%)1.004s (~)0.010s (-16.5% 🟢)1.016s (~)0.810s101.18x
💻 LocalNitro0.209s (-2.2%)1.003s (~)0.008s (-36.8% 🟢)1.013s (-0.6%)0.804s101.20x
🐘 PostgresNitro0.212s (+3.4%)0.995s (~)0.001s (-20.0% 🟢)1.010s (~)0.798s101.22x
stream pipeline with 5 transform steps (1MB)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.616s1.009s0.006s1.023s0.407s591.00x
🐘 PostgresExpress0.625s (-0.7%)1.022s (+1.6%)0.004s (~)1.039s (+1.6%)0.414s581.01x
🐘 PostgresNitro0.626s (~)1.022s (+1.6%)0.004s (-6.2% 🟢)1.039s (+1.6%)0.413s581.02x
💻 LocalNitro0.749s (-10.7% 🟢)1.029s (+1.7%)0.010s (+3.3%)1.135s (+1.7%)0.386s531.22x
💻 LocalNext.js (Turbopack)0.888s1.011s0.010s1.229s0.341s491.44x
💻 LocalExpress0.969s (+28.0% 🔺)1.011s (-1.8%)0.009s (-1.6%)1.226s (+17.9% 🔺)0.257s491.57x
10 parallel streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Next.js (Turbopack)0.926s1.092s0.000s1.108s0.182s551.00x
🐘 PostgresExpress0.967s (+0.7%)1.226s (-4.1%)0.000s (+43.8% 🔺)1.257s (-3.8%)0.290s481.04x
🐘 PostgresNitro0.998s (+3.0%)1.326s (+6.3% 🔺)0.000s (+60.0% 🔺)1.341s (+6.6% 🔺)0.343s451.08x
💻 LocalNitro1.082s (-11.5% 🟢)1.780s (-11.9% 🟢)0.000s (+76.5% 🔺)1.782s (-11.9% 🟢)0.700s341.17x
💻 LocalExpress1.191s (-2.8%)2.019s (~)0.000s (+20.0% 🔺)2.021s (~)0.830s301.29x
💻 LocalNext.js (Turbopack)1.288s2.019s0.000s2.022s0.735s301.39x
fan-out fan-in 10 streams (1MB each)

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Nitro1.756s (-2.0%)2.102s (-1.8%)0.000s (-100.0% 🟢)2.113s (-2.8%)0.357s291.00x
🐘 PostgresExpress1.757s (-0.9%)2.068s (-5.0% 🟢)0.000s (+Infinity% 🔺)2.118s (-3.7%)0.361s291.00x
🐘 PostgresNext.js (Turbopack)1.869s2.146s0.000s2.152s0.284s281.06x
💻 LocalNitro3.126s (-7.7% 🟢)3.675s (-8.8% 🟢)0.001s (-0.7%)3.678s (-8.9% 🟢)0.551s171.78x
💻 LocalExpress3.413s (-1.6%)4.032s (~)0.000s (-41.7% 🟢)4.035s (~)0.622s151.94x
💻 LocalNext.js (Turbopack)3.681s4.164s0.001s4.168s0.487s152.10x

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNitro17/21
🐘 PostgresNext.js (Turbopack)12/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres19/21
Next.js (Turbopack)🐘 Postgres17/21
Nitro🐘 Postgres16/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

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
✅ 🐘 Local Postgres9590861045
✅ 📋 Other267018285
Total333222763610

❌ 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
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
ContributorAuthor

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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/errorsAnsi 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
FileDescription
pnpm-lock.yamlAdds chalk + vitest for @workflow/errors and updates lock snapshots.
packages/errors/src/index.tsRe-exports Ansi from the package entrypoint.
packages/errors/src/ansi.tsNew ANSI/box-drawing composition helpers (uses chalk).
packages/errors/src/ansi.test.tsAdds unit tests for Ansi rendering behavior.
packages/errors/package.jsonAdds chalk dependency, vitest devDependency, and a package-level test script.
packages/errors/mocks/chalk.tsManual chalk mock to make style output snapshot-friendly.
packages/core/src/workflow/index.tsSwitches workflow stubs to throw the new structured context errors.
packages/core/src/workflow/get-workflow-metadata.tsAdds a note about avoiding cycles, but still throws a plain Error when out of context.
packages/core/src/workflow/define-hook.tsUses UnavailableInWorkflowContextError for defineHook().resume() in workflow exports.
packages/core/src/workflow/create-hook.tsUses NotInWorkflowContextError when workflow VM hook function is absent.
packages/core/src/step/writable-stream.tsUses NotInWorkflowOrStepContextError when no step/workflow context exists.
packages/core/src/step/get-workflow-metadata.tsUses NotInWorkflowOrStepContextError when called outside context.
packages/core/src/step/get-step-metadata.tsUses NotInStepContextError when called outside step context.
packages/core/src/sleep.tsUses NotInWorkflowContextError when called outside workflow context.
packages/core/src/define-hook.tsUses NotInWorkflowContextError for defineHook().create() in non-workflow exports.
packages/core/src/create-hook.tsUses NotInWorkflowContextError for createHook() / createWebhook() stubs.
packages/core/src/context-errors.tsNew context error classes built on @workflow/errorsAnsi framing.
packages/core/src/context-errors.test.tsAdds tests validating the new structured context error messages.
.changeset/friendlier-context-errors.mdDocuments 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;
}

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 threadpackages/core/src/context-errors.ts Outdated

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

CopilotAIApr 23, 2026

Copy link

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
returnname;
returnname
.replaceAll('workflow//',Ansi.dim('workflow//'))
.replaceAll('step//',Ansi.dim('step//'));

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

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 threadpackages/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;

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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'
);

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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 on lines +2 to +3
'@workflow/core': patch
'@workflow/errors': patch

CopilotAIApr 23, 2026

Copy link

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
ContributorAuthor

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';

CopilotAIApr 23, 2026

Copy link

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*asAnsifrom'./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
ContributorAuthor

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.

@pranaygppranaygp reopened this Apr 24, 2026
@pranaygppranaygp mentioned this pull request Apr 24, 2026
2 tasks

@VaguelySeriousVaguelySerious left a comment

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.

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
ContributorAuthor

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

Sign up for freeto 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

@pranaygp@TooTallNate@VaguelySerious