diff --git a/src/commands/sessions-tail.test.ts b/src/commands/sessions-tail.test.ts index b609b4b8e162..e238aa991268 100644 --- a/src/commands/sessions-tail.test.ts +++ b/src/commands/sessions-tail.test.ts @@ -188,6 +188,18 @@ describe("sessionsTailCommand", () => { expect(output).toContain("tool.result"); }); + it("rejects tail counts that exceed JavaScript safe integer precision", async () => { + const runtime = makeRuntime(); + + await sessionsTailCommand({ store: storePath, sessionKey, tail: "9007199254740992" }, runtime); + + expect(runtime.error).toHaveBeenCalledWith( + "--tail must be a non-negative integer, for example --tail 25.", + ); + expect(runtime.exit).toHaveBeenCalledWith(1); + expect(runtime.log).not.toHaveBeenCalled(); + }); + it("uses a session trajectory pointer for relocated runtime files", async () => { const runtime = makeRuntime(); const relocatedDir = path.join(tmpDir, "relocated-trajectories"); diff --git a/src/commands/sessions-tail.ts b/src/commands/sessions-tail.ts index f72ad038e955..9fa909a55ba9 100644 --- a/src/commands/sessions-tail.ts +++ b/src/commands/sessions-tail.ts @@ -14,6 +14,7 @@ import { listSessionEntries } from "../config/sessions/session-accessor.js"; import type { SessionEntry } from "../config/sessions/types.js"; import { resolveStoredSessionKeyForAgentStore } from "../gateway/session-store-key.js"; import { formatErrorMessage } from "../infra/errors.js"; +import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js"; import { resolveAgentIdFromSessionKey } from "../routing/session-key.js"; import type { RuntimeEnv } from "../runtime.js"; import { @@ -90,14 +91,7 @@ function parseTailCount(value: string | number | undefined): number | null { if (value === undefined) { return DEFAULT_TAIL_COUNT; } - if (typeof value === "number") { - return Number.isInteger(value) && value >= 0 ? value : null; - } - const trimmed = value.trim(); - if (!/^\d+$/.test(trimmed)) { - return null; - } - return Number.parseInt(trimmed, 10); + return parseStrictNonNegativeInteger(value) ?? null; } function toOptionalString(value: unknown): string | undefined {