Skip to content

feat(queen): Implement real daemonize for tri queen start #428

@gHashTag

Description

@gHashTag

Problem

tri queen start --daemon is a stub — it prints messages but doesn't actually daemonize. This causes a restart loop when supervisor scripts try to run it.

Current State

// src/queen/queen_trinity.zig:304-316
fn runQueenStart(allocator: Allocator, args: []const []const u8) !void {
    if (daemon_mode) {
        std.debug.print("👑 Queen starting in daemon mode...\n", .{});
        std.debug.print("   Daemon mode: Running (background)\n", .{});
    }
    // Function exits — no actual daemonize!
}

Result: 20,000+ lines in launcher.err showing restart loop.

Requirements

  1. fork() + detach — proper Unix daemon pattern
  2. PID file — write to .trinity/queen/queen.pid
  3. Signal handling — SIGTERM for graceful shutdown
  4. Stdio redirection — stdout/stderr → launcher.log
  5. Idempotency — check if already running, don't duplicate

Implementation Plan

  1. Add std.posix.fork() with double-fork pattern
  2. Write PID file on successful daemonize
  3. Setup signal handlers (SIGTERM, SIGINT)
  4. Redirect stdio to log file
  5. Add tri queen stop command (read PID, send SIGTERM)

Success Criteria

  • tri queen start --daemon returns immediately
  • Queen process runs in background
  • ps aux | grep queen shows running daemon
  • tri queen stop gracefully terminates
  • No restart loop in launcher.err

References

  • Queen state: .trinity/queen_state.json
  • Doctor binary: ./zig-out/bin/queens doctor

φ² + 1/φ² = 3 = TRINITY

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions