Skip to content

Commit 4b0f712

Browse files
authored
fix(browser): preserve response-body timeout diagnostics (#129803)
1 parent 6b02b00 commit 4b0f712

6 files changed

Lines changed: 54 additions & 37 deletions

File tree

‎extensions/browser/src/cli/browser-cli-actions-input/register.files-downloads.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ describe("browser action input file/download commands", () => {
9393
timeoutMs: 45000,
9494
},
9595
});
96-
expect(getLastRequestOptions()?.timeoutMs).toBeGreaterThan(45000);
96+
expect(getLastRequestOptions()?.timeoutMs).toBe(50000);
9797
});
9898

9999
it("keeps the outer waitfordownload request open for the advertised default wait", async () => {
100100
const program = createActionInputProgram();
101101

102102
await program.parseAsync(["browser", "waitfordownload"], { from: "user" });
103103

104-
expect(getLastRequestOptions()?.timeoutMs).toBeGreaterThan(120000);
104+
expect(getLastRequestOptions()?.timeoutMs).toBe(125000);
105105
});
106106

107107
it("accepts signed and zero-padded download timeouts", async () => {
@@ -111,7 +111,7 @@ describe("browser action input file/download commands", () => {
111111
from: "user",
112112
});
113113

114-
expect(getLastRequestOptions()?.timeoutMs).toBeGreaterThan(25_000);
114+
expect(getLastRequestOptions()?.timeoutMs).toBe(30000);
115115
});
116116

117117
it("uses custom download timeouts as the inner wait plus outer slack", async () => {
@@ -124,7 +124,7 @@ describe("browser action input file/download commands", () => {
124124
},
125125
);
126126

127-
expect(getLastRequestOptions()?.timeoutMs).toBeGreaterThan(25000);
127+
expect(getLastRequestOptions()?.timeoutMs).toBe(30000);
128128
});
129129

