Skip to content
Open
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
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ Pre-1.0 note: while `pg_durable` is in major version `0`, minor releases may inc

## [Unreleased]

### Changed

- **Dependencies:** pg_durable now pins `duroxide` to `0.2.1` and `duroxide-pg`
to `0.2.0` from crates.io. The runtime fixes a race between graceful and
forced shutdown. The provider includes batched pruning and a new worker-queue
index; notification-driven polling remains disabled by default.
- **Historical execution retention (#415):** reconciliation now removes completed,
non-current execution generations and their history after
`pg_durable.retention_days`, including generations of still-running workflows
and nested loops. Current and Running executions remain protected. Cleanup
advances through bounded pages under server-side deadlines, reducing the page
size after query cancellation so otherwise-prunable generations do not remain
stuck in an oversized batch. `pg_durable.reconcile_interval = 0` disables it.
- **Execution inspection (#415):** `df.instance_executions()` reads execution
details and event counts in one snapshot so concurrent pruning does not fail
the listing. Pruned generations no longer appear in subsequent inspections.

> **Upgrade:** Stop and drain all provider callers, not just workers, before
> upgrading. A full PostgreSQL stop/start drains pg_durable's old server
> processes; coordinate any external clients and deletion jobs sharing the
> provider store too. The new worker backfills missing completion timestamps
> before publishing readiness. Large stores can extend this window and generate
> substantial WAL, while submissions and engine operations must wait. Review
> retention cutoffs before restarting because recovered timestamps can make old
> generations eligible for cleanup immediately. The `statement_timeout` in effect for
> `pg_durable.worker_role` in the control database must allow the backfill to
> complete. Missing terminal history leaves the timestamp NULL with a warning
> rather than guessing its age; malformed JSONB aborts the migration with the
> affected history key in the error. No `ALTER EXTENSION UPDATE` is needed for
> this provider-managed change. See [upgrade and repair guidance](docs/upgrade-testing.md#historical-execution-pruning).

### Security

- **Start admission quotas (#139):** `df.max_concurrent_per_user` (default
Expand Down
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ percent-encoding = "2.3"
postgres-protocol = "0.6"

# duroxide integration
duroxide = "=0.1.30"
duroxide-pg = "=0.1.34"
duroxide = "=0.2.1"
duroxide-pg = "=0.2.0"
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time"] }

# For ExecuteSQL activity (connecting back to PostgreSQL)
Expand Down
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Rust dependencies declared in Cargo.toml:
License: MIT OR Apache-2.0
Source: https://github.com/zslayton/cron

- duroxide 0.1.29
- duroxide 0.2.1
License: MIT
Source: https://github.com/microsoft/duroxide

- duroxide-pg 0.1.34
- duroxide-pg 0.2.0
License: MIT
Source: https://github.com/microsoft/duroxide-pg

Expand Down
94 changes: 80 additions & 14 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2011,8 +2011,9 @@ runtime. Distinguish three roles:
`database` argument selects another database on the same cluster; that target
does not need the extension unless the SQL itself calls `df` APIs.

Satellite installation requires a compatible control worker with readiness schema
version `3` (including its origin registry and protected submission accounting).
Satellite installation requires a compatible control worker with the current
readiness schema version, including its provider migrations, origin registry,
and protected submission accounting.
Provider migrations run only in control through the worker's `ApplyAll`;
satellite creation never creates control
automatically. The provider namespace is extension-owned, its contents are created
Expand Down Expand Up @@ -2533,19 +2534,25 @@ satellite `df._worker_epoch` is normal; satellites do not have separate workers.
pg_durable tracks each workflow in its own `df` tables, while the durable engine
keeps workflow state in a separate schema. To keep those two stores consistent —
and to keep `df.instances`/`df.nodes` from growing without bound — the background
worker runs a **best-effort reconciliation pass** that does two things:
worker runs a **best-effort reconciliation pass** that:

- **Removes expired terminal instances.** Old **terminal** instances (status
`completed`, `failed`, or `cancelled`) and their `df.nodes` rows are deleted,
along with their engine records. Retention does not remove running or pending
instances from an existing installation, regardless of age.
along with their engine records. Retention does not remove running or pending
instances from an existing installation, regardless of age.
- **Reclaims orphaned engine records.** `df.start()` writes the `df` rows in the
caller's transaction but hands the workflow to the engine over a separate
connection; if that transaction **rolls back**, the `df` rows vanish while the
engine keeps an inert record (it can never load its rolled-back graph, so it
ends up failed). Reconciliation deletes such df-less engine records once they
age past `retention_days`. Anything the engine is still tracking with a live
`df` row is left untouched.
age past `retention_days`. Instances with a live `df` row are not orphans.
- **Prunes old execution generations.** Loops start a new execution generation
on each iteration. Reconciliation removes historical generations and their
history events once their completion is older than `retention_days`, including
those belonging to still-running workflows and nested loops in any origin.
The current execution and any running execution are always preserved. This
does not remove the workflow's `df` rows or its current results, but old
generations will no longer appear in execution-history inspection.

After the corresponding engine work, history, and origin metadata are gone,
reconciliation removes the protected submission record and frees its retained
Expand All @@ -2570,6 +2577,29 @@ for at most one 1,000-candidate page, then other origins get a turn before a bus
origin resumes. Only age-expired or excess-over-10,000 rows consume the retention
candidate budget. Legacy orphan candidates exclude satellite roots and children
in SQL before their bounded page is loaded into memory.
Execution pruning scans at most 1,000 execution keys per slice, including young
and protected generations. Each batch deletes at most those 1,000 generations;
this is a work limit, not a generation-count retention policy. Failed pages are
logged. Query cancellations, including statement timeouts, retry the same position
with smaller pages, down to one execution. The smaller limit is retained for the
rest of that scan; the next scan starts at 1,000 again. Lock timeouts and other
failures, or cancellation of a single-execution page, skip that page until the
next scan so they cannot block later pages. Pruning uses the maintenance
connection, not the workflow runtime's connection pool, with server-side
five-second statement and
1.5-second lock deadlines. A timeout rolls back the batch. The number of history
events in one generation is not capped; an individual generation that cannot
finish within the deadline can remain unpruned despite aging past the retention
window. Smaller pages can lengthen the scan, but other pending maintenance work
still gets a turn between pruning slices.

Pruning old generations holds instance-row locks until the batch transaction
ends. Acknowledgements for those same workflows can wait even though their
current generations are preserved and pruning uses a separate connection.
Expect brief turn-latency spikes during scans; an expensive batch can hold those
locks for close to the five-second statement deadline. The first scans after
upgrade can cause more contention because backfill makes accumulated history
eligible at once.

Metadata queries have server-side deadlines and satellite operations have a
15-second overall deadline. The candidate limit bounds materialized rows, not
Expand All @@ -2587,12 +2617,13 @@ Two Postmaster-context GUCs govern it (set in `postgresql.conf`, restart to appl
pg_durable.reconcile_interval = 3600

# Days a terminal instance is retained before reconciliation removes it (and its
# engine record); also the age bound for reclaiming orphaned engine records.
# 0 removes terminal instances as soon as the next pass runs.
# engine record); also the age bound for orphaned engine records and completed
# historical execution generations. The current execution is never pruned.
# 0 makes cleanup eligible on the next pass.
pg_durable.retention_days = 30
```

Retention combines that window with a fixed hard cap:
Terminal-instance retention combines that window with a fixed hard cap:

- **Hard cap per origin — at most 10,000 terminal instances are retained, regardless of
age.** The newest 10,000 terminal instances are kept; any beyond that are
Expand All @@ -2604,9 +2635,44 @@ Equivalently, a terminal instance is retained only while it is **both** among th
newest 10,000 terminal instances **and** younger than `retention_days`; otherwise
it is eligible for removal.

Historical execution generations use only the age window, not a count cap.
Pruning bounds how long completed history is retained, not its byte size: a
busy workflow can still retain many generations within the window. An execution
that has not continued into a new generation retains its current history.
Completed child instances created by earlier loop iterations retain their current
execution until the owning workflow is removed.
Setting `reconcile_interval = 0` also disables execution pruning.

On binary upgrade, the worker recovers missing completion timestamps for older
continued generations from their recorded terminal history events. If an event
is missing, it logs a migration warning and leaves that generation ineligible for
age-based pruning rather than guessing its age. Malformed history that cannot be
decoded as JSONB instead aborts the migration and identifies the affected schema,
instance, execution, and event in the initialization error. The worker retries
initialization; it does not skip the malformed history.

This upgrade requires all old provider calls and transactions to finish before
migrations run, not a rolling upgrade. Pause deletion/pruning jobs and stop and
drain every provider caller, including clients and direct SQL callers as well as
workers. A full PostgreSQL stop/start drains pg_durable's old server processes;
also coordinate any external callers sharing the provider store. The new
background worker applies migrations automatically. Wait for its readiness
before resuming provider traffic, and use only updated external callers.

The one-time backfill can delay readiness and generate substantial WAL on a large
history store. New submissions and engine operations such as signals and
cancellation must wait. Review retention settings before restarting: recovered
timestamps may make many old generations eligible for deletion on the next scan.
Allow sufficient time for the backfill: the `statement_timeout` in effect for
`pg_durable.worker_role` in the control database must permit it to finish.
Adjust the applicable role or database timeout defaults for the upgrade if
necessary; otherwise startup retries the backfill instead of completing.
See [upgrade and repair guidance](docs/upgrade-testing.md#historical-execution-pruning),
including the special handling of databases that used earlier pre-release pins.

Notes:

- "Age" is measured from `completed_at` when set (instances that reached
- Terminal-instance "age" is measured from `completed_at` when set (instances that reached
`completed`), otherwise from `created_at`. `updated_at` is intentionally **not**
used, because it is user-writable and would let a low-privilege user influence
what is removed.
Expand Down Expand Up @@ -3117,7 +3183,7 @@ The main connection categories are:
|----------|---------|-----|---------|
| **Management pool** | Control metadata, origin lookup and registration | `pg_durable.max_management_connections` | 6 |
| **Origin routes** | Satellite metadata connections, shared by activities and maintenance | `pg_durable.max_origin_connections` | 12 |
| **Duroxide pool** | Orchestration state, LISTEN/NOTIFY for work dispatch | `pg_durable.max_duroxide_connections` | 10 |
| **Duroxide pool** | Orchestration state and polling the work queues | `pg_durable.max_duroxide_connections` | 10 |
| **User-execution** | SQL execution and HTTP credential catalog reads, authenticated as the submitting user | `pg_durable.max_user_connections` | 10 |
| **New-start loopback** | Extra launch sessions in the caller's database, capped per database | `pg_durable.max_new_transaction_starts` | 2 |

Expand All @@ -3143,8 +3209,8 @@ pg_durable.max_management_connections = 6
# Range: 2..1000. Each active route reserves 1 metadata slot.
pg_durable.max_origin_connections = 12

# Duroxide provider pool: orchestration state + LISTEN/NOTIFY
# Minimum: 2 (1 reserved for listener). Worker refuses to start if < 2.
# Duroxide provider pool. pg_durable uses short polling, with no listener slot.
# The worker requires at least 2 connections.
pg_durable.max_duroxide_connections = 10

# Maximum concurrent SQL execution and HTTP catalog connections
Expand Down
Loading
Loading