Skip to content

fix(swarm): release stale task owners on terminal states - #4272

Merged
ruvnet merged 1 commit into
ruvnet:mainfrom
Tong-bit-art:fix/terminal-task-stale-owners
Oct 19, 2026
Merged

ruvnet merged 1 commit into
ruvnet:mainfrom
Tong-bit-art:fix/terminal-task-stale-owners

Conversation

@Tong-bit-art

Copy link
Copy Markdown
Contributor

Problem and change

assignTaskToDomain() can leave a task with two AgentState owners. #4245 deliberately keeps the previous generic owner busy when a task is retargeted to another domain because the retarget does not prove that worker stopped executing; its regression test asserts both agents are busy with currentTask pointing at the same task.

The terminal handlers only cleared one side:

  • handleTaskComplete() cleared and released the reporting agent;
  • handleTaskFail()'s terminal branch cleared and released the reporting agent;
  • cancelTask() cleared and released task.assignedTo.

The other owner kept currentTask === taskId forever. It stayed busy, its domain-pool slot stayed reserved, and the shared reservation could never be resolved even though the task was already completed/failed/cancelled.

Change: add a private releaseStaleTaskOwners(taskId, exceptAgentId?) that runs after a task reaches a terminal state and clears + releases every other agent whose currentTask still points at that task. The reporting (or assignedTo) agent remains handled by the existing path; retries are deliberately untouched because the task is still live and another owner may still be executing it.

This completes the multi-owner model introduced by #4245 without changing retargeting semantics.

Validation

  • 3 new regressions in v3/@claude-flow/swarm/__tests__/terminal-task-stale-owners.test.ts:
    • completion from the second owner releases the first;
    • cancellation releases the non-assigned owner;
    • terminal failure releases the non-reporting owner.
  • Against main b93144803: 3/3 fail (the non-reporting owner stays busy with currentTask === taskId).
  • Candidate: 3/3 pass; full @claude-flow/swarm suite 335/335, 28/28 files; tsc --noEmit 0 errors; git diff --check clean.
  • Root v3 vitest config also collects and passes the new file (3/3).

Scope / known limitations

Compatibility

  • The helper is private and only touches AgentState/existing domain release paths.
  • Non-domain agents are cleared and become generically available; domain agents are released through releaseDomainAgent() and their pool state self-heals through reconcileReservations().
  • No dependency, lockfile or persistence-format changes.

assignTaskToDomain() can leave two AgentState owners after retargeting (ruvnet#4245 keeps the previous owner busy until a terminal report). The terminal handlers only cleared the reporting or assignedTo agent, leaving the other owner busy with currentTask === taskId forever. Clear and release every remaining owner once the task is completed, terminally failed or cancelled.
@Tong-bit-art
Tong-bit-art requested a review from ruvnet as a code owner October 18, 2026 07:14
@ruvnet
ruvnet merged commit d83c61c into ruvnet:main Oct 19, 2026
110 checks passed
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