Skip to content

Fix runFlow error handling, useFlow lifecycle, and Next helpers - #1

Merged
javaquasar merged 2 commits into
mainfrom
claude/repository-analysis-improvements-7e17f9
Dec 2, 2026
Merged

javaquasar merged 2 commits into
mainfrom
claude/repository-analysis-improvements-7e17f9

Conversation

@javaquasar

@javaquasar javaquasar commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes runtime correctness bugs found during a repository review. Each one was reproduced before the fix and is covered by a regression test.

runFlow

  • Retries could re-run a successful mutation. When a post-success step (invalidate, consistency, redirect, reconcile, onSuccess, afterSuccess) threw, the error was retried, so the server action ran again, and optimistic state was rolled back. Now only the action and its middleware are retried or rolled back. Post-success failures settle with status: "error" and keep data.
  • A throw from beforeRun or optimistic.apply used to reject runFlow and skip onSettled. The run now settles as an error and the action is not called.
  • Errors thrown by onError, afterError, onSettled or rollback are collected in hookErrors and no longer skip the remaining hooks.
  • throw undefined was reported as a success. Results now carry status and rolledBack.
  • The abort listener on the caller's signal is removed when the run settles.

useFlow

  • pending is cleared in finally.
  • In-flight runs are aborted on unmount and on reset(), and results from runs started before a reset are ignored.
  • The optimistic stage is now actually visible.
  • cancel() without an argument targets the latest run.

mutaflow/next

  • tags/paths builders were thenable, so await tags.todos hung. They also serialized incorrectly with JSON.stringify.
  • createServerActionAdapter used to forward { flowId, attempt, signal } to every Server Action. A live Next.js 15.5 check showed this does not throw, but the AbortSignal cannot be used on the server, so the argument was misleading. The adapter now calls action(input). The new forwardContext: true option passes { flowId, attempt }.

Behavior changes

  • The adapter no longer forwards context by default.
  • The flow:error stage is rolled_back only when a rollback actually happened.
  • testkit expectRollback and expectReconciled check result.status.

Test plan

  • npm test: 39/39 pass (11 new regression tests)
  • npm run typecheck
  • Next.js 15.5 example app: creating a todo through the server action works with both the old and the new adapter

🤖 Generated with Claude Code

Artur Buzov and others added 2 commits December 2, 2026 11:19
- runFlow: retry and roll back only the action; post-success failures
  settle as errors without re-running the mutation. beforeRun and
  optimistic.apply failures no longer reject. Hook errors are collected
  in hookErrors. Add status and rolledBack to FlowRunResult. Remove the
  abort listener from the caller signal.
- useFlow: clear pending in finally, abort in-flight runs on unmount and
  reset, ignore stale results after reset, use result.status.
- tags/paths builders: not thenable, serialize to { kind, value }.
- createServerActionAdapter: call action(input) only; optional
  forwardContext passes serializable { flowId, attempt }.
- testkit: check result.status; add regression tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs on pushes to main and on pull requests across Node 20, 22 and 24.
The README badge already points at this workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@javaquasar
javaquasar merged commit bb241d8 into main Dec 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant