mirror of https://github.com/openclaw/openclaw.git
fix(gateway): reject inter_session delivery before run tracking
This commit is contained in:
parent
9efa86be99
commit
9f3d7a3e7d
|
|
@ -522,6 +522,7 @@ describe("gateway agent handler", () => {
|
|||
it("rejects deliver=true when backend callers use the inter_session sentinel", async () => {
|
||||
primeMainAgentRun();
|
||||
mocks.agentCommand.mockClear();
|
||||
const context = makeContext();
|
||||
const selectionSpy = vi.spyOn(channelSelection, "resolveMessageChannelSelection");
|
||||
selectionSpy.mockResolvedValue({
|
||||
channel: "telegram",
|
||||
|
|
@ -540,6 +541,7 @@ describe("gateway agent handler", () => {
|
|||
},
|
||||
{
|
||||
reqId: "inter-session-backend-deliver-1",
|
||||
context,
|
||||
client: {
|
||||
connect: {
|
||||
role: "operator",
|
||||
|
|
@ -566,6 +568,11 @@ describe("gateway agent handler", () => {
|
|||
code: "INVALID_REQUEST",
|
||||
message: expect.stringContaining("inter_session"),
|
||||
});
|
||||
expect(context.addChatRun).not.toHaveBeenCalled();
|
||||
expect(mocks.registerAgentRunContext).not.toHaveBeenCalledWith(
|
||||
"test-inter-session-backend-deliver",
|
||||
expect.anything(),
|
||||
);
|
||||
expect(mocks.agentCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -313,6 +313,23 @@ export const agentHandlers: GatewayRequestHandlers = {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const wantsDelivery = request.deliver === true;
|
||||
const requestedInterSessionForDelivery = [request.channel, request.replyChannel].some((value) =>
|
||||
isInterSessionChannel(normalizeMessageChannel(value)),
|
||||
);
|
||||
if (wantsDelivery && requestedInterSessionForDelivery) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
errorShape(
|
||||
ErrorCodes.INVALID_REQUEST,
|
||||
"delivery channel cannot use the inter_session sentinel",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let resolvedSessionId = request.sessionId?.trim() || undefined;
|
||||
let sessionEntry: SessionEntry | undefined;
|
||||
let bestEffortDeliver = requestedBestEffortDeliver ?? false;
|
||||
|
|
@ -472,21 +489,6 @@ export const agentHandlers: GatewayRequestHandlers = {
|
|||
}
|
||||
}
|
||||
|
||||
const wantsDelivery = request.deliver === true;
|
||||
const requestedInterSessionForDelivery = [request.channel, request.replyChannel].some((value) =>
|
||||
isInterSessionChannel(normalizeMessageChannel(value)),
|
||||
);
|
||||
if (wantsDelivery && requestedInterSessionForDelivery) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
errorShape(
|
||||
ErrorCodes.INVALID_REQUEST,
|
||||
"delivery channel cannot use the inter_session sentinel",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const explicitTo =
|
||||
typeof request.replyTo === "string" && request.replyTo.trim()
|
||||
? request.replyTo.trim()
|
||||
|
|
|
|||
Loading…
Reference in New Issue