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
11 changes: 10 additions & 1 deletion rust/src/runtime/all_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ pub(super) const POLICY: &str = "parallel_group_policy";
/// The explicit policies native records and runs. A known policy outside
/// this list is refused at admission, before any write, until its runtime
/// behavior is implemented here; it is never recorded as a legacy group.
pub(super) const ADMITTED_POLICIES: &[&str] = &["propagate"];
/// `propagate` keeps the fail-fast wake. `settle` wakes the workflow once
/// every member has an outcome, whatever it is.
pub(super) const ADMITTED_POLICIES: &[&str] = &["propagate", "settle"];

/// Whether a member's path contains a `settle` group: its failure does not
/// wake the workflow until every member of that group has an outcome.
pub(super) fn settles(metadata: &Value) -> bool {
metadata["parallel_group_path"].as_array()
.is_some_and(|path| path.iter().any(|group| group[POLICY] == "settle"))
}

pub(super) fn invalid() -> super::RuntimeError {
refuse(
Expand Down
5 changes: 3 additions & 2 deletions rust/src/runtime/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,9 @@ where
let event_id = Self::append_returning(tx, &parent_run, event_type, payload, None, None).await?;
// Record the outcome even while the all barrier remains closed. The
// last successful member observes every committed call under the same
// parent transition lock; any failed member wakes the parent at once.
if matches!(resolution, ChildResolution::Completed(_))
// parent transition lock; any failed member wakes the parent at once,
// except in a `settle` group, which waits for every outcome.
if (matches!(resolution, ChildResolution::Completed(_)) || super::all_groups::settles(&parallel))
&& !Self::all_groups_closed(tx, &parent_run, &parallel).await?
{
if let Some(previous_sequence) = previous_sequence {
Expand Down
23 changes: 17 additions & 6 deletions rust/src/runtime/selections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ where
/// published PHP's `ParallelChildGroup::shouldWakeParentOnClosure` would
/// not: a successful close inside an all-of group waits until every
/// member of every enclosing group has closed successfully. A failed
/// member wakes it at once. Selections resolve their own winner.
/// member wakes it at once, except inside a `settle` group (.github#232),
/// which waits until every member has an outcome. Selections resolve
/// their own winner.
pub(super) async fn selection_resume(
tx: &mut Transaction<'_, DB>,
run_id: &str,
Expand All @@ -629,7 +631,9 @@ where
successful: bool,
) -> Result<Option<String>> {
if metadata.get("parallel_group_id").is_some() {
if successful && !is_selection(metadata) && !Self::all_groups_closed(tx, run_id, metadata).await? {
if (successful || super::all_groups::settles(metadata))
&& !is_selection(metadata) && !Self::all_groups_closed(tx, run_id, metadata).await?
{
return Ok(None);
}
// A leased worker may be replaying an older history snapshot.
Expand All @@ -646,7 +650,9 @@ where

/// `groupCompletedSuccessfully` for each all-of group on a member's path:
/// Every authored member has completed. A retried child or a reopened
/// condition retains its original position in the barrier.
/// condition retains its original position in the barrier. A `settle`
/// group (.github#232) closes once every member has any outcome; a
/// retrying member has none yet.
pub(super) async fn all_groups_closed(
tx: &mut Transaction<'_, DB>,
run_id: &str,
Expand All @@ -664,6 +670,7 @@ where
return Ok(true);
};
let last = base + size - 1;
let settled = group[super::all_groups::POLICY] == "settle";
if group["parallel_group_kind"] == "child" {
// Use the open-wait index to get a hint, then confirm the
// authored sequence and status against the authoritative call.
Expand All @@ -687,22 +694,26 @@ where
}
}
let mut closed = std::collections::BTreeSet::new();
for (sql, done) in [
for (sql, done, outcome) in [
(
"SELECT sequence,status FROM workflow_run_timers WHERE workflow_run_id=$1 AND sequence>=$2 AND sequence<=$3",
"fired",
&["fired", "cancelled"][..],
),
(
"SELECT sequence,status FROM activity_executions WHERE workflow_run_id=$1 AND sequence>=$2 AND sequence<=$3",
"completed",
&["completed", "failed", "cancelled"][..],
),
(
"SELECT sequence,status FROM workflow_child_calls WHERE parent_workflow_run_id=$1 AND sequence>=$2 AND sequence<=$3",
"completed",
&["completed", "failed", "cancelled", "terminated"][..],
),
] {
for row in Self::query(sql).bind(run_id).bind(base).bind(last).fetch_all(&mut **tx).await? {
if DB::string(&row, "status")? == done {
let status = DB::string(&row, "status")?;
if status == done || settled && outcome.contains(&status.as_str()) {
closed.insert(DB::number(&row, "sequence")?);
}
}
Expand All @@ -721,7 +732,7 @@ where
else { continue };
if let Some(index) = member["parallel_group_index"].as_i64().filter(|index| (0..size).contains(index)) {
let position = base + index;
if positions.insert(position) && wait.completed_successfully() {
if positions.insert(position) && (wait.completed_successfully() || settled && !wait.is_open()) {
closed.insert(position);
}
}
Expand Down
Loading