Skip to content

Conversation

@luojiyin1987
Copy link

Fixes #64

Summary

Fix broken infinite loop protection in extract_toc_content().

Problem

The function used len(chat_history) > 5 to exit the loop, but chat_history was rebuilt every iteration with exactly 2 elements, making the check never true.

Change

  • Add explicit attempt counter initialized to 0
  • Add max_attempts = 5 constant
  • Check attempt > max_attempts instead of len(chat_history) > 5
  • Move check to beginning of loop for earlier exit

Test

Manual code review - the logic now correctly counts iterations and exits after 5 attempts.

The while loop exit condition used len(chat_history), but chat_history
was rebuilt every iteration with exactly 2 elements, making the check
len(chat_history) > 5 never true.

Replace with explicit attempt counter and max_attempts limit.
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.

fix: prevent infinite loop in extract_toc_content

1 participant