Joining and Moving Parallel Agent Work

Lesson 2 of 4

A Failed Branch Is a Result

Estimated time: 10 minutes

A failed branch is a result

When a fan-out branch fails, the easy move is to treat the whole join as failed and throw the run away. That discards the work of every branch that did answer and hides which branch caused the failure, so the next attempt repeats the same mistake.

Report a branch, do not raise it

A branch reports what happened, including failure, instead of raising into the coordinator. The coordinator then holds the full picture: which branches answered, which failed, and which are still running.

Decide once, with the report in hand

A decision can still be made with a branch missing, as long as the missing branch is named alongside the result. A result that says two of five branches failed and names them can be judged, while a result that only says the run failed cannot.

def join(reports):
    answered = [r for r in reports if r["ok"]]
    failed = [r for r in reports if not r["ok"]]
    return {"answered": len(answered),
            "failed": [r["branch"] for r in failed]}

Retry the branch on its own

A branch that failed on a passing cause can be retried without rerunning the others. Retrying the whole fan-out repeats the work of every branch that already succeeded, and repeats any effect they caused.

Keep the named branch in the record

The name of the failed branch belongs in the result, because that is what makes a follow-up possible. A count of failures with no names cannot be acted on.