mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:50:42 +00:00
refactor: name subagent outcome update decision
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user