Skip to content

refactor: dry shared helpers across openworkflow backends, worker, and cli#494

Merged
jamescmartinez merged 6 commits intomainfrom
cleanup
Apr 27, 2026
Merged

refactor: dry shared helpers across openworkflow backends, worker, and cli#494
jamescmartinez merged 6 commits intomainfrom
cleanup

Conversation

@jamescmartinez
Copy link
Copy Markdown
Contributor

lots of stuff:

  • core: centralize pagination, cursor decoding, cancel/fail conflict resolution
  • backends: extract owned-by-worker WHEREs, AND-composition (pg), row parsers (sqlite)
  • worker: dry step-attempt and workflow-run lifecycle helpers
  • cli: consolidate init writers and ensure-entry writers

…d cli

lots of stuff:

- core: centralize pagination, cursor decoding, cancel/fail conflict resolution
- backends: extract owned-by-worker WHEREs, AND-composition (pg), row parsers (sqlite)
- worker: dry step-attempt and workflow-run lifecycle helpers
- cli: consolidate init writers and ensure-entry writers
Copilot AI review requested due to automatic review settings April 27, 2026 16:40
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 27, 2026

Open in StackBlitz

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

commit: 2ea02fd

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 OpenWorkflow to reduce duplication by centralizing shared helpers across the core layer, the Postgres/SQLite backends, the worker execution engine, and the CLI.

Changes:

  • Centralizes cursor pagination (cursor decoding + next/prev computation) into core helpers and reuses them in both backends.
  • Extracts shared “owned-by-worker” WHERE logic and standardizes “mutation must return a row” checks via a core helper.
  • DRYs worker step-attempt creation/completion and CLI init/setup file-writing / entry-appending helpers.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/openworkflow/worker/execution.ts Extracts shared helpers for creating/completing step attempts and consolidates repeated workflow-run failure transitions.
packages/openworkflow/sqlite/backend.ts Reuses shared pagination/cursor helpers, extracts shared WHERE fragments + params for “owned-by-worker” checks, and DRYs row parsing.
packages/openworkflow/postgres/postgres.ts Exposes a PostgresFragment type alias for shared query-fragment helpers.
packages/openworkflow/postgres/backend.ts Reuses shared pagination/cursor helpers, extracts “owned-by-worker” WHERE fragments, and centralizes AND-joining of WHERE fragments.
packages/openworkflow/core/workflow-run.ts Adds shared conflict-resolution helper for cancel-workflow behavior when UPDATE affects 0 rows.
packages/openworkflow/core/workflow-run.test.ts Adds tests for resolveCancelWorkflowRunConflict.
packages/openworkflow/core/workflow-definition.ts Minor refactor to reduce duplication in failed-workflow update computation.
packages/openworkflow/core/error.ts Adds requireRow helper to standardize “mutation must return a row” validation.
packages/openworkflow/core/cursor.ts Adds shared pagination utilities (DEFAULT_PAGINATION_PAGE_SIZE, decodeListCursor, buildPaginatedResponse).
packages/openworkflow/core/cursor.test.ts Adds unit tests for the new cursor/pagination helpers.
packages/cli/commands.ts Consolidates init cancel handling, file writers, and “append entry if missing” helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/openworkflow/core/error.ts
Comment thread packages/openworkflow/sqlite/backend.ts Outdated
Copilot AI review requested due to automatic review settings April 27, 2026 16:55
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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 OpenWorkflow to centralize shared helpers across core, backends (Postgres/SQLite), the worker execution path, and the CLI—aiming to reduce duplication and standardize common behaviors (pagination, “row required” mutation checks, cancel conflict handling, and step/run lifecycle helpers).

Changes:

  • Centralizes cursor pagination helpers (DEFAULT_PAGINATION_PAGE_SIZE, decodeListCursor, buildPaginatedResponse) and adopts them in Postgres/SQLite backends.
  • Standardizes backend mutation “must return a row” checks via requireRow(...), and centralizes cancel conflict resolution via resolveCancelWorkflowRunConflict(...).
  • DRYs worker step-attempt creation/completion recording and CLI init file/env/gitignore writers.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/openworkflow/worker/execution.ts Extracts shared step-attempt creation/completion + consolidates workflow-run failure transitions.
packages/openworkflow/sqlite/backend.ts Extracts owned-by-worker WHERE fragments/param helpers, adopts shared pagination + shared row parsing, uses requireRow in many mutations.
packages/openworkflow/postgres/postgres.ts Exposes PostgresFragment type alias for shared fragment helpers.
packages/openworkflow/postgres/backend.ts Adopts shared pagination + requireRow, extracts owned-by-worker WHERE fragments and AND-composition helper.
packages/openworkflow/core/workflow-run.ts Adds shared resolveCancelWorkflowRunConflict helper for cancel idempotency/conflicts.
packages/openworkflow/core/workflow-run.test.ts Adds unit tests for resolveCancelWorkflowRunConflict.
packages/openworkflow/core/workflow-definition.ts Refactors failed-run update construction to reuse a single “failed payload” builder.
packages/openworkflow/core/error.ts Adds requireRow assertion helper for backend mutations.
packages/openworkflow/core/cursor.ts Adds shared pagination constants/helpers (decodeListCursor, buildPaginatedResponse).
packages/openworkflow/core/cursor.test.ts Adds tests for decodeListCursor and buildPaginatedResponse.
packages/cli/commands.ts DRYs cancel/exit flow, file writers under openworkflow/, and generic “append line if missing” helpers.
Comments suppressed due to low confidence (1)

packages/openworkflow/sqlite/backend.ts:699

  • This branch still manually returns Promise.reject(new Error(...)) when no row is updated, while most other mutations in this file now use requireRow(...) for consistent error messages and type narrowing. Consider switching this to requireRow(row, "reschedule workflow run after failed step attempt") and then returning the parsed row, to keep the mutation-style consistent across the backend.
    if (!row) {
      return Promise.reject(
        new Error(
          "Failed to reschedule workflow run after failed step attempt",
        ),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/openworkflow/core/cursor.ts Outdated
@jamescmartinez jamescmartinez merged commit c37b270 into main Apr 27, 2026
12 of 13 checks passed
@jamescmartinez jamescmartinez deleted the cleanup branch April 27, 2026 17:48
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