豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Hive-mind worker tracking is non-functional: task lifecycle never syncs agent state #1392

@clement-livdeo

Description

@clement-livdeo

Related

Follow-up to #1391 (wrong MCP tool prefix in hive-mind prompt). This issue covers the underlying tracking pipeline that makes workers permanently show idle with 0 completed tasks.

Summary

When using hive-mind spawn --claude, the spawned queen is instructed to coordinate virtual workers via task tools. However, nothing connects the task system to the agent system:

  1. task_assign writes agent IDs to tasks/store.json but never updates agents.json → workers stay idle forever, currentTask stays null
  2. task_complete marks the task done but never increments the worker's taskCountCompleted column in rf-status stays at 0
  3. hive-mind_status reports queen.load as 0.3 + Math.random() * 0.4 (line 266 of hive-mind-tools.js) — a random number, not derived from actual task state
  4. queen.tasksQueued reads from consensus.pending.length instead of pending tasks

The result: hive-mind status always shows all workers as idle / 0 completed regardless of actual work done, and queen load is random noise.

Version

ruflo v3.5.41

Steps to Reproduce

ruflo hive-mind init -t hierarchical-mesh
ruflo hive-mind spawn -n 3
# Use MCP tools:
# 1. task_create → get taskId
# 2. task_assign(taskId, [workerId])
# 3. task_complete(taskId)
# 4. Check: ruflo hive-mind status

Expected Behavior

After task_assign, the assigned worker should show status: active and currentTask: <taskId>. After task_complete, the worker should return to idle with taskCount incremented. Queen load should reflect active tasks / worker count.

Actual Behavior

Workers permanently show idle, Completed: 0, Current Task: -. Queen load is Math.random().

Root Cause

task-tools.ts and hive-mind-tools.ts operate on separate JSON files (tasks/store.json vs agents.json) with zero cross-references:

  • task_assign handler (task-tools.ts ~L279-300): writes task.assignedTo = agentIds, saves task store. Does NOT touch agent store.
  • task_complete handler (task-tools.ts ~L194-216): sets task.status = 'completed', saves task store. Does NOT update agent taskCount or status.
  • hive-mind_status handler (hive-mind-tools.ts ~L266): load: 0.3 + Math.random() * 0.4

The v2 codebase (v2/src/hive-mind/core/HiveMind.ts) had EventEmitter-based lifecycle events, a SwarmOrchestrator, and auto-assignment. The v3 rewrite replaced this with flat JSON CRUD that lost the cross-system linkage.

Suggested Fix

task_assign handler — sync agent state on assignment

When a task is assigned to workers:

  • Set agent.status = 'active' and agent.currentTask = taskId in agents.json
  • Auto-transition task to in_progress if it was pending
  • On unassign: revert worker to idle

task_complete handler — sync agent state on completion

When a task completes:

  • Set assigned agents back to status: 'idle', currentTask: null
  • Increment agent.taskCount

hive-mind_status handler — real metrics

Replace:

load: 0.3 + Math.random() * 0.4
tasksQueued: state.consensus.pending.length

With:

load: activeTaskCount / Math.max(1, workerCount)
tasksQueued: pendingTaskCount  // from tasks/store.json

Prompt — explicit lifecycle instructions

The queen prompt (generateHiveMindPrompt()) should explicitly instruct: task_create → task_assign(workerId) → [do work] → task_complete for every subtask, with round-robin worker selection.

Files to Fix

  • v3/@claude-flow/cli/src/mcp-tools/task-tools.tstask_assign and task_complete handlers
  • v3/@claude-flow/cli/src/mcp-tools/hive-mind-tools.tshive-mind_status handler (line ~266)
  • v3/@claude-flow/cli/src/commands/hive-mind.tsgenerateHiveMindPrompt() execution protocol

Local Patch Verified

I've patched all three files locally on v3.5.41 and verified the full cycle works:

  • task_assign → worker goes active, shows currentTask
  • task_complete → worker returns idle, Completed increments
  • Queen load shows real ratio (e.g., 33.3% = 1 active task / 3 workers)

Happy to submit a PR if the approach is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions