mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
fix: lower successful agent stop completion logs (#101703)
This commit is contained in:
@@ -63,6 +63,63 @@ afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("resolveAgentRunLifecycleEndLogLevel", () => {
|
||||
it("logs successful stop and tool-use metadata at info", () => {
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
aborted: false,
|
||||
stopReason: "stop",
|
||||
}),
|
||||
).toBe("info");
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
aborted: false,
|
||||
stopReason: "toolUse",
|
||||
}),
|
||||
).toBe("info");
|
||||
});
|
||||
|
||||
it("does not log ordinary end-turn completions", () => {
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
aborted: false,
|
||||
stopReason: "end_turn",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(testing.resolveAgentRunLifecycleEndLogLevel({ aborted: false })).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps timeout metadata out of error severity", () => {
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
aborted: true,
|
||||
stopReason: "timeout",
|
||||
}),
|
||||
).toBe("warn");
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
stopReason: "stop",
|
||||
timeoutPhase: "provider",
|
||||
providerStarted: true,
|
||||
}),
|
||||
).toBe("warn");
|
||||
});
|
||||
|
||||
it("logs cancelled and failed endings at error", () => {
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
aborted: true,
|
||||
stopReason: "stop",
|
||||
}),
|
||||
).toBe("error");
|
||||
expect(
|
||||
testing.resolveAgentRunLifecycleEndLogLevel({
|
||||
stopReason: "error",
|
||||
}),
|
||||
).toBe("error");
|
||||
});
|
||||
});
|
||||
|
||||
function makeResult(overrides?: Record<string, unknown>) {
|
||||
return {
|
||||
payloads: [{ text: "hello", mediaUrl: "" }],
|
||||
|
||||
@@ -73,6 +73,7 @@ import {
|
||||
resolveMessageChannel,
|
||||
} from "../utils/message-channel.js";
|
||||
import { estimateUsageCost, resolveModelCostConfig } from "../utils/usage-format.js";
|
||||
import { buildAgentRunTerminalOutcome } from "./agent-run-terminal-outcome.js";
|
||||
import { resolveAgentRuntimeConfig } from "./agent-runtime-config.js";
|
||||
import {
|
||||
clearAutoFallbackPrimaryProbeSelection,
|
||||
@@ -250,6 +251,37 @@ function parseAgentCommandModelRef(
|
||||
type AttemptExecutionRuntime = typeof import("./command/attempt-execution.runtime.js");
|
||||
type AgentAttemptResult = Awaited<ReturnType<AttemptExecutionRuntime["runAgentAttempt"]>>;
|
||||
|
||||
function resolveAgentRunLifecycleEndLogLevel(meta: {
|
||||
aborted?: unknown;
|
||||
error?: unknown;
|
||||
stopReason?: unknown;
|
||||
livenessState?: unknown;
|
||||
timeoutPhase?: unknown;
|
||||
providerStarted?: unknown;
|
||||
}): "info" | "warn" | "error" | undefined {
|
||||
const status =
|
||||
meta.stopReason === "timeout" || meta.timeoutPhase
|
||||
? "timeout"
|
||||
: meta.aborted === true || meta.error || meta.stopReason === "error"
|
||||
? "error"
|
||||
: "ok";
|
||||
const outcome = buildAgentRunTerminalOutcome({
|
||||
status,
|
||||
error: meta.error,
|
||||
stopReason: meta.stopReason,
|
||||
livenessState: meta.livenessState,
|
||||
timeoutPhase: meta.timeoutPhase,
|
||||
providerStarted: meta.providerStarted,
|
||||
});
|
||||
if (!outcome.stopReason || outcome.stopReason === "end_turn") {
|
||||
return undefined;
|
||||
}
|
||||
if (outcome.reason === "completed") {
|
||||
return "info";
|
||||
}
|
||||
return outcome.status === "timeout" ? "warn" : "error";
|
||||
}
|
||||
|
||||
function applyAgentRunAbortMetadata<T extends { meta: object }>(
|
||||
result: T,
|
||||
signal: AbortSignal | undefined,
|
||||
@@ -1874,8 +1906,9 @@ async function agentCommandInternal(
|
||||
}
|
||||
attemptLifecycleState.lifecycleEnded = true;
|
||||
const stopReason = runResult.meta.stopReason;
|
||||
if (stopReason && stopReason !== "end_turn") {
|
||||
console.error(`[agent] run ${runId} ended with stopReason=${stopReason}`);
|
||||
const logLevel = resolveAgentRunLifecycleEndLogLevel(runResult.meta);
|
||||
if (logLevel) {
|
||||
log[logLevel](`[agent] run ${runId} ended with stopReason=${stopReason}`);
|
||||
}
|
||||
emitAgentEvent({
|
||||
runId,
|
||||
@@ -2736,6 +2769,7 @@ export const testing = {
|
||||
resolveAgentRuntimeConfig,
|
||||
prepareAgentCommandExecution,
|
||||
resolveExplicitAgentCommandSessionKey,
|
||||
resolveAgentRunLifecycleEndLogLevel,
|
||||
ingressDiagnosticChannel,
|
||||
emitIngressModelUsageDiagnostic,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user