fix(sdk): classify an authored resume step failure as step_failed

Merged
KJ
3mo ago
+151-26

Merging this does not reach the operator's CLI. publish.yml is
workflow_dispatch-only — no push or tag trigger — and its package input
states that single-package selections are dry-run only, so a real publish
needs a deliberate run with package: all. Both packages/sdk and
packages/surface are at 2.0.12, which npm already has, so a version
bump is required
for any of this to reach a user. Please do not read a
merge here as "the flow can be re-run."

Why this exists

#430 fixed this misclassification for flows run and left flows resume on
the old path. It merged before the fix landed, so on main today an authored
root whose f.agent step failed still prints exactly what #430 set out to
remove:

FAILED [protocol_error] relayflowd could not complete the resume request: ...
RUN 01M2NDS2RYK3MH6YBSB1CHA9SE unknown

Verified on main at packages/sdk/src/cli/run.ts:235.

#430 also shipped the docs/SURFACE.md claim that a step which ran and failed
reports step_failed with status: failed "for authored TypeScript as well as
declarative ones". main has documented that since the merge without doing it.
This PR makes the code match the doc rather than walking the doc back.

Found by Cursor Bugbot on #430, reported after the merge
(BUGBOT_BUG_ID: 93b20728-614e-4055-b42c-0c996ad4f983).

The fix

resumeFlow's catch sent AuthoredFlowExecutionError with code step_failed
to protocolFailure, which is wrong twice over: it blames the daemon for a run
it drove correctly, and it builds a report with no status — which is the
whole of what RUN <id> unknown ever meant, not a status the renderer failed
to recognise.

Both paths now go through one exported authoredStepFailure rather than a
second copy of the same branch. That is the actual point of the change: a copy
is how they drifted. runDirectFlow had a test and resumeFlow did not, so
the gap survived review of the very change that created it.

The test, and a trap worth naming

tests/resume-failure.test.ts pins resumeFlow specifically, plus a negative:
a plain Error on resume must still report protocol_error with no status,
so the classification is not over-broadened.

The error is injected at run.resume rather than at
resumeDurableAuthoredFlow, deliberately. vi.mock of authored-root.js does
not reach run.ts's own import of it, so a mocked readAuthoredRootMetadata
is silently bypassed — the real one swallows its failure and returns
undefined, and the test then runs the non-authored resume path while
appearing to assert the authored one. My first draft did exactly that and
failed with status: undefined, which looks identical to the bug being
unfixed. CALLS_read=0 is what proved the mock was never invoked. The comment
in the test records this so the next person does not re-lay it.

Tests

npm test in packages/sdk (tsc + tsc tests + build + vitest), exit 1:

Test Files  3 failed | 102 passed | 2 skipped (107)
     Tests  9 failed | 1670 passed | 14 skipped (1693)

typecheck and typecheck:tests both exit 0.

Against the pre-change run on this same tree (1668 passed, 9 failed), this
adds exactly the 2 new tests and no new failures. The 9 are pre-existing and
environmental — I ran the same three files on a pristine origin/main
worktree and got identical results (3 failed / 9 failed | 1 passed | 10 skipped): spawnSync .../kernel/target/debug/relayflowd ENOENT (those live
tests hardcode a target path ops/cargo.sh no longer writes to, having moved
CARGO_TARGET_DIR outside the repo) plus one unrelated
expected '1.3.14' to be '1.4.0'. Files: webhook-live,
provider-trigger-executor, authored-node-runtime.

Touched-file results: resume-failure 2 ✓, direct-run-failure 7 ✓,
step-failure-diagnostic 16 ✓, classify-outcome 2 ✓, observer-link 39 ✓.

Holding at merge-ready; I will not merge.

🤖 Generated with Claude Code


[!NOTE]
Low Risk
CLI error-reporting only; no auth, daemon protocol, or execution semantics changes beyond how resume failures are classified and surfaced.

Overview
Aligns flows resume with flows run when an authored flow step fails: AuthoredFlowExecutionError with code step_failed is no longer routed through protocolFailure, which blamed relayflowd and left the report without status (RUN <id> unknown).

The fix extracts shared authoredStepFailure in run.ts and wires both runDirectFlow and resumeFlow through it so run and resume cannot drift again. Reports now get status: failed, completionReason: step_failed, and a [step_failed] diagnostic (with the redundant step_failed: prefix stripped from the message).

resume-failure.test.ts pins resume classification—step failures vs genuine transport errors still reported as protocol_error without status.

Reviewed by Cursor Bugbot for commit b730729be9dbcb5f0ded080280c6a3d6b7e6f259. Bugbot is set up for automated code reviews on this repo. Configure here.