Skip to content

MCP dispatch releases the shared response buffer before the agentic loop can parse multi-chunk responses #664

Description

@leseb

Clawpatch finding

Evidence

MCP dispatch releases the shared response buffer before the agentic loop can parse multi-chunk responses

  • apis/src/openai/responses/mcp_dispatch/mod.rs:220-228 (McpDispatchFilter::on_response_body)
  • apis/src/openai/responses/agentic_loop/mod.rs:258-274 (AgenticLoopFilter::on_response_body)
  • ../praxis/protocol/src/http/pingora/handler/response_body_filter.rs:122-135 (execute)
  • apis/src/openai/responses/mcp_dispatch/tests.rs:879-887 (on_response_body_not_end_of_stream_returns_release)

Description

MCP dispatch releases the shared response buffer before the agentic loop can parse multi-chunk responses

Body mode is merged across the pipeline, so Release affects the shared StreamBuffer rather than only this filter. On the first non-EOS response chunk, MCP dispatch releases the buffer. Subsequent chunks are no longer accumulated, and at EOS agentic_loop receives only the final streamed chunk rather than the complete JSON response. JSON parsing then fails, clears tool_calls, and incorrectly signals done. The agentic loop therefore works only when the complete provider response happens to arrive as one EOS chunk.

Reproduction

MCP dispatch releases the shared response buffer before the agentic loop can parse multi-chunk responses

Run the documented agentic pipeline and have the inference upstream return a non-streaming Responses JSON object split across at least two Pingora body chunks. After the first chunk, openai_mcp_dispatch returns Release. At EOS, agentic_loop cannot parse the final fragment and no MCP call is dispatched.

Recommendation

MCP dispatch releases the shared response buffer before the agentic loop can parse multi-chunk responses

Return Continue for non-EOS chunks. MCP dispatch does not inspect the body directly and must allow the shared StreamBuffer to remain active until agentic_loop parses the complete response at EOS.


Reported from scheduled Clawpatch Codex/xhigh review after rebasing /Users/leseb/Documents/AI/ai to origin/main (1cc0a47). Please validate before assigning or starting implementation.

Metadata

Metadata

Assignees

Labels

HUMAN REVIEWEDHas been reviewed by a human and considered a valid bug

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions