feat: implement work heartbeat service for health checks and task dispatching

- Introduced a new heartbeat service that runs at defined intervals to perform health checks on workers and fill available task slots based on priority.
- Added a health tool to scan worker health across projects with optional auto-fix capabilities.
- Updated the status tool to provide a lightweight overview of worker states and queue counts without health checks.
- Enhanced task creation tool descriptions to clarify task state handling.
- Implemented tests for the work heartbeat logic, ensuring proper project resolution, worker state management, and task prioritization.
This commit is contained in:
Lauren ten Hoor
2026-02-11 01:04:30 +08:00
parent 71a3ea2352
commit f2e71a35d8
13 changed files with 1044 additions and 426 deletions

View File

@@ -26,7 +26,7 @@ Read the comments carefully — they often contain clarifications, decisions, or
- Clean up the worktree after merging
- When done, call work_finish with role "dev", result "done", and a brief summary
- If you discover unrelated bugs, call task_create to file them
- Do NOT call work_start, status, or project_register
- Do NOT call work_start, status, health, work_heartbeat, or project_register
`;
export const DEFAULT_QA_INSTRUCTIONS = `# QA Worker Instructions
@@ -41,7 +41,7 @@ export const DEFAULT_QA_INSTRUCTIONS = `# QA Worker Instructions
- result "fail" with specific issues if problems found
- result "refine" if you need human input to decide
- If you discover unrelated bugs, call task_create to file them
- Do NOT call work_start, status, or project_register
- Do NOT call work_start, status, health, work_heartbeat, or project_register
`;
export const AGENTS_MD_TEMPLATE = `# AGENTS.md - Development Orchestration (DevClaw)
@@ -82,7 +82,7 @@ If you discover unrelated bugs or needed improvements during your work, call \`t
### Tools You Should NOT Use
These are orchestrator-only tools. Do not call them:
- \`work_start\`, \`status\`, \`auto_pickup\`, \`project_register\`
- \`work_start\`, \`status\`, \`health\`, \`work_heartbeat\`, \`project_register\`
---
@@ -99,7 +99,8 @@ All orchestration goes through these tools. You do NOT manually manage sessions,
| \`project_register\` | One-time project setup: creates labels, scaffolds role files, adds to projects.json |
| \`task_create\` | Create issues from chat (bugs, features, tasks) |
| \`task_update\` | Update issue title, description, or labels |
| \`status\` | Scans issue queue + worker state + health checks |
| \`status\` | Task queue and worker state per project (lightweight dashboard) |
| \`health\` | Scan worker health: zombies, stale workers, orphaned state. Pass fix=true to auto-fix |
| \`work_start\` | End-to-end: label transition, tier assignment, session create/reuse, dispatch with role instructions |
| \`work_finish\` | End-to-end: label transition, state update, issue close/reopen. Auto-ticks queue after completion. |
@@ -149,7 +150,7 @@ Workers receive role-specific instructions appended to their task message. These
### Heartbeats
On heartbeat, call \`auto_pickup\` — it runs health checks and picks up available work automatically.
**Do nothing.** The \`work_heartbeat\` service runs automatically as an internal interval-based process — zero LLM tokens. It handles health checks (zombie detection, stale workers) and queue dispatch (filling free worker slots by priority) every 60 seconds by default. Configure via \`plugins.entries.devclaw.config.work_heartbeat\` in openclaw.json.
### Safety
@@ -161,15 +162,5 @@ On heartbeat, call \`auto_pickup\` — it runs health checks and picks up availa
export const HEARTBEAT_MD_TEMPLATE = `# HEARTBEAT.md
On each heartbeat, call \`auto_pickup\` (no parameters needed for a full sweep).
It will automatically:
1. Run health checks (zombie workers, stale sessions)
2. Scan queues across all projects
3. Pick up available work by priority: To Improve > To Test > To Do
4. Choose appropriate developer tier based on task complexity
If you want to target a single project, pass \`projectGroupId\`.
If nothing needs attention, it reports HEARTBEAT_OK.
Do nothing. An internal token-free \`work_heartbeat\` service handles health checks and queue dispatch automatically.
`;