Skip to content

Commit 40e5bec

Browse files
authored
Merge pull request #2237 from dgageot/board/reset-loop-count-on-error-in-tui-fa5544d2
Reset tool loop detector after degenerate loop error
2 parents 513e243 + e35095f commit 40e5bec

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

pkg/runtime/loop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ func (r *LocalRuntime) RunStream(ctx context.Context, sess *session.Session) <-c
352352
loopDetector.consecutive, toolName)
353353
events <- Error(errMsg)
354354
r.executeNotificationHooks(ctx, a, sess.ID, "error", errMsg)
355+
loopDetector.reset()
355356
return
356357
}
357358

pkg/runtime/tool_loop_detector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ func newToolLoopDetector(threshold int) *toolLoopDetector {
2424
return &toolLoopDetector{threshold: threshold}
2525
}
2626

27+
// reset clears the detector state so it can be reused after recovery.
28+
func (d *toolLoopDetector) reset() {
29+
d.lastSignature = ""
30+
d.consecutive = 0
31+
}
32+
2733
// record updates the detector with the latest tool call batch and returns
2834
// true if the consecutive-duplicate threshold has been reached.
2935
func (d *toolLoopDetector) record(calls []tools.ToolCall) bool {

0 commit comments

Comments
 (0)