Skip to content

Fix workflow stack traces (no more evalmachine)#256

Merged
pranaygp merged 1 commit into
mainfrom
copilot/fix-sourcemap-tracking
Nov 9, 2025
Merged

Fix workflow stack traces (no more evalmachine)#256
pranaygp merged 1 commit into
mainfrom
copilot/fix-sourcemap-tracking

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 7, 2025

Don't mind the broken dev test. it seems a bit flaky and gets fixed properly down the PR stack

Workflow code executes in a VM context via runInContext(), which defaults to evalmachine.<anonymous> in stack traces, making debugging difficult:

Error: test error
    at addTenWorkflow (evalmachine.<anonymous>:451:9)
    at async ...

Fixes #151

Solution

This PR implements comprehensive source map support for workflow stack traces by:

  1. Generating inline source maps in the intermediate workflow bundle
  2. Providing meaningful filenames to the VM context via runInContext()
  3. Remapping stack traces using inline source maps to show original source locations

Changes

Core Runtime

  • packages/core/src/source-map.ts (NEW) - Source map remapping logic using @jridgewell/trace-mapping
  • packages/core/src/workflow.ts - Use parseWorkflowName() to extract clean file paths and pass as filename parameter to runInContext()
  • packages/core/src/runtime.ts - Apply source map remapping to workflow error logs

Builder Configuration

  • packages/builders/src/base-builder.ts - Set intermediate workflow bundle to use sourcemap: 'inline' (the VM-executed code needs inline source maps)

Tests

  • packages/core/src/workflow.test.ts - Added test for nested stack traces
  • packages/core/e2e/e2e.test.ts - Added e2e test for cross-file error stack traces
  • workbench/example/workflows/helpers.ts (NEW) - Test helper module for verifying cross-file stack traces
  • workbench/example/workflows/99_e2e.ts - Added nestedErrorWorkflow and crossFileErrorWorkflow with helper functions

Dependencies

  • Added @jridgewell/trace-mapping to @workflow/core for pure-JS source map processing (no WASM dependency)

Results

Before

Error: test error
    at addTenWorkflow (evalmachine.<anonymous>:451:9)

After - Simple Error

Error: test error
    at addTenWorkflow (example/workflows/99_e2e.ts:23:10)

After - Nested Functions (Same File)

Error: Error from deeply nested function
    at deepFunction (../example/workflows/99_e2e.ts:33:10)
    at middleFunction (../example/workflows/99_e2e.ts:37:4)
    at topLevelHelper (../example/workflows/99_e2e.ts:41:4)
    at addTenWorkflow (../example/workflows/99_e2e.ts:24:4)

After - Cross-File Errors (Imported Modules)

Error: Error from imported helper module
    at throwError (../example/workflows/helpers.ts:3:10)
    at callThrower (../example/workflows/helpers.ts:6:4)
    at crossFileErrorWorkflow (../example/workflows/99_e2e.ts:447:4)

Stack traces now correctly show:

  • ✅ Actual source file paths (not evalmachine.<anonymous>)
  • ✅ Correct function names
  • ✅ Source-mapped line and column numbers
  • ✅ Cross-file call chains with correct file paths for each frame

Testing

  • All 186 unit tests pass (including new nested stack trace test)
  • New e2e test validates cross-file error stack traces
  • Tested with nested errors, cross-file imports, and complex call stacks

Fixes #151


This is part 1 of 3 in a stack made with GitButler:

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Nov 7, 2025

🦋 Changeset detected

Latest commit: 8c93c65

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

This PR includes changesets to release 11 packages
Name Type
@workflow/builders Patch
@workflow/core Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/sveltekit Patch
@workflow/web-shared Patch
workflow Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch

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

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

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 9, 2025 8:00pm
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 9, 2025 8:00pm
example-workflow Ready Ready Preview Comment Nov 9, 2025 8:00pm
workbench-nitro-workflow Ready Ready Preview Comment Nov 9, 2025 8:00pm
workbench-nuxt-workflow Ready Ready Preview Comment Nov 9, 2025 8:00pm
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 9, 2025 8:00pm
workbench-vite-workflow Ready Ready Preview Comment Nov 9, 2025 8:00pm
workflow-docs Ready Ready Preview Comment Nov 9, 2025 8:00pm

@pranaygp pranaygp marked this pull request as ready for review November 8, 2025 05:09
@pranaygp pranaygp force-pushed the copilot/fix-sourcemap-tracking branch from c93cf92 to 0343d72 Compare November 8, 2025 05:19
@pranaygp pranaygp force-pushed the copilot/fix-sourcemap-tracking branch from 0343d72 to 984e756 Compare November 8, 2025 05:21
@pranaygp pranaygp changed the title Fix workflow stack traces to show source filenames instead of evalmachine Fix workflow stack traces (no more evalmachine) Nov 8, 2025
@pranaygp pranaygp force-pushed the copilot/fix-sourcemap-tracking branch from 1f0f74d to b128b07 Compare November 8, 2025 05:50
@pranaygp pranaygp requested review from TooTallNate and ijjk November 8, 2025 05:51
@pranaygp pranaygp force-pushed the copilot/fix-sourcemap-tracking branch from b128b07 to 3ffca64 Compare November 8, 2025 05:51
This was referenced Nov 8, 2025
Comment thread packages/builders/src/base-builder.ts Outdated
Comment thread packages/core/src/workflow.ts Outdated
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Couple small nits/questions, but otherwise :lgtm:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack traces in workflow context

3 participants