fix(subagents): ignore unsafe log limits

This commit is contained in:
Peter Steinberger
2026-05-29 05:29:44 -04:00
parent c7127c7c34
commit 75c011b606
2 changed files with 24 additions and 2 deletions

View File

@@ -71,4 +71,22 @@ describe("subagents log", () => {
params: { sessionKey: "agent:main:subagent:log", limit: 5 },
});
});
it("clamps a zero history limit to one", async () => {
await handleSubagentsLogAction(buildLogContext(["1", "0"], [makeRun()]));
expect(callGatewayMock).toHaveBeenCalledWith({
method: "chat.history",
params: { sessionKey: "agent:main:subagent:log", limit: 1 },
});
});
it("ignores unsafe history limit tokens", async () => {
await handleSubagentsLogAction(buildLogContext(["1", "9007199254740992"], [makeRun()]));
expect(callGatewayMock).toHaveBeenCalledWith({
method: "chat.history",
params: { sessionKey: "agent:main:subagent:log", limit: 20 },
});
});
});

View File

@@ -1,4 +1,5 @@
import { callGateway } from "../../../gateway/call.js";
import { parseStrictNonNegativeInteger } from "../../../shared/number-coercion.js";
import { normalizeLowercaseStringOrEmpty } from "../../../shared/string-coerce.js";
import type { CommandHandlerResult } from "../commands-types.js";
import { formatRunLabel } from "../subagents-utils.js";
@@ -23,8 +24,11 @@ export async function handleSubagentsLogAction(
const includeTools = restTokens.some(
(token) => normalizeLowercaseStringOrEmpty(token) === "tools",
);
const limitToken = restTokens.slice(1).find((token) => /^\d+$/.test(token));
const limit = limitToken ? Math.min(200, Math.max(1, Number.parseInt(limitToken, 10))) : 20;
const limitToken = restTokens
.slice(1)
.find((token) => parseStrictNonNegativeInteger(token) !== undefined);
const parsedLimit = parseStrictNonNegativeInteger(limitToken);
const limit = parsedLimit === undefined ? 20 : Math.min(200, Math.max(1, parsedLimit));
const targetResolution = resolveSubagentEntryForToken(runs, target);
if ("reply" in targetResolution) {