Skip to content

refactor(openworkflow): extract StepHistory from execution.ts#474

Merged
jamescmartinez merged 5 commits intomainfrom
exec-refactor
Apr 17, 2026
Merged

refactor(openworkflow): extract StepHistory from execution.ts#474
jamescmartinez merged 5 commits intomainfrom
exec-refactor

Conversation

@jamescmartinez
Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI review requested due to automatic review settings April 17, 2026 20:47
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/openworkflowdev/openworkflow/@openworkflow/cli@474
npm i https://pkg.pr.new/openworkflowdev/openworkflow/@openworkflow/dashboard@474
npm i https://pkg.pr.new/openworkflowdev/openworkflow@474

commit: 120f495

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 StepExecutor and the sleep pre-pass to delegate step ledger operations to StepHistory.
  • Added unit tests for StepHistory behavior (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);
Comment on lines +304 to +316
* 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);
Copilot AI review requested due to automatic review settings April 17, 2026 21:58
@jamescmartinez jamescmartinez merged commit 88ba273 into main Apr 17, 2026
12 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 97.79006% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/openworkflow/worker/step-history.ts 96.94% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 StepHistory to encapsulate step-attempt cache, running/failed tracking, failure counts, step-name resolution, and step-attempt limit enforcement.
  • Updated StepExecutor and sleep pre-pass logic in execution.ts to delegate step-attempt bookkeeping to StepHistory.
  • Added unit tests covering StepHistory APIs 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()]);
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