diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a38cb1..15e5f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,10 @@ non-matching signal pushed the deadline back. The worker now reopens with the time remaining since the first `ConditionWaitOpened`, rounded up to whole seconds and never below zero; a reopen after the deadline opens with a zero - timeout so the Server resolves it as timed out. This applies to condition - waits inside `parallel` and `select` groups too; sdk-php 3.9.x re-sends a - grouped wait with its authored timeout (aligning under sdk-php#278), and each - SDK replays only its own histories. Histories whose reopens + timeout so the Server resolves it as timed out. A condition wait inside a + `parallel` or `select` group reopens with its authored timeout, as sdk-php + does, because the PHP Server accepts a grouped reopen only when its timeout + equals the original open's (#189). Histories whose reopens carry the full timeout still replay, and a reopen longer than the authored timeout is still refused. A reopen links only to the same logical wait (`condition_wait_occurrence_id`), so a separate wait that follows a timed-out diff --git a/src/lib.rs b/src/lib.rs index 15dfbdd..662f70d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15627,6 +15627,7 @@ impl Future for ConditionWaitCall { let mut result = None; let mut pending_delivery = false; let mut first_sequence = None; + let mut latest_timeout_seconds = None; loop { if cursor > initial_cursor && matches!( @@ -15679,6 +15680,7 @@ impl Future for ConditionWaitCall { return Poll::Ready(Err(error)); } first_sequence.get_or_insert(sequence); + latest_timeout_seconds = timeout_seconds; if result == Some(ConditionWaitResult::TimedOut) { return Poll::Ready(Err(Error::NonDeterministicReplay(ReplayFailure::new( "condition_wait_reopened_after_timeout", @@ -15713,6 +15715,19 @@ impl Future for ConditionWaitCall { return Poll::Pending; } match (result, first_sequence) { + // A grouped (parallel or select) reopen keeps the authored + // timeout while the history does: the PHP Server accepts a + // grouped reopen only when its timeout equals both the original + // and the latest open (#189), so the remaining time would stall + // the run. A history that already recorded a shorter grouped + // reopen came from a Server that accepts them; keep its + // convention. + (None, Some(_)) + if !self.parallel_group_path.is_empty() + && latest_timeout_seconds == options.timeout_seconds => + { + None + } (None, Some(first_sequence)) => { // The logical wait stays open: its deadline is fixed at the // first physical open, not reset by a wake that left the @@ -24460,6 +24475,90 @@ mod tests { .collect() } + // #189: the PHP Server accepts a grouped reopen only with the authored + // timeout, so a parallel or select member reopens with it, not with the + // remaining time an ungrouped wait uses. + #[test] + fn grouped_condition_reopen_sends_the_authored_timeout() { + let fixture: Value = serde_json::from_str(include_str!( + "../tests/fixtures/replay-regressions/grouped-condition-physical-reopen.json" + )) + .expect("grouped condition fixture"); + let base = fixture["history"].as_array().expect("fixture history")[..2].to_vec(); + for mode in ["parallel", "select"] { + let mut history = base + .iter() + .map(|event| { + let mut payload = event["payload"].clone(); + if mode == "select" { + let index = payload["parallel_group_index"].as_u64().unwrap(); + payload["parallel_group_id"] = json!("select-calls:1:2"); + payload["parallel_group_mode"] = json!("select"); + payload["selection_member_key"] = + json!(if index == 0 { "timer" } else { "votes" }); + payload["selection_member_index"] = json!(index); + payload["selection_member_base_sequence"] = json!(index + 1); + payload["selection_member_size"] = json!(1); + payload["selection_member_kind"] = + json!(if index == 0 { "timer" } else { "condition" }); + } + if event["event_type"] == "ConditionWaitOpened" { + payload["timeout_seconds"] = json!(300); + } + timed_event( + event["event_type"].as_str().unwrap(), + "2026-11-04T02:36:05.000000+00:00", + payload, + ) + }) + .collect::>(); + history.push(approval_signal( + "vote", + "v1", + "2026-11-04T02:36:17.000000+00:00", + )); + let ctx = workflow_context(history); + let condition = ConditionWaitOptions::new("two-votes", "sha256:two-votes-v1") + .timeout(Duration::from_secs(300)); + let mut task_context = TaskContext::from_waker(noop_waker_ref()); + let poll = if mode == "parallel" { + let mut group = Box::pin(ctx.parallel(vec![ + ParallelOperation::timer(Duration::from_secs(300)), + ParallelOperation::condition(condition, || Ok(false)), + ])); + group + .as_mut() + .poll(&mut task_context) + .map(|result| result.map(|_| ())) + } else { + let mut group = Box::pin(ctx.select_keyed(vec![ + ("timer", ParallelOperation::timer(Duration::from_secs(300))), + ( + "votes", + ParallelOperation::condition(condition, || Ok(false)), + ), + ])); + group + .as_mut() + .poll(&mut task_context) + .map(|result| result.map(|_| ())) + }; + assert!(matches!(poll, Poll::Pending), "{mode}: {poll:?}"); + let commands = ctx.take_commands().expect("commands"); + let reopens = commands + .iter() + .filter(|command| command["type"] == "open_condition_wait") + .collect::>(); + assert_eq!(reopens.len(), 1, "{mode}: {commands:?}"); + assert_eq!( + reopens[0]["condition_wait_occurrence_id"], + json!("rust:condition-wait:0"), + "{mode}" + ); + assert_eq!(reopens[0]["timeout_seconds"], json!(300), "{mode}"); + } + } + // #187: a grouped reopen carries the remaining time, so the next task must // accept a smaller recorded timeout and still refuse a larger or missing one. #[test] diff --git a/tests/fixtures/replay-regressions/grouped-condition-false-wake-authored-timeout.json b/tests/fixtures/replay-regressions/grouped-condition-false-wake-authored-timeout.json new file mode 100644 index 0000000..3efbdf0 --- /dev/null +++ b/tests/fixtures/replay-regressions/grouped-condition-false-wake-authored-timeout.json @@ -0,0 +1,65 @@ +{ + "$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json", + "fixture_schema": "durable-workflow.replay-regression/v1", + "id": "rust-grouped-condition-false-wake-authored-timeout", + "protocol_version": "1.20", + "bindings": [ + "rust" + ], + "workflow": { + "type": "corpus.grouped-condition-timed-reopen", + "input": [], + "payload_codec": "avro" + }, + "history": [ + { + "event_type": "TimerScheduled", + "timestamp": "2026-11-04T02:36:05.000000+00:00", + "payload": { + "sequence": 1, + "timer_id": "timer-1", + "delay_seconds": 300, + "parallel_group_id": "parallel-calls:1:2", + "parallel_group_kind": "mixed", + "parallel_group_base_sequence": 1, + "parallel_group_size": 2, + "parallel_group_index": 0 + } + }, + { + "event_type": "ConditionWaitOpened", + "timestamp": "2026-11-04T02:36:05.000000+00:00", + "payload": { + "sequence": 2, + "condition_wait_id": "condition-2", + "condition_wait_occurrence_id": "rust:condition-wait:0", + "condition_key": "two-votes", + "condition_definition_fingerprint": "sha256:two-votes-v1", + "parallel_group_id": "parallel-calls:1:2", + "parallel_group_kind": "mixed", + "parallel_group_base_sequence": 1, + "parallel_group_size": 2, + "parallel_group_index": 1, + "timeout_seconds": 30 + } + }, + { + "event_type": "SignalReceived", + "timestamp": "2026-11-04T02:36:17.000000+00:00", + "payload": { + "signal_name": "vote", + "arguments": { + "codec": "avro", + "blob": "wwHioz3/VYAiNwwCCgZBZGEA" + } + } + } + ], + "expected": { + "type": "open_condition_wait", + "condition_wait_occurrence_id": "rust:condition-wait:0", + "condition_key": "two-votes", + "condition_definition_fingerprint": "sha256:two-votes-v1", + "timeout_seconds": 30 + } +} diff --git a/tests/fixtures/replay-regressions/selected-condition-false-wake-authored-timeout.json b/tests/fixtures/replay-regressions/selected-condition-false-wake-authored-timeout.json new file mode 100644 index 0000000..651ae92 --- /dev/null +++ b/tests/fixtures/replay-regressions/selected-condition-false-wake-authored-timeout.json @@ -0,0 +1,77 @@ +{ + "$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json", + "fixture_schema": "durable-workflow.replay-regression/v1", + "id": "rust-selected-condition-false-wake-authored-timeout", + "protocol_version": "1.20", + "bindings": [ + "rust" + ], + "workflow": { + "type": "corpus.selected-condition-timed-reopen", + "input": [], + "payload_codec": "avro" + }, + "history": [ + { + "event_type": "TimerScheduled", + "timestamp": "2026-11-04T02:36:05.000000+00:00", + "payload": { + "sequence": 1, + "timer_id": "timer-1", + "delay_seconds": 300, + "parallel_group_id": "select-calls:1:2", + "parallel_group_kind": "mixed", + "parallel_group_base_sequence": 1, + "parallel_group_size": 2, + "parallel_group_index": 0, + "parallel_group_mode": "select", + "selection_member_key": "timer", + "selection_member_index": 0, + "selection_member_base_sequence": 1, + "selection_member_size": 1, + "selection_member_kind": "timer" + } + }, + { + "event_type": "ConditionWaitOpened", + "timestamp": "2026-11-04T02:36:05.000000+00:00", + "payload": { + "sequence": 2, + "condition_wait_id": "condition-2", + "condition_wait_occurrence_id": "rust:condition-wait:0", + "condition_key": "two-votes", + "condition_definition_fingerprint": "sha256:two-votes-v1", + "parallel_group_id": "select-calls:1:2", + "parallel_group_kind": "mixed", + "parallel_group_base_sequence": 1, + "parallel_group_size": 2, + "parallel_group_index": 1, + "parallel_group_mode": "select", + "selection_member_key": "votes", + "selection_member_index": 1, + "selection_member_base_sequence": 2, + "selection_member_size": 1, + "selection_member_kind": "condition", + "timeout_seconds": 30 + } + }, + { + "event_type": "SignalReceived", + "timestamp": "2026-11-04T02:36:17.000000+00:00", + "payload": { + "signal_name": "vote", + "arguments": { + "codec": "avro", + "blob": "wwHioz3/VYAiNwwCCgZBZGEA" + } + } + } + ], + "expected": { + "type": "open_condition_wait", + "condition_wait_occurrence_id": "rust:condition-wait:0", + "condition_key": "two-votes", + "condition_definition_fingerprint": "sha256:two-votes-v1", + "timeout_seconds": 30 + } +} diff --git a/tests/replay_regression_corpus.rs b/tests/replay_regression_corpus.rs index aff54d5..3cf4d7a 100644 --- a/tests/replay_regression_corpus.rs +++ b/tests/replay_regression_corpus.rs @@ -482,6 +482,7 @@ async fn execute_fixture_delivery(fixture: &Value, delivery_id: &str) -> Result< | "corpus.condition-search-adjacent" | "corpus.grouped-condition-reopen" | "corpus.grouped-condition-timed-reopen" + | "corpus.selected-condition-timed-reopen" | "corpus.cancellation-remaining-condition" | "corpus.durable-selection" | "corpus.durable-selection-portable-affinity" @@ -780,6 +781,23 @@ async fn execute_fixture_delivery(fixture: &Value, delivery_id: &str) -> Result< Ok(json!(context.remaining()?.as_secs_f64())) }); } + "corpus.selected-condition-timed-reopen" => { + worker.register_workflow(workflow_type, |ctx, _| async move { + ctx.select_keyed(vec![ + ("timer", ParallelOperation::timer(Duration::from_secs(300))), + ( + "votes", + ParallelOperation::condition( + ConditionWaitOptions::new("two-votes", "sha256:two-votes-v1") + .timeout(Duration::from_secs(30)), + || Ok(false), + ), + ), + ]) + .await?; + Ok(Value::Null) + }); + } "corpus.grouped-condition-timed-reopen" => { worker.register_workflow(workflow_type, |ctx, _| async move { ctx.parallel(vec![