mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 21:22:56 +00:00
fix(agents): clamp embedded run drain polling
This commit is contained in:
@@ -393,6 +393,28 @@ describe("embedded-agent runner run registry", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("clamps oversized active-run drain poll intervals", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
const handle = createRunHandle();
|
||||
setActiveEmbeddedRun("session-a", handle);
|
||||
|
||||
const waitPromise = waitForActiveEmbeddedRuns(undefined, {
|
||||
pollMs: Number.MAX_SAFE_INTEGER,
|
||||
});
|
||||
await Promise.resolve();
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
|
||||
clearActiveEmbeddedRun("session-a", handle);
|
||||
await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS);
|
||||
await expect(waitPromise).resolves.toEqual({ drained: true });
|
||||
} finally {
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("shares active run state across distinct module instances", async () => {
|
||||
const runsA = await importFreshModule<typeof import("./runs.js")>(
|
||||
import.meta.url,
|
||||
|
||||
@@ -617,7 +617,7 @@ export async function waitForActiveEmbeddedRuns(
|
||||
opts?: { pollMs?: number },
|
||||
): Promise<{ drained: boolean }> {
|
||||
const pollMsRaw = opts?.pollMs ?? 250;
|
||||
const pollMs = Math.max(10, Math.floor(pollMsRaw));
|
||||
const pollMs = resolveTimerTimeoutMs(pollMsRaw, 250, 10);
|
||||
if (timeoutMs !== undefined && timeoutMs <= 0) {
|
||||
return { drained: getActiveEmbeddedRunCount() === 0 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user