Skip to content

fix(utils): stop should_abort() from polluting LoopDetector history - #177

Merged
Zongwei9888 merged 4 commits into
HKUDS:mainfrom
hobostay:fix/loop-detector-history
Aug 12, 2026
Merged

Zongwei9888 merged 4 commits into
HKUDS:mainfrom
hobostay:fix/loop-detector-history

Conversation

@hobostay

Copy link
Copy Markdown
Contributor

Problem

LoopDetector.should_abort() probes the detector without intending to record anything:

def should_abort(self) -> bool:
    status = self.check_tool_call("")  # Check without adding to history
    return status["should_stop"]

but check_tool_call unconditionally appends the tool name — so every probe appends "" to tool_history, contradicting the comment. The implementation workflow calls should_abort() once per iteration (workflows/code_implementation_workflow.py:860), so after 5 consecutive iterations the last max_repeats history entries are all "" and the repeat check fires:

⚠️ Loop detected:  called 5 times consecutively

This aborts healthy runs — precisely during the tool-less iterations the workflow's "no tool calls detected" guidance is designed to recover from. Conversely, the stray "" entries interleaved into the history can also break up runs of identical real tool names, so genuine loop detection via the abort path is weakened too (verified: should_abort() returns False right after 5 identical real calls).

Fix

Skip the history append for empty probe names, and report the actually-repeated tool (recent_tools[0]) in the loop message instead of the probe argument:

if tool_name:
    self.tool_history.append(tool_name)
    if len(self.tool_history) > 10:
        self.tool_history = self.tool_history[-10:]

Tests

Added tests/test_loop_detector.py:

  • should_abort() no longer mutates history or false-triggers after repeated probes (fails on old code)
  • 5 identical real tool calls are still detected as a loop, including via the abort path (also fails on old code, because the probe pollution masked it)

hobostay and others added 4 commits August 11, 2026 14:41
should_abort() probed the detector with check_tool_call(''), which
unconditionally appended the empty name to tool_history despite the
'Check without adding to history' comment. The implementation workflow
calls should_abort() once per iteration, so five consecutive iterations
left the history as five identical '' entries and the repeat check fired
a bogus abort:

    Loop detected:  called 5 times consecutively

killing healthy runs — precisely during the tool-less iterations the
workflow's no-tool-call guidance is meant to recover from. The stray ''
entries could also break up runs of identical real tool names, weakening
genuine loop detection via the same path.

Skip the history append for empty probe names, report the actual
repeated tool in the loop message, and add regression tests covering
both the false abort and genuine loop detection.

@Zongwei9888 Zongwei9888 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the focused loop-detector fix and regression coverage. I reproduced both the false-positive history pollution and the masking of genuine repeated tool calls, reviewed the probe behavior, and verified the updated branch with the complete remote CI matrix. All checks are green.

@Zongwei9888
Zongwei9888 merged commit b077c60 into HKUDS:main Aug 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants