Skip to content

Commit 7e3090c

Browse files
committed
fix(agents): retry sessions_send active steering
1 parent 4da2d3a commit 7e3090c

2 files changed

Lines changed: 67 additions & 7 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,55 @@ describe("sessions tools", () => {
14091409
});
14101410
});
14111411

1412+
it("sessions_send preserves active delivery when transcript commit wait is unsupported", async () => {
1413+
const calls: Array<{ method?: string }> = [];
1414+
const runScopedCallerKey = "agent:leasing-ops:cron:monthly-utility:run:run-fast";
1415+
const queueMessage = vi.fn(async () => {});
1416+
setActiveEmbeddedRun(
1417+
"caller-active-session",
1418+
{
1419+
queueMessage,
1420+
isStreaming: () => true,
1421+
isCompacting: () => false,
1422+
abort: () => {},
1423+
},
1424+
runScopedCallerKey,
1425+
);
1426+
callGatewayMock.mockImplementation(async (opts: unknown) => {
1427+
const request = opts as { method?: string };
1428+
calls.push(request);
1429+
if (request.method === "agent") {
1430+
throw new Error("fallback agent should not start");
1431+
}
1432+
return {};
1433+
});
1434+
1435+
const tool = createOpenClawTools({
1436+
agentSessionKey: "agent:re-portal:main",
1437+
agentChannel: "telegram",
1438+
}).find((candidate) => candidate.name === "sessions_send");
1439+
if (!tool) {
1440+
throw new Error("missing sessions_send tool");
1441+
}
1442+
1443+
const result = await tool.execute("call-run-scoped-caller", {
1444+
sessionKey: runScopedCallerKey,
1445+
message: "[TASK-COMPLETE] re-portal occupancy ready",
1446+
timeoutSeconds: 0,
1447+
});
1448+
1449+
const details = sessionsSendDetails(result.details);
1450+
expect(details.status).toBe("accepted");
1451+
expect(details.sessionKey).toBe(runScopedCallerKey);
1452+
expect(queueMessage).toHaveBeenCalledOnce();
1453+
expect(queueMessage).toHaveBeenCalledWith(expect.stringContaining("[Inter-session message]"), {
1454+
steeringMode: "all",
1455+
debounceMs: 0,
1456+
deliveryTimeoutMs: 30_000,
1457+
});
1458+
expect(calls.some((call) => call.method === "agent")).toBe(false);
1459+
});
1460+
14121461
it("sessions_send reports run-scoped fallback admission failures", async () => {
14131462
const runScopedCallerKey = "agent:leasing-ops:cron:monthly-utility:run:run-fast";
14141463
const queueMessage = vi.fn(async () => {

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { listAgentIds } from "../agent-scope.js";
2323
import { resolveNestedAgentLaneForSession } from "../lanes.js";
2424
import {
25+
type EmbeddedPiQueueMessageOptions,
2526
formatEmbeddedPiQueueFailureSummary,
2627
queueEmbeddedPiMessageWithOutcomeAsync,
2728
resolveActiveEmbeddedRunSessionId,
@@ -187,16 +188,26 @@ async function startAgentRun(params: {
187188
const messageText =
188189
typeof params.sendParams.message === "string" ? params.sendParams.message : undefined;
189190
if (activeRunSessionId && fallbackSessionKey && messageText) {
190-
const queueOutcome = await queueEmbeddedPiMessageWithOutcomeAsync(
191+
const queueOptions: EmbeddedPiQueueMessageOptions = {
192+
steeringMode: "all",
193+
debounceMs: 0,
194+
deliveryTimeoutMs: params.deliveryTimeoutMs,
195+
waitForTranscriptCommit: true,
196+
};
197+
let queueOutcome = await queueEmbeddedPiMessageWithOutcomeAsync(
191198
activeRunSessionId,
192199
messageText,
193-
{
194-
steeringMode: "all",
195-
debounceMs: 0,
196-
deliveryTimeoutMs: params.deliveryTimeoutMs,
197-
waitForTranscriptCommit: true,
198-
},
200+
queueOptions,
199201
);
202+
if (!queueOutcome.queued && queueOutcome.reason === "transcript_commit_wait_unsupported") {
203+
const bestEffortQueueOptions = { ...queueOptions };
204+
delete bestEffortQueueOptions.waitForTranscriptCommit;
205+
queueOutcome = await queueEmbeddedPiMessageWithOutcomeAsync(
206+
activeRunSessionId,
207+
messageText,
208+
bestEffortQueueOptions,
209+
);
210+
}
200211
if (queueOutcome.queued) {
201212
return { ok: true, runId: params.runId, activeRunQueue: true };
202213
}

0 commit comments

Comments
 (0)