130130
it("rejects non-decimal file and download timeouts before dispatch", async () => {

‎extensions/browser/src/cli/browser-cli-actions-input/register.files-downloads.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
BROWSER_TAB_REFERENCE_HELP,
88
callBrowserRequest,
99
parseBrowserPositiveIntegerOption,
10+
withBrowserActionTimeoutSlack,
1011
type BrowserParentOpts,
1112
} from "../browser-cli-shared.js";
1213
import {
@@ -15,7 +16,7 @@ import {
1516
resolveExistingUploadPaths,
1617
shortenHomePath,
1718
} from "../core-api.js";
18-
import { resolveBrowserActionContext, withBrowserActionTimeoutSlack } from "./shared.js";
19+
import { resolveBrowserActionContext } from "./shared.js";
1920

2021
const DEFAULT_BROWSER_HOOK_TIMEOUT_MS = 120000;
2122

‎extensions/browser/src/cli/browser-cli-actions-input/shared.ts‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*/
44
import fs from "node:fs/promises";
55
import type { Command } from "commander";
6-
import { addTimerTimeoutGraceMs } from "openclaw/plugin-sdk/number-runtime";
7-
import { BROWSER_ACTION_TRANSPORT_SLACK_MS } from "../../browser/act-policy.js";
8-
import { callBrowserRequest, type BrowserParentOpts } from "../browser-cli-shared.js";
6+
import {
7+
callBrowserRequest,
8+
withBrowserActionTimeoutSlack,
9+
type BrowserParentOpts,
10+
} from "../browser-cli-shared.js";
911
import {
1012
danger,
1113
defaultRuntime,
@@ -19,18 +21,6 @@ type BrowserActionContext = {
1921
profile: string | undefined;
2022
};
2123

22-
const DEFAULT_BROWSER_ACTION_TIMEOUT_MS = 20000;
23-
24-
/** Adds gateway slack to a Browser action timeout so route work can finish cleanly. */
25-
export function withBrowserActionTimeoutSlack(timeoutMs: number | undefined): number {
26-
return (
27-
addTimerTimeoutGraceMs(
28-
timeoutMs ?? DEFAULT_BROWSER_ACTION_TIMEOUT_MS,
29-
BROWSER_ACTION_TRANSPORT_SLACK_MS,
30-
) ?? 1
31-
);
32-
}
33-
3424
/** Resolves inherited Browser action context from a commander command. */
3525
export function resolveBrowserActionContext(
3626
cmd: Command,

‎extensions/browser/src/cli/browser-cli-actions-observe.test.ts‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,40 @@ describe("browser action observe commands", () => {
8585
expect(mocks.callBrowserRequest).not.toHaveBeenCalled();
8686
});
8787

88-
it("passes responsebody limits through to the request and outer timeout", async () => {
89-
const program = createActionObserveProgram();
88+
it.each([
89+
{
90+
label: "default",
91+
timeout: undefined,
92+
operationTimeoutMs: undefined,
93+
requestTimeoutMs: 25000,
94+
},
95+
{ label: "minimum explicit", timeout: "1", operationTimeoutMs: 1, requestTimeoutMs: 5001 },
96+
{
97+
label: "signed explicit",
98+
timeout: "+030000",
99+
operationTimeoutMs: 30000,
100+
requestTimeoutMs: 35000,
101+
},
102+
])(
103+
"keeps the $label responsebody request open past its operation deadline",
104+
async ({ timeout, operationTimeoutMs, requestTimeoutMs }) => {
105+
const program = createActionObserveProgram();
106+
const args = ["browser", "responsebody", "**/api", "--max-chars", "0100"];
107+
if (timeout !== undefined) {
108+
args.push("--timeout-ms", timeout);
109+
}
90110

91-
await program.parseAsync(
92-
["browser", "responsebody", "**/api", "--timeout-ms", "+030000", "--max-chars", "0100"],
93-
{ from: "user" },
94-
);
111+
await program.parseAsync(args, { from: "user" });
95112

96-
const request = mocks.callBrowserRequest.mock.calls.at(-1)?.[1] as
97-
| { body?: { timeoutMs?: number; maxChars?: number } }
98-
| undefined;
99-
const options = mocks.callBrowserRequest.mock.calls.at(-1)?.[2] as
100-
| { timeoutMs?: number }
101-
| undefined;
102-
expect(request?.body?.timeoutMs).toBe(30000);
103-
expect(request?.body?.maxChars).toBe(100);
104-
expect(options?.timeoutMs).toBe(30000);
105-
});
113+
const request = mocks.callBrowserRequest.mock.calls.at(-1)?.[1] as
114+
| { body?: { timeoutMs?: number; maxChars?: number } }
115+
| undefined;
116+
const options = mocks.callBrowserRequest.mock.calls.at(-1)?.[2] as
117+
| { timeoutMs?: number }
118+
| undefined;
119+
expect(request?.body?.timeoutMs).toBe(operationTimeoutMs);
120+
expect(request?.body?.maxChars).toBe(100);
121+
expect(options?.timeoutMs).toBe(requestTimeoutMs);
122+
},
123+
);
106124
});

‎extensions/browser/src/cli/browser-cli-actions-observe.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
parseBrowserPositiveIntegerOption,
1010
printBrowserJsonResult,
1111
runBrowserCliCommand as runBrowserObserve,
12+
withBrowserActionTimeoutSlack,
1213
type BrowserParentOpts,
1314
} from "./browser-cli-shared.js";
1415
import { defaultRuntime, shortenHomePath } from "./core-api.js";
@@ -112,7 +113,7 @@ export function registerBrowserActionObserveCommands(
112113
maxChars,
113114
},
114115
},
115-
{ timeoutMs: timeoutMs ?? 20000 },
116+
{ timeoutMs: withBrowserActionTimeoutSlack(timeoutMs) },
116117
);
117118
if (printBrowserJsonResult(parent, result)) {
118119
return;

‎extensions/browser/src/cli/browser-cli-shared.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
* Shared Browser CLI option parsing and gateway request helpers.
33
*/
44
import {
5+
addTimerTimeoutGraceMs,
56
parseStrictNonNegativeInteger,
67
parseStrictPositiveInteger,
78
} from "openclaw/plugin-sdk/number-runtime";
89
import {
910
BROWSER_REQUEST_GATEWAY_METHOD,
1011
BROWSER_REQUEST_GATEWAY_SCOPES,
1112
} from "../browser-gateway-contract.js";
13+
import { BROWSER_ACTION_TRANSPORT_SLACK_MS } from "../browser/act-policy.js";
1214
import { normalizeBrowserTimerDelayMs } from "../browser/timer-delay.js";
1315
import { danger, defaultRuntime, runCommandWithRuntime } from "../core-api.js";
1416
import { callGatewayFromCli, type GatewayRpcOpts } from "./core-api.js";
@@ -30,6 +32,11 @@ type BrowserRequestParams = {
3032
body?: unknown;
3133
};
3234

35+
/** Adds gateway slack to a Browser action timeout so route work can finish cleanly. */
36+
export function withBrowserActionTimeoutSlack(timeoutMs: number | undefined): number {
37+
return addTimerTimeoutGraceMs(timeoutMs ?? 20_000, BROWSER_ACTION_TRANSPORT_SLACK_MS) ?? 1;
38+
}
39+
3340
/** Runs a Browser CLI command with the standard runtime error handling. */
3441
export function runBrowserCliCommand(action: () => Promise<void>) {
3542
return runCommandWithRuntime(defaultRuntime, action, (error) => {

0 commit comments

Comments
 (0)