Skip to content

feat(openworkflow): export the backend API and test suite - #893

Open
cliftonc wants to merge 2 commits into
openworkflowdev:mainfrom
cliftonc:backend-api
Open

cliftonc wants to merge 2 commits into
openworkflowdev:mainfrom
cliftonc:backend-api

Conversation

@cliftonc

Copy link
Copy Markdown
Contributor

Follow-up to #880

Summary

As discussed in #880, this exposes the Backend API and the backend test suite so backends can be maintained outside this repo. The Drizzle backend will live in a separate openworkflow-drizzle package that builds on both.

Changes

  • openworkflow/backend: the Backend interface and its param and result types, plus the helpers the built-in backends share for logic that doesn't depend on storage (computeFailedWorkflowRunUpdate, prepareWorkflowRerun, resolveCancelWorkflowRunConflict, nextScheduleOccurrence, isTerminalStatus, the cursor/pagination helpers, toWorkflowRunCounts, requireRow, wrapError). It only re-exports what the SQLite and Postgres backends already import from core/.
  • openworkflow/testing: testBackend() and TestBackendOptions. files re-includes dist/testing/backend.testsuite.* and dist/testing/schedules.testsuite.*, and vitest becomes an optional peer dependency.
  • A Custom Backends docs page under Backends that covers the interface, the helpers, and running testBackend. It says the backend API is experimental before 1.0 and may change in a minor release, so backends should pin the OpenWorkflow versions they support.

I added /backend as a new subpath instead of adding to openworkflow/internal, since internal is what the CLI and dashboard use and isn't documented. Happy to fold it into internal if you'd prefer.

The two exports are separate commits if you'd like to take only one.

Tested by packing the tarball into a scratch project, typechecking imports from openworkflow/backend, and running testBackend from openworkflow/testing against BackendSqlite (86 tests pass). npm run ci checks pass locally.

Add a documented subpath for people writing their own `Backend`. It exports
the `Backend` interface and its param and result types, plus the helpers the
built-in backends share for the rules that don't depend on storage: retry on
failure, rerun, cancel conflicts, schedule occurrences, pagination, and row
and error checks. A custom backend that uses them behaves the same way as the
SQLite and Postgres backends.

`openworkflow/internal` stays as it is for the CLI and dashboard. The new docs
page marks the backend API as experimental before 1.0, so backends should pin
the OpenWorkflow versions they support.
…ting

Publish `testBackend()`, the suite the SQLite and Postgres backends run, so
people can check a custom `Backend` against the same tests. Vitest becomes an
optional peer dependency.
@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: b26c2dc

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium impact] Exports backend API and test suite as public interfaces.

The PR appears safe to merge, with a non-blocking correction to the shutdown advice.

Findings

  1. P2 Automatic cleanup is incorrectly promised ▶

Summary

This PR lets external packages implement and test OpenWorkflow backends.

  • Custom backends can use OpenWorkflow’s public backend contract and shared rules.
  • Custom backends can run OpenWorkflow’s shared backend test suite.

Reviews (1) · Last reviewed commit: "feat(openworkflow): export the backend t..." · Reviewed by Greptile

Comment on lines +48 to +49
A backend owns its connections and its schema. `stop()` is called when the
client or worker shuts down.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Automatic cleanup is incorrectly promised

The guide says the client or worker calls the backend’s stop(), but OpenWorkflow has no shutdown method and Worker.stop() never calls backend.stop(). Readers relying on this promise can leave database connections open. Say that callers must explicitly call backend.stop() after stopping their workers.

Suggested change
A backend owns its connections and its schema. `stop()` is called when the
client or worker shuts down.
A backend owns its connections and its schema. Call `backend.stop()` explicitly
when you're done with it, after stopping any workers that use it. The client and
worker do not call it for you.

This branch has not been deployed

No deployments
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.

1 participant