Repository navigation
Description
Summary
The direct openai-completions provider snapshots the first nonempty streamed function.name and refuses to replace it on later deltas. OpenAI's pinned SDK and OpenClaw's managed Chat Completions transport both use the latest nonempty name snapshot.
A valid corrected/repeated name event can therefore publish a complete executable tool call under a stale name while pairing it with final arguments.
Deterministic reproduction
Feed two schema-valid decoded chunks for one stable tool-call index/ID:
- chunk 1: name
get_, arguments{"city": - chunk 2: name
weather, arguments"Paris"}, terminaltool_calls
Observed results:
direct streamOpenAICompletions: name="get_", arguments={"city":"Paris"}
managed processCompletionsStream: name="weather", arguments={"city":"Paris"}
pinned [email protected] accumulator: name="weather", arguments={"city":"Paris"}
Root cause
In packages/ai/src/providers/openai-completions.ts, a new block records the first name. Continuations update it only while block.name is empty, although argument bytes always append. Terminal validation checks only that the resulting name is nonempty and arguments are complete, then publishes it.
The authoritative pinned SDK (ChatCompletionStream) and managed sibling (packages/ai/src/transports/openai-completions-stream.ts) replace the stored name on every later nonempty snapshot.
Impact
The turn can fail as an unknown tool or dispatch to the wrong available tool if the stale name itself is valid. Managed Chat Completions and Responses are unaffected.
Expected behavior
Mirror the pinned SDK/managed rule: every nonempty name snapshot replaces the block name; empty continuations must not erase it.
Regression coverage
Use stable ID/index, two different nonempty name snapshots, split valid JSON arguments, and terminal tool_calls; assert latest name, final arguments, balanced lifecycle, and no scratch fields. Add empty-name continuation and managed-parity assertions.
Frozen-source provider suites passed 107/107 assertions, and direct/managed/SDK in-process comparisons reproduced the divergence. Live main was checked at 41acededbc5751d6c6eafa0716c73326459451b4; the direct provider owner is unchanged from reproduced SHA a434545620127a3105699513d662395a43b43eb1.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Aug 21, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 25, 2026, 5:34 PM ET / 21:34 UTC.
Summary
Keep open. Current main still retains the first nonempty direct-stream tool name while the managed sibling replaces later snapshots; the protected maintainer label requires provider-owner handling.
Reproducibility: yes. Current source gives a deterministic two-chunk path: direct streaming retains the first nonempty name, while managed streaming replaces it with the later nonempty snapshot.
Regression provenance
Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.
Maintainer decision needed
Why: The repository’s protected maintainer label requires human handling; the remaining choice is whether managed-path parity is the intended canonical contract for the direct provider.
Next step
The source defect is narrow, but the protected
maintainerlabel requires explicit provider-owner handling rather than automated repair dispatch.Review details
Best possible solution:
Make direct tool-call assembly replace the stored name on every nonempty snapshot, preserve it across empty snapshots, and add direct-versus-managed regression coverage for split JSON arguments.
Do we have a high-confidence way to reproduce the issue?
Yes. Current source gives a deterministic two-chunk path: direct streaming retains the first nonempty name, while managed streaming replaces it with the later nonempty snapshot.
Is this the best way to solve the issue?
Yes, subject to provider-owner confirmation. Align the direct assignment rule with the managed sibling and test nonempty replacement plus empty-name preservation at the streamed-call boundary.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against f21c70768976.
Label changes
Label justifications:
P1: A valid streamed response can reach tool dispatch with a stale executable name and otherwise complete arguments.impact:other: The concrete impact is corrupted provider tool-call assembly, outside the narrower owned issue-impact categories.Evidence reviewed
What I checked:
packages/ai/src/providers/openai-completions.ts:581, f21c70768976)packages/ai/src/transports/openai-completions-stream.ts:542, f21c70768976)packages/ai/src/providers/openai-completions-tool-calls.ts:233, f21c70768976)packages/ai/src/providers/openai-completions.test.ts:1695, f21c70768976)packages/ai/src/providers/openai-completions.ts:581, 66bfdeffb9b4)packages/ai/package.json:109, f21c70768976)Likely related people:
packages/ai/src/providers/openai-completions.ts,packages/ai/src/transports/openai-completions-stream.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.1 remaining item