@@ -56,6 +56,7 @@ import {
5656 buildFallbackNotice ,
5757 resolveFallbackTransition ,
5858} from "../fallback-state.js" ;
59+ import type { SourceReplyDeliveryMode } from "../get-reply-options.types.js" ;
5960import { DEFAULT_HEARTBEAT_ACK_MAX_CHARS , stripHeartbeatToken } from "../heartbeat.js" ;
6061import {
6162 isReplyPayloadStatusNotice ,
@@ -131,6 +132,8 @@ import type { TypingController } from "./typing.js";
131132const BLOCK_REPLY_SEND_TIMEOUT_MS = 15_000 ;
132133const 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
135138function 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+
187212function 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