@@ -73,7 +73,10 @@ import {
7373 resolveMessageChannel ,
7474} from "../utils/message-channel.js" ;
7575import { estimateUsageCost , resolveModelCostConfig } from "../utils/usage-format.js" ;
76- import { buildAgentRunTerminalOutcome } from "./agent-run-terminal-outcome.js" ;
76+ import {
77+ buildAgentRunTerminalOutcome ,
78+ type AgentRunTerminalOutcome ,
79+ } from "./agent-run-terminal-outcome.js" ;
7780import { resolveAgentRuntimeConfig } from "./agent-runtime-config.js" ;
7881import {
7982 clearAutoFallbackPrimaryProbeSelection ,
@@ -154,6 +157,27 @@ import { ensureAgentWorkspace } from "./workspace.js";
154157
155158const log = createSubsystemLogger ( "agents/agent-command" ) ;
156159
160+ /**
161+ * Maps a normalized terminal outcome to a lifecycle-end log level.
162+ *
163+ * Completed runs are informational; timeouts and cancellations are warnings;
164+ * hard failures (including aborted, blocked, and abandoned liveness states)
165+ * remain at error level so they surface in monitoring.
166+ */
167+ function resolveAgentRunLifecycleEndLogLevel (
168+ outcome : AgentRunTerminalOutcome ,
169+ ) : "info" | "warn" | "error" {
170+ if ( outcome . reason === "completed" ) return "info" ;
171+ if (
172+ outcome . reason === "cancelled" ||
173+ outcome . reason === "timed_out" ||
174+ outcome . reason === "hard_timeout"
175+ ) {
176+ return "warn" ;
177+ }
178+ return "error" ;
179+ }
180+
157181function hasExactConfiguredProviderModel ( params : {
158182 cfg : OpenClawConfig ;
159183 provider : string ;
@@ -1888,12 +1912,13 @@ async function agentCommandInternal(
18881912 ? { providerStarted : runResult . meta . providerStarted }
18891913 : { } ) ,
18901914 } ) ;
1891- const logMsg = `[agent] run ${ runId } ended with stopReason=${ stopReason } ` ;
1892- if ( outcome . reason === "completed" || outcome . reason === "cancelled" ) {
1893- console . info ( logMsg ) ;
1894- } else {
1895- console . warn ( logMsg ) ;
1896- }
1915+ const level = resolveAgentRunLifecycleEndLogLevel ( outcome ) ;
1916+ log [ level ] ( `run ${ runId } ended with stopReason=${ stopReason } ` , {
1917+ runId,
1918+ stopReason,
1919+ reason : outcome . reason ,
1920+ status : outcome . status ,
1921+ } ) ;
18971922 }
18981923 emitAgentEvent ( {
18991924 runId,
@@ -2756,6 +2781,7 @@ export const testing = {
27562781 resolveExplicitAgentCommandSessionKey,
27572782 ingressDiagnosticChannel,
27582783 emitIngressModelUsageDiagnostic,
2784+ resolveAgentRunLifecycleEndLogLevel,
27592785} ;
27602786
27612787/** @deprecated Use `testing`. */
0 commit comments