Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [0.13.0] - 2026-03-16

### Breaking Changes

#### @coji/durably

- **Lease-based runtime model**: Complete rewrite of the execution engine. Runs are now claimed via leases with fencing tokens (`lease_generation`), enabling safe recovery from worker crashes. Expired leases are automatically reclaimed (#101)
- **`preserveSteps` replaces `cleanupSteps`**: Option renamed and default flipped for clarity. `preserveSteps: false` (default) deletes step data on terminal state — same behavior as before (#101)
- **Labels normalized into indexed table**: `durably_run_labels` replaces JSON-in-column storage for efficient label filtering. Migration is automatic (#103)
- **`retrigger()` validates input against current schema**: Throws if the original run's input doesn't match the current job's input schema (#104)

### Added

#### @coji/durably

- **`purgeRuns()` API**: Batch-delete terminal runs older than a cutoff date. Cascade-deletes associated steps, logs, and labels (#109)
```ts
const deleted = await durably.purgeRuns({
olderThan: new Date(Date.now() - 30 * 86400000),
limit: 500,
})
```
- **`retainRuns` option**: Auto-delete terminal runs during idle worker polling. Supports `'30d'`, `'24h'`, `'60m'` duration formats (#109)
```ts
const durably = createDurably({
dialect,
retainRuns: '30d',
})
```
- **PostgreSQL support**: Kysely PostgreSQL dialect now supported alongside SQLite/libSQL (#101)
- **Concurrency key enforcement via SQL**: `activeLeaseGuard` subquery in `claimNext` prevents duplicate leases for the same concurrency key without JS-side filtering (#101)

### Fixed

#### @coji/durably

- **SSE subscribe race condition**: Subscribe to events before reading DB state to prevent missed updates (#108)
- **SSE reconnection**: Only dispatch error on permanent CLOSED state, not transient disconnects (#108)

### Performance

#### @coji/durably

- **Remove `getRuns({ status: 'leased' })` from polling hot path**: `claimNext`'s SQL subquery already handles concurrency exclusion, eliminating a full table scan + JOIN + JSON parse per poll cycle (#109)

### Documentation

- Deployment guide with mode comparison (#104)
- `purgeRuns` and `retainRuns` in API reference, llms.md, and CLAUDE.md (#109)
- Runtime rearchitecture RFC (#97, #99)

## [0.12.0] - 2026-03-07

### Breaking Changes
Expand Down
9 changes: 4 additions & 5 deletions examples/fullstack-react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@
"@libsql/kysely-libsql": "^0.4.1",
"@react-router/node": "7.13.1",
"@react-router/serve": "7.13.1",
"isbot": "^5.1.35",
"isbot": "^5.1.36",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-router": "7.13.1",
"zod": "^4.3.6"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@react-router/dev": "7.13.1",
"@tailwindcss/vite": "^4.2.1",
"@types/node": "^25.3.5",
"@types/node": "^25.5.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
"tailwindcss": "^4.2.1",
"typescript": "^5.9.3",
"vite": "^7.3.1",
"vite-tsconfig-paths": "^6.1.1"
"vite": "^8.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/fullstack-react-router/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { reactRouter } from '@react-router/dev/vite'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
resolve: { tsconfigPaths: true },
plugins: [tailwindcss(), reactRouter()],
})
11 changes: 5 additions & 6 deletions examples/fullstack-vercel-turso/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
"@libsql/kysely-libsql": "^0.4.1",
"@react-router/node": "7.13.1",
"@react-router/serve": "7.13.1",
"@vercel/react-router": "^1.2.5",
"isbot": "^5.1.35",
"@vercel/react-router": "^1.2.6",
"isbot": "^5.1.36",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-router": "7.13.1",
"zod": "^4.3.6"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@react-router/dev": "7.13.1",
"@tailwindcss/vite": "^4.2.1",
"@types/node": "^25.3.5",
"@types/node": "^25.5.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
"tailwindcss": "^4.2.1",
"typescript": "^5.9.3",
"vite": "^7.3.1",
"vite-tsconfig-paths": "^6.1.1"
"vite": "^8.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/fullstack-vercel-turso/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { reactRouter } from '@react-router/dev/vite'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
resolve: { tsconfigPaths: true },
plugins: [tailwindcss(), reactRouter()],
})
6 changes: 3 additions & 3 deletions examples/server-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"@coji/durably": "workspace:*",
"@libsql/client": "^0.17.0",
"@libsql/kysely-libsql": "^0.4.1",
"kysely": "^0.28.11",
"kysely": "^0.28.12",
"zod": "^4.3.6"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@types/node": "^25.3.5",
"@biomejs/biome": "^2.4.7",
"@types/node": "^25.5.0",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
"tsx": "^4.21.0",
Expand Down
11 changes: 5 additions & 6 deletions examples/spa-react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@
"@coji/durably": "workspace:*",
"@coji/durably-react": "workspace:*",
"@react-router/node": "7.13.1",
"isbot": "^5.1.35",
"kysely": "^0.28.11",
"isbot": "^5.1.36",
"kysely": "^0.28.12",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-router": "7.13.1",
"sqlocal": "^0.17.0",
"zod": "^4.3.6"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@react-router/dev": "7.13.1",
"@tailwindcss/vite": "^4.2.1",
"@types/node": "^25.3.5",
"@types/node": "^25.5.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
"tailwindcss": "^4.2.1",
"typescript": "^5.9.3",
"vite": "^7.3.1",
"vite-tsconfig-paths": "^6.1.1"
"vite": "^8.0.0"
}
}
3 changes: 1 addition & 2 deletions examples/spa-react-router/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { reactRouter } from '@react-router/dev/vite'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
resolve: { tsconfigPaths: true },
plugins: [
tailwindcss(),
reactRouter(),
tsconfigPaths(),
// COOP/COEP headers for SQLite WASM (required for browser-only mode)
{
name: 'configure-response-headers',
Expand Down
8 changes: 4 additions & 4 deletions examples/spa-vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
"dependencies": {
"@coji/durably": "workspace:*",
"@coji/durably-react": "workspace:*",
"kysely": "^0.28.11",
"kysely": "^0.28.12",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"sqlocal": "^0.17.0",
"zod": "^4.3.6"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@tailwindcss/vite": "^4.2.1",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.4",
"@vitejs/plugin-react": "^6.0.1",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
"tailwindcss": "^4.2.1",
"typescript": "^5.9.3",
"vite": "^7.3.1"
"vite": "^8.0.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"db:down": "docker compose -f docker-compose.postgres.yml down"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@types/node": "^25.3.5",
"@vitest/coverage-v8": "4.0.18",
"@biomejs/biome": "^2.4.7",
"@types/node": "^25.5.0",
"@vitest/coverage-v8": "4.1.0",
"lefthook": "2.1.2",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions packages/durably-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coji/durably-react",
"version": "0.12.0",
"version": "0.13.0",
"description": "React bindings for Durably - step-oriented resumable batch execution",
"type": "module",
"main": "./dist/index.js",
Expand Down Expand Up @@ -59,15 +59,15 @@
}
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@coji/durably": "workspace:*",
"@testing-library/react": "^16.3.2",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.4",
"@vitest/browser": "^4.0.18",
"@vitest/browser-playwright": "4.0.18",
"kysely": "^0.28.11",
"@vitejs/plugin-react": "^6.0.1",
"@vitest/browser": "^4.1.0",
"@vitest/browser-playwright": "4.1.0",
"kysely": "^0.28.12",
"playwright": "^1.58.2",
"prettier": "^3.8.1",
"prettier-plugin-organize-imports": "^4.3.0",
Expand All @@ -76,7 +76,7 @@
"sqlocal": "^0.17.0",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"vitest": "^4.0.18",
"vitest": "^4.1.0",
"zod": "^4.3.6"
}
}
4 changes: 2 additions & 2 deletions packages/durably/docs/llms.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ Pending and leased runs are never deleted.
// Delete terminal runs older than 30 days
const deleted = await durably.purgeRuns({
olderThan: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
limit: 500, // optional batch size (default: 1000)
limit: 500, // optional batch size (default: 500)
})
```

For automatic cleanup, use the `retainRuns` option (see Quick Start). Cleanup runs during idle worker polling cycles, at most once per minute, in batches of 100.
For automatic cleanup, use the `retainRuns` option (see Core Concepts). Cleanup runs during idle worker polling cycles, at most once per minute, in batches of 100.

## Events

Expand Down
16 changes: 8 additions & 8 deletions packages/durably/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coji/durably",
"version": "0.12.0",
"version": "0.13.0",
"description": "Step-oriented resumable batch execution for Node.js and browsers using SQLite",
"type": "module",
"main": "./dist/index.js",
Expand Down Expand Up @@ -63,19 +63,19 @@
"ulidx": "^2.4.1"
},
"devDependencies": {
"@biomejs/biome": "^2.4.6",
"@biomejs/biome": "^2.4.7",
"@libsql/client": "^0.17.0",
"@libsql/kysely-libsql": "^0.4.1",
"@testing-library/react": "^16.3.2",
"@types/better-sqlite3": "^7.6.13",
"@types/pg": "^8.15.6",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.4",
"@vitest/browser": "^4.0.18",
"@vitest/browser-playwright": "4.0.18",
"jsdom": "^28.1.0",
"kysely": "^0.28.11",
"@vitejs/plugin-react": "^6.0.1",
"@vitest/browser": "^4.1.0",
"@vitest/browser-playwright": "4.1.0",
"jsdom": "^29.0.0",
"kysely": "^0.28.12",
"pg": "^8.16.3",
"playwright": "^1.58.2",
"prettier": "^3.8.1",
Expand All @@ -85,7 +85,7 @@
"sqlocal": "^0.17.0",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"vitest": "^4.0.18",
"vitest": "^4.1.0",
"zod": "^4.3.6"
}
}
12 changes: 9 additions & 3 deletions packages/durably/src/durably.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,15 @@ function createDurablyInstance<
const purgeNow = Date.now()
state.lastPurgeAt = purgeNow
const cutoff = new Date(purgeNow - state.retainRunsMs).toISOString()
storage.purgeRuns({ olderThan: cutoff, limit: 100 }).catch(() => {
// Purge failure is non-fatal — will retry on next interval
})
storage
.purgeRuns({ olderThan: cutoff, limit: 100 })
.catch((error) => {
eventEmitter.emit({
type: 'worker:error',
error: getErrorMessage(error),
context: 'auto-purge',
})
})
}
return false
}
Expand Down
3 changes: 2 additions & 1 deletion packages/durably/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export function createKyselyStore(
trx: Kysely<Database>,
ids: string[],
): Promise<void> {
if (ids.length === 0) return
await trx.deleteFrom('durably_steps').where('run_id', 'in', ids).execute()
await trx.deleteFrom('durably_logs').where('run_id', 'in', ids).execute()
await trx
Expand Down Expand Up @@ -671,7 +672,7 @@ export function createKyselyStore(
olderThan: string
limit?: number
}): Promise<number> {
const limit = options.limit ?? 1000
const limit = options.limit ?? 500

return await db.transaction().execute(async (trx) => {
const rows = await trx
Expand Down
Loading