Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

Add daemon process management infrastructure:

  • DaemonError: TaggedError for daemon failures
  • DaemonState: running, stopped, starting, stopping
  • DaemonOptions: PID file, signal handlers, cleanup hooks
  • Daemon interface: start, stop, status, isRunning
  • createDaemon() factory with PID file management
  • Graceful signal handling (SIGTERM, SIGINT)

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Contributes to #56

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Adds the @outfitter/daemon package implementing daemon lifecycle management with PID file handling, signal processing, and graceful shutdown capabilities
  • Introduces comprehensive type system with DaemonError using TaggedError pattern, DaemonState enum for process states, and interfaces for daemon configuration and control
  • Implements createDaemon() factory function with finite state machine, re-entry protection during shutdown, and integration with existing foundation packages

Important Files Changed

Filename Overview
packages/daemon/src/lifecycle.ts New daemon implementation with PID file management, signal handling, and graceful shutdown with timeout protection
packages/daemon/src/types.ts New comprehensive type definitions including DaemonError, DaemonState enum, and daemon interfaces

Confidence score: 4/5

  • This PR introduces well-structured daemon lifecycle management with proper error handling and follows established repository patterns
  • Score reflects solid implementation but potential complexity in concurrent shutdown scenarios and signal handler cleanup timing
  • Pay close attention to packages/daemon/src/lifecycle.ts for shutdown re-entry logic and signal handler management

Sequence Diagram

sequenceDiagram
    participant User
    participant Daemon
    participant PIDFile as "PID File System"
    participant SignalHandler as "Signal Handler"
    participant ShutdownHandler as "Shutdown Handler"

    User->>Daemon: "start()"
    Daemon->>Daemon: "Check if already running"
    Daemon->>PIDFile: "Check if PID file exists"
    PIDFile-->>Daemon: "File status"
    Daemon->>PIDFile: "Write PID file"
    PIDFile-->>Daemon: "Success"
    Daemon->>SignalHandler: "Register SIGTERM/SIGINT handlers"
    SignalHandler-->>Daemon: "Handlers registered"
    Daemon-->>User: "Result.ok()"

    Note over Daemon: Daemon is now running

    User->>Daemon: "onShutdown(handler)"
    Daemon->>Daemon: "Add to shutdown handlers list"

    SignalHandler->>Daemon: "SIGTERM/SIGINT received"
    Daemon->>Daemon: "Set state to stopping"
    Daemon->>ShutdownHandler: "Run all registered handlers"
    ShutdownHandler-->>Daemon: "Handlers completed"
    Daemon->>SignalHandler: "Remove signal handlers"
    Daemon->>PIDFile: "Remove PID file"
    PIDFile-->>Daemon: "File removed"
    Daemon->>Daemon: "Set state to stopped"

    User->>Daemon: "stop()"
    Daemon->>Daemon: "Check if running"
    Daemon->>ShutdownHandler: "Run all registered handlers"
    ShutdownHandler-->>Daemon: "Handlers completed"
    Daemon->>SignalHandler: "Remove signal handlers"
    Daemon->>PIDFile: "Remove PID file"
    PIDFile-->>Daemon: "File removed"
    Daemon-->>User: "Result.ok()"
Loading

@galligan galligan changed the base branch from p3-20/index/fts5-impl to graphite-base/83 January 23, 2026 21:53
@galligan galligan force-pushed the p3-21/daemon/types-lifecycle branch from dfbbb85 to 2f370ee Compare January 23, 2026 21:58
@galligan galligan changed the base branch from graphite-base/83 to p3-20/index/fts5-impl January 23, 2026 21:58
@galligan
Copy link
Contributor Author

Added a root entrypoint for @outfitter/daemon (exports types + createDaemon) and a basic smoke test so bun test no longer fails on empty suites. Also resolved the restack conflict to keep the IPC/health exports in index.ts.

galligan and others added 2 commits January 23, 2026 18:06
Add daemon process management infrastructure:
- DaemonError: TaggedError for daemon failures
- DaemonState: running, stopped, starting, stopping
- DaemonOptions: PID file, signal handlers, cleanup hooks
- Daemon interface: start, stop, status, isRunning
- createDaemon() factory with PID file management
- Graceful signal handling (SIGTERM, SIGINT)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan force-pushed the p3-21/daemon/types-lifecycle branch from 2f370ee to a1e44c2 Compare January 23, 2026 23:09
@galligan galligan force-pushed the p3-20/index/fts5-impl branch from 86b969f to c319824 Compare January 23, 2026 23:09
@galligan
Copy link
Contributor Author

Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants