fix(gateway): resolve undefined PID and NODE_OPTIONS errors in packaged app (#315)

This commit is contained in:
paisley
2026-03-06 11:03:56 +08:00
committed by GitHub
Unverified
parent 0901d9912a
commit 01efd87642

View File

@@ -269,6 +269,8 @@ export class GatewayManager extends EventEmitter {
if (msg.includes('ExperimentalWarning')) return { level: 'debug', normalized: msg }; if (msg.includes('ExperimentalWarning')) return { level: 'debug', normalized: msg };
if (msg.includes('DeprecationWarning')) return { level: 'debug', normalized: msg }; if (msg.includes('DeprecationWarning')) return { level: 'debug', normalized: msg };
if (msg.includes('Debugger attached')) return { level: 'debug', normalized: msg }; if (msg.includes('Debugger attached')) return { level: 'debug', normalized: msg };
// Electron restricts NODE_OPTIONS in packaged apps; this is expected and harmless.
if (msg.includes('NODE_OPTIONs are not supported in packaged apps')) return { level: 'debug', normalized: msg };
return { level: 'warn', normalized: msg }; return { level: 'warn', normalized: msg };
} }
@@ -1150,6 +1152,10 @@ export class GatewayManager extends EventEmitter {
// Inject fetch preload so OpenRouter requests carry ClawX headers. // Inject fetch preload so OpenRouter requests carry ClawX headers.
// The preload patches globalThis.fetch before any module loads. // The preload patches globalThis.fetch before any module loads.
// NODE_OPTIONS --require is blocked by Electron in packaged apps, so skip
// this injection when packaged to avoid the "NODE_OPTIONs not supported"
// errors being printed to the gateway's stderr on every startup.
if (!app.isPackaged) {
try { try {
const preloadPath = ensureGatewayFetchPreload(); const preloadPath = ensureGatewayFetchPreload();
if (existsSync(preloadPath)) { if (existsSync(preloadPath)) {
@@ -1161,6 +1167,7 @@ export class GatewayManager extends EventEmitter {
} catch (err) { } catch (err) {
logger.warn('Failed to set up OpenRouter headers preload:', err); logger.warn('Failed to set up OpenRouter headers preload:', err);
} }
}
// utilityProcess.fork() runs the .mjs entry directly without spawning a // utilityProcess.fork() runs the .mjs entry directly without spawning a
// shell or visible console window. Works identically in dev and packaged. // shell or visible console window. Works identically in dev and packaged.
@@ -1213,13 +1220,13 @@ export class GatewayManager extends EventEmitter {
} }
}); });
// Store PID // PID is only available after the child process has fully spawned.
if (child.pid) { // utilityProcess.fork() is asynchronous — child.pid is undefined if read
// synchronously right after fork(). Use the 'spawned' event instead.
child.on('spawn', () => {
logger.info(`Gateway process started (pid=${child.pid})`); logger.info(`Gateway process started (pid=${child.pid})`);
this.setStatus({ pid: child.pid }); this.setStatus({ pid: child.pid });
} else { });
logger.warn('Gateway process spawned but PID is undefined');
}
resolve(); resolve();
}); });