Skip to content

fix(platform): return structured error codes from workflow execution mutations (#2013) - #2210

Merged
yannickmonney merged 2 commits into
mainfrom
tale/xs707d8mcyxd89wppjr98g4fxx89enrg
Jun 29, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
tale/xs707d8mcyxd89wppjr98g4fxx89enrg

Conversation

@larryro

@larryro larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Workflow execution management mutations/actions threw raw Error, which Convex redacts to an opaque "Server Error" in production. The workflow builder/debug UI had no way to distinguish a not-found from a wrong-state or unauthenticated rejection. This converts those throws to structured ConvexError({ code }), matching the convention already used in workflows/triggers/slug_mutations.ts (fixed in #2056).

Changes

  • workflow_executions/mutations.ts (cancelExecution):
    • EXECUTION_NOT_FOUND
    • EXECUTION_NOT_CANCELABLE (carries status)
  • workflow_executions/actions.ts (startWorkflowFromFile, rerunExecution, getExecutionVariables):
    • UNAUTHENTICATED
    • EXECUTION_NOT_FOUND
    • EXECUTION_MISSING_SLUG
  • workflows/executions/resume_debug_step.ts:
    • EXECUTION_NOT_FOUND
    • EXECUTION_NOT_RESUMABLE (carries status)
    • EXECUTION_NOT_PAUSED
    • EXECUTION_MISSING_WORKFLOW_ID

workflows/triggers/slug_mutations.ts (also listed in the issue) already throws ConvexError({ code }) — no change needed there.

Tests

  • Updated actions.test.ts and resume_debug_step.test.ts to assert on the structured code instead of message substrings.
  • Added workflow_executions/mutations_error_codes.test.ts (end-to-end via convexTest) covering cancelExecution → EXECUTION_NOT_FOUND and EXECUTION_NOT_CANCELABLE.

Verified locally: vitest (13 passing), oxlint --type-aware (0 errors), tsc --noEmit (clean).

Closes #2013

@larryro

larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Desk review — PR #2210 (fixes #2013)

Verdict: NOT READY — CHANGES REQUIRED.

Evidence

  • CI: confirmed green — every required check on gh pr checks reports pass (Lint, Type check, Unit, Format, Knip, Build platform, all 16 Playwright shards, Smoke test, etc.). The only non-pass jobs are conditional skipping ones (Trivy, fork-PR/container jobs). mergeable: MERGEABLE.
  • Tests (run locally on the branch): bunx vitest --run --project server workflow_executions/mutations_error_codes.test.ts workflow_executions/actions.test.ts workflows/executions/resume_debug_step.test.ts → 3 files, 13 tests, all passing.

What's correct (confirmed)

  • Backend scope is complete: every in-scope raw throw new Error(...) in workflow_executions/mutations.ts (cancelExecution), workflow_executions/actions.ts (startWorkflowFromFile / rerunExecution / getExecutionVariables) and workflows/executions/resume_debug_step.ts is converted to ConvexError({ code, … }). No in-scope raw Error remains. slug_mutations.ts (also listed in the issue) was already converted in Bug: Backend raw Errors leave the client with no actionable message — chat approval/human-input cards, knowledge-entry duplicate toast, automations-trigger dialogs #2056, so omitting it here is correct.
  • Security preserved: the cross-tenant IDOR ordering in rerunExecution/getExecutionVariables (auth → load → org-membership check) is unchanged.
  • Code naming/payload (EXECUTION_* prefix, status extra field) is reasonable and consistent with the multi-operation namespace.

BLOCKING 1 — User-visible regression: error toasts now render a raw JSON blob

The backend half of the #2056 pattern was shipped, but not the client half, and the result is a tangible regression at existing consumer sites.

Convex sets Error.message = JSON.stringify(data) for object-payload ConvexErrors (verified against convex/dist/esm/values/errors.js and at runtime):

new ConvexError({ code:'EXECUTION_NOT_CANCELABLE', status:'completed' }).message
  === '{"code":"EXECUTION_NOT_CANCELABLE","status":"completed"}'   // instanceof Error === true

The following consumers surface raw err.message directly (they were not updated by this PR), so the user now sees that JSON string instead of the previous "Server Error" (prod) / original sentence (dev):

  • app/features/operator/components/embedded-run.tsx:65 — RerunButton (rerunExecution → EXECUTION_NOT_FOUND / EXECUTION_MISSING_SLUG)
  • app/features/operator/components/embedded-run.tsx:93 — StopButton (cancelExecution → EXECUTION_NOT_FOUND / EXECUTION_NOT_CANCELABLE)
  • app/features/chat/components/human-input-request-card.tsx:220 — handleCancel (cancelExecution)
  • app/features/chat/components/workflow-run-approval-card.tsx:172, 193, 208, 297 — run/reject/cancel/submit handlers (incl. cancelExecution)

This is the exact UI surface the issue is about ("execution management rejections are opaque Server Errors"), so the user-facing goal isn't delivered — it's arguably worsened (internal JSON leaked to end users). Note mapHumanInputError (human-input-request-card.tsx:67) and mapTriggerError already establish the intended pattern, and the repo provides convexErrorCode / convexErrorMessage in app/lib/utils/convex-error.ts — but none of these is wired to the new EXECUTION_* codes.

Required fix (either approach):

  • (a) Add an execution-error mapper (mirror map-trigger-error.ts, keyed via convexErrorCode) and use it at the four consumer sites above so each code maps to a localized t(...) message; or
  • (b) Include a human-readable message field in each ConvexError data payload and switch those sites from raw err.message to convexErrorMessage(err, fallback).

Either way: no consumer of these mutations/actions may display raw err.message.

BLOCKING 2 — The UNAUTHENTICATED conversion is untested

actions.ts converts three throw new Error('Unauthenticated') → ConvexError({ code:'UNAUTHENTICATED' }) (startWorkflowFromFile:32, rerunExecution:100, getExecutionVariables:188), but no test exercises the unauthenticated branch — the mock in actions.test.ts:46 always returns a non-null auth user. Add a case that forces getAuthUserIdentity to return null and asserts code UNAUTHENTICATED for at least one action.


Non-blocking (fix alongside, or track)

  • Error-boundary retry mismatch: app/components/error-boundaries/boundaries/layout-error-boundary.tsx:27 gates session-rotation retries on msg.includes('Unauthenticated'). The new message {"code":"UNAUTHENTICATED"} does not match (case-sensitive). Real-world impact is low (these three actions surface errors through local try/catch, and the boundary's retries are primarily driven by Convex's own native Unauthenticated platform errors, which are unchanged), but it's a latent inconsistency. Resolving BLOCKING 1 via a message field, or matching on the code, removes it.
  • status field unasserted: the status payload on EXECUTION_NOT_CANCELABLE / EXECUTION_NOT_RESUMABLE is never asserted; codeOf/catchCode only read code. Add an assertion so the contract can't silently drift.

Verdict: NOT READY — CHANGES REQUIRED (BLOCKING 1: map the new error codes to user-facing messages at the four err.message consumer sites so no raw JSON blob is shown; BLOCKING 2: add a test covering the UNAUTHENTICATED branch).

…ages (#2013)

Address PR review on the #2013 backend fix:

- BLOCKING 1: the EXECUTION_* / UNAUTHENTICATED ConvexError codes raised by
  cancelExecution and rerunExecution were surfaced as raw err.message at four
  consumer sites, leaking the ConvexError JSON blob to users. Add
  mapExecutionError (mirrors mapTriggerError, keyed via convexErrorCode) and
  wire it into embedded-run (Re-run/Stop) and the chat cancel handlers, with
  localized common.executionErrors.* messages (en/de/fr).
- BLOCKING 2: add a test covering the UNAUTHENTICATED branch in actions.test.ts.
- Non-blocking: assert the status field on EXECUTION_NOT_CANCELABLE, and let the
  layout error boundary also match the upper-cased UNAUTHENTICATED code form.
@larryro

larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Desk review — #2013 (structured error codes for workflow execution management)

Verdict: READY TO MERGE. ✅

Reviewed via two rounds (breadth fan-out across correctness / robustness / tests / i18n / boundaries, then independent re-verification of every candidate finding). Branch checked out locally, tests run, CI confirmed green.

CI

All checks pass (Analyze, Build platform/convex, Lint, Format, Knip, Opengrep, Migrations, and all 16 Playwright platform shards + docs/web). No red, no pending.

Tests (run locally)

  • bunx vitest --run --project server convex/workflow_executions/mutations_error_codes.test.ts convex/workflow_executions/actions.test.ts convex/workflows/executions/resume_debug_step.test.ts lib/utils/convex-error.test.ts → 20 passed
  • bunx vitest --run --config vitest.ui.config.ts app/features/operator/lib/map-execution-error.test.ts → 4 passed
  • bunx vitest --run --project server lib/i18n/messages.test.ts (i18n parity/usage) → 23 passed

What's correct

  • All 12 user-facing raw-Error throw sites in mutations.ts, actions.ts, and resume_debug_step.ts converted to ConvexError({ code }); EXECUTION_NOT_CANCELABLE/EXECUTION_NOT_RESUMABLE correctly carry status. No raw throw new Error remains in any of the four issue-named files.
  • The fourth file the issue lists, workflows/triggers/slug_mutations.ts, already throws ConvexError({ code }) (since Bug: Backend raw Errors leave the client with no actionable message — chat approval/human-input cards, knowledge-entry duplicate toast, automations-trigger dialogs #2056) — the PR's "no change needed" claim is verified accurate.
  • Auth ordering and the cross-tenant IDOR (org-membership) check in rerunExecution/getExecutionVariables/startWorkflowFromFile are unchanged — UNAUTHENTICATED still fires before any data read.
  • New client mapExecutionError reuses the existing convexErrorCode helper and mirrors the sibling mapTriggerError convention; all 4 mapped keys exist under common.executionErrors in en/de/fr with full parity; every call site scopes t to common and the useCallback deps were updated.
  • Tests assert on the structured code (not message substrings) and re-throw non-ConvexError, so they fail correctly if the code regressed to a raw Error.

Non-blocking notes (optional follow-ups, not required to merge)

  1. resume_debug_step's three codes (EXECUTION_NOT_RESUMABLE, EXECUTION_NOT_PAUSED, EXECUTION_MISSING_WORKFLOW_ID) are not in mapExecutionError, and automation-debug-controls.tsx calls resumeDebugStep with no custom error handling. Confirmed this is not a regression and leaks no raw JSON: useConvexMutation's default onError shows a fixed generic toast (t('error.generic'), no err.message), exactly as before the fix. Adding these three to the mapper + an errorToast would just upgrade the debug toast from generic to specific.
  2. getExecutionVariables (UNAUTHENTICATED / NOT_FOUND) and startWorkflowFromFile (UNAUTHENTICATED) conversions have no direct unit test. The code is one-line and structurally identical to the tested rerunExecution guards, so this is a thoroughness gap, not a correctness risk.
  3. EXECUTION_NOT_RESUMABLE's status payload isn't asserted in its test (unlike EXECUTION_NOT_CANCELABLE, which is). Minor.

These are enhancements; none block merge.

@yannickmonney
yannickmonney merged commit 47c2c32 into main Jun 29, 2026
51 checks passed
@yannickmonney
yannickmonney deleted the tale/xs707d8mcyxd89wppjr98g4fxx89enrg branch June 29, 2026 17:19
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.

Bug: workflow execution mutations/actions throw raw Error — execution management rejections are opaque Server Errors

2 participants