mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-27 02:09:33 +00:00
refactor(agents): remove unused command poll suggestion
This commit is contained in:
@@ -2,35 +2,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SessionState } from "../logging/diagnostic-session-state.js";
|
||||
import {
|
||||
calculateBackoffMs,
|
||||
getCommandPollSuggestion,
|
||||
pruneStaleCommandPolls,
|
||||
recordCommandPoll,
|
||||
resetCommandPollCount,
|
||||
} from "./command-poll-backoff.js";
|
||||
|
||||
describe("command-poll-backoff", () => {
|
||||
describe("calculateBackoffMs", () => {
|
||||
it("returns 5s for first poll", () => {
|
||||
expect(calculateBackoffMs(0)).toBe(5000);
|
||||
});
|
||||
|
||||
it("returns 10s for second poll", () => {
|
||||
expect(calculateBackoffMs(1)).toBe(10000);
|
||||
});
|
||||
|
||||
it("returns 30s for third poll", () => {
|
||||
expect(calculateBackoffMs(2)).toBe(30000);
|
||||
});
|
||||
|
||||
it("returns 60s for fourth and subsequent polls (capped)", () => {
|
||||
expect(calculateBackoffMs(3)).toBe(60000);
|
||||
expect(calculateBackoffMs(4)).toBe(60000);
|
||||
expect(calculateBackoffMs(10)).toBe(60000);
|
||||
expect(calculateBackoffMs(100)).toBe(60000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("recordCommandPoll", () => {
|
||||
it("returns 5s on first no-output poll", () => {
|
||||
const state: SessionState = {
|
||||
@@ -94,30 +71,6 @@ describe("command-poll-backoff", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCommandPollSuggestion", () => {
|
||||
it("returns undefined for untracked command", () => {
|
||||
const state: SessionState = {
|
||||
lastActivity: Date.now(),
|
||||
state: "processing",
|
||||
queueDepth: 0,
|
||||
};
|
||||
expect(getCommandPollSuggestion(state, "unknown")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns current backoff for tracked command", () => {
|
||||
const state: SessionState = {
|
||||
lastActivity: Date.now(),
|
||||
state: "processing",
|
||||
queueDepth: 0,
|
||||
};
|
||||
|
||||
recordCommandPoll(state, "cmd-123", false);
|
||||
recordCommandPoll(state, "cmd-123", false);
|
||||
|
||||
expect(getCommandPollSuggestion(state, "cmd-123")).toBe(10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resetCommandPollCount", () => {
|
||||
it("removes command from tracking", () => {
|
||||
const state: SessionState = {
|
||||
|
||||
@@ -10,7 +10,7 @@ const BACKOFF_SCHEDULE_MS = [5000, 10000, 30000, 60000];
|
||||
* Calculate suggested retry delay based on consecutive no-output poll count.
|
||||
* Implements exponential backoff schedule: 5s → 10s → 30s → 60s (capped).
|
||||
*/
|
||||
export function calculateBackoffMs(consecutiveNoOutputPolls: number): number {
|
||||
function calculateBackoffMs(consecutiveNoOutputPolls: number): number {
|
||||
const index = Math.min(consecutiveNoOutputPolls, BACKOFF_SCHEDULE_MS.length - 1);
|
||||
return BACKOFF_SCHEDULE_MS[index] ?? 60000;
|
||||
}
|
||||
@@ -45,21 +45,6 @@ export function recordCommandPoll(
|
||||
return calculateBackoffMs(newCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current suggested backoff for a command without modifying state.
|
||||
* Useful for checking current backoff level.
|
||||
*/
|
||||
export function getCommandPollSuggestion(
|
||||
state: SessionState,
|
||||
commandId: string,
|
||||
): number | undefined {
|
||||
const pollData = state.commandPollCounts?.get(commandId);
|
||||
if (!pollData) {
|
||||
return undefined;
|
||||
}
|
||||
return calculateBackoffMs(pollData.count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset poll count for a command (e.g., when command completes).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user