fix(cli): resolve process hang after CLI execution

Root cause: HTTP Keep-Alive connections kept event loop alive,
preventing process.exit() from executing even after CLI_EXECUTION_COMPLETED
event was sent.

Fix: Add `agent: false` and `Connection: close` header to HTTP requests
in notifyDashboard() and broadcastStreamEvent() functions.

- agent: false - Creates new Agent per request instead of global Keep-Alive Agent
- Connection: close - Tells server to close connection after response

Fixes issue where `ccw cli --tool gemini` would complete execution but
Bash command would hang indefinitely.
This commit is contained in:
catlog22
2026-03-01 23:34:31 +08:00
parent 4d17bb02a4
commit deea92581b

View File

@@ -51,9 +51,11 @@ function notifyDashboard(data: Record<string, unknown>): void {
path: '/api/hook', path: '/api/hook',
method: 'POST', method: 'POST',
timeout: 2000, // 2 second timeout to prevent hanging timeout: 2000, // 2 second timeout to prevent hanging
agent: false, // Disable Keep-Alive to allow process exit
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload) 'Content-Length': Buffer.byteLength(payload),
'Connection': 'close' // Ensure connection closes after response
} }
}); });
@@ -93,9 +95,11 @@ function broadcastStreamEvent(eventType: string, payload: Record<string, unknown
path: '/api/hook', path: '/api/hook',
method: 'POST', method: 'POST',
timeout: 1000, // Short timeout for streaming timeout: 1000, // Short timeout for streaming
agent: false, // Disable Keep-Alive to allow process exit
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data) 'Content-Length': Buffer.byteLength(data),
'Connection': 'close' // Ensure connection closes after response
} }
}); });