Skip to content

Commit 0714a0d

Browse files
committed
fix: dispatch tool-bound turns normally
1 parent b036e0c commit 0714a0d

3 files changed

Lines changed: 25 additions & 32 deletions

File tree

‎src/auto-reply/reply/agent-runner.media-paths.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,17 @@ describe("runReplyAgent media path normalization", () => {
572572
});
573573

574574
it("latches audio only after the active reply operation accepts the steer", async () => {
575+
const followupRun = {
576+
...createMockFollowupRun({ prompt: "summarize the audio" }),
577+
currentInboundAudio: true,
578+
} as unknown as FollowupRun;
575579
const operation = createRegisteredReplyOperation({
576580
sessionKey: "agent:main:whatsapp:direct:chat-1",
577581
sessionId: "session",
578582
resetTriggered: false,
579583
});
580584
operation.setPhase("running");
581-
operation.bindToolAuthorityFingerprint(TEST_TOOL_AUTHORITY_FINGERPRINT);
585+
operation.bindToolAuthorityFingerprint(resolveFollowupRunToolAuthorityFingerprint(followupRun));
582586
expect(operation.acceptedSteeredInboundAudio).toBe(false);
583587
queueEmbeddedAgentMessageWithOutcomeAsyncMock.mockImplementation(async (sessionId: string) => ({
584588
queued: true,
@@ -589,16 +593,13 @@ describe("runReplyAgent media path normalization", () => {
589593

590594
await runReplyAgent(
591595
makeRunReplyAgentParams({
596+
followupRun,
592597
replyOperation: operation,
593598
sessionKey: "agent:main:whatsapp:direct:chat-1",
594599
resolvedQueue: { mode: "steer" } as QueueSettings,
595600
shouldSteer: true,
596601
shouldFollowup: true,
597602
isActive: true,
598-
followupRun: {
599-
...createMockFollowupRun({ prompt: "summarize the audio" }),
600-
currentInboundAudio: true,
601-
} as unknown as FollowupRun,
602603
}),
603604
);
604605

‎src/gateway/server-methods/chat-send-message-injection.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function createChatSendMessageInjectionStarter(params: {
4242
const { cfg, entry } = params.session;
4343
const { ctx, isInternalTextSlashCommandTurn, replyOptionImages, replyOptionMedia } = params.turn;
4444
return (): ReplyMessageInjectionAttempt | undefined => {
45-
if (!params.target || isInternalTextSlashCommandTurn) {
45+
if (!params.target || isInternalTextSlashCommandTurn || toolBindings !== undefined) {
4646
return undefined;
4747
}
4848
const { debounceMs } = resolveQueueSettings({

‎src/gateway/server-methods/chat.directive-tags.test.ts‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,6 @@ function createChatContext(): Pick<
10571057
};
10581058
}
10591059

1060-
function beginChatReplyOperation(
1061-
params: Parameters<typeof replyRunRegistry.begin>[0],
1062-
): ReturnType<typeof replyRunRegistry.begin> {
1063-
const operation = replyRunRegistry.begin(params);
1064-
operation.bindToolAuthorityFingerprint("chat-test-authority");
1065-
return operation;
1066-
}
1067-
10681060
type ChatContext = ReturnType<typeof createChatContext>;
10691061

10701062
function useChatTestModel(model: "vision-model" | "text-only") {
@@ -1482,7 +1474,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
14821474
await createGatewayUserTurnSqliteFixture("openclaw-chat-send-targetless-no-leaf-");
14831475
const { context, respond, send } = createChatRequestFixture();
14841476
const queueMessage = vi.fn(async () => {});
1485-
const operation = beginChatReplyOperation({
1477+
const operation = replyRunRegistry.begin({
14861478
sessionKey: "agent:main:main",
14871479
sessionId: mockState.sessionId,
14881480
resetTriggered: false,
@@ -1524,7 +1516,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
15241516
});
15251517
const { context, respond, send } = createChatRequestFixture();
15261518
const queueMessage = vi.fn(async () => {});
1527-
const operation = beginChatReplyOperation({
1519+
const operation = replyRunRegistry.begin({
15281520
sessionKey: "agent:main:main",
15291521
sessionId: mockState.sessionId,
15301522
resetTriggered: false,
@@ -1568,7 +1560,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
15681560
});
15691561
const { context, respond, send } = createChatRequestFixture();
15701562
const queueMessage = vi.fn(async () => {});
1571-
const operation = beginChatReplyOperation({
1563+
const operation = replyRunRegistry.begin({
15721564
sessionKey: "agent:main:main",
15731565
sessionId: mockState.sessionId,
15741566
resetTriggered: false,
@@ -1634,7 +1626,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
16341626
});
16351627
const { context, respond, send } = createChatRequestFixture();
16361628
const queueMessage = vi.fn(async () => {});
1637-
const operation = beginChatReplyOperation({
1629+
const operation = replyRunRegistry.begin({
16381630
sessionKey: "agent:main:main",
16391631
sessionId: mockState.sessionId,
16401632
resetTriggered: false,
@@ -1678,7 +1670,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
16781670
const { context, respond } = createChatRequestFixture();
16791671
const originalQueue = vi.fn(async () => {});
16801672
const successorQueue = vi.fn(async () => {});
1681-
const original = beginChatReplyOperation({
1673+
const original = replyRunRegistry.begin({
16821674
sessionKey: "agent:main:main",
16831675
sessionId: mockState.sessionId,
16841676
resetTriggered: false,
@@ -1720,7 +1712,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
17201712
},
17211713
async () => {
17221714
original.complete();
1723-
successor = beginChatReplyOperation({
1715+
successor = replyRunRegistry.begin({
17241716
sessionKey: "agent:main:main",
17251717
sessionId: mockState.sessionId,
17261718
resetTriggered: false,
@@ -1760,7 +1752,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
17601752
parentId: null,
17611753
});
17621754
const { context, respond, send } = createChatRequestFixture();
1763-
const operation = beginChatReplyOperation({
1755+
const operation = replyRunRegistry.begin({
17641756
sessionKey: "agent:main:main",
17651757
sessionId: mockState.sessionId,
17661758
resetTriggered: false,
@@ -1811,7 +1803,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
18111803
await createGatewayUserTurnSqliteFixture("openclaw-chat-send-steer-before-ack-");
18121804
const { context, respond, send } = createChatRequestFixture();
18131805
const delivery = createDeferred();
1814-
const operation = beginChatReplyOperation({
1806+
const operation = replyRunRegistry.begin({
18151807
sessionKey: "agent:main:main",
18161808
sessionId: mockState.sessionId,
18171809
resetTriggered: false,
@@ -1867,7 +1859,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
18671859
const disposeAudit = onTrustedMessageAuditEvent((event) => auditEvents.push(event));
18681860
const { context, send } = createChatRequestFixture();
18691861
const dispatchCallsBefore = dispatchInboundMessageMock.mock.calls.length;
1870-
const operation = beginChatReplyOperation({
1862+
const operation = replyRunRegistry.begin({
18711863
sessionKey: "agent:main:main",
18721864
sessionId: mockState.sessionId,
18731865
resetTriggered: false,
@@ -1954,7 +1946,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
19541946
reportAcceptance = options?.onQueueAccepted;
19551947
return delivery.promise;
19561948
});
1957-
const operation = beginChatReplyOperation({
1949+
const operation = replyRunRegistry.begin({
19581950
sessionKey: "agent:main:main",
19591951
sessionId: mockState.sessionId,
19601952
resetTriggered: false,
@@ -2041,7 +2033,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
20412033
const originalQueue = vi.fn(async () => {});
20422034
const successorQueue = vi.fn(async () => {});
20432035
const successorCancel = vi.fn();
2044-
const original = beginChatReplyOperation({
2036+
const original = replyRunRegistry.begin({
20452037
sessionKey: "agent:main:main",
20462038
sessionId: mockState.sessionId,
20472039
resetTriggered: false,
@@ -2070,7 +2062,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
20702062
expect(respond).not.toHaveBeenCalled();
20712063
expect(originalQueue).not.toHaveBeenCalled();
20722064
original.complete();
2073-
successor = beginChatReplyOperation({
2065+
successor = replyRunRegistry.begin({
20742066
sessionKey: "agent:main:main",
20752067
sessionId: mockState.sessionId,
20762068
resetTriggered: false,
@@ -2166,7 +2158,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
21662158
const { context, respond, send } = createChatRequestFixture();
21672159
const dispatchCallsBefore = dispatchInboundMessageMock.mock.calls.length;
21682160
const delivery = createDeferred();
2169-
const operation = beginChatReplyOperation({
2161+
const operation = replyRunRegistry.begin({
21702162
sessionKey: "agent:main:main",
21712163
sessionId: mockState.sessionId,
21722164
resetTriggered: false,
@@ -2216,7 +2208,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
22162208
transcriptCommit: "unconfirmed";
22172209
errorMessage: string;
22182210
}>();
2219-
const first = beginChatReplyOperation({
2211+
const first = replyRunRegistry.begin({
22202212
sessionKey: "agent:main:main",
22212213
sessionId: mockState.sessionId,
22222214
resetTriggered: false,
@@ -2241,7 +2233,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
22412233
});
22422234
first.complete();
22432235
const successorCancel = vi.fn();
2244-
const successor = beginChatReplyOperation({
2236+
const successor = replyRunRegistry.begin({
22452237
sessionKey: "agent:main:main",
22462238
sessionId: mockState.sessionId,
22472239
resetTriggered: false,
@@ -2275,7 +2267,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
22752267
await createGatewayUserTurnSqliteFixture("openclaw-chat-send-steer-sync-reject-");
22762268
const { respond, send } = createChatRequestFixture();
22772269
const dispatchCallsBefore = dispatchInboundMessageMock.mock.calls.length;
2278-
const operation = beginChatReplyOperation({
2270+
const operation = replyRunRegistry.begin({
22792271
sessionKey: "agent:main:main",
22802272
sessionId: mockState.sessionId,
22812273
resetTriggered: false,
@@ -2316,7 +2308,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
23162308
await createGatewayUserTurnSqliteFixture("openclaw-chat-send-steer-run-changed-");
23172309
const { context, respond, send } = createChatRequestFixture();
23182310
const dispatchCallsBefore = dispatchInboundMessageMock.mock.calls.length;
2319-
const operation = beginChatReplyOperation({
2311+
const operation = replyRunRegistry.begin({
23202312
sessionKey: "agent:main:main",
23212313
sessionId: mockState.sessionId,
23222314
resetTriggered: false,
@@ -2380,7 +2372,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
23802372
const { context, respond, send } = createChatRequestFixture();
23812373
const dispatchCallsBefore = dispatchInboundMessageMock.mock.calls.length;
23822374
vi.useFakeTimers({ toFake: ["Date"] });
2383-
const operation = beginChatReplyOperation({
2375+
const operation = replyRunRegistry.begin({
23842376
sessionKey: "agent:main:main",
23852377
sessionId: mockState.sessionId,
23862378
resetTriggered: false,

0 commit comments

Comments
 (0)