Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/background-step-unresolved-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflow/core': patch
---

Avoid resolving run data before background step execution.
36 changes: 34 additions & 2 deletions packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
type Event,
getQueueTopicPrefix,
isLegacySpecVersion,
ROOT_RUN_ID_ATTRIBUTE,
resolveQueueNamespace,
SPEC_VERSION_CURRENT,
Expand Down Expand Up @@ -706,7 +707,9 @@ export function workflowEntrypoint(
// will pick up the replay.
if (incomingStepId && incomingStepName) {
try {
const bgRun = await world.runs.get(runId);
const bgRun = await world.runs.get(runId, {
resolveData: 'none',
});
if (bgRun.status !== 'running') {
runtimeLogger.debug(
'Run already finished, skipping background step',
Expand Down Expand Up @@ -850,7 +853,36 @@ export function workflowEntrypoint(
'All parallel steps done, replaying inline after background step',
{ workflowRunId: runId }
);
workflowRun = bgRun;
const runCreatedEvent = cachedEvents.find(
Comment thread
NathanColosimo marked this conversation as resolved.
Resolved
(event) => event.eventType === 'run_created'
);
let replayInput: unknown;
if (runCreatedEvent) {
replayInput = runCreatedEvent.eventData.input;
} else {
if (!isLegacySpecVersion(bgRun.specVersion)) {
throw new WorkflowRuntimeError(
`Workflow run "${runId}" has no "run_created" event`
);
}
// Legacy runs predate the event-sourced run_created
// invariant, so retain the resolved GET only for them.
const legacyRun = await world.runs.get(runId, {
resolveData: 'all',
});
if (legacyRun.status !== 'running') {
return;
}
replayInput = legacyRun.input;
}
workflowRun = {
...bgRun,
Comment thread
vercel[bot] marked this conversation as resolved.
Resolved
Comment thread
NathanColosimo marked this conversation as resolved.
Resolved
input: replayInput,
status: 'running',
output: undefined,
error: undefined,
completedAt: undefined,
};
workflowStartedAt = bgStartedAt;
// cachedEvents and eventsCursor already set from load above
} else {
Expand Down
Loading