fix(cliproxy): keep daemon running after parent exit

This commit is contained in:
Tam Nhu Tran
2026-02-14 09:31:47 +07:00
parent baa621aedd
commit 3136f24b9b
2 changed files with 22 additions and 9 deletions
+3 -6
View File
@@ -76,7 +76,7 @@ async function waitForPort(
}
/**
* Register cleanup handlers to stop proxy on process exit
* Register process-exit cleanup handlers for in-process workers.
*/
function registerCleanup(): void {
if (cleanupRegistered) return;
@@ -87,11 +87,8 @@ function registerCleanup(): void {
tokenRefreshWorker.stop();
tokenRefreshWorker = null;
}
// Then stop proxy process
if (proxyProcess && !proxyProcess.killed) {
proxyProcess.kill('SIGTERM');
proxyProcess = null;
}
// Do not stop detached CLIProxy on parent exit.
// Persistence is expected across CCS command lifecycles.
};
process.once('exit', cleanup);
@@ -8,6 +8,8 @@
import { initUI, header, color, dim, ok, warn, info } from '../../utils/ui';
import { getProxyStatus, stopProxy } from '../../cliproxy/services';
import { detectRunningProxy } from '../../cliproxy/proxy-detector';
import { CLIPROXY_DEFAULT_PORT } from '../../cliproxy/config-generator';
export async function handleProxyStatus(): Promise<void> {
await initUI();
@@ -26,9 +28,23 @@ export async function handleProxyStatus(): Promise<void> {
console.log('');
console.log(dim('To stop: ccs cliproxy stop'));
} else {
console.log(` Status: ${color('Not running', 'warning')}`);
console.log('');
console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.'));
// Fallback: detect untracked/orphaned proxy process (e.g. detached session without lock file).
const detected = await detectRunningProxy();
if (detected.running && detected.verified) {
console.log(` Status: ${color('Running', 'success')}`);
console.log(` PID: ${detected.pid ?? 'unknown'}`);
console.log(` Port: ${CLIPROXY_DEFAULT_PORT}`);
console.log(` Sessions: ${detected.sessionCount || 0} active`);
if (!detected.sessionCount) {
console.log(dim(' Note: Detected running proxy without local session lock'));
}
console.log('');
console.log(dim('To stop: ccs cliproxy stop'));
} else {
console.log(` Status: ${color('Not running', 'warning')}`);
console.log('');
console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.'));
}
}
console.log('');
}