Skip to content

fix(teams): a lost worker's run is never retried, whichever path sees it first (#394) - #522

Merged
mkluiver merged 1 commit into
mainfrom
fix/394-termination-races
Nov 26, 2026
Merged

mkluiver merged 1 commit into
mainfrom
fix/394-termination-races

Conversation

@mblaauw

@mblaauw mblaauw commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Closes #394.

Summary

Two races in worker termination handling (#343):

  1. "Fail without retry" was not durable. The reaper, lease reaper or launch poller failed
    the execution in one transaction and closed the team run without retry later, in the
    best-effort report_ended_execution. The 2-second team-run loop usually saw the failed
    execution first and closed the queue item with a retry, and an API restart between the
    two had the same result. The decision is now read from the stored execution error:

  2. fail_worker_executions fabricated a failure on finish_execution -> Ok(None): it
    cloned the stale record as failed, published it, failed the team step and wrote the
    worker.* audit entry, even when the execution had succeeded or a concurrent refresh
    had already reported it. It now skips executions it did not end; item 1 makes the
    "still close the team run" fallback unnecessary.

Tests: a_lost_worker_run_is_not_retried_when_the_team_poller_sees_it_first (four codes
plus a harness_error control that keeps its retry), the_outcome_reconciler_does_not_ retry_a_lost_worker_run (restart between failing the run and closing its item), and
overlapping_launch_refreshes_report_only_the_failure_they_caused (two concurrent
refreshes plus a late succeeded, eight rounds: succeeded -> no event, audit or failed
run; failed -> exactly one of each). All three fail with the fix reverted. Unit test for
the code list.

Testing

  • cargo fmt --check, clippy --workspace --all-targets -D warnings: clean
  • cargo test --workspace --no-fail-fast on a fresh database: 771 passed, 0 failed
  • New, each failing with the fix reverted: a_lost_worker_run_is_not_retried_when_the_team_poller_sees_it_first (three no-retry codes plus a harness_error control that keeps its retry), the_outcome_reconciler_does_not_retry_a_lost_worker_run (restart between failing the run and closing the queue item), overlapping_launch_refreshes_report_only_the_failure_they_caused (two concurrent refreshes plus a late succeeded, eight rounds; a race test, it caught the old bug in 1 of 2 runs with the fix reverted); unit ended_without_retry_tests
  • pnpm docs:check: passed

No migration: the no-retry decision is read from the stored executions (executions_team_run_idx), so it survives restarts. worker_did_not_start keeps its retry, matching #501. scripts/smoke-worker-termination.sh not run (no cluster). git merge-tree is clean against every open PR that shares a file (#499, #501, #502, #504, #505, #507, #510, #515, #516, #517).

🤖 Generated with Claude Code

… it first (#394)

Two races in worker termination handling (#343):

1. "Fail without retry" was not durable. The reaper, lease reaper or launch poller failed
   the execution in one transaction and closed the team run without retry later, in the
   best-effort `report_ended_execution`. The 2-second team-run loop usually saw the failed
   execution first and closed the queue item with a retry, and an API restart between the
   two had the same result. The decision is now read from the stored execution error:
   - new `Store::team_run_execution_failed_with(run_id, codes)` finds a failed execution
     of the run whose error code is in `ended_without_retry_codes()` (worker_lost,
     worker_oom, worker_evicted, worker_exited, harness_unresponsive; not
     worker_did_not_start, which ran nothing and keeps its retry, also after #399);
   - `close_queue_loop` never offers a retry for such a run, so the team-run loop, the
     outcome reconciler and the platform path all close it the same way;
   - `advance_claimed` routes such a run through `fail_team_run_for_execution` first, so a
     workflow does not follow a "failed" line past that step.

2. `fail_worker_executions` fabricated a failure on `finish_execution -> Ok(None)`: it
   cloned the stale record as `failed`, published it, failed the team step and wrote the
   `worker.*` audit entry, even when the execution had succeeded or a concurrent refresh
   had already reported it. It now skips executions it did not end; item 1 makes the
   "still close the team run" fallback unnecessary.

Tests: `a_lost_worker_run_is_not_retried_when_the_team_poller_sees_it_first` (four codes
plus a harness_error control that keeps its retry), `the_outcome_reconciler_does_not_
retry_a_lost_worker_run` (restart between failing the run and closing its item), and
`overlapping_launch_refreshes_report_only_the_failure_they_caused` (two concurrent
refreshes plus a late `succeeded`, eight rounds: succeeded -> no event, audit or failed
run; failed -> exactly one of each). All three fail with the fix reverted. Unit test for
the code list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkluiver
mkluiver merged commit a7f7c35 into main Nov 26, 2026
15 checks passed
mkluiver added a commit that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worker termination: "fail without retry" loses to the team poller, and terminated-launch handling reports failures for executions it did not fail

2 participants