claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Workflow resumeFromRunId re-dispatches completed agent() calls despite unchanged (prompt, opts)

Open JeanFrancoisGagne opened this issue 3 months ago • 2 comments

Summary

Resuming a Workflow run with resumeFromRunId re-dispatched four agent() calls whose results were already in the run's journal.jsonl, even though their (prompt, opts) were byte-identical to the completed calls. The docs say the longest unchanged prefix of agent() calls returns cached results instantly and only edited or new calls run live; here, completed calls past the edit point re-ran.

Environment

  • Claude Code 2.1.222, VS Code extension host
  • win32 (Windows 11 Pro 10.0.26200)
  • Model: claude-fable-5

Repro shape

  1. Launch a Workflow (ours ran 16 agent() calls: a pipeline of ticket agents followed by verify agents, script passed via script, later iterated via scriptPath).
  2. Mid-run, stop it with TaskStop ("pause clean").
  3. Edit the script file: change ONLY the prompts of calls that had never completed (two resume prompts got an audit-first preamble). All completed calls kept byte-identical (prompt, opts).
  4. Relaunch with Workflow({scriptPath, resumeFromRunId}).

Expected: completed calls replay from journal.jsonl (their results sit there keyed v2:<sha>); only the edited and never-started calls run live.

Observed: four calls that had completed before the stop were dispatched again as live agents. Their journal entries existed with results. The re-runs cost real tokens and wall clock, and, because these agents mutate a git tree, a re-run of a "build X" prompt against a tree where X already landed can duplicate work or conflict with itself. Ours survived only because the prompts were phrased verify-first, so the re-dispatched agents found the work in git log and no-oped.

Guesses at the cause

The four re-dispatched calls were downstream of a pipeline() whose earlier stages interleave; if the cache key includes call ordinal or some interleaving-sensitive component rather than the content hash alone, a resume that reaches calls in a different order would miss the cache. We did not confirm this; the (prompt, opts) bytes were confirmed identical.

Ask

Either replay completed calls from the journal whenever the content hash matches, regardless of dispatch order, or document that resume caching is prefix-ordered and an interleaved pipeline can invalidate completed calls behind an edit point.

JeanFrancoisGagne avatar Aug 26 '26 10:08 JeanFrancoisGagne

Adding a likely root cause for the expectation mismatch here: the two resume descriptions shipped in the same build contradict each other (checked in 2.1.271).

  • The resumeFromRunId parameter description says: "Completed agent() calls with unchanged (prompt, opts) return their cached results instantly; only edited or new calls re-run." — that reads as per-call caching.
  • The tool's Resume section says: "the longest unchanged prefix of agent() calls returns cached results instantly; the first edited/new call and everything after it runs live." — that is prefix caching.

The behaviour reported above (completed calls past the edit point re-dispatched) matches the second description, not the first. We hit the same thing: after editing one prompt mid-script, unchanged side-effecting stages after it re-ran, and a "write a dated sibling if the file exists" rule manufactured duplicate files.

Two doc requests, whichever behaviour is intended: make the parameter description agree with the Resume section; and state that stages after the first edited call must be idempotent (overwrite their own outputs) if a script is going to be resumed.

DirtyDiablo avatar Sep 15 '26 15:09 DirtyDiablo

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Nov 22 '26 22:11 github-actions[bot]