Skip to content

Fix infinite loop in processing graph conditional routing#22

Merged
iamtekson merged 4 commits intodev-geofrom
copilot/sub-pr-21
Dec 30, 2025
Merged

Fix infinite loop in processing graph conditional routing#22
iamtekson merged 4 commits intodev-geofrom
copilot/sub-pr-21

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 30, 2025

The processing graph had conflicting edge definitions that could cause infinite loops when tools are unavailable or fail. The conditional routing from llm node was overridden by an unconditional edge, and there was no protection against repeated tool invocations.

Graph structure fix

  • Removed conflicting unconditional llm → END edge that overrode conditional routing logic
  • Conditional edges now properly control flow: llm → tools (if requested) or llm → END

Loop prevention

  • Added MAX_TOOL_ITERATIONS = 10 constant as recursion limit in graph compilation
  • Prevents unbounded llm → tools → llm cycles

Tool error handling

  • tool_node now handles missing tools gracefully via .get() instead of direct dict access
  • Returns error ToolMessages instead of raising KeyError
  • Catches and reports tool execution exceptions
# Before: Would crash if tool unavailable
tool_inst = TOOLS[call["name"]]  # KeyError if tool commented out

# After: Returns error message to LLM
tool_inst = TOOLS.get(call["name"])
if tool_inst is None:
    content = f"Error: Tool '{call['name']}' is not available."

These changes allow the graph to terminate gracefully even when processing-specific tools are disabled in tools/__init__.py.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 30, 2025 00:45
Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
…ion limit configurable

Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
…ng conversion

Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
Copilot AI changed the title [WIP] Update stacked PR to address feedback from PR #21 Fix infinite loop in processing graph conditional routing Dec 30, 2025
Copilot AI requested a review from iamtekson December 30, 2025 00:50
Copy link
Copy Markdown
Owner

@iamtekson iamtekson left a comment

Choose a reason for hiding this comment

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

looks good. Please fix my comment on this PR.

Comment thread agents/processing.py
# Constants
# ─────────────────────────────────────────────────────────────────────────────
# Maximum number of graph iterations to prevent infinite loops
MAX_TOOL_ITERATIONS = 10
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

move this block to the config -> settings.py file

@iamtekson iamtekson marked this pull request as ready for review December 30, 2025 00:56
@iamtekson iamtekson merged commit 1ccf6a9 into dev-geo Dec 30, 2025
1 check passed
@iamtekson iamtekson deleted the copilot/sub-pr-21 branch December 30, 2025 00:56
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