fix: Handle spawn and branch failures gracefully in dispatch cycle
Wrap agentManager.spawn() in try/catch — on failure, block the task instead of crashing the entire dispatch cycle. Move phase status update to after branch creation succeeds — on branch failure, block the phase and skip task queuing. Fix statement-breakpoint markers in migration 0020 to use separate lines.
This commit is contained in:
@@ -15,7 +15,7 @@ import type {
|
||||
TaskDispatchedEvent,
|
||||
TaskPendingApprovalEvent,
|
||||
} from '../events/index.js';
|
||||
import type { AgentManager, AgentResult } from '../agent/types.js';
|
||||
import type { AgentManager, AgentResult, AgentInfo } from '../agent/types.js';
|
||||
import type { TaskRepository } from '../db/repositories/task-repository.js';
|
||||
import type { MessageRepository } from '../db/repositories/message-repository.js';
|
||||
import type { AgentRepository } from '../db/repositories/agent-repository.js';
|
||||
@@ -397,15 +397,23 @@ export class DefaultDispatchManager implements DispatchManager {
|
||||
}
|
||||
|
||||
// Spawn agent with task (alias auto-generated by agent manager)
|
||||
const agent = await this.agentManager.spawn({
|
||||
taskId: nextTask.taskId,
|
||||
initiativeId: task.initiativeId ?? undefined,
|
||||
phaseId: task.phaseId ?? undefined,
|
||||
prompt: buildExecutePrompt(task.description || task.name),
|
||||
baseBranch,
|
||||
branchName,
|
||||
inputContext,
|
||||
});
|
||||
let agent: AgentInfo;
|
||||
try {
|
||||
agent = await this.agentManager.spawn({
|
||||
taskId: nextTask.taskId,
|
||||
initiativeId: task.initiativeId ?? undefined,
|
||||
phaseId: task.phaseId ?? undefined,
|
||||
prompt: buildExecutePrompt(task.description || task.name),
|
||||
baseBranch,
|
||||
branchName,
|
||||
inputContext,
|
||||
});
|
||||
} catch (err) {
|
||||
const reason = `Spawn failed: ${err instanceof Error ? err.message : String(err)}`;
|
||||
log.error({ taskId: nextTask.taskId, err: reason }, 'agent spawn failed, blocking task');
|
||||
await this.blockTask(nextTask.taskId, reason);
|
||||
return { success: false, taskId: nextTask.taskId, reason };
|
||||
}
|
||||
|
||||
log.info({ taskId: nextTask.taskId, agentId: agent.id }, 'task dispatched');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user