Skip to content

Commit 9dc0314

Browse files
fix(core): preserve workflow input after finish (#1362)
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.
1 parent 17732a3 commit 9dc0314

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@voltagent/core": patch
3+
---
4+
5+
Fixed workflow `state.input` being overwritten with the final output once a workflow finished. `finish()` reassigned the stored input to the current data, so reading `state.input` after completion returned the final result instead of the initial input it documents. The initial input is now preserved through completion; `state.data` still reflects the final value.

‎packages/core/src/workflow/internal/state.spec.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ describe("WorkflowStateManager", () => {
128128
expect(result.status).toBe("completed");
129129
});
130130

131+
it("should preserve the original input after the workflow finishes", () => {
132+
stateManager.start({ value: "original" });
133+
stateManager.update({ data: { value: "final" } });
134+
stateManager.finish();
135+
136+
// `input` is documented as the initial input and must survive completion;
137+
// only `data` should reflect the final value.
138+
expect(stateManager.state.input).toEqual({ value: "original" });
139+
expect(stateManager.state.data).toEqual({ value: "final" });
140+
});
141+
131142
it("should transition from suspended to failed", () => {
132143
stateManager.start({ data: "test" });
133144
stateManager.suspend("Pause");

‎packages/core/src/workflow/internal/state.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ class WorkflowStateManagerInternal<DATA, RESULT> implements WorkflowStateManager
167167

168168
finish() {
169169
assertCanMutate(this.#state);
170-
this.#input = this.#state.data as DATA;
171170
this.#internalUpdate({
172171
endAt: new Date(),
173172
status: "completed",

0 commit comments

Comments
 (0)