-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: clone history events to prevent mutation #479
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function deepClone<T>(item: T): T { | ||
// TODO: more efficient deep clone | ||
return item === undefined ? item : JSON.parse(JSON.stringify(item)); | ||
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create issue? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ export class RemoteExecutorProvider<Context = undefined> | |
executor: WorkflowExecutor<any, any, any> | ||
): Promise<{ storedBytes: number }> { | ||
// provides a shallow copy of the history events. | ||
const historyEvents = executor.history.slice(0); | ||
const historyEvents = executor.historyCloned.slice(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just use the cloned one in the executor's iterator and return the original array in |
||
historyEvents.push(...newHistoryEvents); | ||
const { bytes } = await this.props.executionHistoryStateStore.updateHistory( | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ import { | |
type UnresolvedEventualDefinition, | ||
} from "./eventual-definition.js"; | ||
import { formatExecutionId } from "./execution.js"; | ||
import { deepClone } from "../deep-clone.js"; | ||
|
||
/** | ||
* Put the resolve method on the promise, but don't expose it. | ||
|
@@ -206,13 +207,17 @@ export class WorkflowExecutor<Input, Output, Context = undefined> { | |
) => void; | ||
} = {}; | ||
|
||
// clone the history so it cannot be modified by the user | ||
public historyCloned: HistoryStateEvent[]; | ||
|
||
constructor( | ||
private workflow: Workflow<any, Input, Output>, | ||
public history: HistoryStateEvent[], | ||
// TODO: properties used in the workflow should be encoded in the history to keep them constant between runs | ||
private propertyRetriever: PropertyRetriever, | ||
private eventualFactory: EventualFactory = createDefaultEventualFactory() | ||
) { | ||
this.historyCloned = deepClone(history); | ||
Comment on lines
+210
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use |
||
this.nextSeq = 0; | ||
this.expected = iterator(history, isCallEvent); | ||
this.events = iterator(history, isCompletionEvent); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: delete to clean up