Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
11 changes: 11 additions & 0 deletions pkgs/mcpx/plugin/opencode/mcpx/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading