') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Structured logger metadata + fold in replay-timeout logging by pranaygp · Pull Request #1832 · vercel/workflow · GitHub
Skip to content

Structured logger metadata + fold in replay-timeout logging - #1832

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-1from
pranaygp/friendlier-errors-phase-3-logger
Closed

Structured logger metadata + fold in replay-timeout logging#1832
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-1from
pranaygp/friendlier-errors-phase-3-logger

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 3 of the friendlier-errors stack. Also folds in #1812 so that PR can close as superseded.

  • Structured logger child API.runtimeLogger / stepLogger / webhookLogger etc. now expose .child(metadata) and .forRun(runId, workflowName, extra?), so runtime and step handlers don't have to repeat workflowRunId / workflowName / stepId on every log call.
  • Normalized error metadata. Ad-hoc error: err.message strings are replaced with structured errorName / errorMessage / errorStack fields so log drains can render and group them properly.
  • Comments on silent catches. The EntityConflictError / RunExpiredError paths that swallow expected idempotency conflicts now explain why it's safe to drop the error.

Folded in from #1812 (supersedes it)

  • Standardize the console prefix to [workflow-sdk].
  • Split replay-timeout into warn-while-retrying vs. error-when-giving-up, and surface the underlying error when we can't mark a timed-out run as failed.
  • Include error stacks in the "Fatal runtime error during workflow setup" log and the top-level user-code workflow error log so the stack surfaces in flattened drains.
  • Drop the [Workflows] "<runId>" - prefix from buildWorkflowSuspensionMessage — the structured logger attaches run context now.

Closes / supersedes:#1812

Manual test plan

All tests below use workbench/nextjs-turbopack. Start with cd workbench/nextjs-turbopack && pnpm dev and watch the terminal.

  • Console prefix — trigger any workflow. Every log line should begin with [workflow-sdk]. Search logs for \[Workflows\] — should be zero hits (the old prefix is gone).
  • Structured run/step context — inspect any step log line. It should carry runId, workflowName, stepId as structured metadata (the object after the message), not interpolated into the message string.
  • Error stacks in logs — deliberately throw from a step:
    asyncfunctionbrokenStep(){'use step';thrownewError('boom');}
    Run the workflow. Confirm the full stack is the log message (survives flattened drains like Axiom/Datadog), not relegated to a structured field.
  • Structured error fields — at step-failure / run-failure, confirm errorName, errorMessage, and errorStack appear as structured metadata fields (in addition to the stack in the message).
  • Replay-timeout warn vs. error — set WORKFLOW_REPLAY_TIMEOUT_MS=50 in env and run a workflow with any non-trivial work. On early replay attempts expect a warn-level line ("replay timed out, retrying"); after retries exhaust expect an error-level line with the underlying failure cause visible.
  • Fatal setup error includes stack — if you can induce a fatal-at-setup (e.g. by crashing a worker init path), the "Fatal runtime error during workflow setup" log should include the full stack.
  • Suspension message has no legacy prefix — trigger a workflow that awaits a hook and suspends. The suspension log line should NOT start with [Workflows] "<runId>" - — only [workflow-sdk], with run context in structured metadata.
  • Idempotency conflicts are silently dropped — hard to induce deliberately; verify by reading the commented catches (EntityConflictError / RunExpiredError) around idempotent step-completion paths. No user-visible test.

Unit tests

  • New src/logger.test.ts covers .child, .forRun, metadata merging, and conflict precedence (10 tests).
  • Existing src/util.test.ts updated for new suspension-message format (23 tests pass).
  • pnpm typecheck reports no new errors.

📚 Friendlier errors stack

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

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2→ this PR (#1832)Phase 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

@vercel

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b2b1587

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

This PR includes changesets to release 17 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@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

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10522861140
✅ 🪟 Windows950095
✅ 📋 Other267018285
Total352042763800

❌ 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
🐘 Local Postgres (2 failed)

nuxt-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

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-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
❌ nuxt-stable8726
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack9500
✅ 📋 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: success

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Phase 4 stacked on top of this: #1836SerializationError class + user-facing hints at serialization boundaries.

pranaygpand others added 2 commits April 23, 2026 18:14
Adds a `.child()` and `.forRun(runId, workflowName)` child-logger API to
the structured logger so runtime/step code doesn't have to repeat
`workflowRunId`/`workflowName`/`stepId` on every call. Normalizes error
metadata to structured `errorName` / `errorMessage` / `errorStack` fields
instead of ad-hoc `error: err.message` strings, and adds comments to
silent catches that swallow expected idempotency conflicts.
Also folds in the pending changes from #1812 so that PR can be closed:
- Standardize the console prefix to `[workflow-sdk]`.
- Split the replay-timeout log into a warn-while-retrying vs.
error-when-giving-up, and surface the underlying error when we can't
mark a timed-out run as failed.
- Include the error stack in the "Fatal runtime error during workflow
setup" log and in the top-level user-code workflow error log so the
stack surfaces in flattened log drains.
- Drop the `[Workflows] "<runId>" - ` prefix from
`buildWorkflowSuspensionMessage` — the structured logger now attaches
run context.
Supersedes #1812.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@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.

1 participant

@pranaygp