Skip to content

feat: delay autostopping daemons when leaving directory#108

Merged
jdx merged 3 commits into
mainfrom
feat/autostop-delay
Jan 17, 2026
Merged

feat: delay autostopping daemons when leaving directory#108
jdx merged 3 commits into
mainfrom
feat/autostop-delay

Conversation

@jdx

@jdx jdx commented Jan 17, 2026

Copy link
Copy Markdown
Owner

Summary

Implements GitHub discussion #103. Adds a configurable delay before autostopping daemons when leaving a directory, avoiding unnecessary restarts when briefly switching directories.

  • Add PITCHFORK_AUTOSTOP_DELAY env var (default: 60 seconds)
  • Set to 0 to disable delay and stop immediately (previous behavior)
  • Track pending autostops in supervisor
  • Cancel pending autostops when re-entering a directory

Test plan

  • Set PITCHFORK_AUTOSTOP_DELAY=10 and verify autostop is delayed
  • Leave and return to directory within delay, verify daemon keeps running
  • Set PITCHFORK_AUTOSTOP_DELAY=0 and verify immediate stop behavior
  • Leave directory and wait for full delay, verify daemon stops

Closes #103

🤖 Generated with Claude Code


Note

Introduces delayed autostop behavior controlled via PITCHFORK_AUTOSTOP_DELAY (default 60; 0 for immediate stop).

  • Supervisor tracks pending autostops (pending_autostops) and schedules stops in leave_dir; processes due stops in process_pending_autostops during refresh
  • Cancels pending autostops when re-entering a directory (cancel_pending_autostops_for_dir) and when starting a daemon (run clears pending)
  • Adds E2E tests: delayed stop, cancel on return, and immediate stop with PITCHFORK_AUTOSTOP_DELAY=0
  • Minor CLI help text tweaks for list and logs

Written by Cursor Bugbot for commit 3a21382. This will update automatically on new commits. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/supervisor.rs Outdated
d.dir
.as_ref()
.map(|daemon_dir| daemon_dir.starts_with(dir))
.unwrap_or(false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subdirectory navigation causes daemons to never autostop

Medium Severity

The cancel_pending_autostops_for_dir filter only checks if daemon_dir.starts_with(dir), which cancels autostops for daemons in the entered directory or its subdirectories. However, it doesn't check the reverse direction (dir.starts_with(daemon_dir)), so entering a subdirectory like /project/subdir won't cancel pending autostops for a daemon in /project. This causes the pending autostop entry to be removed later (without stopping the daemon due to the re-check), and when the user eventually leaves, the daemon is never re-scheduled for autostop because leave_dir also doesn't match parent directories.

Fix in Cursor Fix in Web

Comment thread src/supervisor.rs
jdx and others added 3 commits January 17, 2026 14:59
Implements GitHub discussion #103. When leaving a directory with
autostop daemons, pitchfork now waits before stopping them. This
avoids unnecessary restarts when briefly switching directories.

- Add PITCHFORK_AUTOSTOP_DELAY env var (default: 60 seconds)
- Set to 0 to disable delay and stop immediately (previous behavior)
- Track pending autostops in supervisor
- Cancel pending autostops when re-entering a directory
- Process pending autostops during refresh interval

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds tests for the PITCHFORK_AUTOSTOP_DELAY environment variable:
- test_autostop_delay: verifies daemons remain running during delay
- test_autostop_cancel_on_return: verifies returning to directory cancels autostop
- test_autostop_immediate_with_zero_delay: verifies DELAY=0 stops immediately

Also adds helper methods to TestEnv for running commands in different directories.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix subdirectory navigation: entering /project/subdir now cancels
  pending autostop for daemon in /project (check both directions)
- Clear pending autostop when daemon is manually started to prevent
  stale autostop from unexpectedly stopping the daemon

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jdx jdx force-pushed the feat/autostop-delay branch from 0726b51 to 3a21382 Compare January 17, 2026 20:59
@jdx jdx merged commit b49fbd5 into main Jan 17, 2026
4 checks passed
@jdx jdx deleted the feat/autostop-delay branch January 17, 2026 21:11
@github-actions github-actions Bot mentioned this pull request Jan 18, 2026
jdx pushed a commit that referenced this pull request Jan 18, 2026
## 🤖 New release

* `pitchfork-cli`: 0.2.1 -> 0.3.0

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.3.0](v0.2.1...v0.3.0) -
2026-01-18

### Added

- *(web)* add devilish pitchfork theming to web UI
([#115](#115))
- *(web)* add web UI for daemon management
([#112](#112))
- show startup logs on successful daemon start
([#111](#111))
- add HTTP ready check for daemon startup
([#110](#110))
- delay autostopping daemons when leaving directory
([#108](#108))
- *(logs)* clear all logs when no daemon specified
([#109](#109))
- *(list)* show error messages in daemon list output
([#107](#107))
- refactor the code structure of `start` and `run`, allowing for
parallel starting daemons
([#56](#56))
- [**breaking**] support auto start on boot
([#53](#53))
- print logs when failed on `pf start|run`
([#52](#52))
- [**breaking**] support global system/user config
([#46](#46))
- *(test)* refactor tests and add tests for `interval_watch` and
`cron_watch` ([#45](#45))

### Fixed

- add timeouts to IPC operations to prevent shell hook hangs
([#106](#106))
- *(deps)* update rust crate toml to 0.9
([#50](#50))
- replace panics with proper error handling
([#90](#90))
- *(deps)* update rust crate notify to v8
([#78](#78))
- *(deps)* update rust crate duct to v1
([#72](#72))
- *(deps)* update rust crate dirs to v6
([#64](#64))
- *(deps)* update rust crate cron to 0.15
([#48](#48))
- *(deps)* update rust crate sysinfo to 0.37
([#49](#49))
- *(deps)* update rust crate itertools to 0.14
([#33](#33))
- *(deps)* update rust crate strum to 0.27
([#35](#35))
- *(deps)* update rust crate console to 0.16
([#32](#32))
- give a user-friendly error when the work fails
([#44](#44))

### Other

- *(cli)* add long_about with examples to CLI commands
([#91](#91))
- fix documentation issues and inconsistencies
([#89](#89))
- *(deps)* lock file maintenance
([#88](#88))
- *(deps)* update rust crate serde_json to v1.0.149
([#87](#87))
- *(deps)* lock file maintenance
([#85](#85))
- *(deps)* update rust crate serde_json to v1.0.148
([#84](#84))
- *(deps)* update rust crate tempfile to v3.24.0
([#82](#82))
- *(deps)* update rust crate rmp-serde to v1.3.1
([#80](#80))
- *(deps)* update rust crate serde_json to v1.0.147
([#81](#81))
- *(deps)* lock file maintenance
([#79](#79))
- *(deps)* update rust crate shell-words to v1.1.1
([#77](#77))
- *(deps)* lock file maintenance
([#76](#76))
- *(deps)* update rust crate log to v0.4.29
([#75](#75))
- *(deps)* lock file maintenance
([#73](#73))
- *(deps)* lock file maintenance
([#68](#68))
- *(deps)* lock file maintenance
([#65](#65))
- *(deps)* lock file maintenance
([#62](#62))
- *(deps)* update rust crate clap to v4.5.51
([#60](#60))
- *(deps)* lock file maintenance
([#59](#59))
- *(deps)* update rust crate clap to v4.5.50
([#57](#57))
- Update README ([#55](#55))
- *(deps)* lock file maintenance
([#54](#54))
- *(deps)* lock file maintenance
([#47](#47))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@jdx jdx mentioned this pull request Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant