diff --git a/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts b/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts index 805517c36a..0c192a7f84 100644 --- a/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts +++ b/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts @@ -430,6 +430,17 @@ describe("goDurationMs", () => { expect(goDurationMs("soon")).toBeUndefined(); expect(goDurationMs("60s please")).toBeUndefined(); expect(goDurationMs("-30s")).toBeUndefined(); + // #2309: Go's duration ceiling — ParseDuration rejects totals + // past 2^63-1 ns, so extreme spellings are absent, never + // Infinity or a beyond-ceiling cooldown. + expect(goDurationMs("3000000h")).toBeUndefined(); + expect(goDurationMs("99999999999999999999h")).toBeUndefined(); + // Just under the ceiling still parses (the largest Go duration + // is 2562047h47m16.854775807s = 2^63-1 ns). + expect(goDurationMs("2562047h47m16.854775s")).toBeDefined(); + expect(goDurationMs("2562047h47m16.854775s")).toBeLessThanOrEqual(9_223_372_036_854.776); + // #2309: Go accepts a bare "0" as zero. + expect(goDurationMs("0")).toBe(0); }); }); diff --git a/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts b/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts index 991f126da4..a6f5d3c91c 100644 --- a/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts +++ b/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts @@ -102,7 +102,18 @@ export const goDurationMs = (v: string | undefined): number | undefined => { matched += m[0].length; } const body = v.trim().replace(/^[+-]/, ""); + // Go's special case: a bare "0" is a valid duration (zero) even + // though it carries no unit (#2309). "-0" still counts as a + // negative spelling below and stays undefined, as before. + if (body === "0" && !v.trim().startsWith("-")) return 0; if (matched !== body.length || matched === 0) return undefined; + // Go's ceiling: time.ParseDuration rejects any total past the + // int64-nanosecond maximum (2^63-1 ns = 9223372036854.776 ms). + // Without this check an extreme spelling summed to Infinity (or + // past the ceiling), and an infinite discovery cooldown silently + // disabled daemon rediscovery for the whole session (#2309). + // Unparseable-by-Go is this function's "treated as absent". + if (!Number.isFinite(total) || total > 9_223_372_036_854.776) return undefined; return v.trim().startsWith("-") ? undefined : total; };