fix(agents): avoid duplicate subagent ended hook loads

This commit is contained in:
Vincent Koc
2026-04-12 13:06:12 +01:00
parent 6fec1ec2d6
commit 48042c3875
2 changed files with 9 additions and 2 deletions

View File

@@ -265,14 +265,16 @@ export function createSubagentRegistryLifecycleController(params: {
await safeRemoveAttachmentsDir(giveUpParams.entry);
}
const completionReason = resolveCleanupCompletionReason(giveUpParams.entry);
await emitCompletionEndedHookIfNeeded(giveUpParams.entry, completionReason);
logAnnounceGiveUp(giveUpParams.entry, giveUpParams.reason);
// Retry-limit / expiry give-up should not leave cleanup stuck behind the
// best-effort ended hook. Mark the run cleaned first, then fire the hook.
completeCleanupBookkeeping({
runId: giveUpParams.runId,
entry: giveUpParams.entry,
cleanup: giveUpParams.entry.cleanup,
completedAt: Date.now(),
});
await emitCompletionEndedHookIfNeeded(giveUpParams.entry, completionReason);
};
const beginSubagentCleanup = (runId: string) => {
@@ -445,14 +447,16 @@ export function createSubagentRegistryLifecycleController(params: {
await safeRemoveAttachmentsDir(entry);
}
const completionReason = resolveCleanupCompletionReason(entry);
await emitCompletionEndedHookIfNeeded(entry, completionReason);
logAnnounceGiveUp(entry, deferredDecision.reason);
// Giving up on announce delivery is terminal for cleanup even if the
// best-effort hook is still resolving.
completeCleanupBookkeeping({
runId,
entry,
cleanup,
completedAt: now,
});
await emitCompletionEndedHookIfNeeded(entry, completionReason);
return;
}

View File

@@ -324,6 +324,9 @@ async function emitSubagentEndedHookForRun(params: {
sendFarewell?: boolean;
accountId?: string;
}) {
if (params.entry.endedHookEmittedAt) {
return;
}
const cfg = subagentRegistryDeps.loadConfig();
await ensureSubagentRegistryPluginRuntimeLoaded({
config: cfg,