Skip to content

Commit 0f3df0e

Browse files
feat: add grace retry for empty assistant messages (#10297)
Implements grace retry error handling for 'no assistant messages' API errors, following the same pattern as PR #10196 for 'no tools used'. - Add consecutiveNoAssistantMessagesCount counter to Task.ts - First failure: silent retry (grace retry) - After 2+ consecutive failures: show MODEL_NO_ASSISTANT_MESSAGES error - Add UI handling in ChatRow.tsx with ErrorRow component - Add localized strings to all 18 locale files - Add comprehensive tests for the grace retry behavior
1 parent 71f312b commit 0f3df0e

File tree

21 files changed

+522
-18
lines changed

21 files changed

+522
-18
lines changed

src/core/task/Task.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
311311
consecutiveMistakeLimit: number
312312
consecutiveMistakeCountForApplyDiff: Map<string, number> = new Map()
313313
consecutiveNoToolUseCount: number = 0
314+
consecutiveNoAssistantMessagesCount: number = 0
314315
toolUsage: ToolUsage = {}
315316

316317
// Checkpoints
@@ -1985,6 +1986,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
19851986

19861987
// Reset consecutive error counters on abort (manual intervention)
19871988
this.consecutiveNoToolUseCount = 0
1989+
this.consecutiveNoAssistantMessagesCount = 0
19881990

19891991
// Force final token usage update before abort event
19901992
this.emitFinalTokenUsageUpdate()
@@ -3158,6 +3160,8 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
31583160
)
31593161

31603162
if (hasTextContent || hasToolUses) {
3163+
// Reset counter when we get a successful response with content
3164+
this.consecutiveNoAssistantMessagesCount = 0
31613165
// Display grounding sources to the user if they exist
31623166
if (pendingGroundingSources.length > 0) {
31633167
const citationLinks = pendingGroundingSources.map((source, i) => `[${i + 1}](${source.url})`)
@@ -3291,6 +3295,15 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
32913295
// or tool_use content blocks from API which we should assume is
32923296
// an error.
32933297

3298+
// Increment consecutive no-assistant-messages counter
3299+
this.consecutiveNoAssistantMessagesCount++
3300+
3301+
// Only show error and count toward mistake limit after 2 consecutive failures
3302+
// This provides a "grace retry" - first failure retries silently
3303+
if (this.consecutiveNoAssistantMessagesCount >= 2) {
3304+
await this.say("error", "MODEL_NO_ASSISTANT_MESSAGES")
3305+
}
3306+
32943307
// IMPORTANT: For native tool protocol, we already added the user message to
32953308
// apiConversationHistory at line 1876. Since the assistant failed to respond,
32963309
// we need to remove that message before retrying to avoid having two consecutive

0 commit comments

Comments
 (0)