mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 03:04:56 +00:00
fix: parse embedded abort settle timeout strictly
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveEmbeddedAbortSettleTimeoutMs } from "./attempt.abort-settle-timeout.js";
|
||||
|
||||
describe("resolveEmbeddedAbortSettleTimeoutMs", () => {
|
||||
it("uses a positive decimal integer override", () => {
|
||||
expect(
|
||||
resolveEmbeddedAbortSettleTimeoutMs({
|
||||
OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS: "1250",
|
||||
}),
|
||||
).toBe(1250);
|
||||
});
|
||||
|
||||
it.each(["0x10", "1e3", "12.5"])("ignores non-decimal-integer overrides: %s", (value) => {
|
||||
expect(
|
||||
resolveEmbeddedAbortSettleTimeoutMs({
|
||||
OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS: value,
|
||||
}),
|
||||
).toBe(2_000);
|
||||
});
|
||||
|
||||
it("keeps the fast-test fallback when the override is invalid", () => {
|
||||
expect(
|
||||
resolveEmbeddedAbortSettleTimeoutMs({
|
||||
OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS: "10ms",
|
||||
OPENCLAW_TEST_FAST: "1",
|
||||
}),
|
||||
).toBe(250);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { parseStrictPositiveInteger } from "../../../infra/parse-finite-number.js";
|
||||
|
||||
export function resolveEmbeddedAbortSettleTimeoutMs(
|
||||
env: Pick<
|
||||
NodeJS.ProcessEnv,
|
||||
"OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS" | "OPENCLAW_TEST_FAST"
|
||||
> = process.env,
|
||||
): number {
|
||||
const override = parseStrictPositiveInteger(env.OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS);
|
||||
if (override !== undefined) {
|
||||
return override;
|
||||
}
|
||||
return env.OPENCLAW_TEST_FAST === "1" ? 250 : 2_000;
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
import type { AgentMessage } from "../../runtime/index.js";
|
||||
import { log } from "../logger.js";
|
||||
import { resolveEmbeddedAbortSettleTimeoutMs } from "./attempt.abort-settle-timeout.js";
|
||||
|
||||
const SESSIONS_YIELD_INTERRUPT_CUSTOM_TYPE = "openclaw.sessions_yield_interrupt";
|
||||
const SESSIONS_YIELD_CONTEXT_CUSTOM_TYPE = "openclaw.sessions_yield";
|
||||
function resolveSessionsYieldAbortSettleTimeoutMs(): number {
|
||||
const override = Number(process.env.OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS);
|
||||
if (Number.isFinite(override) && override > 0) {
|
||||
return override;
|
||||
}
|
||||
return process.env.OPENCLAW_TEST_FAST === "1" ? 250 : 2_000;
|
||||
}
|
||||
|
||||
const SESSIONS_YIELD_ABORT_SETTLE_TIMEOUT_MS = resolveSessionsYieldAbortSettleTimeoutMs();
|
||||
const SESSIONS_YIELD_ABORT_SETTLE_TIMEOUT_MS = resolveEmbeddedAbortSettleTimeoutMs();
|
||||
|
||||
// Persist a hidden context reminder so the next turn knows why the runner stopped.
|
||||
function buildSessionsYieldContextMessage(message: string): string {
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import type { SubscribeEmbeddedAgentSessionParams } from "../../embedded-agent-subscribe.types.js";
|
||||
import { log } from "../logger.js";
|
||||
|
||||
function resolveEmbeddedAbortSettleTimeoutMs(): number {
|
||||
const override = Number(process.env.OPENCLAW_EMBEDDED_ABORT_SETTLE_TIMEOUT_MS);
|
||||
if (Number.isFinite(override) && override > 0) {
|
||||
return override;
|
||||
}
|
||||
return process.env.OPENCLAW_TEST_FAST === "1" ? 250 : 2_000;
|
||||
}
|
||||
import { resolveEmbeddedAbortSettleTimeoutMs } from "./attempt.abort-settle-timeout.js";
|
||||
|
||||
export const EMBEDDED_ABORT_SETTLE_TIMEOUT_MS = resolveEmbeddedAbortSettleTimeoutMs();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user