Skip to content

fix(core): preserve workflow input after finish#1362

Merged
omeraplak merged 1 commit into
VoltAgent:mainfrom
VihaanAgarwal:fix/workflow-input-preserved-after-finish
Jun 30, 2026
Merged

fix(core): preserve workflow input after finish#1362
omeraplak merged 1 commit into
VoltAgent:mainfrom
VihaanAgarwal:fix/workflow-input-preserved-after-finish

Conversation

@VihaanAgarwal

@VihaanAgarwal VihaanAgarwal commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What this fixes

WorkflowStateManager.finish() reassigned the stored input to the current data:

finish() {
  assertCanMutate(this.#state);
  this.#input = this.#state.data as DATA;   // removed
  ...
}

WorkflowState.input is documented as the initial input to the workflow, and update() deliberately preserves it across the run. But finish() overwrote it with the final data, so reading state.input after a workflow completed returned the final output instead of the original input.

Repro

const sm = createWorkflowStateManager();
sm.start({ value: "original" });
sm.update({ data: { value: "final" } });
sm.finish();
sm.state.input; // { value: "final" }  — expected { value: "original" }

Fix

Remove the reassignment in finish(). The input is set once in start() and now stays put through completion; state.data still reflects the final value. Added a regression test, and the full workflow suite (164 tests) stays green.


Summary by cubic

In @voltagent/core, fix WorkflowStateManager.finish() overwriting state.input with the final data, so completed workflows now preserve their original input. Removed the reassignment and added a regression test; state.data still reflects the final value.

Written for commit 79496a1. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Fixed workflow completion so the original input remains preserved after a run finishes.
    • Ensured the final workflow state still reflects the completed output separately from the initial input.
  • Tests
    • Added coverage verifying that completed workflows keep the starting input unchanged while updating the final data value.

WorkflowStateManager.finish() reassigned the stored input to the current
data, so reading state.input after a workflow completed returned the final
output instead of the initial input it documents. update() already preserves
the input during a run; finish() now does too. state.data still reflects the
final value. Adds a regression test.
@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79496a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c2a67c2-ca6c-4e01-8f6d-b4f32cdda8d9

📥 Commits

Reviewing files that changed from the base of the PR and between 17732a3 and 79496a1.

📒 Files selected for processing (3)
  • .changeset/workflow-input-preserved-after-finish.md
  • packages/core/src/workflow/internal/state.spec.ts
  • packages/core/src/workflow/internal/state.ts
💤 Files with no reviewable changes (1)
  • packages/core/src/workflow/internal/state.ts

📝 Walkthrough

Walkthrough

Removes a single line from WorkflowStateManagerInternal.finish() that overwrote #input with the current #state.data. A test is added to verify state.input retains the original value while state.data holds the final result. A changeset documents the patch.

Changes

Workflow state input preservation

Layer / File(s) Summary
finish() fix, regression test, and changeset
packages/core/src/workflow/internal/state.ts, packages/core/src/workflow/internal/state.spec.ts, .changeset/workflow-input-preserved-after-finish.md
Removes the assignment #input = #state.data`` from finish() so the original input is retained; adds a test asserting `state.input` stays as the initial value while `state.data` reflects the final update; adds a patch changeset.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • VoltAgent/voltagent#1048: Resume logic reads workflowState.input from storage, which was affected by the same finish() overwrite this PR corrects.

Suggested reviewers

  • omeraplak

🐇 A line removed, a value saved,
state.input no longer misbehaved.
The finish line won't steal your start,
each field now plays its proper part.
Hop hop hooray for clean-cut state! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preserving workflow input after finish.
Description check ✅ Passed The description covers the bug, repro, fix, and testing, though it does not fully follow the template headings and checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@omeraplak
omeraplak merged commit 9dc0314 into VoltAgent:main Jun 30, 2026
22 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.

2 participants