refactor: name subagent outcome update decision

This commit is contained in:
Gustavo Madeira Santana
2026-04-19 18:02:00 -04:00
parent 40c71bd0d8
commit 3abc92dae9
3 changed files with 23 additions and 5 deletions

View File

@@ -68,6 +68,18 @@ describe("emitSubagentEndedHookOnce", () => {
{ status: "ok" },
),
).toBe(true);
expect(
mod.shouldUpdateRunOutcome(
{ status: "ok" },
{ status: "ok", startedAt: 1_000, endedAt: 2_000, elapsedMs: 1_000 },
),
).toBe(true);
expect(
mod.shouldUpdateRunOutcome(
{ status: "ok", startedAt: 1_000, endedAt: 2_000, elapsedMs: 1_000 },
{ status: "ok" },
),
).toBe(false);
});
it("records ended hook marker even when no subagent_ended hooks are registered", async () => {

View File

@@ -42,6 +42,15 @@ export function runOutcomeHasTiming(outcome: SubagentRunOutcome | undefined): bo
);
}
export function shouldUpdateRunOutcome(
current: SubagentRunOutcome | undefined,
next: SubagentRunOutcome | undefined,
): boolean {
return (
!runOutcomesEqual(current, next) || (!runOutcomeHasTiming(current) && runOutcomeHasTiming(next))
);
}
export function resolveLifecycleOutcomeFromRunOutcome(
outcome: SubagentRunOutcome | undefined,
): SubagentLifecycleEndedOutcome {

View File

@@ -23,7 +23,7 @@ import {
resolveCleanupCompletionReason,
resolveDeferredCleanupDecision,
} from "./subagent-registry-cleanup.js";
import { runOutcomeHasTiming, runOutcomesEqual } from "./subagent-registry-completion.js";
import { shouldUpdateRunOutcome } from "./subagent-registry-completion.js";
import {
ANNOUNCE_COMPLETION_HARD_EXPIRY_MS,
ANNOUNCE_EXPIRY_MS,
@@ -594,10 +594,7 @@ export function createSubagentRegistryLifecycleController(params: {
startedAt: entry.startedAt,
endedAt,
});
const shouldPersistOutcome =
!runOutcomesEqual(entry.outcome, outcome) ||
(!runOutcomeHasTiming(entry.outcome) && runOutcomeHasTiming(outcome));
if (shouldPersistOutcome) {
if (shouldUpdateRunOutcome(entry.outcome, outcome)) {
entry.outcome = outcome;
mutated = true;
}