Fix orchestrator process hang after cleanup
The orchestrator process was hanging after completing its work because:
1. Fire-and-forget Redis operations in MessageBus.handleMessage() left
unhandled promises that kept the event loop alive
2. No explicit process.exit() call after cleanup
Changes:
- coordination.ts: Add .catch(() => {}) to fire-and-forget Redis ops
- orchestrator.ts: Add explicit process.exit(exitCode) after cleanup
- orchestrator.ts: Improve error handling in main() with proper exit codes
Tested: Pipeline mksup1wq completed full flow and exited cleanly.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
92d3602852
commit
ccc3b01609
@ -188,10 +188,10 @@ export class MessageBus {
|
||||
}
|
||||
|
||||
private handleMessage(msg: AgentMessage): void {
|
||||
// Store in message log
|
||||
this.redis.rPush(`msg:${this.taskId}:log`, JSON.stringify(msg));
|
||||
this.redis.hIncrBy(`metrics:${this.taskId}`, "total_messages", 1);
|
||||
this.redis.hIncrBy(`metrics:${this.taskId}`, "direct_messages", 1);
|
||||
// Store in message log (fire-and-forget, errors ignored)
|
||||
this.redis.rPush(`msg:${this.taskId}:log`, JSON.stringify(msg)).catch(() => {});
|
||||
this.redis.hIncrBy(`metrics:${this.taskId}`, "total_messages", 1).catch(() => {});
|
||||
this.redis.hIncrBy(`metrics:${this.taskId}`, "direct_messages", 1).catch(() => {});
|
||||
|
||||
// Call registered handlers
|
||||
for (const handler of this.messageHandlers.values()) {
|
||||
|
||||
@ -389,6 +389,7 @@ The solution should consider fault tolerance, data consistency, and cost optimiz
|
||||
|
||||
const orchestrator = new MultiAgentOrchestrator(model);
|
||||
|
||||
let exitCode = 0;
|
||||
try {
|
||||
await orchestrator.initialize();
|
||||
const metrics = await orchestrator.runTask(task);
|
||||
@ -402,9 +403,15 @@ The solution should consider fault tolerance, data consistency, and cost optimiz
|
||||
|
||||
} catch (e: any) {
|
||||
console.error("Orchestrator error:", e.message);
|
||||
exitCode = 1;
|
||||
} finally {
|
||||
await orchestrator.cleanup();
|
||||
// Explicitly exit to ensure all connections are closed
|
||||
process.exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
main().catch((e) => {
|
||||
console.error("Fatal error:", e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user