fix(agents): clamp embedded run drain polling · openclaw/openclaw@edd8aa2
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
File tree
src/agents/embedded-agent-runner
| Original file line number | Diff line number | Diff line change |
|---|
@@ -393,6 +393,28 @@ describe("embedded-agent runner run registry", () => {
|
393 | 393 | } |
394 | 394 | }); |
395 | 395 | |
| 396 | +it("clamps oversized active-run drain poll intervals", async () => { |
| 397 | +vi.useFakeTimers(); |
| 398 | +try { |
| 399 | +const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
| 400 | +const handle = createRunHandle(); |
| 401 | +setActiveEmbeddedRun("session-a", handle); |
| 402 | + |
| 403 | +const waitPromise = waitForActiveEmbeddedRuns(undefined, { |
| 404 | +pollMs: Number.MAX_SAFE_INTEGER, |
| 405 | +}); |
| 406 | +await Promise.resolve(); |
| 407 | + |
| 408 | +expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
| 409 | +clearActiveEmbeddedRun("session-a", handle); |
| 410 | +await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS); |
| 411 | +await expect(waitPromise).resolves.toEqual({ drained: true }); |
| 412 | +} finally { |
| 413 | +await vi.runOnlyPendingTimersAsync(); |
| 414 | +vi.useRealTimers(); |
| 415 | +} |
| 416 | +}); |
| 417 | + |
396 | 418 | it("shares active run state across distinct module instances", async () => { |
397 | 419 | const runsA = await importFreshModule<typeof import("./runs.js")>( |
398 | 420 | import.meta.url, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -617,7 +617,7 @@ export async function waitForActiveEmbeddedRuns(
|
617 | 617 | opts?: { pollMs?: number }, |
618 | 618 | ): Promise<{ drained: boolean }> { |
619 | 619 | const pollMsRaw = opts?.pollMs ?? 250; |
620 | | -const pollMs = Math.max(10, Math.floor(pollMsRaw)); |
| 620 | +const pollMs = resolveTimerTimeoutMs(pollMsRaw, 250, 10); |
621 | 621 | if (timeoutMs !== undefined && timeoutMs <= 0) { |
622 | 622 | return { drained: getActiveEmbeddedRunCount() === 0 }; |
623 | 623 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。