Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

  • isProcessAlive now validates negative PIDs before process.kill()
  • releaseDaemonLock now properly unlinks file instead of clearing

All 23 locking tests pass.

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

Contributes to #56

This was referenced Jan 23, 2026
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

  • Fixes critical daemon locking bugs: PID validation in isProcessAlive() and proper lock file cleanup in releaseDaemonLock()
  • Updates isProcessAlive() to reject negative PIDs (which have special meaning in process.kill()) returning false for invalid process IDs
  • Changes releaseDaemonLock() to properly unlink the lock file instead of just clearing its contents, ensuring complete cleanup

Important Files Changed

Filename Overview
packages/daemon/src/locking.ts Fixed PID validation bug and lock file cleanup bug to improve daemon lifecycle reliability

Confidence score:5/5

  • This PR is safe to merge with minimal risk as it fixes clear bugs without introducing new complexity
  • Score reflects targeted bug fixes with proper validation logic and improved resource cleanup handling
  • No files require special attention as the changes are straightforward defensive programming improvements

Sequence Diagram

sequenceDiagram
    participant User
    participant DaemonLocking as "Daemon Locking"
    participant FileSystem as "File System"
    participant ProcessSystem as "Process System"

    User->>DaemonLocking: "acquireDaemonLock(lockPath)"
    DaemonLocking->>FileSystem: "Check if lock file exists"
    FileSystem-->>DaemonLocking: "File does not exist"
    DaemonLocking->>ProcessSystem: "Get current PID"
    ProcessSystem-->>DaemonLocking: "Return PID"
    DaemonLocking->>FileSystem: "Write PID to lock file"
    FileSystem-->>DaemonLocking: "Write successful"
    DaemonLocking-->>User: "Return LockHandle"
    
    Note over User: Daemon runs...
    
    User->>DaemonLocking: "releaseDaemonLock(handle)"
    DaemonLocking->>FileSystem: "Read lock file content"
    FileSystem-->>DaemonLocking: "Return PID content"
    DaemonLocking->>DaemonLocking: "Verify PID matches handle"
    DaemonLocking->>FileSystem: "Unlink lock file"
    FileSystem-->>DaemonLocking: "File removed"
    DaemonLocking-->>User: "Lock released"
Loading

@galligan galligan changed the base branch from p5/daemon/tests to graphite-base/89 January 23, 2026 22:11
@galligan galligan changed the base branch from graphite-base/89 to p5/daemon/tests January 23, 2026 22:11
@galligan
Copy link
Contributor Author

Restacked and re-submitted after downstack updates. Pre-push tests ran clean; no additional code changes on this branch.

@galligan galligan changed the base branch from p5/daemon/tests to graphite-base/89 January 23, 2026 23:02
@galligan galligan changed the base branch from graphite-base/89 to p5/daemon/tests January 23, 2026 23:03
@galligan
Copy link
Contributor Author

Restacked after downstack updates; no additional changes beyond the rebase. Pre-push tests ran clean.

- isProcessAlive now validates negative PIDs before process.kill()
- releaseDaemonLock now properly unlinks file instead of clearing

All 23 locking tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants