Skip to content

Preview retention-policy impact before guarded application #522

Done

Description

@rmcdaniel

User need and decision

An operator shortening retention should be able to see which existing history will become eligible for irreversible pruning before applying the policy. durable-workflow/durable-workflow.github.io#264 correctly documented that current policy applies retroactively. Keep that truthful documentation, and add a supported prospective impact plan and guarded apply path.

Current NamespaceController::update persists the policy immediately; retentionStatus inspects the already-active policy. The enforcer can subsequently prune newly eligible history. This is an additive data-safety improvement, not a claim that documented retroactive behavior is a defect.

Acceptance

  • Provide a read-only prospective-policy plan scoped to the exact namespace and current policy revision. Show affected retained/pruned history, bounded example identities, count/scan completeness and archive/forever/backup-hold exclusions. Unknown/incomplete counts are explicit.
  • Preview must not mutate policy, mark rows, fetch payload objects or trigger pruning. Preserve original fingerprints in the qualification.
  • Add an explicit guarded apply that confirms retrospective deletion scope and rejects stale policy/plan versions. State what may change between a preview and cleanup; do not describe a non-atomic scan as an exact immutable deletion snapshot.
  • Preserve old clients through an additive/versioned path. Do not silently change the current API's activation contract or weaken holds.
  • Test policy shortening/lengthening, archived/forever/held runs, concurrent policy changes and incomplete scans on published artifacts. Publish the operator journey in CLI/API/UI documentation as applicable.

Existing #500 and durable-workflow/workflow#852/#856 concern distinct retention/summary/export defects. #520 owns independent archives, not permission to prune. Priority P3; no implementation is delivered here. General owns PHP work after the normal source-window agreement; native adoption is separate.

