Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/rust-server-port.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,10 @@ contract fixture before its correction.
and closes `WorkflowTimedOut`, `WorkflowTerminated` or `WorkflowCancelled`
with the embedded 2.29.0 `timeout_cleanup` outcome. Children opt in on
their own, and describe reports the cleanup state; both are registered
native divergences. The server capability stays unadvertised until
installed cross-SDK acceptance
native divergences. Cluster info and worker responses advertise
`timeout_cleanup: {supported: true, version: 1}`, after the contract
vectors 1 to 12 passed against published native with the published PHP
SDK 3.31.0 worker (`scripts/conformance/timeout-cleanup/run.sh`)
([#1201](https://github.com/durable-workflow/server/issues/1201)).
- **Signal and update names PHP cannot store.** PHP validates signal,
update and query names at 1 to 256 bytes with no control characters, but
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.1.0
info:
title: durable-workflow.v2.worker-protocol-api
version: "68"
version: "69"
summary: Durable Workflow worker-plane HTTP+JSON API
description: >
Normative OpenAPI specification for the worker-plane HTTP+JSON API:
Expand Down Expand Up @@ -1881,6 +1881,22 @@ components:
This Server can replay history marked for durable input ordering.
Workers that understand the marker register condition_wait_input_order.
A separate field on the workflow lease permits opening a new marked wait.
timeout_cleanup:
type: object
required: [supported, version]
properties:
supported: { type: boolean, const: true }
version: { type: integer, const: 1 }
description: >
Present when the server implements opt-in deadline-triggered timeout
cleanup version 1 (server#1201). A start with timeout_cleanup_seconds
is admitted only on a queue with a live worker that lists
timeout_cleanup and sends capability_manifest.timeout_cleanup
{supported: true, version: 1}. Cleanup is delivered through the
cooperative cancellation path with a root context cause "timeout".
A worker reports an uncaught timeout-cleanup interruption with
fail_workflow failure.interruption "timeout_cleanup"; any other
failure records failed cleanup. The run always closes timed out.
condition_wait_occurrence_deadline:
type: boolean
description: >
Expand Down
8 changes: 5 additions & 3 deletions rust/src/runtime/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub(super) fn capabilities() -> Value {
for name in unpublished {
map.insert(name.into(), Value::Bool(false));
}
// Server #1201: published only once native passes installed acceptance.
// Server #1201: deadline-triggered timeout cleanup, version 1.
if let Some(advertised) = super::timeout_cleanup::advertisement() {
map.insert(super::timeout_cleanup::CAPABILITY.into(), advertised);
}
Expand Down Expand Up @@ -233,8 +233,10 @@ mod tests {
// occurrence deadline, update outcome reads, task queue pauses and
// command request keys, open-run version usage, guarded build
// retirement, the Prometheus text scrape, signal-with-start,
// signal-external and the task-attention workflow list filter.
assert_eq!(caps.as_object().unwrap().len(), 69);
// signal-external, the task-attention workflow list filter and
// timeout cleanup.
assert_eq!(caps.as_object().unwrap().len(), 70);
assert_eq!(caps[super::super::timeout_cleanup::CAPABILITY], json!({"supported": true, "version": 1}));
assert_eq!(caps[super::super::task_attention::VISIBILITY_FILTER_CAPABILITY], json!(true));
assert_eq!(caps[super::super::external_signals::CAPABILITY], json!(true));
assert_eq!(caps[super::super::version_usage::CAPABILITY], json!(true));
Expand Down
2 changes: 1 addition & 1 deletion rust/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6852,7 +6852,7 @@ fn capabilities_template() -> Value {
.expect("commands")
.push(json!(super::wait_timeouts::RESOLVE_CONDITION_WAIT));
value[super::continuation::CAPABILITY] = super::continuation::capability();
// Gated off until installed acceptance (Server #1201).
// Deadline-triggered timeout cleanup, version 1 (Server #1201).
if let Some(advertised) = super::timeout_cleanup::advertisement() {
value[super::timeout_cleanup::CAPABILITY] = advertised;
}
Expand Down
34 changes: 18 additions & 16 deletions rust/src/runtime/timeout_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub(super) const INTERRUPTION: &str = "timeout_cleanup";
/// The largest admitted allowance.
pub(super) const MAX_ALLOWANCE_SECONDS: i64 = 86_400;
/// Whether `/api/cluster/info` and worker responses advertise
/// `timeout_cleanup: {supported: true, version: 1}`. Off until installed
/// cross-language acceptance against native passes every #1201 item: an SDK
/// worker that advertises the capability and delivers the typed timeout
/// interruption, the shared vectors 1-12 on every backend, and a published
/// SDK/Server tuple. Admission does not depend on it: a start is refused
/// unless an eligible worker on its queue advertises support.
pub(super) const ADVERTISED: bool = false;
/// `timeout_cleanup: {supported: true, version: 1}`. On since installed
/// acceptance of the contract vectors 1-12 passed against published native
/// with the published PHP SDK 3.31.0 worker, the first SDK that advertises
/// the capability and sends the interruption marker. Admission does not
/// depend on it: a start is refused unless an eligible worker on its queue
/// advertises support.
pub(super) const ADVERTISED: bool = true;

const REASON: &str = "Workflow work deadline passed; timeout cleanup requested.";

Expand Down Expand Up @@ -113,7 +113,7 @@ pub(super) fn worker_supports(capabilities: &Value, manifest: &Value) -> bool {
listed && entry["supported"] == Value::Bool(true) && entry.get("version").is_none_or(|version| version == 1)
}

/// The server's advertisement, when enabled.
/// The server's advertisement.
pub(super) fn advertisement() -> Option<Value> {
ADVERTISED.then(|| json!({"supported": true, "version": 1}))
}
Expand Down Expand Up @@ -379,13 +379,15 @@ store_methods! {
Ok(())
}

/// Describe's `timeout_cleanup` (a native addition, registered as the
/// `describe-timeout-cleanup-state` divergence: embedded describe shows
/// neither the state nor the outcome). Only an opted-in run has it:
/// Describe's `timeout_cleanup`, registered as the
/// `describe-timeout-cleanup-state` divergence: embedded Workflow 2.40.0
/// reports only entered or finished cleanup, with the same `outcome`
/// values. Only an opted-in run has it:
/// `armed` before the work deadline is noticed,
/// `cancellation_cleanup_running` with `cause: timeout` while the
/// engine's request is open, then `finished` with the recorded outcome,
/// or `not_entered` when the run closed without entering cleanup.
/// `cancellation_cleanup_running` with `cause: timeout` and the portable
/// `outcome: running` while the engine's request is open, then
/// `finished` with the recorded outcome, or `not_entered` when the run
/// closed without entering cleanup.
pub(super) async fn timeout_cleanup_view(executor: &mut DB::Connection, run: &DB::Row) -> Result<Option<Value>> {
let execution = DB::optional_instant(run, "execution_deadline_at")?;
let run_deadline = DB::optional_instant(run, "run_deadline_at")?;
Expand Down Expand Up @@ -422,7 +424,7 @@ store_methods! {
"work_deadline_at": entered.get("work_deadline_at").cloned().unwrap_or_else(|| json!(iso(hard - chrono::Duration::seconds(allowance)))),
"cleanup_deadline_at": entered.get("cleanup_deadline_at").cloned().unwrap_or_else(|| json!(iso(hard))),
"started_at": entered.get("detected_at").cloned().unwrap_or(Value::Null),
"outcome": outcome.get("outcome").cloned().unwrap_or(Value::Null),
"outcome": if state == "cancellation_cleanup_running" { json!("running") } else { outcome.get("outcome").cloned().unwrap_or(Value::Null) },
"failure_id": outcome.get("failure_id").cloned().unwrap_or(Value::Null)})))
}

Expand Down Expand Up @@ -515,7 +517,7 @@ mod tests {
assert!(!worker_supports(&json!([]), &manifest));
assert!(!worker_supports(&json!(["timeout_cleanup"]), &json!({"timeout_cleanup": {"supported": false}})));
assert!(!worker_supports(&json!(["timeout_cleanup"]), &json!({"timeout_cleanup": {"supported": true, "version": 2}})));
assert!(advertisement().is_none(), "advertisement stays off until installed cross-language acceptance");
assert_eq!(advertisement(), Some(json!({"supported": true, "version": 1})));
}

#[test]
Expand Down
9 changes: 6 additions & 3 deletions rust/tests/execution/timeout_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ async fn admission_refuses_invalid_allowances_and_queues_without_a_capable_worke
let hard = chrono::DateTime::parse_from_rfc3339(payload["execution_deadline_at"].as_str().unwrap()).unwrap();
let work = (hard - chrono::Duration::seconds(ALLOWANCE)).format("%Y-%m-%dT%H:%M:%S+00:00").to_string();
assert_eq!(payload["timeout_cleanup"], json!({"allowance_seconds": ALLOWANCE, "work_deadlines": {"execution": work}}));
// Neither surface advertises end-to-end support yet.
// Both discovery surfaces advertise version 1.
let advertised = json!({"supported": true, "version": 1});
let (_, cluster) = request(&app, "GET", "/api/cluster/info", Value::Null).await;
assert!(cluster["capabilities"].get("timeout_cleanup").is_none(), "{}", cluster["capabilities"]);
assert!(cluster["worker_protocol"]["server_capabilities"].get("timeout_cleanup").is_none());
assert_eq!(cluster["capabilities"]["timeout_cleanup"], advertised, "{}", cluster["capabilities"]);
assert_eq!(cluster["worker_protocol"]["server_capabilities"]["timeout_cleanup"], advertised);
}

// Vector 11: without the option nothing changes.
Expand Down Expand Up @@ -533,6 +534,7 @@ async fn the_earliest_hard_deadline_names_the_kind_and_describe_follows_the_stat
let (_, described) = request(&app, "GET", "/api/workflows/tc-run-kind", Value::Null).await;
assert_eq!(described["timeout_cleanup"]["state"], "armed", "{described}");
assert_eq!(described["timeout_cleanup"]["cause"], Value::Null);
assert_eq!(described["timeout_cleanup"]["outcome"], Value::Null);
assert_eq!(described["timeout_cleanup"]["allowance_seconds"], ALLOWANCE);
assert_eq!(described["timeout_cleanup"]["timeout_kind"], "run");
let first = cleanup_poll(&app, "cleanup-worker").await;
Expand All @@ -548,6 +550,7 @@ async fn the_earliest_hard_deadline_names_the_kind_and_describe_follows_the_stat
let (_, described) = request(&app, "GET", "/api/workflows/tc-run-kind", Value::Null).await;
let view = &described["timeout_cleanup"];
assert_eq!((view["state"].as_str(), view["cause"].as_str()), (Some("cancellation_cleanup_running"), Some("timeout")), "{view}");
assert_eq!(view["outcome"], "running", "the portable open-cleanup outcome");
assert_eq!(view["started_at"], entered["detected_at"]);
assert_eq!(view["cleanup_deadline_at"], json!(iso));
let task = cleanup_poll(&app, "cleanup-worker").await;
Expand Down
2 changes: 1 addition & 1 deletion scripts/conformance/server-parity/native-divergences.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"since": "native source PR #1235 (unreleased)",
"applies_to": ["timeout-cleanup"],
"published_php": "Published PHP does not admit timeout cleanup on service starts, and embedded Workflow 2.29.0 run detail and describe show neither the cleanup state nor its outcome; the outcome is visible only on the terminal history event and in the timeout failure message.",
"native": "Describe and run detail of an opted-in run carry timeout_cleanup {state: armed | cancellation_cleanup_running | finished | not_entered, cause (timeout once entered), allowance_seconds, timeout_kind, work_deadline_at, cleanup_deadline_at, started_at, outcome, failure_id}. A run without the opt-in has no timeout_cleanup key.",
"native": "Describe and run detail of an opted-in run carry timeout_cleanup {state: armed | cancellation_cleanup_running | finished | not_entered, cause (timeout once entered), allowance_seconds, timeout_kind, work_deadline_at, cleanup_deadline_at, started_at, outcome (running while cleanup is open, as embedded Workflow 2.40.0 reports it, then the recorded outcome), failure_id}. A run without the opt-in has no timeout_cleanup key; an opted-in run that has not entered cleanup reports it armed or not_entered where embedded 2.40.0 omits the field.",
"harness": "No recorded corpus run opts in, so no comparator changes. The all-backend execution tests cover every state and outcome."
},
{
Expand Down
147 changes: 147 additions & 0 deletions scripts/conformance/timeout-cleanup/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# Installed timeout-cleanup acceptance (Server #1201): the contract vectors
# 1-12 from Workflow's docs/architecture/timeout-cleanup.md against a published
# native Server image (SQLite), with workers that run a published PHP SDK
# installed from Packagist. Nothing here builds product source.
#
# SERVER_IMAGE=durableworkflow/server@sha256:... PHP_SDK_VERSION=3.31.0 \
# scripts/conformance/timeout-cleanup/run.sh [evidence-dir]
#
# EXPECT_ADVERTISED=true|false also checks the Server's timeout_cleanup
# advertisement in /api/cluster/info. Containers, the network (unless NETWORK
# names an existing one) and the PHP image this creates are removed on exit.
set -euo pipefail

here=$(cd "$(dirname "$0")" && pwd)
evidence=$(mkdir -p "${1:-$PWD/timeout-cleanup-evidence}" && cd "${1:-$PWD/timeout-cleanup-evidence}" && pwd)
: "${SERVER_IMAGE:?Set SERVER_IMAGE to a published native Server image}"
: "${PHP_SDK_VERSION:?Set PHP_SDK_VERSION to a published PHP SDK version}"
php_base=${PHP_IMAGE:-php:8.3-cli-bookworm}
composer_image=${COMPOSER_IMAGE:-composer:2}
prefix=${NAME_PREFIX:-dw-timeout-cleanup-$$}
limits=(--init --cpus "${CONTAINER_CPUS:-2}" --memory "${CONTAINER_MEMORY:-2g}" --pids-limit 1024)
token=timeout-cleanup-token
user="$(id -u):$(id -g)"
work=$(mktemp -d)
php_image="$prefix-php:local"
created_network=
if [[ -n "${NETWORK:-}" ]]; then
network=$NETWORK
else
network="$prefix-net"
docker network create "$network" >/dev/null
created_network=1
fi

containers=()
cleanup() {
status=$?
for container in "${containers[@]}"; do
docker logs "$container" > "$evidence/$container.log" 2>&1 || true
docker rm -f "$container" >/dev/null 2>&1 || true
done
docker image rm "$php_image" >/dev/null 2>&1 || true
[[ -n "$created_network" ]] && docker network rm "$network" >/dev/null 2>&1 || true
rm -rf "$work"
exit "$status"
}
trap cleanup EXIT

# The harness and the exact published SDK, installed without dev packages.
cp "$here/worker.php" "$here/vectors.php" "$work/"
printf '{"require":{"durable-workflow/sdk":"%s"},"config":{"platform-check":false}}\n' "$PHP_SDK_VERSION" > "$work/composer.json"
docker run --rm --name "$prefix-composer" "${limits[@]}" --user "$user" -e COMPOSER_HOME=/tmp/composer -v "$work:/app" -w /app "$composer_image" \
install --no-dev --no-interaction --no-progress --ignore-platform-req=ext-pcntl >/dev/null
docker run --rm --name "$prefix-composer" "${limits[@]}" --user "$user" -v "$work:/app" -w /app "$composer_image" \
show --format=json durable-workflow/sdk > "$evidence/php-sdk.json"
# Cooperative PHP workers need pcntl and posix.
printf 'FROM %s\nRUN docker-php-ext-install pcntl >/dev/null\n' "$php_base" | docker build -q -t "$php_image" - >/dev/null

mkdir -p "$work/state" "$evidence"
: > "$evidence/results.jsonl"
: > "$evidence/observations.jsonl"
docker run -d --name "$prefix-server" "${limits[@]}" --user "$user" --network "$network" --network-alias server \
-e DW_RUST_EXPERIMENTAL=1 -e DW_AUTH_TOKEN="$token" -e DB_DATABASE=/state/server.sqlite \
-e DW_BIND_ADDRESS=0.0.0.0:8080 -e DW_WORKFLOW_TASK_TIMEOUT=8 \
-v "$work/state:/state" "$SERVER_IMAGE" >/dev/null
containers+=("$prefix-server")

php() {
docker run --rm "${limits[@]}" --user "$user" --network "$network" -e TC_TOKEN="$token" \
-e TC_RUN_SUFFIX="$suffix" -v "$work:/harness:ro" -v "$evidence:/evidence" "$php_image" php "/harness/$1" "${@:2}"
}

worker() {
local name=$1; shift
docker run -d --name "$prefix-$name" "${limits[@]}" --user "$user" --network "$network" -e TC_TOKEN="$token" \
-e TC_WORKER_ID="$name" "$@" -v "$work:/harness:ro" -v "$evidence:/evidence" "$php_image" php /harness/worker.php >/dev/null
containers+=("$prefix-$name")
}

for _ in $(seq 60); do
if docker exec "$prefix-server" bash -c 'exec 3<>/dev/tcp/127.0.0.1/8080 && printf "GET /api/ready HTTP/1.0\r\n\r\n" >&3 && head -n1 <&3 | grep -q " 200 "' 2>/dev/null; then
break
fi
sleep 1
done
suffix=$(date +%s)

worker main -e TC_QUEUE=timeout-cleanup
worker plain -e TC_QUEUE=tc-plain-queue -e TC_COOPERATIVE=0
worker doomed -e TC_QUEUE=tc-replace -e TC_DIE_ON_CLEANUP=1
sleep 5

docker run --rm --name "$prefix-discovery" "${limits[@]}" --network "$network" "$php_image" php -r '
$context = stream_context_create(["http" => ["header" => "Authorization: Bearer '"$token"'\r\nX-Namespace: default\r\nX-Durable-Workflow-Control-Plane-Version: 2\r\n"]]);
echo file_get_contents("http://server:8080/api/cluster/info", false, $context);' > "$evidence/cluster-info.json"
advertised=$(jq -c '.capabilities.timeout_cleanup // null' "$evidence/cluster-info.json")
echo "Server timeout_cleanup advertisement: $advertised"
failed=0
if [[ -n "${EXPECT_ADVERTISED:-}" ]]; then
expected=null
[[ "$EXPECT_ADVERTISED" == true ]] && expected='{"supported":true,"version":1}'
if [[ "$advertised" == "$expected" ]] \
&& [[ "$(jq -c '.worker_protocol.server_capabilities.timeout_cleanup // null' "$evidence/cluster-info.json")" == "$expected" ]]; then
echo '{"vector":"discovery","check":"advertisement matches EXPECT_ADVERTISED","passed":true}' >> "$evidence/results.jsonl"
else
echo "{\"vector\":\"discovery\",\"check\":\"advertisement matches EXPECT_ADVERTISED\",\"passed\":false,\"detail\":$advertised}" >> "$evidence/results.jsonl"
failed=1
fi
fi

php vectors.php main || failed=1

# Vector 5: the Server is paused from before the work deadline until after
# it, so the engine first notices it late.
resume_at=$(php vectors.php late-start | tail -n1)
docker pause "$prefix-server" >/dev/null
date +%s.%N > "$evidence/paused-at"
while (( $(date +%s) < resume_at )); do sleep 1; done
docker unpause "$prefix-server" >/dev/null
date +%s.%N > "$evidence/unpaused-at"
php vectors.php late-check || failed=1

# Vector 6: the worker holding the cleanup turn dies; a fresh process with
# the same code finishes it once the task lease expires.
php vectors.php replace-start || failed=1
timeout 60 docker wait "$prefix-doomed" > "$evidence/doomed-exit-code" || failed=1
worker replacement -e TC_QUEUE=tc-replace
php vectors.php replace-check || failed=1

passed=$(jq -s '[.[] | select(.passed)] | length' "$evidence/results.jsonl")
total=$(jq -s 'length' "$evidence/results.jsonl")
{
echo "### Installed timeout cleanup vectors"
echo
echo "- Server image: \`$SERVER_IMAGE\` ($(docker image inspect "$SERVER_IMAGE" --format '{{index .RepoDigests 0}}' 2>/dev/null || echo unresolved))"
echo "- PHP SDK: \`$(jq -r '.name + " " + (.versions[0] // "")' "$evidence/php-sdk.json")\` from Packagist, source \`$(jq -r '.source.reference // "unknown"' "$evidence/php-sdk.json")\`"
echo "- Server advertisement: \`$advertised\`"
echo "- Checks passed: $passed of $total"
echo
echo "| Vector | Check | Result |"
echo "| --- | --- | --- |"
jq -r '"| \(.vector) | \(.check) | \(if .passed then "pass" else "FAIL" end) |"' "$evidence/results.jsonl"
} > "$evidence/summary.md"
[[ -n "${GITHUB_STEP_SUMMARY:-}" ]] && cat "$evidence/summary.md" >> "$GITHUB_STEP_SUMMARY"
cat "$evidence/summary.md"
[[ "$failed" == 0 && "$passed" == "$total" ]]
Loading