Skip to content

Commit f2843d3

Browse files
committed
fix: validate session send timeout
1 parent d7fca57 commit f2843d3

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎src/agents/openclaw-tools.sessions.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe("sessions tools", () => {
284284
expect(schemaProp("sessions_list", "search").type).toBe("string");
285285
expect(schemaProp("sessions_list", "includeDerivedTitles").type).toBe("boolean");
286286
expect(schemaProp("sessions_list", "includeLastMessage").type).toBe("boolean");
287-
expect(schemaProp("sessions_send", "timeoutSeconds").type).toBe("number");
287+
expect(schemaProp("sessions_send", "timeoutSeconds").type).toBe("integer");
288288
});
289289

290290
it("sessions_list forwards mailbox filters and includes messages", async () => {

‎src/agents/tools/sessions-send-tool.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
SESSIONS_SEND_TOOL_DISPLAY_SUMMARY,
3939
} from "../tool-description-presets.js";
4040
import type { AnyAgentTool } from "./common.js";
41-
import { jsonResult, readStringParam } from "./common.js";
41+
import { jsonResult, readNonNegativeIntegerParam, readStringParam } from "./common.js";
4242
import {
4343
createSessionVisibilityGuard,
4444
createAgentToAgentPolicy,
@@ -55,7 +55,7 @@ const SessionsSendToolSchema = Type.Object({
5555
label: Type.Optional(Type.String({ minLength: 1, maxLength: SESSION_LABEL_MAX_LENGTH })),
5656
agentId: Type.Optional(Type.String({ minLength: 1, maxLength: 64 })),
5757
message: Type.String(),
58-
timeoutSeconds: Type.Optional(Type.Number({ minimum: 0 })),
58+
timeoutSeconds: Type.Optional(Type.Integer({ minimum: 0 })),
5959
});
6060

6161
type GatewayCaller = typeof callGateway;
@@ -283,6 +283,7 @@ export function createSessionsSendTool(opts?: {
283283
const params = args as Record<string, unknown>;
284284
const gatewayCall = opts?.callGateway ?? callGateway;
285285
const message = readStringParam(params, "message", { required: true });
286+
const timeoutSeconds = readNonNegativeIntegerParam(params, "timeoutSeconds") ?? 30;
286287
const { cfg, mainKey, alias, effectiveRequesterKey, restrictToSpawned } =
287288
resolveSessionToolContext(opts);
288289

@@ -435,10 +436,6 @@ export function createSessionsSendTool(opts?: {
435436
// Normalize sessionKey/sessionId input into a canonical session key.
436437
const resolvedKey = visibleSession.key;
437438
const displayKey = visibleSession.displayKey;
438-
const timeoutSeconds =
439-
typeof params.timeoutSeconds === "number" && Number.isFinite(params.timeoutSeconds)
440-
? Math.max(0, Math.floor(params.timeoutSeconds))
441-
: 30;
442439
const timeoutMs = timeoutSeconds * 1000;
443440
const announceTimeoutMs = timeoutSeconds === 0 ? 30_000 : timeoutMs;
444441
const idempotencyKey = crypto.randomUUID();

‎src/agents/tools/sessions.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,19 @@ describe("sessions_send gating", () => {
724724
expect(callGatewayMock).not.toHaveBeenCalled();
725725
});
726726

727+
it.each([1.5, -1, "1sec"])("rejects invalid timeoutSeconds value %s", async (timeoutSeconds) => {
728+
const tool = createMainSessionsSendTool();
729+
730+
await expect(
731+
tool.execute("call-invalid-timeout", {
732+
sessionKey: MAIN_AGENT_SESSION_KEY,
733+
message: "hi",
734+
timeoutSeconds,
735+
}),
736+
).rejects.toThrow("timeoutSeconds must be a non-negative integer");
737+
expect(callGatewayMock).not.toHaveBeenCalled();
738+
});
739+
727740
it("returns an error when label resolution fails", async () => {
728741
callGatewayMock.mockRejectedValueOnce(new Error("No session found with label: nope"));
729742
const tool = createMainSessionsSendTool();

0 commit comments

Comments
 (0)