Skip to content

fix: preserve streaming tool_calls when provider omits finish_reason - #98575

Closed
sergioperezcheco wants to merge 1 commit into
openclaw:mainfrom
sergioperezcheco:fix/streaming-tool-calls-without-finish-reason
Closed

sergioperezcheco wants to merge 1 commit into
openclaw:mainfrom
sergioperezcheco:fix/streaming-tool-calls-without-finish-reason

Conversation

@sergioperezcheco

Copy link
Copy Markdown

Some OpenAI-compatible providers (e.g., Evolink deepseek-v4-pro) send valid delta.tool_calls chunks but end the stream with data: [DONE] without a final finish_reason chunk. Previously, this caused an error that discarded all accumulated tool call blocks, making tool-using agent workflows silently fail.

Now we infer the stop reason from the accumulated content: toolUse if tool calls were parsed, stop otherwise. This matches the existing fallback logic that already promotes stop -> toolUse when tool calls are present.

Fixes #97994

Changes

  • src/llm/providers/openai-completions.ts: Instead of throwing when stream ends without finish_reason, infer stopReason from accumulated content blocks (toolUse if has tool calls, stop otherwise)
  • src/llm/providers/openai-completions.test.ts: Added test for stream ending without finish_reason but with valid tool_calls

Testing

All 36 existing tests pass plus the new test case.

Some OpenAI-compatible providers (e.g., Evolink deepseek-v4-pro) send
valid delta.tool_calls chunks but end the stream with data: [DONE]
without a final finish_reason chunk. Previously, this caused an error
that discarded all accumulated tool call blocks.

Now we infer the stop reason from the accumulated content: toolUse if
tool calls were parsed, stop otherwise. This matches the existing
fallback logic that already promotes stop -> toolUse when tool calls
are present.

Fixes openclaw#97994
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the linked issue’s active embedded-agent path is the boundary-aware OpenAI completions transport, and #98124 is an open, mergeable, proof-positive candidate for that path; this PR changes the lower-level provider path and broadens EOF-only tool execution unsafely.

Root-cause cluster
Relationship: superseded
Canonical: #98124
Summary: The current PR attempts the same linked no-finish OpenAI-compatible streamed tool-call fix, but the open canonical PR targets the active transport path and has positive proof; this branch is superseded.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this PR and continue review of #98124 as the canonical transport-level fix, preserving clean [DONE] versus EOF safeguards.

So I’m closing this here and keeping the remaining discussion on #98124.

Review details

Best possible solution:

Close this PR and continue review of #98124 as the canonical transport-level fix, preserving clean [DONE] versus EOF safeguards.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main’s OpenAI completions transport strips no-finish streamed tool-call blocks unless an explicit stop finish reason was seen, and the linked issue includes redacted provider chunks showing valid delta.tool_calls followed by data: [DONE].

Is this the best way to solve the issue?

No. This branch is not the best fix because it changes the legacy provider path and cannot distinguish clean [DONE] from EOF-only truncation; #98124 is the safer current transport-layer solution.

Security review:

Security review needs attention: The diff changes a model-output-to-tool-execution boundary and would execute no-finish parsed tool calls without proving a clean stream terminal.

  • [medium] No-finish tool calls can execute after EOF-only streams — src/llm/providers/openai-completions.ts:511
    The added branch promotes any accumulated tool call to toolUse when no finish reason was seen, but this path cannot tell clean [DONE] from transport EOF after the SDK has consumed SSE framing.
    Confidence: 0.86

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • MonkeyLeeT: Authored the merged stop-finished OpenAI-compatible tool-call fix that added the explicit terminal guard and no-finish fail-closed coverage this issue narrows. (role: recent fix author; confidence: high; commits: 9dcc70332ede, 12e6715e567f; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts, src/llm/providers/openai-completions.ts)
  • Jerry-Xin: Authored the merged guard that strips spurious tool-call blocks when the final stop reason is not executable tool use, which is the safety invariant affected here. (role: introduced adjacent guard; confidence: high; commits: 6c11d06dd71e, fdd568522b7e; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts, src/llm/providers/openai-completions.ts)
  • steipete: Merged adjacent stop-finished/spurious-tool-call work and authored the truncated-tool-call safety PR that reinforces toolUse as the dispatch gate. (role: recent safety contributor and merger; confidence: high; commits: 964ca3e140b9, e080b60311d3; files: packages/agent-core/src/agent-loop.ts, src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts)
  • vincentkoc: Current blame for the transport finalizer and legacy provider finalizer in this checkout points to recent OpenAI-compatible stream consolidation work. (role: current-main line contributor; confidence: medium; commits: 59b6bdf36c7c; files: src/agents/openai-transport-stream.ts, src/llm/providers/openai-completions.ts)

Codex review notes: model internal, reasoning high; reviewed against 1b0b8c294a3e.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI-compatible streaming tool calls are dropped when provider omits finish_reason

1 participant