refactor(openworkflow): extract StepHistory from execution.ts#474
refactor(openworkflow): extract StepHistory from execution.ts#474jamescmartinez merged 5 commits intomainfrom
Conversation
Move the in-memory step-attempt ledger (successful-result cache, running/ failed maps, failure counts, resolved step names, step-attempt limit) out of StepExecutor and into a dedicated StepHistory class. StepExecutor now delegates to a narrow API instead of manipulating several parallel maps inline. Pure refactor — no behavior change.
commit: |
There was a problem hiding this comment.
Pull request overview
This PR refactors the OpenWorkflow worker execution path by extracting the in-memory step-attempt bookkeeping out of execution.ts and into a dedicated StepHistory class, reducing the amount of parallel map manipulation inside StepExecutor.
Changes:
- Introduced
StepHistory(plus related helpers/constants) to encapsulate cached results, running/failed tracking, deterministic step-name resolution, and step-attempt limit enforcement. - Updated
StepExecutorand the sleep pre-pass to delegate step ledger operations toStepHistory. - Added unit tests for
StepHistorybehavior (name resolution, lookups, mutations, wait-time helpers).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/openworkflow/worker/step-history.ts |
New StepHistory abstraction plus extracted step execution/wait-time helpers and step-limit error type/consts. |
packages/openworkflow/worker/step-history.test.ts |
New Vitest suite covering StepHistory APIs and behaviors. |
packages/openworkflow/worker/execution.ts |
Refactors StepExecutor + sleep pre-pass to use StepHistory; re-exports step-limit/state helpers from the new module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @returns Timeout deadline | ||
| */ | ||
| export function defaultWaitTimeoutAt(base: Readonly<Date> = new Date()): Date { | ||
| const timeoutAt = new Date(base); |
| * the in-progress wait the caller is about to park on). Always returns a | ||
| * concrete date. | ||
| * @param fallback - Candidate timestamp for the in-progress wait | ||
| * @returns The earlier of the fallback or any known running wait | ||
| */ | ||
| resolveEarliestRunningWaitResumeAt(fallback: Readonly<Date>): Date { | ||
| const earliest = this.earliestRunningWaitResumeAt(); | ||
| if (!earliest) return new Date(fallback); | ||
|
|
||
| const fallbackMs = fallback.getTime(); | ||
| if (!Number.isFinite(fallbackMs)) return earliest; | ||
|
|
||
| return earliest.getTime() < fallbackMs ? earliest : new Date(fallback); |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR refactors the workflow worker execution path by extracting the in-memory step-attempt ledger and related utilities out of StepExecutor (execution.ts) into a dedicated StepHistory class/module, reducing StepExecutor’s direct manipulation of multiple parallel maps.
Changes:
- Added
StepHistoryto encapsulate step-attempt cache, running/failed tracking, failure counts, step-name resolution, and step-attempt limit enforcement. - Updated
StepExecutorand sleep pre-pass logic inexecution.tsto delegate step-attempt bookkeeping toStepHistory. - Added unit tests covering
StepHistoryAPIs and behaviors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/openworkflow/worker/step-history.ts | Introduces StepHistory and moves step-ledger + wait-time helper logic out of execution.ts. |
| packages/openworkflow/worker/step-history.test.ts | Adds focused unit tests for step-ledger behavior (naming, lookups, mutations, wait-time helpers). |
| packages/openworkflow/worker/execution.ts | Refactors execution to construct/use StepHistory and re-export prior step-ledger helpers/constants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Build step execution state from loaded attempts in one pass. | ||
| * @param attempts - Loaded step attempts for the workflow run | ||
| * @returns Successful cache plus failed-attempt counts by step name |
| * @returns Earliest wake-up timestamp, or null when no running wait exists | ||
| */ | ||
| earliestRunningWaitResumeAt(): Date | null { | ||
| return getEarliestRunningWaitResumeAt([...this.runningByStepName.values()]); |
Move the in-memory step-attempt ledger (successful-result cache, running/ failed maps, failure counts, resolved step names, step-attempt limit) out of StepExecutor and into a dedicated StepHistory class. StepExecutor now delegates to a narrow API instead of manipulating several parallel maps inline.