Skip to content

Commit d3be3b3

Browse files
committed
fix(auto-reply): surface empty interactive replies
1 parent 0602930 commit d3be3b3

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

‎src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,40 @@ describe("runReplyAgent typing (heartbeat)", () => {
942942
expect(res).toBeUndefined();
943943
});
944944

945+
it("surfaces an empty interactive completion instead of silently dropping the reply", async () => {
946+
state.runEmbeddedAgentMock.mockResolvedValueOnce({
947+
payloads: [],
948+
meta: {},
949+
});
950+
951+
const { run } = createMinimalRun({
952+
sessionCtx: {
953+
Provider: "telegram",
954+
OriginatingChannel: "telegram",
955+
MessageSid: "8836419572",
956+
},
957+
});
958+
const res = await run();
959+
const payload = Array.isArray(res) ? res[0] : res;
960+
961+
expect(payload?.isError).toBe(true);
962+
expect(payload?.text).toContain("did not produce a visible reply");
963+
});
964+
965+
it("preserves empty message-tool-only completions as intentional silence", async () => {
966+
state.runEmbeddedAgentMock.mockResolvedValueOnce({
967+
payloads: [],
968+
meta: {},
969+
});
970+
971+
const { run } = createMinimalRun({
972+
opts: { sourceReplyDeliveryMode: "message_tool_only" },
973+
runOverrides: { sourceReplyDeliveryMode: "message_tool_only" },
974+
});
975+
976+
await expect(run()).resolves.toBeUndefined();
977+
});
978+
945979
it("does not start typing on assistant message start without prior text in message mode", async () => {
946980
state.runEmbeddedAgentMock.mockImplementationOnce(async (params: AgentRunParams) => {
947981
await params.onAssistantMessageStart?.();

‎src/auto-reply/reply/agent-runner.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
buildFallbackNotice,
5757
resolveFallbackTransition,
5858
} from "../fallback-state.js";
59+
import type { SourceReplyDeliveryMode } from "../get-reply-options.types.js";
5960
import { DEFAULT_HEARTBEAT_ACK_MAX_CHARS, stripHeartbeatToken } from "../heartbeat.js";
6061
import {
6162
isReplyPayloadStatusNotice,
@@ -131,6 +132,8 @@ import type { TypingController } from "./typing.js";
131132
const BLOCK_REPLY_SEND_TIMEOUT_MS = 15_000;
132133
const RESTART_LIFECYCLE_REPLY_TEXT =
133134
"⚠️ Gateway is restarting. Please wait a few seconds and try again.";
135+
const EMPTY_INTERACTIVE_REPLY_TEXT =
136+
"⚠️ I finished this turn, but it did not produce a visible reply. Please try again, or use /new if this keeps happening.";
134137

135138
function scheduleFollowupDrainAfterReplyOperationClear(params: {
136139
operation: ReplyOperation;
@@ -184,6 +187,28 @@ function buildSilentFallbackFailurePayload(params: {
184187
});
185188
}
186189

190+
function buildEmptyInteractiveReplyPayload(params: {
191+
isHeartbeat: boolean;
192+
hasSuccessfulSideEffectDelivery: boolean;
193+
allowEmptyAssistantReplyAsSilent?: boolean;
194+
silentExpected?: boolean;
195+
sourceReplyDeliveryMode?: SourceReplyDeliveryMode;
196+
}): ReplyPayload | undefined {
197+
if (
198+
params.isHeartbeat ||
199+
params.allowEmptyAssistantReplyAsSilent === true ||
200+
params.silentExpected === true ||
201+
params.sourceReplyDeliveryMode === "message_tool_only" ||
202+
params.hasSuccessfulSideEffectDelivery
203+
) {
204+
return undefined;
205+
}
206+
return markReplyPayloadForSourceSuppressionDelivery({
207+
text: EMPTY_INTERACTIVE_REPLY_TEXT,
208+
isError: true,
209+
});
210+
}
211+
187212
function resolveSourceReplyPolicy(params: {
188213
cfg: OpenClawConfig;
189214
sessionCtx: TemplateContext;
@@ -2017,6 +2042,27 @@ export async function runReplyAgent(params: {
20172042
await signalTypingIfNeeded([silentFallbackFailurePayload], typingSignals);
20182043
return returnWithQueuedFollowupDrain(silentFallbackFailurePayload);
20192044
};
2045+
const returnEmptyInteractiveReplyFailureIfNeeded = async (): Promise<
2046+
ReplyPayload | undefined
2047+
> => {
2048+
const emptyInteractiveReplyPayload = buildEmptyInteractiveReplyPayload({
2049+
isHeartbeat,
2050+
hasSuccessfulSideEffectDelivery: successfulSideEffectDelivery,
2051+
allowEmptyAssistantReplyAsSilent: followupRun.run.allowEmptyAssistantReplyAsSilent,
2052+
silentExpected: followupRun.run.silentExpected,
2053+
sourceReplyDeliveryMode:
2054+
followupRun.run.sourceReplyDeliveryMode ?? opts?.sourceReplyDeliveryMode,
2055+
});
2056+
if (!emptyInteractiveReplyPayload) {
2057+
return undefined;
2058+
}
2059+
replyOperation.fail(
2060+
"run_failed",
2061+
new Error("agent completed without a visible reply payload"),
2062+
);
2063+
await signalTypingIfNeeded([emptyInteractiveReplyPayload], typingSignals);
2064+
return returnWithQueuedFollowupDrain(emptyInteractiveReplyPayload);
2065+
};
20202066

20212067
const fallbackNoticePayloads: ReplyPayload[] = [];
20222068
if (
@@ -2094,6 +2140,10 @@ export async function runReplyAgent(params: {
20942140
if (silentFallbackFailurePayload) {
20952141
return silentFallbackFailurePayload;
20962142
}
2143+
const emptyInteractiveReplyPayload = await returnEmptyInteractiveReplyFailureIfNeeded();
2144+
if (emptyInteractiveReplyPayload) {
2145+
return emptyInteractiveReplyPayload;
2146+
}
20972147
return returnWithQueuedFollowupDrain(undefined);
20982148
}
20992149

@@ -2148,6 +2198,10 @@ export async function runReplyAgent(params: {
21482198
if (silentFallbackFailurePayload) {
21492199
return silentFallbackFailurePayload;
21502200
}
2201+
const emptyInteractiveReplyPayload = await returnEmptyInteractiveReplyFailureIfNeeded();
2202+
if (emptyInteractiveReplyPayload) {
2203+
return emptyInteractiveReplyPayload;
2204+
}
21512205
return returnWithQueuedFollowupDrain(undefined);
21522206
}
21532207

0 commit comments

Comments
 (0)