Skip to content

Adds detached support. Closes #1511#1533

Merged
garrytrinder merged 2 commits intodotnet:mainfrom
waldekmastykarz:detached
Feb 25, 2026
Merged

Adds detached support. Closes #1511#1533
garrytrinder merged 2 commits intodotnet:mainfrom
waldekmastykarz:detached

Conversation

@waldekmastykarz
Copy link
Collaborator

Adds detached support. Closes #1511

Renamed to --detach to align with existing flags like --record and --discover

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner February 25, 2026 09:34
Copilot AI review requested due to automatic review settings February 25, 2026 09:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and logs CLI commands backed by a persisted state.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.

Copy link
Contributor

@garrytrinder garrytrinder left a comment

Choose a reason for hiding this comment

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

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.

@copilot

- 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)
@garrytrinder garrytrinder merged commit 45dbbf8 into dotnet:main Feb 25, 2026
4 checks passed
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.

Add --detached to run Dev Proxy in the background

3 participants