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
1 change: 1 addition & 0 deletions pkg/runtime/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func (r *LocalRuntime) RunStream(ctx context.Context, sess *session.Session) <-c
loopDetector.consecutive, toolName)
events <- Error(errMsg)
r.executeNotificationHooks(ctx, a, sess.ID, "error", errMsg)
loopDetector.reset()
return
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/runtime/tool_loop_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func newToolLoopDetector(threshold int) *toolLoopDetector {
return &toolLoopDetector{threshold: threshold}
}

// reset clears the detector state so it can be reused after recovery.
func (d *toolLoopDetector) reset() {
d.lastSignature = ""
d.consecutive = 0
}

// record updates the detector with the latest tool call batch and returns
// true if the consecutive-duplicate threshold has been reached.
func (d *toolLoopDetector) record(calls []tools.ToolCall) bool {
Expand Down
Loading