mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 05:12:57 +00:00
fix(subagents): ignore unsafe log limits
This commit is contained in:
@@ -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 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user