Skip to content

fix(swarm): keep coordinator cancellation terminal - #4244

Merged
ruvnet merged 1 commit into
ruvnet:mainfrom
rudycelekli:fix/swarm-cancel-terminal-20261016
Oct 17, 2026
Merged

ruvnet merged 1 commit into
ruvnet:mainfrom
rudycelekli:fix/swarm-cancel-terminal-20261016

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Problem and change

UnifiedSwarmCoordinator.cancelTask() sent a task_fail notification to its assigned agent's bus subscription. That subscription interpreted the notification as a worker failure report and retried the task after cancellation returned. With no retries remaining, cancellation instead became a failure and incremented failure counters. Cancelling the old task again could also release an agent already assigned to new work.

Set the cancellation state before yielding to the bus, make cancellation of settled tasks idempotent, and ignore completion/failure reports for cancelled, completed, or failed tasks. This preserves the cancelled verdict and prevents duplicate completion accounting.

Validation

  • Against main 1882006a02487590c8c66a7eec8d7504f6af33c3, the eight-case regression suite has 6 failures / 2 passes. Candidate: 8/8 pass.
  • Three initial reproductions use only public coordinator methods and event-loop turns. Additional tests exercise real MessageBus report delivery, ordinary failure retries, duplicate completion, and both late-report and explicit-cancel cleanup after existing wait timeouts.
  • 285/285 tests pass across all 19 swarm package test files using its checked-in Vitest configuration. Running from the repository root initially used a shorter default test timeout; rerunning through the package configuration resolves those timing failures.
  • Independent review reran 38/38 coordination tests and verified the timeout cleanup controls.
  • Full swarm package TypeScript build, strict targeted typecheck, and compiled-JavaScript public API smoke pass; git diff --check passes.

This fixes the canonical coordinator's cancellation lifecycle. Existing wait-timeout behavior remains unchanged: a wait timeout does not stop a worker, and late reports can still clean up that assignment. No new dependency or public method is introduced.

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
@rudycelekli
rudycelekli requested a review from ruvnet as a code owner October 17, 2026 03:49
@ruvnet
ruvnet merged commit 8b95c5e into ruvnet:main Oct 17, 2026
110 checks passed
ruvnet added a commit to Tong-bit-art/ruflo that referenced this pull request Oct 17, 2026
…lict

unified-coordinator.ts conflicted in three spots: ruvnet#4244 (already on
main) replaced the "capture task.status in a wasTerminal var, mutate
unconditionally" pattern with an upfront `!isTaskSettled(task)` guard
that skips the whole handler body for an already-settled task (fixing
a double-processing bug the old pattern had: duplicate metric
increments and duplicate emitted events for a late/duplicate message).

This PR's `wasTerminal` captures were reading task.status at a point
where main's guard already guarantees non-terminal, so they were
always false/true trivially. Resolution: keep main's guard/fencing
behavior as-is, drop the now-redundant `wasTerminal` variable, and
make the `releaseDomainAgent` calls unconditional within the
already-guarded block — preserving this PR's domain-pool-release fix
without reintroducing the double-processing bug ruvnet#4244 fixed.

Verified: full @claude-flow/swarm test suite (26 files, 321 tests)
passes, including coordinator.cancellation.test.ts and
domain-pool-agent-release.test.ts from both lineages.

Co-Authored-By: RuFlo <ruv@ruv.net>
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.

2 participants