Skip to content

Implement opt-in deadline-triggered timeout cleanup and portable interruption outcomes #1201

Done

Description

@rmcdaniel

Workflow #863 and draft #1129 implement opt-in deadline-triggered cleanup for embedded queue workers. Native delivery needs the same agreed contract in workflow/docs/architecture/timeout-cleanup.md; embedded publication alone does not complete the service-mode behavior.

Owners: Server owns native runtime and capability admission. Workflow owns the portable contract and embedded runtime. PHP, Python and Rust SDK owners own worker delivery. Their current parser/subtype PRs (sdk-php#402, sdk-python#311, sdk-rust#248) are preparatory and must not advertise end-to-end support yet.

Acceptance:

  • Immutable admission: finite allowance 1–86,400 seconds, smaller than each configured hard timeout; work deadline = hard deadline minus allowance. No clock is based on detection or worker restart. Native reads the admitted values from WorkflowStarted, with no new native column required.
  • Under the run lock, enter once at the earliest work deadline and before the earliest hard deadline. Record WorkflowTimeoutCleanupStarted with timeout_kind, work_deadline_at, cleanup_deadline_at, hard_deadline_at and detected_at, plus an engine-owned cooperative request.
  • Deliver a top-level optional cancellation-context v1/v2 cause (timeout or cancellation; absent means cancellation). Preserve explicit cancellation on round-trip. Descendants, including scoped children, do not inherit the root's cause. The kind and work deadline are event fields, not context fields. Reuse cancellation cleanup delivery and its original deadline.
  • Publish timeout_cleanup: {supported: true, version: 1} only after runtime support, and refuse an opted-in start when no eligible worker on the queue advertises support. Do not silently fall back to hard timeout. The capability check is admission-only.
  • Every final cleanup result is WorkflowTimedOut with failure_category timeout and a separate timeout_cleanup outcome: completed, failed with linked failure_id, expired, or preempted on hard cancel/terminate. Describe, export and failure lists say cleanup failed plainly. Repairable replay/version/history errors remain blocked for repair.
  • A user cooperative request during timeout cleanup is audited without replacing the engine request or renewing the deadline. An earlier cooperative request owns cleanup; if the hard timeout wins, mark that cooperative cleanup preempted. Keep activity cancellation-policy semantics, including settlement before terminal history.
  • Continue-as-new and redrive inherit the allowance and execution clocks; new run clocks are derived as today. Run contract vectors 1–12 plus task-boundary expiry, scoped descendants, replay-blocking precedence, user/hard cancellation, and worker replacement.

The rethrow marker must be language-neutral. Proposed portable failure field for review: interruption: "timeout_cleanup" on fail_workflow.failure. SDK workers set it only for an uncaught timeout-cleanup interruption. The runtime maps it to timeout_cleanup.outcome completed only while the run's canonical engine-owned timeout request is active; other failures remain cleanup failed. Never infer interruption from PHP/Python exception class names or let this marker initiate cleanup. The marker is gated by timeout_cleanup capability, and malformed/unknown markers are refused before writes. Server and SDK owners should confirm the exact wire placement here before implementation.

Next action: Server reviews the marker placement and owns an isolated native implementation PR. Workflow will link the qualified embedded release and exact published-tuple acceptance here; ordinary SDK parsing alone is not conformance evidence.

Activity

  1. rmcdaniel commented on Nov 13, 2026

    @rmcdaniel
    MemberAuthor

    Rust SDK review: fail_workflow.failure.interruption = "timeout_cleanup" is a suitable language-neutral placement. Rust can set it only when an uncaught Error::CooperativeCancellationRequested carries CancellationRequest::cause() == CancellationCause::Timeout, and only after exact timeout_cleanup capability admission. A caught interruption followed by application failure must remain failed. The runtime must verify its active canonical engine-owned timeout request before interpreting the marker; the marker cannot initiate cleanup, change deadlines or turn any other run into a successful cleanup. Unknown/malformed values should refuse before writes. Parser-only sdk-rust#248 is preparatory and will not emit this marker or advertise runtime support; worker delivery/settlement follows the qualified Server implementation here. Owner for that Rust follow-through: sdk-rust.

  2. rmcdaniel commented on Nov 13, 2026

    @rmcdaniel
    MemberAuthor

    Python confirms the proposed exact placement: commands[].type=fail_workflow with failure.interruption="timeout_cleanup", only for an uncaught WorkflowTimeoutCleanupRequested and only after timeout_cleanup capability admission. The runtime must require the canonical active engine timeout request and original deadline; the marker cannot start cleanup or override a non-timeout failure. Parser/subtype PR sdk-python#311 remains preparatory and does not add this marker or advertise capability. Owner: sdk-python for the later worker mapping, Server for runtime/marker admission.

  3. rmcdaniel commented on Nov 13, 2026

    @rmcdaniel
    MemberAuthor

    PHP owner review: sdk-php#402 remains cause-only parser/subtype preparation; it does not advertise timeout_cleanup or send an interruption marker. The proposed nested fail_workflow.failure.interruption="timeout_cleanup" placement is suitable as a language-neutral marker, provided only a canonical active engine-owned cleanup request authorizes the completed outcome and unknown/malformed markers refuse before writes, as stated here. PHP will add the marker in a separate capability-gated worker change after the native wire contract is final, with retained-history replay coverage. Ordinary failures and a caught/returned timeout interruption must keep the runtime-defined outcomes.

  4. rmcdaniel commented on Nov 13, 2026

    @rmcdaniel
    MemberAuthor

    Native wire review: fail_workflow.failure.interruption: "timeout_cleanup" is an appropriate language-neutral placement. Reserve that exact string as an engine-interruption discriminator; do not derive it from exception class names or a user-supplied failure category.

    Before any state write, native must validate a closed marker set and its type, require the negotiated timeout-cleanup capability, and verify the run's canonical engine-owned timeout request is already active under the transition lock. The marker cannot initiate cleanup, replace a request, extend a deadline, or change a scoped descendant's cause. A valid uncaught interruption then means cleanup completed and the run still closes as timed out; an ordinary failure remains cleanup failed. Include malformed/unknown marker, unsupported capability, inactive or user-cancellation context, wrong run/scope, hard-deadline race, and replacement-worker controls in the shared vectors.

    Owner/next action: server implements native admission/delivery only after the portable contract and the current #934 release correction. The proposed marker and SDK parser/subtype changes do not advertise runtime support. Capability publication still needs the runtime and installed cross-language evidence described in this issue.

  5. added
    kind:feature
    status:ready
    priority:P2
    on Nov 13, 2026
  6. rmcdaniel commented on Nov 13, 2026

    @rmcdaniel
    MemberAuthor

    Python follow-through owner remains sdk-python. Parser/exception PR sdk-python#311 is refreshed on published 2.17.1 source, with all 21 checks green and final Security countercheck requested. General confirmed it may merge as experimental preparation, with no capability advertisement and no standalone version-alignment release. Next action when the producer is qualified: sdk-python adds the agreed failure.interruption mapping and capability admission, then publishes and verifies a named installed SDK/Server tuple. The preparatory parser itself is not end-to-end timeout-cleanup acceptance.

  7. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    The native implementation shipped dark in Server 3.14.0 (#1235):

    • Admission is recorded in WorkflowStarted, with one-time entry under the run lock (WorkflowTimeoutCleanupStarted).
    • cause: "timeout" is set on the root context only.
    • WorkflowTimedOut records the completed, failed, expired or preempted outcome. User requests are audited.
    • Continue-as-new and redrive inherit the setting.
    • The failure.interruption: "timeout_cleanup" marker is validated before any write.
    • 15 execution tests run on all four backends.

    timeout_cleanup::ADVERTISED is still false, so the capability is not published.

    Remaining:

    Next action: implement the capability and marker in one SDK worker (Rust is the smallest surface) against Server 3.28.0, then run the installed vectors.

  8. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    The PHP SDK worker side is merged in durable-workflow/sdk-php#481 (merge 840be2c235115360488f318efeb790f7b98da7e2). A worker with cooperative cancellation enabled registers timeout_cleanup with manifest {supported: true, minimum_protocol_version: "1.20", version: 1}. When the delivered WorkflowTimeoutCleanupRequested escapes, uncaught or rethrown, the worker sends fail_workflow.failure.interruption: "timeout_cleanup". The marker requires the engine's root context with cause: timeout. Constructed, wrapped and ordinary-cancellation failures are not marked.

    I ran a source-checkout check against published native 3.28.0 (sha256:43242a89…):

    • A start on a queue with only a non-cooperative worker got 422 timeout_cleanup_not_supported.
    • Cleanup that returned and an interruption rethrown after compensation both ended WorkflowTimedOut with outcome completed.
    • A compensation exception gave failed with failure_id.
    • Running past the hard deadline gave expired.

    Each run had one WorkflowTimeoutCleanupStarted and closed failed/timed_out.

    Next: a PHP SDK minor release. Server can then run installed vectors 1 to 12 against that published tuple and flip ADVERTISED.

  9. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    PHP SDK 3.31.0 is published (Packagist reference ab9e1238) with this issue's PHP worker support (the `timeout_cleanup` capability and interruption marker, sdk-php#481).

  10. rmcdaniel commented on Nov 25, 2026

    @rmcdaniel
    MemberAuthor

    Native now advertises timeout_cleanup: {supported: true, version: 1} in cluster info and in worker responses (#1336, merge 6d03a7d1). It is unreleased: it will ship in the next native release.

    • Installed acceptance: vectors 1 to 12 pass (110 of 110 checks) against published native 3.29.0 (sha256:a2f588ec…, SQLite) with workers on the published PHP SDK 3.31.0. The run covers admission refusals, completed (returned and rethrown), failed with failure_id, expired, preempted by terminate and hard cancel, late detection, worker SIGKILL and replacement, continue-as-new on execution and run clocks, earliest-deadline kind, user-request preemption, unchanged default, and allowance validation.
      • The harness is scripts/conformance/timeout-cleanup/run.sh. After the release, rerun it with the new image and EXPECT_ADVERTISED=true.
    • Describe and run detail report outcome: "running" while cleanup is open, matching Workflow 2.40.0.
    • SDK workers (merged, unreleased) advertise the capability and send failure.interruption: "timeout_cleanup", the same as PHP:

    Remaining for this issue:

    1. Release native, the Rust SDK and the Python SDK.
    2. Run the installed vectors against the released native image, with Python and Rust workers as well as PHP.
    3. Native's bounded run observation (Waterline) does not yet return top-level timeout_cleanup as the contract says. Add it or register a divergence.

    🤖 Generated with Claude Code

  11. rmcdaniel commented on Nov 26, 2026

    @rmcdaniel
    MemberAuthor

    Released: native Server 3.30.0 advertises timeout_cleanup: {supported: true, version: 1} (#1336) and returns the run observation (#1344). The supporting workers are PHP SDK 3.31.0+ (3.32.0 for the stricter marker rule), Rust SDK 4.25.0 and Python SDK 2.24.0. The 3.30.0 release notes carry the mixed-queue upgrade paragraph.

    Published-tuple vectors (server#1363): against image sha256:b7bb6007… (3.30.0) with EXPECT_ADVERTISED=true, PHP SDK 3.32.0, Python SDK 2.24.0 and Rust SDK 4.25.0 each pass 110/110: vectors 1–12, admission refusal and discovery. A Python run under 2-CPU contention hit an SDK spawn-readiness timeout and then passed on rerun; that is tracked in sdk-python#388.

    This stays open for the acceptance items the harness doesn't cover: task-boundary expiry, scoped descendants not inheriting the cause, replay-blocking precedence, redrive inheritance, and refusal of a malformed marker or one from a non-capable worker, all against the published tuple.

  12. rmcdaniel commented on Nov 26, 2026

    @rmcdaniel
    MemberAuthor

    The remaining cases pass against the published tuple, so this issue is done.

    Run: native Server 3.30.0 image sha256:b7bb6007… (SQLite, advertises timeout_cleanup v1) with PHP SDK 3.32.0 workers. The harness change is #1373 (merge 118d05ce). The full default run passed 188 of 188 checks: vectors 1–12 plus admission and discovery (110), and the new extended cases (78). After review tightened the scoped-descendant checks, the final extended run passed 80 of 80.

    Case Result
    Task-boundary expiry A completion after the cleanup deadline is refused. The run ends WorkflowTimedOut expired at the original deadline, never completed.
    Scoped descendants A cancellation scope open at the work deadline is requested under the engine's request. Its scoped context's own lineage hop is the opened scope and has no cause; the timeout cause stays only on its root context. A child cancelled by the parent's cleanup (try_cancel) gets a request with no cause, rooted at the parent's request, and its code sees an ordinary WorkflowCancelled.
    Replay-blocking precedence A nondeterministic replay failure on the cleanup turn is blocked for repair (next_task_id: null, nothing claimable), not failed cleanup, until the hard deadline expires it. An ordinary failure is retried instead.
    Redrive inheritance An opted-in run that failed at an activity step redrives into a successor that keeps the allowance, the execution work deadline and the execution hard cap. Its run work deadline comes from its own run clock. A timed-out run is final, so redrive refuses it, in native and embedded alike.
    Malformed marker "cancellation", 1, true or an object is refused with 422 invalid_workflow_failure_interruption before any write. A marker sent before cleanup starts is refused with 409 timeout_cleanup_interruption_not_active.
    Marker from a non-capable worker A cooperative-only worker that claims the cleanup turn on a mixed queue gets 409 timeout_cleanup_not_supported for the marker. Its unmarked failure records failed.

    No native defect was found, so nothing new ships in the next release for this issue.

    Recorded decision on marker normalization. Native normalizes every request body like Laravel does (TrimStrings, then ConvertEmptyStringsToNull), and the marker is no exception:

    • interruption: "" is treated as absent, so it is an ordinary failure recorded as failed.
    • " timeout_cleanup " is trimmed to the reserved value. On a turn that holds the active engine request and negotiated the capability, it records completed.

    Neither case can create a false completion. That would still need the active engine request and a capable claim. The harness locks both behaviours in.

    Closing.

    🤖 Generated with Claude Code

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:P2status:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions