Skip to content

feat: Auto-purge old run records with retainRuns option #88

@coji

Description

@coji

Problem

durably_runs records accumulate indefinitely. While individual records are small, over time (e.g., hourly cron jobs running for months) the table grows unbounded. Currently, the only way to remove old runs is manually calling deleteRun().

This is separate from step data cleanup (#87, cleanupSteps option) — step output is the large data and is now cleaned up automatically. Run records are lightweight but should still have an optional retention policy.

Proposal

const durably = createDurably({
  dialect,
  // Auto-delete terminal runs older than 30 days
  retainRuns: '30d',
})
  • Only deletes runs in terminal states (completed, failed, cancelled)
  • Runs in pending or running are never auto-deleted
  • Cleanup runs periodically (e.g., once per polling cycle or on a separate interval)
  • Default: no retention (keep all runs, backward compatible)

Alternatives

  • Explicit purge API: await durably.purgeRuns({ olderThan: '30d', status: ['completed'] }) — useful as a manual escape hatch regardless of whether auto-purge is implemented
  • Both: retainRuns for automatic + purgeRuns() for manual control

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions