Files
openclaw/src/agents/run-timeout-attribution.ts
2026-06-17 08:32:26 +08:00

28 lines
951 B
TypeScript

/** Agent run phases used when attributing timeout/cancellation sources. */
const AGENT_RUN_TIMEOUT_PHASES = [
"queue",
"preflight",
"provider",
"post_turn",
"gateway_draining",
] as const;
/** Timeout attribution phase for agent run lifecycle spans. */
export type AgentRunTimeoutPhase = (typeof AGENT_RUN_TIMEOUT_PHASES)[number];
const AGENT_RUN_TIMEOUT_PHASE_SET = new Set<string>(AGENT_RUN_TIMEOUT_PHASES);
/** Normalizes raw timeout phase metadata into a known agent run phase. */
export function normalizeAgentRunTimeoutPhase(value: unknown): AgentRunTimeoutPhase | undefined {
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim();
return AGENT_RUN_TIMEOUT_PHASE_SET.has(normalized)
? (normalized as AgentRunTimeoutPhase)
: undefined;
}
/** Normalizes provider-started timeout attribution metadata. */
export { asBoolean as normalizeProviderStarted } from "../utils/boolean.js";