fix(qa): clamp transport wait intervals · openclaw/openclaw@0303f3a
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -153,4 +153,12 @@ describe("qa channel transport", () => {
|
153 | 153 | "ok", |
154 | 154 | ); |
155 | 155 | }); |
| 156 | + |
| 157 | +it("keeps oversized wait helper intervals within the timeout", async () => { |
| 158 | +const transport = createQaChannelTransport(createQaBusState()); |
| 159 | + |
| 160 | +await expect( |
| 161 | +transport.capabilities.waitForCondition(async () => undefined, 5, Number.MAX_SAFE_INTEGER), |
| 162 | +).rejects.toThrow("timed out after 5ms"); |
| 163 | +}); |
156 | 164 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { setTimeout as sleep } from "node:timers/promises"; |
2 | 2 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
| 3 | +import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime"; |
3 | 4 | import type { QaProviderMode } from "./model-selection.js"; |
4 | 5 | import { extractQaFailureReplyText } from "./reply-failure.js"; |
5 | 6 | import type { |
@@ -85,13 +86,18 @@ export async function waitForQaTransportCondition<T>(
|
85 | 86 | timeoutMs = 15_000, |
86 | 87 | intervalMs = 100, |
87 | 88 | ): Promise<T> { |
| 89 | +const pollIntervalMs = resolveTimerTimeoutMs(intervalMs, 100, 0); |
88 | 90 | const startedAt = Date.now(); |
89 | 91 | while (Date.now() - startedAt < timeoutMs) { |
90 | 92 | const value = await check(); |
91 | 93 | if (value !== null && value !== undefined) { |
92 | 94 | return value; |
93 | 95 | } |
94 | | -await sleep(intervalMs); |
| 96 | +const remainingMs = timeoutMs - (Date.now() - startedAt); |
| 97 | +if (remainingMs <= 0) { |
| 98 | +break; |
| 99 | +} |
| 100 | +await sleep(Math.min(pollIntervalMs, remainingMs)); |
95 | 101 | } |
96 | 102 | throw new Error(`timed out after ${timeoutMs}ms`); |
97 | 103 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。