Activity

  1. added
    kind:feature
    priority:P3
    status:ready
    on Oct 20, 2026
  2. rmcdaniel commented on Nov 4, 2026

    @rmcdaniel
    MemberAuthor

    Server open-item pass, 2026-11-04.

    Owner: Server for native prospective-policy read/guarded apply; CLI/Waterline for the eventual operator journey, General for policy compatibility. The existing retroactive activation contract remains true; this is additive protection, not a silent change to old clients.

    Next artifact defines namespace/policy revision binding, bounded examples and count completeness, exclusions and explicit stale-plan refusal. Preview must make zero writes and no provider/object requests. Guarded apply confirms retrospective scope without calling a non-atomic scan an immutable deletion set. General: review that versioned compatibility boundary; Server then prepares shortening/lengthening/hold/concurrent-change source controls. No retention preview, policy change or prune was executed.

  3. rmcdaniel commented on Nov 11, 2026

    @rmcdaniel
    MemberAuthor

    Triage 2026-11-11: still open; no preview path in native retention. Owner: server. Backlog after #633 and #500.

  4. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    Current state on native Server 3.28.0: a namespace update still activates retention_mode/retention_days immediately (rust/src/runtime/namespaces.rs). GET /api/system/retention and POST /api/system/retention/pass inspect or apply only the active policy. There is no prospective plan and no guarded apply. The documented retroactive behavior is unchanged and accurate.

    Scope update: PHP Server is frozen at 2.11.8, so this is native-only.

    Remaining:

    • server: a read-only plan endpoint bound to the namespace and current policy revision. It returns eligible counts, bounded examples, scan completeness and archive/forever/hold exclusions, and writes nothing.
    • server: a versioned guarded apply that refuses a stale plan or policy revision, leaving the existing update contract unchanged.
    • cli and docs: the operator journey.

    Next action: server implements the read-only plan endpoint, with tests for shortening, lengthening and held runs.

  5. rmcdaniel commented on Nov 26, 2026

    @rmcdaniel
    MemberAuthor

    #522 complete: acceptance met

    Acceptance Delivered
    Read-only prospective plan bound to the namespace and current policy revision, with affected retained and pruned history, bounded example identities, count and scan completeness, archive, forever and hold exclusions, and explicit unknown or incomplete counts #1332 (POST /api/namespaces/{ns}/retention-plan, retention-plan.v1)
    Preview never mutates policy, marks rows, fetches payload objects or prunes; original fingerprints preserved #1332 execution tests, plus the published-artifact fingerprints below
    Explicit guarded apply that confirms retrospective deletion scope, refuses stale policy and plan versions, and says what can change before cleanup #1350 (POST /api/namespaces/{ns}/retention-plan/apply, retention-apply.v1, plan_revision, confirm_retroactive_pruning)
    Old clients preserved, activation contract unchanged, holds not weakened PUT /api/namespaces/{ns} is unchanged (row 9 below). Holds are still checked at prune time (row 10).
    Shortening, lengthening, archived, forever and held runs, concurrent policy changes and incomplete scans tested on published artifacts Native Server 3.30.0 (released 2026-11-26), qualified on SQLite, PostgreSQL 17 and MySQL 8.0. Evidence below.
    Operator journey in CLI, API and UI documentation API: docs/server-reference.md (#1350, precision fixed in #1364). Docs site: durable-workflow.github.io#620, all 7 locales. CLI: durable-workflow/cli#178 (dw namespace:retention-plan, dw namespace:retention-apply). Waterline UI: no retention-policy UI exists to extend.

    One precision point came out of the qualification and is now documented (#1364, #620). policy_revision includes the namespace's updated_at, which PostgreSQL and MySQL round to the whole second and MariaDB truncates. Any change to the retention mode or days always produces a new revision. A non-retention namespace update that stores the same second does not.

    Published-artifact qualification: retention plan + guarded apply (native Server 3.30.0)

    Artifact: ghcr.io/durable-workflow/server@sha256:b7bb6007e2cfeb76823fdaf497e279656e3d10cf441c735b7181c72f698087bd (the same digest as durableworkflow/server:3.30.0). Release label 3.30.0, revision e00022c9. /api/cluster/info reports version: 3.30.0, implementation: rust. The image was pulled by digest, not built from source, and no release was touched.

    Backends: each backend ran in a fresh database with the same script and the same seed.

    Backend Setup
    SQLite Image default (/app/database/database.sqlite), single container
    PostgreSQL 17.11 (postgres:17-alpine) DB_CONNECTION=pgsql, schema-bootstrap
    MySQL 8.0.46 (mysql:8.0) DB_CONNECTION=mysql, schema-bootstrap. Root applied the checkpoint DDL, which is the documented compose path: bootstrap answered native_child_checkpoint_trigger_privilege_required.

    Common setup: token auth with DW_AUTH_TOKEN plus role tokens. Plans and applies used the admin token and X-Durable-Workflow-Control-Plane-Version: 2 over real HTTP. An operator token gets 403 forbidden (allowed_roles: ["admin"]) on both plan and apply. DW_RUST_MAINTENANCE_LOOP=0 was set so the background retention loop could not prune between steps or move fingerprints. Enforcement was then exercised explicitly with POST /api/system/retention/pass (row 10).

    Seed: namespace q522, bounded, 30 days. Runs were seeded with raw worker HTTP on protocol 1.20: start, poll, then complete_workflow or fail_workflow.

    Run Closed Note
    age40-completed 40 d ago
    age20-completed 20 d ago
    age20-failed 20 d ago
    age10-completed 10 d ago
    age3-completed 3 d ago
    age0-completed now
    age20-archived 20 d ago Archived with POST /api/workflows/{id}/archive
    age40-archived 40 d ago Archived with POST /api/workflows/{id}/archive
    age20-held 20 d ago Real held run, details below
    open-run open Never closed

    age20-held scheduled an activity with cancellation_policy: "abandon". Its run was then closed by canonical cooperative cancellation: request-cancellation, then deliver-cancellation, then complete_workflow. That gives WorkflowCancelled, run cancelled, and the activity still pending.

    Deviation: close ages were backdated directly in the database. Native 3.30.0 has no supported path to backdate a close time and no clock override. After each run closed through the API, the script ran UPDATE workflow_runs/workflow_run_summaries SET closed_at=<now − N days − 1 h> WHERE id=<run>. Those are the only direct writes, and they all happened before the "before" fingerprint. Every other state was produced through the API.

    Scenario results (identical on SQLite, PostgreSQL and MySQL; 40/40 checks each)

    # Scenario Request Observed
    2 Shortening 30 → 7 plan {"retention_days":7} 200, schema retention-plan.v1, read_only: true, retroactive: true, complete: true. newly_eligible count 4: age20-completed, age20-failed, age20-held, age10-completed. unchanged_eligible 1 (age40). unchanged_retained 2 (age3, age0). no_longer_eligible 0. policy_revision and plan_revision are sha256:….
    2 Apply without confirmation apply with both revisions, no flag, and again with false 422 retention_pruning_confirmation_required, retroactive: true. Policy stays at 30.
    2 Apply with confirmation confirm_retroactive_pruning: true 200 retention-apply.v1, retroactive: true, confirmed_retroactive_pruning: true, new policy_revision. Namespace is now 7. Re-sending the same apply gives 409 retention_policy_revision_stale, so a plan cannot be applied twice.
    3 Lengthening 7 → 30 plan, then apply with no flag Plan: retroactive: false, no_longer_eligible 4, newly_eligible 0. Apply: 200, retroactive: false, namespace 30.
    4 bounded → forever guarded plan and apply Plan: retroactive: false, exclusions.forever 7 (every closed, unarchived run, including the held one). Apply: 200, mode forever.
    4 forever → bounded 30 plan, apply without flag, apply with flag Plan: retroactive: true, newly_eligible 1 (age40). Apply without flag: 422 retention_pruning_confirmation_required, mode stays forever. Apply with flag: 200, now bounded 30.
    5 Archived runs the 30 → 7 plan exclusions.archived count 2 (age20-archived, age40-archived). Neither appears in any changes count or example.
    5 Held run the 30 → 7 plan exclusions.detached_activity_hold count 1, example age20-held. hold_inspection.inspected: 5, complete: true. exclusions.not_terminal 1 (open-run).
    6 Concurrent policy change plan 7 at 30, then PUT {"retention_days":14}, then apply with the old revisions 409 retention_policy_revision_stale. The answer carries the new current policy_revision. Namespace stays at 14 from the PUT.
    6 Non-policy change plan, wait more than 1 s, PUT {"description":…}, then apply 409 retention_policy_revision_stale
    6 Mismatched proposal plan 7, then apply retention_days: 5 with that plan's revisions 409 retention_plan_revision_mismatch. Namespace unchanged.
    6 Missing revisions apply without revisions 422 validation_failed (policy_revision and plan_revision required)
    7 Incomplete scan plan 7 with scan_limit: 1, hold_scan_limit: 1 complete: false. newly_eligible, unchanged_retained and exclusions.archived are {count: null, lower_bound: 1, complete: false}. The three hold counts are {count: null, lower_bound: 0, complete: false} with hold_inspection.inspected: 1. incomplete lists 3 × scan_limit_reached and 3 × hold_scan_limit_reached. Counts within the bound stay exact (unchanged_eligible 1, not_terminal 1).
    8 Preview writes nothing fingerprints before and after (next table) Unchanged on all three backends
    9 The old PUT PUT {"retention_days":3} at 14 days, which is retroactive 200, no plan or confirmation needed. Describe shows 3 days immediately. GET /api/system/retention shows the 3-day cutoff with expired_run_count 6.
    10 Enforcement after a guarded apply PUT 30, plan 7, confirmed apply, then POST /api/system/retention/pass processed 5, pruned 4, skipped 1. Pruned: age40, age20-completed, age20-failed, age10. age20-held skipped with detached_activity_still_open. Archived runs were not candidates. A plan made afterwards still reports the held run in detached_activity_hold, and archived 2.

    Preview fingerprints (scenario 8)

    Between the two fingerprints the script ran:

    • 6 plans: 30→7, 30→60, 30→forever, 30→30, 30→7 with scan_limit 1 / hold_scan_limit 1, and 30→7 again.
    • 2 refused applies: no confirmation flag, and confirm_retroactive_pruning: false, both 422.

    Each fingerprint has two parts:

    • API: SHA-256 over describe namespace, GET /api/workflows/{id} for all 10 runs, GET /api/workflows and GET /api/system/retention.
    • Database: SHA-256 of a full logical dump. SQLite: .dump of a copy of database.sqlite with its -wal and -shm files. PostgreSQL: pg_dump, with the random per-dump \restrict token lines removed. MySQL: mysqldump --skip-dump-date --order-by-primary --hex-blob.
    Backend API before = after DB dump before = after
    SQLite 56c8f67667014c7cf1bdd2b17e85fce18785de71b200be768e1530c697537850 6ca4e682c210c40573c06d6fb3d450660fb997f5b4b65a6a064149fa0a7a97cc (171,677 B)
    PostgreSQL 17 e52ee28caacfedd00d50c207dcbdc383728f96077cef29a330975ebd27c6e2f1 7b7120c5ad7613b748a21e90e73ffc263099f7529d6d99df1683b2832e9d8719 (272,525 B)
    MySQL 8.0 d207d7a63b8531f3e4269bd38a0fe232b578614c008696ee99670972c1c141d9 615c7f00f19bf64d64a41d5fff6dcb6bc381d2adaf5be5f5081deabd5221f26c (255,103 B)

    Observation (low severity; docs precision, not a safety gap)

    On PostgreSQL and MySQL, workflow_namespaces.updated_at is timestamp(0) (whole seconds). A description-only PUT in the same second as the previous namespace write therefore leaves policy_revision unchanged.

    • Repro: plan 7 at 14, then immediately PUT {"description":…}, then an unconfirmed apply. PG and MySQL answered 422 retention_pruning_confirmation_required, which means the revision check passed. SQLite (millisecond updated_at) answered 409 retention_policy_revision_stale. Nothing was written in either case.
    • Impact: any change to retention mode or days still changes the revision, because both are in the digest. The plan is therefore never applied over a different policy. The guide's sentence "Other namespace updates move updated_at too, so they also produce a new revision" holds only at one-second granularity on PG and MySQL.
    • Suggested fix: say so in the docs, or digest a sub-second or monotonic namespace version.

    Per backend, from the 30 → 7 plan:

    Backend policy_revision plan_revision
    SQLite sha256:c198c26c…2628f9 sha256:467859a4…e844b
    PostgreSQL sha256:4a713e09…7ed0 sha256:b8c47de8…d83f
    MySQL sha256:4216f92e…c112 sha256:1d9bcbd1…129b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:featurepriority:P3status:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions