Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
consecutiveMistakeLimit: number
consecutiveMistakeCountForApplyDiff: Map<string, number> = new Map()
consecutiveNoToolUseCount: number = 0
consecutiveNoAssistantMessagesCount: number = 0
toolUsage: ToolUsage = {}

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

// Reset consecutive error counters on abort (manual intervention)
this.consecutiveNoToolUseCount = 0
this.consecutiveNoAssistantMessagesCount = 0

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

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

// Increment consecutive no-assistant-messages counter
this.consecutiveNoAssistantMessagesCount++

// Only show error and count toward mistake limit after 2 consecutive failures
// This provides a "grace retry" - first failure retries silently
if (this.consecutiveNoAssistantMessagesCount >= 2) {
await this.say("error", "MODEL_NO_ASSISTANT_MESSAGES")
}

// IMPORTANT: For native tool protocol, we already added the user message to
// apiConversationHistory at line 1876. Since the assistant failed to respond,
// we need to remove that message before retrying to avoid having two consecutive
Expand Down
Loading
Loading