@jive-sh/workflow-platform 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -739,9 +739,17 @@ const syncList = function* (input: { readonly workflow: WorkflowRow; readonly ev
739
739
  }
740
740
 
741
741
  /**
742
- * Records the failure and puts the task back at the front of the queue it was taken from, to be taken again: at once,
743
- * or after the step's `retries.delayMs`. At the step's `retries.limit` of failed runs in a row it leaves through
744
- * `retries.giveUp` instead.
742
+ * How long a task waits after its step failed, when the step names no `retries`: a minute after its first failure in a
743
+ * row, doubling with each one after, up to half an hour. A failure puts the task back at the front of its queue, so
744
+ * without a wait a step failing every time is taken again at once, as often as a worker can take it: Verification
745
+ * sources' inputs gate failed 125 times in 17 minutes on 2026-11-29. Pure.
746
+ */
747
+ export const failureDelayMs = (failuresInARow: number): number => Math.min(60_000 * 2 ** Math.max(0, failuresInARow - 1), 30 * 60_000)
748
+
749
+ /**
750
+ * Records the failure and puts the task back at the front of the queue it was taken from, to be taken again: after
751
+ * the step's `retries.delayMs`, or, with no `retries`, after `failureDelayMs`. At the step's `retries.limit` of failed
752
+ * runs in a row it leaves through `retries.giveUp` instead.
745
753
  */
746
754
  export const fail = function* (input: { readonly run: Id<"stepRuns">; readonly error: string; readonly measurements: Option.Option<StepMeasurements> }): Run<void> {
747
755
  const store = yield* WorkflowStore
@@ -750,14 +758,14 @@ export const fail = function* (input: { readonly run: Id<"stepRuns">; readonly e
750
758
  const workflow = yield* workflowNamed(run.workflow)
751
759
  const step = yield* stepNamed({ workflow, step: run.step })
752
760
  const retries = step.retries
753
- if (retries === undefined) {
754
- yield* store.moveFlow({ flow: run.flow, place: run.takenFrom.place, enteredAt: run.takenFrom.enteredAt })
755
- return yield* advance(run.workflow)
756
- }
757
761
  // The failed runs in a row of this flow in this step, this one included.
758
762
  const runs = (yield* store.stepRunsOfTask(run.task)).filter((candidate) => candidate.flow === run.flow && candidate.step === run.step)
759
763
  const inARow = [...runs].sort((a, b) => b.startedAt - a.startedAt || b._creationTime - a._creationTime).findIndex((candidate) => candidate.status !== "failed")
760
764
  const failures = inARow === -1 ? runs.length : inARow
765
+ if (retries === undefined) {
766
+ yield* store.moveFlow({ flow: run.flow, place: run.takenFrom.place, enteredAt: run.takenFrom.enteredAt, notBefore: store.now + failureDelayMs(failures) })
767
+ return yield* advance(run.workflow)
768
+ }
761
769
  if (failures >= retries.limit) {
762
770
  yield* store.insertTaskNote({ task: run.task, note: `${step.id} gave up after ${failures} failed runs in a row; the last: ${input.error.slice(0, 500)}` })
763
771
  yield* leaveStep({ workflow, flow: yield* flowWithId(run.flow), step, endState: retries.giveUp, measurements: Option.none(), note: Option.none() })
@@ -0,0 +1,21 @@
1
+ import { expect, test } from "bun:test"
2
+ import { failureDelayMs } from "./engine"
3
+
4
+ test("a step with no retries waits a minute after its first failure, doubling with each one in a row", () => {
5
+ expect([1, 2, 3, 4, 5].map(failureDelayMs)).toEqual([60_000, 120_000, 240_000, 480_000, 960_000])
6
+ })
7
+
8
+ test("the wait stops growing at half an hour", () => {
9
+ expect(failureDelayMs(6)).toBe(30 * 60_000)
10
+ expect(failureDelayMs(125)).toBe(30 * 60_000)
11
+ })
12
+
13
+ test("a gate failing every time, as Verification sources' did, is taken 5 times in its first 17 minutes, not 125", () => {
14
+ let at = 0
15
+ let takes = 0
16
+ for (let failures = 1; at < 17 * 60_000; failures++) {
17
+ takes += 1
18
+ at += failureDelayMs(failures)
19
+ }
20
+ expect(takes).toBe(5)
21
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jive-sh/workflow-platform",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Durable workflows in Convex: one workflow primitive with a task schema, queues on every line, workflow budgets, named end states, events and sub-workflows; worker processes run the steps.",