From 2910fc0b136ea45179e962e9e3971ec9d5821c15 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:48:38 +0800 Subject: [PATCH] fix(electron): refuse a wait longer than Node can schedule (#11606) An Electron scenario wait accepted any non-negative duration_ms, and Playwright's waitForTimeout schedules a delay above 2147483647 ms as 1 ms, so a very long wait returned at once. Bound it at admission with the shared Node timer maximum, as the browser scenario wait already does. Refs #11601 --- .../tools/capture_electron_scenario.json | 2 +- src/domain/analysisResourceLimits.ts | 8 ++--- .../javascript/electronActiveObservation.ts | 9 +++++- tests/boundary/mcp/electronMcp.test.ts | 31 +++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json b/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json index c0874ac63e..31bda6287d 100644 --- a/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json +++ b/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "1966487f98e87f51", + "input compact": "88ba9b1c0d33d10f", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/src/domain/analysisResourceLimits.ts b/src/domain/analysisResourceLimits.ts index 3c4db8f799..5eac06b621 100644 --- a/src/domain/analysisResourceLimits.ts +++ b/src/domain/analysisResourceLimits.ts @@ -79,10 +79,6 @@ export const MINIMUM_HOPPER_CALLER_SCAN_BUDGET_MS = 1; */ export const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647; -/** - * A positive whole-millisecond duration Node can schedule exactly. Zero and - * negative values are not a deadline. - */ /** * The per-call control of a caller-selectable millisecond deadline, named by * its contract field; each adapter names the option that sets it. @@ -102,6 +98,10 @@ export const deadlineParameterLimit = ( applies_at: "next_call", }); +/** + * A positive whole-millisecond duration Node can schedule exactly. Zero and + * negative values are not a deadline. + */ export const timerDurationMsSchema = z .int() .min(1) diff --git a/src/domain/javascript/electronActiveObservation.ts b/src/domain/javascript/electronActiveObservation.ts index 82bf312ab0..3522e9874c 100644 --- a/src/domain/javascript/electronActiveObservation.ts +++ b/src/domain/javascript/electronActiveObservation.ts @@ -1,4 +1,5 @@ import { z } from "zod"; +import { MAX_NODE_TIMER_DELAY_MS } from "../analysisResourceLimits.js"; import { absoluteLocalPathStringSchema } from "../localPath.js"; const absolutePathSchema = z @@ -37,7 +38,13 @@ const actionSchema = z.discriminatedUnion("kind", [ z.strictObject({ step_id: z.string().min(1), kind: z.literal("wait"), - duration_ms: z.int().min(0), + duration_ms: z + .int() + .min(0) + .max(MAX_NODE_TIMER_DELAY_MS) + .describe( + `Wait this many milliseconds, from 0 to ${String(MAX_NODE_TIMER_DELAY_MS)}; the wait ends early on cancellation.`, + ), window_index: windowIndexSchema.optional(), }), z.strictObject({ diff --git a/tests/boundary/mcp/electronMcp.test.ts b/tests/boundary/mcp/electronMcp.test.ts index a5ba91b9c4..f8b6c15b7f 100644 --- a/tests/boundary/mcp/electronMcp.test.ts +++ b/tests/boundary/mcp/electronMcp.test.ts @@ -838,6 +838,37 @@ it("reports every unresolved Electron path without starting a provider", async ( await client.ping(); }); +it("refuses an Electron wait longer than Node can schedule", async () => { + const capture = vi.fn(); + const client = await activePathAdmissionClient(capture); + // Playwright's waitForTimeout(2 ** 31) returns after 1 ms. + const result = await client.callTool({ + name: "capture_electron_scenario", + arguments: { + executable_path: process.execPath, + application_path: process.execPath, + actions: [{ step_id: "settle", kind: "wait", duration_ms: 2 ** 31 }], + }, + }); + expect(result.isError).toBe(true); + expect(parseMcpToolError(result)).toMatchObject({ + error: { + code: "invalid_request", + details: { + issues: expect.arrayContaining([ + expect.objectContaining({ + path: ["actions", 0, "duration_ms"], + reason: "out_of_range", + maximum: 2_147_483_647, + }), + ]), + }, + }, + }); + expect(capture).not.toHaveBeenCalled(); + await client.ping(); +}); + it.skipIf(process.platform === "win32")( "refuses obstructed Electron selections and admits native symlink traversal through MCP", async () => {