refactor: add daemon-managed proxy process#189
Open
unive3sal wants to merge 2 commits into
Open
Conversation
Owner
|
The daemon-managed proxy direction looks good to me. I don’t see a runtime blocker in the daemon path itself from this review. Must fix before merge:
Follow-up direction:
|
* Move proxy worker lifecycle ownership into the daemon, including signal-safe shutdown cleanup and per-app proxy port preservation. * Consolidate proxy daemon and failover CI checks into the integration test workflow. * change fmt and integration trigger from "pull_request_target" to "pull_request".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The daemon-managed proxy design is needed to make proxy lifecycle management reliable as cc-switch grows from a single foreground process into a multi-app proxy manager.
It gives cc-switch a stable owner for multi-app proxy workers. Instead of tying proxy runtime state to whichever CLI or TUI command happened to start it, the daemon becomes the single coordinator for Claude, Codex, Gemini, and future app-specific proxy sessions. This makes enabling, disabling, and inspecting per-app proxy state much simpler and more predictable.
Proxy workers should not be orphaned to the init process after the cc-switch TUI exits. When the foreground UI quits, the proxy may still need to keep serving traffic, but it should remain under cc-switch control. The daemon provides that control boundary: the TUI can come and go, while the daemon continues to own worker lifecycle and cleanup.
The daemon can actively monitor worker health. If a proxy worker exits unexpectedly, the daemon can detect it, update runtime state, and restart the worker when appropriate instead of leaving users with a silently broken proxy.
The daemon also gives us a dedicated place to write informative lifecycle traces, including startup, shutdown, worker registration, restart attempts, and IPC decisions. These logs make proxy issues much easier to diagnose than relying on transient foreground output.
Centralizing lifecycle ownership helps keep the metadata database consistent in abnormal situations such as stale sockets, killed workers, interrupted shutdowns, or repeated toggles from different clients. The daemon can reconcile desired state, runtime state, and persisted state from one place, reducing the chance that the database says a proxy is active when no managed worker is actually running.
Summary
Data schema change
Integration test scope