feat: run observability with listRuns and resume#49
Open
danfry1 wants to merge 2 commits into
Open
Conversation
e704d43 to
1afdb7b
Compare
1afdb7b to
a994a19
Compare
Add two operational primitives for inspecting and recovering runs: - engine.listRuns(filter?) lists runs most-recent-first for inspection and dead-letter visibility, filtered by status/workflow and paged with limit + a before (createdAt) cursor. - engine.resume(runId) re-queues a failed or cancelled run. Completed steps are preserved and skipped on replay, so execution resumes at the step that failed; the failed step's result is discarded and re-run. StorageAdapter gains listRuns() and requeueRun(), implemented across all built-in adapters (memory, sqlite-node, sqlite-bun, sqlite-node-builtin) with matching tests. New exported ListRunsFilter type.
- listRuns: deterministic order (createdAt DESC, id DESC) across all adapters, and a keyset cursor (before + beforeId) so pagination is exact even when runs share a createdAt. The SQLite adapters order by id rather than rowid so the cursor and order agree. - resume(): return false for a missing run, and throw WorkflowNotFoundError when the run's workflow is not registered, rather than re-queuing it into an unclaimable pending state. - sqlite-bun requeueRun: read the affected-row count from the run() result (inherits the change-detection fix this branch is rebased on). - Tests: tied-createdAt keyset pagination (memory + sqlite), resume on missing/unregistered-workflow runs, requeue of a running run.
a994a19 to
f907606
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two operational primitives for inspecting and recovering workflow runs — the foundation for run observability in Reflow.
engine.listRuns(filter?)— lists runs in reverse-chronological order for inspection and dead-letter visibility. Filter bystatusand/orworkflow; paginate withlimitand abefore(createdAt) cursor. A non-positivelimitis rejected with aConfigError.engine.resume(runId)— re-queues afailedorcancelledrun. Completed steps are preserved and skipped on replay, so execution resumes at the step that failed; the failed step's result is discarded and re-run. Returnsfalsewhen the run is not in a resumable state (pending/running/completed/ missing).Storage interface
StorageAdaptergains two methods, implemented across every built-in adapter (memory,sqlite-node,sqlite-bun,sqlite-node-builtin):listRuns(filter?)— backsengine.listRuns().requeueRun(runId)— resets afailed/cancelledrun topendingand deletes itsfailedstep results in a transaction; backsengine.resume().Custom adapters must implement these two methods.
Tests
+27 tests (387 total, all passing). Coverage added for both methods across the memory, better-sqlite3, and
node:sqliteadapters, plus end-to-end engine tests: resume-from-failure without re-running completed steps, resume rejection on non-resumable runs, dead-letter listing, and limit validation.Typecheck, build, and
lint:depsall pass.Public API
New exported type:
ListRunsFilter. No breaking changes to existing surface.