daemon-health-check
Skill22 starsChanged 11 months agoApache-2.0View on GitHub
Design and implement health check, doctor command, and reconciliation logic for the daemon
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- daemon-debugSkill
- flake-triageSkill
- messaging-queueSkill
- searchSkill
- security-boundary-reviewSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill when implementing or modifying health check, reconciliation, or doctor functionality.
- Distinctive: line 40
Update daemon cache to match reality
- Distinctive: line 46
CRITICAL: Never kill a process that is producing output, even error output.
- Distinctive: line 49
No stdout/stderr output for stall threshold (default 120s)
- Distinctive: line 100
When implementing health check:
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Daemon Health Check & Doctor
Use this skill when implementing or modifying health check, reconciliation, or doctor functionality.
Reconciliation Algorithm
The daemon's in-memory state is a cache. Reconciliation verifies it against OS truth and fixes mismatches.
Step 1: Gather Expected State
- Parse
.agnt.kdlfor all projects with running scripts - Build expected set:
{script → process, proxy → target, port → owner}
Step 2: Gather Actual State (OS Truth)
Cross-platform requirement — every probe must go through internal/platform/:
| Probe | Linux/macOS | Windows | WSL |
| PID alive | kill(pid, 0) or /proc/<pid> | OpenProcess | kill(pid, 0), cmd.exe for Windows-spawned |
| Port owner | ss -tlnp / lsof -i | netstat -ano | ss for Linux, netstat.exe for Windows |
| Proxy health | TCP connect / HTTP GET | Same | Same |
Step 3: Diff Expected vs Actual
| Finding | State update | Event |
| Process in daemon but PID dead | Mark Dead | Emit ScriptStopped |
| Port in use but not by our process | Flag rogue | Record PID in warning |
| Proxy in daemon but not responding | Mark unhealthy | Emit warning |
| Config expects proxy but none exists | Attempt fallback-port | Emit warning if no fallback |
| Process running, no URL detected, has fallback-port | Create proxy via fallback | Log proxy creation |
| Process producing error output | Mark Running With Errors | Surface to AI agent |
Step 4: Reconcile
- Update daemon cache to match reality
- Emit events for each state change
- Return diff report (for doctor command)
Stall Detection
CRITICAL: Never kill a process that is producing output, even error output.
A process is stalled ONLY when ALL are true:
- No stdout/stderr output for stall threshold (default 120s)
- AlertScanner has no recent classifications
- Process is not in Starting state
Error output IS activity:
- AlertScanner classifies: compile errors, panics, exceptions
- Recent alerts → "Running With Errors", not stalled
- "Running With Errors" → surface to AI agent for code fixes, NEVER kill
Stall detection is disabled during shutdown.
Doctor Command
MCP tool doctor (or action in overlay panel):
Input
{"action": "doctor", "project_path": "/optional/filter"}Output Format (compact)
=== Doctor Report ===
HEALTHY (2)
backend (pid 12345): running, port 6111 ✓, proxy api ✓
frontend (pid 12346): running, port 6112 ✓, proxy web ✓
WARNINGS (1)
api proxy: created via fallback-port (URL detection failed)
ERRORS (1)
deck:dev (pid 0): dead, port 5173 held by rogue process (pid 34954)
→ action: kill rogue and restart, or skip
ACTIONS AVAILABLE
[1] Kill rogue process on port 5173 and restart deck:dev
[2] Create missing proxy for backend using fallback-port 6111Output Format (raw JSON)
Full structured report with all fields for programmatic consumption.
Three Reconciliation Triggers
- On session connect: Full check before first query response. AI agent must receive verified state.
- Periodic (30s): Background check, emits events only. No developer output.
- Doctor command: Developer-initiated, returns full report with offered actions.
Implementation Checklist
When implementing health check:
- Create platform-specific PID probe in
internal/platform/ - Create platform-specific port ownership probe in
internal/platform/ - Create proxy health probe (TCP connect with timeout)
- Implement reconciliation loop in
internal/daemon/ - Wire periodic check into daemon startup (configurable interval)
- Wire on-connect check into session registration
- Implement doctor MCP tool in
internal/tools/ - Integrate AlertScanner classifications into stall detection
- Implement fallback-port proxy creation in reconciliation
- Add tests for each platform path
- Add tests for stall vs error distinction
- Add e2e test: script running with errors is NOT killed
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

