Skip to content

Direct OpenAI Chat Completions freezes a stale first streamed function name #127601

Closed

Description

@steipete

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"}, terminal tool_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.

Activity

  1. added
    bug
    maintainer
    P1
    clawsweeper:source-repro
    impact:other
    on Aug 21, 2026
  2. added
    issue-rating: 🦞 diamond lobster
    on Aug 21, 2026
  3. clawsweeper commented on Aug 21, 2026

    @clawsweeper
    Contributor

    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

    Question Recommendation
    Should the provider owner approve the focused direct-path parity repair despite unavailable current-SDK and release-contract checks? Approve the parity repair: Update the direct path to replace every nonempty name snapshot and require focused direct/managed regression coverage.

    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 maintainer label 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:

    • The current OpenAI SDK accumulator contract could not be inspected because dependencies and GitHub DNS were unavailable.
    • The latest release’s behavior could not be read from this partial checkout.

    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:

    Likely related people:

    • steipete: Current-line blame and the available source-history boundary attribute both affected provider-stream surfaces to Peter Steinberger; the GitHub context identifies the contributor handle as steipete. (role: recent provider-stream contributor; confidence: medium; commits: 66bfdeffb9b4; files: packages/ai/src/providers/openai-completions.ts, packages/ai/src/transports/openai-completions-stream.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  4. added
    clawsweeper:needs-maintainer-review
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-live-repro
    issue-rating: 🐚 platinum hermit
    clawsweeper:needs-product-decision
    clawsweeper:source-repro
    and removed
    clawsweeper:source-repro
    issue-rating: 🦞 diamond lobster
    on Aug 22, 2026
  5. 1 remaining item

  6. added
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    and removed
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    clawsweeper:needs-live-repro
    issue-rating: 🐚 platinum hermit
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1bugclawsweeper:source-reproimpact:otherissue-rating: 🦞 diamond lobstermaintainer

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions