fix(subagents): ignore unsafe log limits · openclaw/openclaw@75c011b
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -71,4 +71,22 @@ describe("subagents log", () => {
|
71 | 71 | params: { sessionKey: "agent:main:subagent:log", limit: 5 }, |
72 | 72 | }); |
73 | 73 | }); |
| 74 | + |
| 75 | +it("clamps a zero history limit to one", async () => { |
| 76 | +await handleSubagentsLogAction(buildLogContext(["1", "0"], [makeRun()])); |
| 77 | + |
| 78 | +expect(callGatewayMock).toHaveBeenCalledWith({ |
| 79 | +method: "chat.history", |
| 80 | +params: { sessionKey: "agent:main:subagent:log", limit: 1 }, |
| 81 | +}); |
| 82 | +}); |
| 83 | + |
| 84 | +it("ignores unsafe history limit tokens", async () => { |
| 85 | +await handleSubagentsLogAction(buildLogContext(["1", "9007199254740992"], [makeRun()])); |
| 86 | + |
| 87 | +expect(callGatewayMock).toHaveBeenCalledWith({ |
| 88 | +method: "chat.history", |
| 89 | +params: { sessionKey: "agent:main:subagent:log", limit: 20 }, |
| 90 | +}); |
| 91 | +}); |
74 | 92 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { callGateway } from "../../../gateway/call.js"; |
| 2 | +import { parseStrictNonNegativeInteger } from "../../../shared/number-coercion.js"; |
2 | 3 | import { normalizeLowercaseStringOrEmpty } from "../../../shared/string-coerce.js"; |
3 | 4 | import type { CommandHandlerResult } from "../commands-types.js"; |
4 | 5 | import { formatRunLabel } from "../subagents-utils.js"; |
@@ -23,8 +24,11 @@ export async function handleSubagentsLogAction(
|
23 | 24 | const includeTools = restTokens.some( |
24 | 25 | (token) => normalizeLowercaseStringOrEmpty(token) === "tools", |
25 | 26 | ); |
26 | | -const limitToken = restTokens.slice(1).find((token) => /^\d+$/.test(token)); |
27 | | -const limit = limitToken ? Math.min(200, Math.max(1, Number.parseInt(limitToken, 10))) : 20; |
| 27 | +const limitToken = restTokens |
| 28 | +.slice(1) |
| 29 | +.find((token) => parseStrictNonNegativeInteger(token) !== undefined); |
| 30 | +const parsedLimit = parseStrictNonNegativeInteger(limitToken); |
| 31 | +const limit = parsedLimit === undefined ? 20 : Math.min(200, Math.max(1, parsedLimit)); |
28 | 32 | |
29 | 33 | const targetResolution = resolveSubagentEntryForToken(runs, target); |
30 | 34 | if ("reply" in targetResolution) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。