Files
openclaw/src/auto-reply/reply/queue-policy.ts
T
Peter Steinberger dba9fb8509 fix(queue): deliver queued steers in arrival order across turn boundaries (#120420)
* fix(queue): deliver queued steers in arrival order across turn boundaries

* test(queue): align steer fallback with pre-dispatch injection
2026-08-07 18:52:46 -07:00

34 lines
1.1 KiB
TypeScript

// Resolves queue mode and admission policy for a reply turn.
import type { QueueSettings } from "./queue.js";
/** Queue decisions for messages that arrive while an agent run is active. */
export type ActiveRunQueueAction = "run-now" | "enqueue-followup" | "drop";
/** Resolves whether an active session should run, queue, or drop a new inbound turn. */
export function resolveActiveRunQueueAction(params: {
queueAdmissionState?: "empty" | "steering" | "ready";
isActive: boolean;
isHeartbeat: boolean;
shouldFollowup: boolean;
queueMode: QueueSettings["mode"];
resetTriggered?: boolean;
}): ActiveRunQueueAction {
if (!params.isActive && (!params.queueAdmissionState || params.queueAdmissionState === "empty")) {
return "run-now";
}
if (params.isHeartbeat) {
return "drop";
}
if (params.resetTriggered) {
return "run-now";
}
if (params.queueAdmissionState && params.queueAdmissionState !== "empty") {
return "enqueue-followup";
}
// Follow-up queueing is only meaningful for non-heartbeat user turns.
if (params.shouldFollowup) {
return "enqueue-followup";
}
return "run-now";
}