Skip to content

Clean up old generations that are building up in active long-running workflows - #415

Open
Thom Chiovoloni (thomcc-work) wants to merge 9 commits into
mainfrom
thomcc/exe-clean
Open

Thom Chiovoloni (thomcc-work) wants to merge 9 commits into
mainfrom
thomcc/exe-clean

Conversation

@thomcc-work

@thomcc-work Thom Chiovoloni (thomcc-work) commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

continue_as_new starts a fresh execution for replay, but previously every older generation stayed in the database until the workflow itself was removed. Reconciliation now prunes completed, non-current generations and their history once they are older than pg_durable.retention_days, even while the workflow is still running.

This PR pins both duroxide and duroxide-pg to the 0.2.0 crates.io releases. The provider release includes microsoft/duroxide-pg#32; no git dependency or local override is needed. The HTTP policies in #429 are separate.

Retention and inspection

  • The age cutoff applies to root, nested-loop, and satellite-origin executions. Pruning preserves current and running executions, df metadata, and current results. It does not cap a single execution’s history or reclaim separate child instances.
  • Each maintenance slice scans at most 1,000 execution keys, including ineligible rows. Pruning uses the maintenance connection with server-side deadlines. A cancelled batch rolls back before retrying from the same cursor with fewer keys; a single generation that cannot finish is deferred so later keys still get a turn. pg_durable.reconcile_interval = 0 disables pruning.
  • df.instance_executions() reads execution details and event counts in one snapshot, so a concurrent prune cannot turn a disappearing historical row into a lookup error.

Upgrade

Drain all old provider callers and transactions, including external clients and deletion jobs. The new worker applies provider migrations before publishing readiness; pruning requires no ALTER EXTENSION UPDATE. Backfilling completion timestamps can generate substantial WAL and make old generations eligible on the first scan. Acknowledgements for affected workflows can briefly wait on pruning locks.

The released pruning migrations (0027/0028) are byte-identical to the last development pin (79870890). The release also installs the worker-queue index (0029) and disabled notification triggers (0030); pg_durable continues to use short polling. See the upgrade notes for index locking, missing or malformed history, and databases initialized with earlier draft migrations.

Validation

Tested this branch independently of #429 using the released crates and the shared PostgreSQL test lock on PG17:

  • 465 unit tests passed (16 ignored); all 273 E2E cases passed, including live root, nested-loop, and satellite pruning.
  • All 177 upgrade checks passed, including resuming workflows created by the real v0.2.9 binary across binary-only and schema upgrades.
  • All 6 pg_regress, 6 shutdown, and 7 epoch/lifecycle checks passed. The locked build, formatting check, and strict Clippy also passed.

🐾 Generated with PAW

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The unreleased provider dependency and deletion of active-workflow history require human review and upgrade/replay validation before landing.

1 open finding
What changed in this PR

Adds age-based cleanup of historical execution generations, including those belonging to active workflows, while preserving current and running executions.

Changes:

  • Adds bounded pruning with deadlines and failed-page recovery.
  • Makes execution-history inspection consistent during concurrent pruning.
  • Updates dependencies, readiness checks, tests, and retention documentation.
File Description
USER_GUIDE.md Documents pruning behavior and upgrade considerations.
tests/​e2e/​sql/​89_execution_pruning.sql Tests root, nested, and satellite workflow pruning.
src/​worker.rs Implements bounded pruning and regression tests.
src/​types.rs Updates retention documentation.
src/​monitoring.rs Reads execution details in one snapshot.
src/​lib.rs Updates readiness version and retention descriptions.
scripts/​test-e2e-local.sh Routes pruning tests to reconciliation configuration.
scripts/​test-e2e-docker.sh Skips the configuration-dependent pruning test.
docs/​upgrade-testing.md Documents migrations and release prerequisites.
Cargo.toml Updates runtime and provider dependencies.
Cargo.lock Records updated dependency resolutions.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Cargo.toml Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The unreleased provider dependency adds startup backfill and destructive history pruning alongside runtime shutdown changes, requiring previous-binary upgrade/replay and PostgreSQL shutdown validation with the final dependency pair.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@thomcc-work
Thom Chiovoloni (thomcc-work) marked this pull request as ready for review November 3, 2026 16:03
Also:

- Updated upgrade guidance for fully drained callers, malformed-history diagnostics, WAL/retention impact, and timestamp repair.
- Documented that databases using earlier pre-release migrations won’t automatically receive revised function bodies.
- Added a regression confirming protected generations advance the cursor without waiting on instance locks.
Compare snapshot inspection against the Client metadata API using tables created by the pinned provider's migrations and populated through provider operations. Document the existing migrated-schema coverage of pruning keys.

Ref: #415 review finding 415-1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Explain that pruning holds candidate instance locks until commit and can briefly delay acknowledgements, particularly during the first post-backfill scans. Preserve the existing batch and timeout policies.

Ref: #415 review finding 415-2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Distinguish the provider's ^0.1.32 requirement from pg_durable's deliberate =0.1.32 pin. Record that the combined release with PR 429 needs later runtime changes and coordinated exact pins with replay validation.

Ref: #415 review finding 415-3

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pin both runtime and provider to crates.io now that the provider ships the pruning API. Its 0027 and 0028 migrations are byte-identical to the last development pin, so stores initialized with that pin can proceed to the queue migrations without reinstalling pruning functions.

Document the worker-queue index build and disabled notification triggers. Keep short polling and the existing connection minimum.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

2 participants