Skip to content

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

Closed as not planned

Description

@Kunal-Somani

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.

Activity

  1. Kunal-Somani commented on Mar 21, 2026

    @Kunal-Somani
    Author

    /assign

  2. added a commit that references this issue on Mar 21, 2026
    e070733
  3. chasecadet commented on Nov 20, 2026

    @chasecadet
    Contributor

    Thank you for reporting this!

    We are closing pre-restructure issues targeting the legacy server/, server-https/, manifests/, kagent-feast-mcp/, or in-process SentenceTransformer prototype code. In #207, #210, #233, #240, and #249, kubeflow/docs-agent migrated to dedicated TEI (text-embeddings-inference), FastMCP (docs-agent-mcp/mcp-server/), shared modular KFP pipelines (docs-agent-mcp/pipelines/), and Helm charts (docs-agent-mcp/charts/).

    If you still observe an equivalent issue on the current main stack, please feel free to open a new issue using the current issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions