-
Notifications
You must be signed in to change notification settings - Fork 223
[core] Extend flow route duration to "max" and fail runs where replay takes too long #1567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@workflow/sveltekit": patch | ||
| "@workflow/builders": patch | ||
| "@workflow/errors": patch | ||
| "@workflow/core": patch | ||
| "@workflow/next": patch | ||
| --- | ||
|
|
||
| Increase flow route limit to max fluid duration and fail run if a single replay exceeds 300s | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ import { | |
| WorkflowRuntimeError, | ||
| } from '@workflow/errors'; | ||
| import { classifyRunError } from './classify-error.js'; | ||
| import { MAX_QUEUE_DELIVERIES } from './runtime/constants.js'; | ||
| import { | ||
| MAX_QUEUE_DELIVERIES, | ||
| REPLAY_TIMEOUT_MS, | ||
| } from './runtime/constants.js'; | ||
| import { parseWorkflowName } from '@workflow/utils/parse-name'; | ||
| import { | ||
| type Event, | ||
|
|
@@ -161,6 +164,37 @@ export function workflowEntrypoint( | |
|
|
||
| const spanLinks = await linkToCurrentContext(); | ||
|
|
||
| // --- Replay timeout guard --- | ||
| // If the replay takes longer than the timeout, fail the run and exit. | ||
| // This must be lower than the function's maxDuration (180s) to ensure | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: This comment says |
||
| // the failure is recorded before the platform kills the function. | ||
| const replayTimeout = setTimeout(async () => { | ||
| runtimeLogger.error('Workflow replay exceeded timeout', { | ||
| workflowRunId: runId, | ||
| timeoutMs: REPLAY_TIMEOUT_MS, | ||
| }); | ||
| try { | ||
| const world = getWorld(); | ||
| await world.events.create( | ||
| runId, | ||
| { | ||
| eventType: 'run_failed', | ||
| specVersion: SPEC_VERSION_CURRENT, | ||
| eventData: { | ||
| error: { | ||
| message: `Workflow replay exceeded maximum duration (${REPLAY_TIMEOUT_MS / 1000}s)`, | ||
| }, | ||
| errorCode: RUN_ERROR_CODES.REPLAY_TIMEOUT, | ||
| }, | ||
| }, | ||
| { requestId } | ||
| ); | ||
| } catch { | ||
| // Best effort — process exits regardless | ||
| } | ||
| process.exit(1); | ||
| }, REPLAY_TIMEOUT_MS); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: This is the first use of This is purely defensive — the |
||
|
|
||
| // Invoke user workflow within the propagated trace context and baggage | ||
| return await withTraceContext(traceContext, async () => { | ||
| // Set workflow context as baggage for automatic propagation | ||
|
|
@@ -525,6 +559,8 @@ export function workflowEntrypoint( | |
| ); // End trace | ||
| } | ||
| ); // End withWorkflowBaggage | ||
| }).finally(() => { | ||
| clearTimeout(replayTimeout); | ||
| }); // End withTraceContext | ||
| } | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,10 @@ | |
| // At 48 attempts the total elapsed time is approximately 20 hours, which is | ||
| // safely under the 24-hour message visibility limit. | ||
| export const MAX_QUEUE_DELIVERIES = 48; | ||
|
|
||
| // Maximum time allowed for a single workflow replay execution (in ms). | ||
| // If a replay exceeds this duration, the run is failed and the process exits. | ||
| // This must be lower than the function's maxDuration to ensure the | ||
| // timeout handler has time to post the run_failed event before the platform | ||
| // kills the function. | ||
| export const REPLAY_TIMEOUT_MS = 240_000; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: Worth noting that on the Hobby plan, This is probably acceptable — Hobby plan workflows are expected to be short-lived — but a short comment here explaining the plan-dependent behavior would help future readers. For example: // Note: On plans where maxDuration < REPLAY_TIMEOUT_MS (e.g., Hobby at 60s),
// the platform will kill the function before this fires. In that case, VQS
// retries handle the failure via MAX_QUEUE_DELIVERIES. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: The changeset says "exceeds 300s" but
REPLAY_TIMEOUT_MSis240_000(240s). Should be: