Skip to content

feat(queen): Add proper daemon supervisor with PID tracking #430

@gHashTag

Description

@gHashTag

Problem

Queen daemon lacks proper supervision — no heartbeat monitoring, auto-restart, or health tracking.

Requirements

  1. PID trackingqueen.pid file with process lifecycle
  2. Health monitor — periodic heartbeat checks
  3. Auto-restart — restart on crash (with backoff)
  4. Graceful shutdown — SIGTERM handling with cleanup
  5. Status commandtri queen status shows real state

Implementation Plan

Phase 1: PID File

// .trinity/queen/queen.pid
{
  "pid": 12345,
  "started_at": 1773945606,
  "heartbeat": 1774273571
}

Phase 2: Monitor Loop

  • Read PID file every 30s
  • Check if process exists (kill -0)
  • If dead: log, wait, restart (exponential backoff)

Phase 3: Signal Handling

  • SIGTERM: graceful shutdown (save state, close connections)
  • SIGINT: same as SIGTERM
  • SIGHUP: reload config

Phase 4: Status Command

tri queen status
# → Running: ✓ | PID: 12345 | Uptime: 3d 2h | Heartbeat: 5s ago

Success Criteria

  • PID file created on start, removed on exit
  • Monitor detects dead Queen within 30s
  • Auto-restart with max 3 retries/hour
  • tri queen status shows accurate info
  • Graceful shutdown saves state

References

  • Doctor: ./zig-out/bin/queens doctor
  • State: .trinity/queen_state.json

φ² + 1/φ² = 3 = TRINITY

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions