kubeflow / kubeflow/docs-agent

bug(server-https): mutual recursion between stream_llm_response and handle_tool_follow_up causes unbounded stack growth

Open
#152 1 comment 0 reactions 1 assignee View on GitHub

@Kunal-Somani is already working on this.

Since Mar 21, 2026.

Dominant language
Python
Stars
42
Forks
111
Avg merge
6d 23m
Merged PRs (30d)
2

Description

Bug Description

stream_llm_response and handle_tool_follow_up in server-https/app.py call each other with no depth limit, creating unbounded mutual recursion.

Call Chain

stream_llm_response()
  └─► handle_tool_follow_up()
        └─► stream_llm_response()       # follow-up triggers another tool_calls
              └─► handle_tool_follow_up()
                    └─► stream_llm_response()
                          └─► ... (no stopping condition)

Root Cause

When the LLM returns finish_reason == "tool_calls" in a follow-up response, stream_llm_response calls handle_tool_follow_up again. There is no recursion depth counter or maximum hop limit — so a model that repeatedly requests tools will cause a stack overflow and crash the server process.

This is a real failure mode in agentic workloads where the LLM issues multiple sequential tool calls — exactly the multi-hop scenario this system is designed to support.

Impact

  • Server process crashes under multi-hop agentic queries
  • No error is surfaced to the client — connection drops silently
  • Affects all users sharing the same server process

Proposed Fix

Introduce a max_depth parameter (default: 3) passed through both functions. If depth exceeds the limit, return a graceful fallback response instead of recursing further.

I will submit a PR with this fix.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.