Adds detached support. Closes #1511#1533
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a “detached” (background/daemon) execution mode for Dev Proxy, including state persistence and new CLI commands to manage and inspect a running background instance, addressing #1511.
Changes:
- Introduces a detached/daemon startup flow that spawns a background process, writes a state file, and redirects console output to a log file.
- Adds
status,stop, andlogsCLI commands backed by a persistedstate.json. - Adds an API endpoint to stream/read daemon logs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| DevProxy/Program.cs | Implements detached spawning, daemon stdout/stderr redirection to file, and state file lifecycle. |
| DevProxy/Commands/DevProxyCommand.cs | Adds --detach and hidden --_internal-daemon options plus new subcommands. |
| DevProxy/Commands/DevProxyConfigOptions.cs | Parses --port early so the daemon can persist it in state. |
| DevProxy/State/StateManager.cs | Adds state/log path management and log cleanup for detached instances. |
| DevProxy/State/ProxyInstanceState.cs | Defines persisted detached instance metadata (PID, API URL, log file, etc.). |
| DevProxy/Commands/StatusCommand.cs | Implements devproxy status based on state file + optional live API probe. |
| DevProxy/Commands/StopCommand.cs | Implements devproxy stop (API stop + optional force kill). |
| DevProxy/Commands/LogsCommand.cs | Implements devproxy logs (tail + follow). |
| DevProxy/ApiControllers/ProxyController.cs | Adds /proxy/logs endpoint with optional SSE streaming and filtering. |
| DevProxy/Proxy/ProxyEngine.cs | Disables interactive hotkey loop for internal daemon runs. |
| DevProxy/Extensions/ILoggingBuilderExtensions.cs | Minor formatting-only change. |
6546cab to
162a69c
Compare
There was a problem hiding this comment.
When testing detached I noticed that when stop command was being used the network settings are not being undone...
The two problems
Problem 1: ToggleSystemProxy has no timeout. At ProxyEngine.cs:703, process.WaitForExit() blocks indefinitely. In a daemon context
with no controlling terminal, networksetup can hang, blocking the entire shutdown path. The 10-second wait in StopCommand gives up, but the daemon stays alive and stuck.
Problem 2: ForceStopAsync does no proxy cleanup. At StopCommand.cs:119-131, it just calls process.Kill() and deletes the state file. It never calls toggle-proxy.sh off itself. The kill signal doesn't give the daemon a chance to clean up either since SIGKILL is non-catchable.
Both paths can leave your macOS network settings pointing at a proxy that no longer exists, which is exactly what broke your network.
- Add 10s timeout to ToggleSystemProxy to prevent indefinite hangs in daemon context (Problem 1) - Add proxy cleanup in ForceStopAsync before killing the process to prevent orphaned system proxy settings (Problem 2)
Adds detached support. Closes #1511
Renamed to
--detachto align with existing flags like--recordand--discover