fix(sdk): make --resume work for script workflows#725
Merged
Conversation
Script workflows (TS files that call workflow(...).run()) could not
be resumed. Two linked bugs:
1. WorkflowBuilder.run() constructed a WorkflowRunner without a db
option, so it silently defaulted to InMemoryWorkflowDb and the
.agent-relay/workflow-runs.jsonl file was never written. --resume
then found no db entry.
2. The cache-reconstruction fallback (reconstructRunFromCache) bailed
out for script workflows because builder.run() called
runner.resume(runId, vars) with only two args, never forwarding
the config it just built. reconstructRunFromCache then tried to
read relay.yaml from disk (which does not exist for script
workflows) and returned null, triggering the "Run not found
(no database entry or cached step outputs)" error even when
step outputs WERE cached on disk.
Fix both by:
- defaulting WorkflowBuilder.run() to JsonFileWorkflowDb pointed
at {cwd}/.agent-relay/workflow-runs.jsonl, matching the YAML
CLI code path in cli.ts
- forwarding the built config into both runner.resume() call sites
Adds vitest coverage in builder-resume-persistence.test.ts for both
the "run state persisted" and "resume from cache without jsonl"
paths. Full sdk test suite remains green.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Script workflows (TS files that call
workflow(...).run()) could not be resumed. Three linked bugs inpackages/sdk/src/workflows/builder.ts:WorkflowBuilder.run()constructed aWorkflowRunnerwithout adboption, so it silently defaulted toInMemoryWorkflowDband.agent-relay/workflow-runs.jsonlwas never written for script workflows.--resumethen found no db entry.reconstructRunFromCache) bails out for script workflows because it looks forrelay.yamlon disk when no config is passed — and script workflows do not have arelay.yaml.runner.resume()call sites inbuilder.tsonly pass(resumeRunId, options.vars)— never forwarding the config the script just built. Even if (2) were fixed, the config still would not reach the fallback.Net effect: a script workflow that fails mid-DAG with cached step outputs on disk still threw
Run "<id>" not found (no database entry or cached step outputs)on resume.Fix
WorkflowBuilder.run()toJsonFileWorkflowDbpointed at<cwd>/.agent-relay/workflow-runs.jsonl— matching the YAML CLI code path incli.ts:338.configas the third arg into bothrunner.resume()call sites soreconstructRunFromCachecan use it without needingrelay.yaml.Test plan
builder-resume-persistence.test.tswith two tests — "run state persisted to JSONL by default" and "resume reconstructs from cached step outputs when jsonl is missing"packages/sdktest suite green (regression sweep coversresume-fallback,builder-deterministic,start-from)packages/sdkand grepped the compileddist/workflows/builder.jsforJsonFileWorkflowDband the 3-argrunner.resume(...)callRepro before this fix
agent-relay run workflows/my.tsagent-relay run workflows/my.ts --resume <run-id>→ throwsRun "<id>" not found (no database entry or cached step outputs)even though.agent-relay/step-outputs/<run-id>/has cached.mdfiles on disk🤖 Generated with Claude Code