Skip to content

Add namespace:retention-plan and namespace:retention-apply (server#522) - #178

Merged
rmcdaniel merged 2 commits into
mainfrom
general/cli-522-retention-plan
Nov 26, 2026
Merged

rmcdaniel merged 2 commits into
mainfrom
general/cli-522-retention-plan

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

For durable-workflow/server#522. Native Server 3.30.0 can now preview a namespace retention change and then apply it only while that preview still holds (server#1332, #1350; documented in the server reference under "Retention plan" and "Guarded apply"). This PR adds both routes to the shipped Rust dw.

Commands

namespace:retention-plan <name> [--retention=N] [--retention-mode=bounded|forever] [--scan-limit=N] [--hold-scan-limit=N] [--json]

  • Sends one read-only POST /api/namespaces/{name}/retention-plan. Any field you leave out keeps its current value.
  • The human output shows:
    • the current and proposed policy, each with its cutoff
    • Retroactive and Complete
    • both revisions
    • a table of every changes.* and exclusions.* count. A count that hit its bound shows as at least N.
    • the incomplete fields and the hold inspection
    • example runs, oldest first
    • the Server's scope sentence
    • the exact dw namespace:retention-apply … command for this plan, with --confirm-retroactive-pruning added when the plan is retroactive
  • --json returns the durable-workflow.v2.retention-plan.v1 document unchanged.

namespace:retention-apply <name> [--retention=N] [--retention-mode=…] --policy-revision=… --plan-revision=… [--confirm-retroactive-pruning] [--plan-file=plan.json] [--json]

  • Sends one guarded POST …/retention-plan/apply and never resends it. confirm_retroactive_pruning is always sent, as true or false.
  • --plan-file takes the resolved proposal and both revisions from a plan saved with namespace:retention-plan --json. It checks the plan's schema and namespace first. Because the file supplies the proposal and both revisions, it can't be combined with --retention, --retention-mode or the revision options.
  • Each refusal changed nothing. dw prints the Server's message, the reason and a specific next step, then exits 2:
    • 409 retention_policy_revision_stale: shows the current policy_revision and suggests dw namespace:retention-plan <name> to plan again.
    • 409 retention_plan_revision_mismatch: apply the plan's exact proposal, or plan this one.
    • 422 retention_pruning_confirmation_required: review newly_eligible, then repeat with --confirm-retroactive-pruning.
  • With --json, a refusal returns the usual error envelope: reason, status_code, server_response, and recommendations[0].id set to retention_plan.stale, retention_plan.mismatch or retention_plan.confirmation_required.
  • A 404 whose reason is not namespace_not_found means the Server doesn't have these routes. dw exits 5 and says native Server 3.30.0 or later is needed. Server 3.30.0 advertises no capability for these routes, so there is no capability preflight.

Bad option values (non-positive integers, an unknown mode, --retention together with forever, missing revisions, a bad or mismatched plan file) are refused with exit 2 before any request. Each name is sent as one encoded path segment. namespace:update is unchanged.

Notes for review

  • Option names. --retention (days) matches namespace:create and namespace:update, and --retention-mode is its companion. I used these instead of --retention-days and --mode.
  • Rust only. These are Rust-only catalog additions, the same pattern as task-queue:retire and workflow:history-archive. They are registered in rust/parity/catalog-additions.json, rust/src/catalog.json, main.rs, the rust-only list in test_parity.py, and the parity script comments. The PHP 2.3.x maintenance line is untouched.
  • Docs. docs/cli-reference.md has a new "Retention plan and guarded apply" section with the refusal table, and both README.md and rust/README.md mention the commands.
  • The embedded dev Server is pinned to a 3.12-era revision, so the tests use the loopback Server harness, not a live 3.30 Server.

Local checks (Rust 1.99, Docker)

  • cargo fmt --check: pass
  • cargo clippy --locked --all-targets -- -D warnings: pass
  • cargo test --test namespace_retention: 9/9 pass. The tests cover the plan request and full human output, a forever plan, apply bodies, --plan-file, all three refusals in human and JSON form, a Server without the routes, local validation, path encoding and a lost response.
  • cargo test --bin dw: 139 pass. queues_workers, namespace_list and system_debug: pass.
  • python3 -m unittest test_parity: 27/27 pass.
  • The full suite and the 2.x parity run are left to CI.

🤖 Generated with Claude Code

Native Server 3.30.0 previews a proposed namespace retention policy and
applies it only while that plan still holds (durable-workflow/server#522,
#1332, #1350). Expose it in the shipped Rust dw:

- namespace:retention-plan <name> [--retention=N] [--retention-mode=bounded|forever]
  [--scan-limit=N] [--hold-scan-limit=N]: one read-only POST of
  /namespaces/{name}/retention-plan. Human output shows the current and
  proposed policy with cutoffs, whether it is retroactive, complete, both
  revisions, a count for every change and exclusion ("at least N" when a
  count reached its bound), the incomplete fields, the hold inspection,
  example runs, the scope sentence and the exact apply command for the
  plan. --json returns the Server document unchanged.
- namespace:retention-apply <name> [--retention=N] [--retention-mode=...]
  --policy-revision=R --plan-revision=R [--confirm-retroactive-pruning]
  [--plan-file=plan.json]: one guarded POST of .../retention-plan/apply,
  never resent. --plan-file takes the resolved proposal and both
  revisions from a saved plan (namespace and schema checked) and cannot be
  combined with those four options. A stale (409), mismatched (409) or
  unconfirmed (422) apply changed nothing: dw prints the reason and the
  next step (re-plan, with the current policy_revision, for stale) and
  exits 2; --json keeps the error envelope with the full body. A 404 that
  is not namespace_not_found means the Server lacks the routes and points
  at native Server 3.30.0.

Option names follow namespace:create/update (--retention for days).
Invalid options are refused with exit 2 before any request. Server 3.30.0
advertises no capability for these routes, so there is no capability
preflight. namespace:update is unchanged.

Like the other native-only commands they are Rust-only catalog additions;
the PHP 2.3.x maintenance line is unchanged. Docs: cli-reference, README,
rust/README.

Tests: 9 loopback-Server integration tests (tests/namespace_retention.rs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at head 5ccd3e4

I reviewed the change at 9f0ff8d. The head 5ccd3e4 only adds a merge of current main (the 2.13.0 release prep and the parity version normalization), because the strict status check rule required the branch to be up to date. The PR's own diff is unchanged.

What I verified against durable-workflow/server main (rust/src/runtime/retention_plan.rs, namespaces.rs, http.rs and the "Retention plan" and "Guarded apply" sections of docs/server-reference.md):

  • Routes and wire format. The commands send POST /api/namespaces/{name}/retention-plan and .../retention-plan/apply, each with the name as one encoded segment. The fields are retention_mode, retention_days, scan_limit, hold_scan_limit, policy_revision, plan_revision and confirm_retroactive_pruning. Both requests go through namespace_request, which sets X-Durable-Workflow-Control-Plane-Version from compat::control_plane_version() and sends the bearer token. Leaving out a field keeps its current value, which matches requested_retention and resolved_retention. The server's admin-only gate (retention_plan_route) matches the docs.
  • Revision binding. The server computes plan_revision over the resolved mode and days. Both the printed apply command and --plan-file send proposed_policy.retention_mode and, for bounded only, retention_days, which are exactly the resolved values. For forever they send only the mode, which resolves to (forever, None). So a faithful apply matches. If someone edits the plan file's proposal, the server refuses it with 409 retention_plan_revision_mismatch, so it can't silently apply a different proposal. Before any request, --plan-file checks the file's schema (durable-workflow.v2.retention-plan.v1) and namespace (case-insensitively, as the server lowercases). It also refuses to combine the file with --retention, --retention-mode or either revision option.
  • Refusals. Stale (409), mismatch (409) and confirmation-required (422) each exit 2 under the existing from_http_status mapping. Each prints the server message, the reason and a next step, and gives a typed recommendations[0].id in the JSON envelope (retention_plan.stale, .mismatch, .confirmation_required). The stale message shows the current policy_revision and says to plan again. A 422 validation error or invalid_namespace_definition falls through to the ordinary request.invalid handling. A 404 without namespace_not_found maps to retention_plan.unsupported and exits 5. namespace_not_found keeps resource.not_found.
  • Incomplete counts. count_label prints an exact number only when complete is true and count is a number. Otherwise it prints at least <lower_bound>. This covers the scan-limit counts and the hold counts while hold inspection is incomplete.
  • No retry. The apply is one control_plane_request. The SDK 4.18.0 raw_request path has no retry loop, and a_lost_apply_response_is_never_resent confirms one request and exit 3 when the connection drops.
  • --json passes the server document through unchanged (serde_json uses preserve_order). Errors use the standard envelope.
  • Rust-only placement. The 2.3.x PHAR line is security-fix only until 2027-02-28 (README). The commands are added the same way as task-queue:retire and workflow:history-archive: rust_only in both catalog-additions.json and src/catalog.json (the entries are identical), the expected list in test_parity.py, and the comments in parity.py and update-catalog.sh.
  • Option names. --retention matches namespace:create and namespace:update, and --retention-mode is a coherent companion.
  • Tests. Nine integration tests in rust/tests/namespace_retention.rs cover each path: the request bodies, the human at least N output, forever, --plan-file, all three refusals in human and JSON form, the unsupported server, local validation before any request, path encoding and a lost response. They fail without the change because the commands and recommendations don't exist without it.
  • Docs. docs/cli-reference.md, README.md and rust/README.md agree with the server contract and the behavior.
  • CI: all 32 checks pass at 5ccd3e4, including Rust unit tests and 2.x parity, parity against published Servers, Target branch qualification and every platform build.

Non-blocking suggestions for a follow-up:

  1. rust/src/error.rs, retention_plan_recommendation. The command for the stale and mismatch refusals is a bare dw namespace:retention-plan <name>. Run as written, it plans the current policy against itself, not the policy the user proposed. Mismatch's "plan this policy first" reads as if the command does that. Consider adding the attempted --retention-mode and --retention to the hint, or wording it as "dw namespace:retention-plan with the same --retention/--retention-mode".
  2. namespace:update and namespace:create give --retention the shortcut -r. The new commands don't, so -r 7 is rejected there.
  3. The rust/README.md paragraph "Commands with no 2.x equivalent ..." still names only the batch, activity dispatch and update-outcome commands. It predates this PR, but it could list #519, #520 and #522 too.

@rmcdaniel
rmcdaniel merged commit e6072f3 into main Nov 26, 2026
32 checks passed
@rmcdaniel
rmcdaniel deleted the general/cli-522-retention-plan branch November 26, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant