1.8 KiB
1.8 KiB
Fix: Computer HTTP Server Race Condition
Date: 2026-04-08
Author: dongdada29
Commit: 9880646
Problem
Computer HTTP Server (startComputerServer) starts asynchronously in bootstrap/startup.ts, but agentService.init() is only called after the user completes the Setup Wizard.
When a request from the Java backend arrives before Setup Wizard is completed:
T0: startup.ts → startComputerServer() async (fire-and-forget)
T1: Computer HTTP Server listening on port 60001 (isReady = false)
T2: Request arrives → baseConfig == null
T3: Setup Wizard completes → agentService.init() → baseConfig set
The request would fail with "Agent not initialized" error because agentService.getOrCreateEngine() throws when baseConfig is null.
Solution
Added early readiness check in computerServer.ts handleRequest():
if (pathname.startsWith("/computer/") && !agentService.isReady) {
log.warn(`[HTTP] Agent not ready, rejecting request: ${method} ${pathname}`);
sendJson(res, 503, httpError("SERVICE_NOT_READY", "Agent service is not initialized yet"));
return;
}
Returns HTTP 503 with SERVICE_NOT_READY error code, allowing the client to retry once the agent is ready.
Files Changed
crates/agent-electron-client/src/main/services/computerServer.ts(+15 lines)
Verification
- Start app, observe Setup Wizard
- Send request to
POST /computer/chat→ should get 503SERVICE_NOT_READY - Complete Setup Wizard
- Send request again → should succeed
Related
bootstrap/startup.ts— where Computer HTTP Server starts asynchronouslyserviceManager.ts— whereagentService.init()is called after SetupunifiedAgent.ts—isReadygetter returnsthis.baseConfig !== null