Skip to content

fix(ai): replace streamed function name on same-id continuation - #130537

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/openai-streamed-function-name-127601
Aug 27, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/openai-streamed-function-name-127601

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #127601

What Problem This Solves

A tool call streamed in fragments (e.g. the function name arriving as get_ then weather) was published by the direct OpenAI Chat Completions provider under the stale first fragment, so the call could fail as an unknown tool or dispatch to the wrong one. The direct provider now takes the latest nonempty function-name snapshot, matching the pinned OpenAI SDK and the managed transport.

  • Problem: The direct openai-completions provider recorded only the first nonempty streamed function.name and refused to replace it on later deltas, while the pinned OpenAI SDK (ChatCompletionStream) and the managed processCompletionsStream transport both replace the stored name on every nonempty snapshot.
  • Solution: Replace the stored name on every nonempty snapshot that belongs to the established tool identity, so a fragmented or corrected name no longer freezes on the first fragment.
  • What changed: packages/ai/src/transports/openai-completions-stream.ts — the name-assignment guard in processCompletionsStream (shared by the direct provider via mode: "direct" and the managed transport); packages/ai/src/providers/openai-completions.test.ts — four regression tests covering same-id fragmented names, idless index-resolved continuations, conflicting-id continuations, and the existing first-tool-identity contract.
  • What did NOT change: The managed transport's behavior (already correct), the mistral/responses/anthropic providers (independent accumulators), argument accumulation, tool-call id handling, and the direct provider's first-tool-identity contract for explicitly conflicting ids.

Why This Change Was Made

processCompletionsStream is the single stream processor shared by both the direct provider and the managed transport. After #129962 unified the two implementations, the name-assignment guard (!directMode || !block.name) carried forward the direct path's original "first nonempty name wins" semantics, while the managed path (where !directMode is true) already used latest-snapshot semantics — so the divergence reported in #127601 survived the unification.

The guard is now conflictingId = directMode && block.id && toolCall.id && block.id !== toolCall.id; if (toolCall.function?.name && !conflictingId). A nonempty name replaces the stored name on the managed path (unchanged, since directMode is false there) and on the direct path whenever the delta is not an explicitly conflicting id. Crucially, a continuation that re-uses the established index but omits its id is treated as a continuation rather than a conflict: the block has already been resolved by index (or by id) at the top of the loop, so an absent id is not identity evidence either way — only an id that is present and differs from the established block.id keeps the first name. This matches how the pinned OpenAI SDK accumulator accepts a later name-only frame on the same index, while still preserving direct mode's preserves-the-first-tool-identity contract for an explicitly conflicting id (locked by the existing test added in #129962).

  • Best fix: Yes — a one-guard change at the unified name-assignment point. The previous guard (!directMode || !block.id || block.id === toolCall.id) conflated an omitted continuation id with an explicitly conflicting id, so a fragmented stream that sent the id only on its first frame still froze on the first fragment. Distinguishing the two — absent id = continuation, present-and-differing id = conflict — is required to fix the reported stale-name failure without breaking the first-tool-identity contract.
  • Alternative considered: Unconditional replacement (if (toolCall.function?.name)). Rejected — it regresses the different-id same-index case (the existing preserves the first tool identity test); see the new keeps the first name when a continuation carries a conflicting id test.
  • Refactor: No. The two accumulators already share one processor after refactor(ai): unify OpenAI-compatible completion stream processing #129962; no further unification is needed.
  • Risk / non-goals: Direct mode intentionally still diverges from the managed transport when a later delta carries an id that explicitly conflicts with the established block — that divergence is the first-tool-identity contract, not a residual bug. Real multi-fragment provider traffic was not captured; proof is via in-process SSE-chunk reproduction mirroring the issue's fixture and the pinned SDK's accumulator semantics.

User Impact

When a model streams a tool-call name across multiple fragments (or corrects the name mid-stream), the direct OpenAI-compatible provider now publishes the complete, final name instead of the first fragment. Calls that previously failed as "unknown tool" or silently dispatched to a wrong-but-valid tool now resolve correctly. No configuration changes; managed Chat Completions and Responses paths were already correct and are unaffected.

Evidence

Real-behavior proof via an unmocked local OpenAI-compatible SSE endpoint — a local HTTP server streams real ChatCompletionChunk bytes over SSE (no vi.mock, no synthetic chunk injection), and the real streamOpenAICompletions direct provider consumes them via real fetch:

$ node --import tsx/esm proof-fragmented-name.mts
=== PR #130537 real-behavior proof (unmocked local SSE) ===
endpoint: http://127.0.0.1:37557/v1  (local HTTP server, real fetch, no vi.mock)
streamed name fragments: "get_" -> "weather" (same index, id omitted on 2nd frame)

=== Result ===
stopReason: toolUse
toolCall count: 1
toolCall.id:    call_proof
toolCall.name:  weather
toolCall.args:  {"city":"Paris"}

=== Verdict ===
expected name: "weather" (latest nonempty snapshot)
actual name:   "weather"
result:        PASS ✅ — fragmented name resolved to final snapshot

The local SSE server emits three frames on the wire: (1) tool_calls[0] with id="call_proof", function.name="get_", function.arguments='{"city":'; (2) tool_calls[0] with the id omitted (index-resolved continuation), function.name="weather", function.arguments='"Paris"}'; (3) finish_reason="tool_calls". The direct provider (mode: "direct") resolves the block by index, then replaces the stored name on the nonempty weather snapshot — matching the pinned OpenAI SDK accumulator and the managed transport.

Pre-fix (prior !directMode || !block.id || block.id === toolCall.id guard), same unmocked SSE stream — name froze on the first fragment:

$ node --import tsx/esm proof-fragmented-name.mts   # pre-fix guard restored
=== Result ===
stopReason: toolUse
toolCall count: 1
toolCall.id:    call_proof
toolCall.name:  get_                     ← STALE (first fragment)
toolCall.args:  {"city":"Paris"}

=== Verdict ===
result:        FAIL ❌ — name froze on first fragment

Bidirectional guard: pre-fix FAIL (name: "get_", frozen on first fragment) → post-fix PASS (name: "weather", latest nonempty snapshot). The prior guard treated the absent continuation id as a conflict; the fix distinguishes absent id (continuation) from present-and-differing id (conflict).

Pinned SDK accumulator confirmation ([email protected], client.chat.completions.stream → ChatCompletionStream._accumulateChatCompletion):

The same unmocked local SSE stream is fed to the pinned SDK's own accumulator to independently confirm the idless-continuation contract:

$ node --import tsx/esm proof-pinned-sdk-accumulator.mts
=== Pinned OpenAI SDK accumulator proof ([email protected]) ===
SDK version: [email protected]
endpoint: http://127.0.0.1:39947/v1  (local SSE server, real fetch, no mock)
streamed name fragments: "get_" -> "weather" (same index, id omitted on 2nd frame)

=== SDK accumulator result ===
finalChatCompletion tool_calls[0]:
  id:    call_sdk
  name:  weather
  args:  {"city":"Paris"}

=== Verdict ===
expected name: "weather" (latest nonempty snapshot, no id check)
actual name:   "weather"
result:        PASS ✅ — pinned SDK accumulator resolves to final snapshot

The pinned SDK resolves the block by index and replaces the stored name on every nonempty fn.name without consulting id (ChatCompletionStream.js:455 resolves by index, :474 replaces name unconditionally). The fix's conflictingId guard aligns: an idless continuation replaces the name (matching the SDK), and only an explicitly conflicting id preserves the first name (the direct-mode contract the SDK does not carry).


Post-fix regression tests (direct provider, node/vitest runtime, in-process SSE chunks mirroring the issue's two-chunk fixture and the pinned OpenAI SDK accumulator semantics):

npx vitest run --dir packages/ai packages/ai/src/providers/openai-completions.test.ts \
  -t "fragmented continuation|index-resolved continuation|conflicting id|preserves the first tool identity"

 ✓ replaces the stored function name on a same-id fragmented continuation
 ✓ replaces the stored name when an index-resolved continuation omits the id
 ✓ keeps the first name when a continuation carries a conflicting id
 ✓ does not erase the stored name when a continuation carries an empty name
 ✓ preserves the first tool identity and publishes argument-free tool fragments
 Test Files  1 passed (1)
      Tests  5 passed (5)

Before/after divergence matrix — same in-process chunks fed to streamOpenAICompletions (direct, mode: "direct") and createOpenAICompletionsTransportStreamFn (managed):

scenario                                              => direct name   managed name  parity
A same-id fragmented (get_ -> weather)                => weather       weather       MATCHED   (bug fixed)
B different-id same-index (original -> replaced)      => original      replaced      DIVERGENT (direct keeps first identity — contract)
C idless index-continuation (call_A first -> no-id 2) => second        second        MATCHED   (bug fixed)

Pre-fix (HEAD~1, the prior !directMode || !block.id || block.id === toolCall.id guard), scenarios A and C:

scenario                                              => direct name   managed name  parity
A same-id fragmented (get_ -> weather)                => get_ (STALE)  weather       DIVERGENT
C idless index-continuation (call_A first -> no-id 2) => first (STALE) second        DIVERGENT

Pre-fix the direct provider froze on the first fragment (get_ for A, first for C); post-fix it matches the managed transport (weather / second). Scenario B is unchanged from pre-fix — the preserves-the-first-tool-identity contract for an explicitly conflicting id is preserved.

Bidirectional guard verification (each new/changed test confirmed to fail pre-fix for the expected reason, then pass post-fix):

  • replaces the stored function name on a same-id fragmented continuation: pre-fix Expected "weather", Received "get_"; post-fix pass.
  • replaces the stored name when an index-resolved continuation omits the id: pre-fix Expected "second", Received "first" (the prior guard treated the absent id as a conflict); post-fix pass.
  • keeps the first name when a continuation carries a conflicting id: pass pre- and post-fix — the first-tool-identity contract is preserved by both guards.

Full openai-completions.test.ts suite (68 tests) and openai-completions-stream.tool-assembly.test.ts (3 tests) green; oxlint -c .oxlintrc.json and oxfmt --check clean on both changed files.

Pinned SDK accumulator source ([email protected], the package pin in packages/ai/package.json):

The direct provider's name-assignment guard mirrors the pinned OpenAI SDK's own ChatCompletionStream accumulator (node_modules/openai/lib/ChatCompletionStream.js, _accumulateChatCompletion):

451  for (const { index, id, type, function: fn, ... } of tool_calls) {
452    if (!Number.isSafeInteger(index) || index < 0 || ...) { throw ... }
455    const tool_call = (toolCallSnapshots[index] ?? (toolCallSnapshots[index] = {}));  // resolved by index
457    if (id) { tool_call.id = id; }                                                   // id written only when present, not consulted for name
474    if (fn.name) { functionSnapshot.name = fn.name; }                                // any nonempty name replaces — no id check
475  }

The SDK resolves the snapshot by index and replaces the stored name on every nonempty fn.name without consulting id at all. The fix's conflictingId = directMode && block.id && toolCall.id && block.id !== toolCall.id aligns with this: an idless index-resolved continuation replaces the name (matching if (fn.name)), and the guard only diverges from the SDK by additionally preserving the first name for an explicitly conflicting id — the direct-mode preserves-the-first-tool-identity contract (#129962), which the SDK does not carry because it has no direct/managed split. The prior guard (block.id === toolCall.id) violated the SDK semantics by treating an absent id as a conflict, freezing the name on the first fragment.

What was not tested: No live external model-provider traffic captured (the local unmocked SSE endpoint above reproduces the fragmented-name stream shape from the issue's fixture, but no real hosted model was queried). The mistral provider's analogous fragmented-name handling (#127603) is a separate issue and intentionally not touched here.

Managed-parity assertion: openai-completions-stream.tool-calls.test.ts drives processCompletionsStream without mode: "direct" (the managed path) with the same fragmented-name chunks (name get_ → weather, same index, id omitted on 2nd frame) and asserts the published name is weather — confirming the managed path resolves fragmented names identically to the direct provider.

Empty-name continuation: openai-completions.test.ts feeds a continuation with function.name: "" on the second frame and asserts the stored name is not erased (get_weather preserved) — the guard's truthiness check skips empty snapshots.

AI Assistance

  • AI-assisted: Yes
  • Tools: Claude Code (glm-5.2)
  • Prompts / session excerpts: Drove the open-source-pr workflow for Direct OpenAI Chat Completions freezes a stale first streamed function name #127601 — issue triage, source-level root-cause trace through refactor(ai): unify OpenAI-compatible completion stream processing #129962's unification, fix implementation, adversarial pre-review (spawned a ClawSweeper-style subagent that surfaced the idless-continuation regression, which was then fixed and regression-tested), and real-behavior proof. Round 2 (ClawSweeper re-review): addressed the P1 finding that the prior guard conflated an omitted continuation id with an explicitly conflicting id — narrowed the guard to reject only a present-and-differing id, flipped the idless-continuation test to assert the replaced name, added a conflicting-id regression test, and fixed two await-of-non-Promise lint errors in the new tests. Pre-fix/post-fix bidirectional verification re-run. Round 2 proof pass: added pinned [email protected] SDK accumulator source (ChatCompletionStream.js:451-475) showing the SDK resolves by index and replaces the name on every nonempty fn.name with no id check, cross-checking the guard against the exact pinned version. Full session log available on request.
  • Confirmed understanding of code changes: Yes — the guard change (absent id = continuation, conflicting id = conflict), the block.id !== toolCall.id narrowing, and all four regression tests are explained above.
  • autoreview: N/A (no autoreview skill configured locally; oxlint + oxfmt + full openai-completions vitest shard run instead).

Re-review round (2026-08-27)

ClawSweeper flagged the prior Evidence as mock-only (vi.mock("openai") chunk injection). Added an unmocked local OpenAI-compatible SSE endpoint proof: a local HTTP server streams real ChatCompletionChunk bytes over SSE, and streamOpenAICompletions (direct provider) consumes them via real fetch — no module mock. Pre-fix the name froze on get_; post-fix it resolves to weather. The proof script lives outside the repo (/home/code/github/contributions/pr-130537-evidence/). No production code changes this round — the patch was already approved at 🐚 platinum hermit (4/6) patch quality with zero findings. Added two regression tests closing issue acceptance criteria gaps identified by adversarial self-review: (1) empty-name continuation does not erase the stored name (openai-completions.test.ts), and (2) managed-path parity assertion for fragmented names (openai-completions-stream.tool-calls.test.ts). Both tests satisfy the issue's explicit "empty-name continuation" and "managed-parity assertions" requirements. Also added a pinned SDK accumulator proof (node --import tsx driving [email protected]'s own ChatCompletionStream against the same local SSE stream) to independently confirm the idless-continuation contract.

Maintainer landing proof (2026-08-27)

  • Exact head: b1a73fdda482ffa2b2ba58a2537b5369abf57c52.
  • Current-main reproduction: 42ce03e72e34adeb34a79c91f534a906df46f882 published get_ instead of weather, and first instead of second, in the two owner-boundary regression cases.
  • Dependency contract: installed [email protected] resolves by tool-call index and replaces every later nonempty function name (ChatCompletionStream.js:451-475).
  • Focused proof: 83 direct and managed stream tests passed; format and Oxlint checks passed.
  • CI: exact-head attempt 2 passed, including checks-node-compact-small-45 and openclaw/ci-gate.

Telegram real-user proof used only the canonical telegram-e2e-userbot runner with a fresh gateway and dedicated QA user lease. Secrets are omitted:

E2E_MOCK_SERVER_PATH=<stable-name-fixture> \
E2E_TELEGRAM_PROVIDER_API=openai-completions \
E2E_ROOT_CONFIG_PATCH=<weather-tool-fixture> \
E2E_TELEGRAM_CONFIG_PATCH=<progress-streaming> \
node run-mock-sut-user-e2e.mjs \
  --gateway-port 19979 --mock-port 19982 --dm --timeout-ms 45000 \
  --text 'Exercise the stable-id streamed function-name scenario.' \
  --record <proof>/events.ndjson --output <proof>/summary.json
  • Fixture: stable ID call_stable_weather; names get_ then weather; arguments {"city": then "Paris"}.
  • Provider record: two requests; request 2 carried assistant tool call name: "weather" and complete arguments {"city":"Paris"}.
  • Telegram timeline: user message 14; four SUT typing events; progress message 2403 showed Weather blocked; final message 2404 was STREAM_NAME_E2E_OK; progress message 2403 was then deleted.
  • Evidence bundle: complete events.ndjson, summary.json, gateway.log, and mock-openai-requests.ndjson retained locally.
  • Local ClawSweeper: pass; patch correct; zero findings; security cleared; no maintainer decision; zero Rank-up moves.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@SunnyShu0925
SunnyShu0925 force-pushed the fix/openai-streamed-function-name-127601 branch from 10eba8e to ff49b54 Compare August 27, 2026 00:45
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 1:24 AM ET / 05:24 UTC.

ClawSweeper review

What this changes

The branch updates shared OpenAI-compatible tool-call stream assembly so later nonempty function names replace earlier fragments unless a continuation supplies a conflicting tool-call ID.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open for maintainer review: current main still freezes the direct provider’s name at its first nonempty fragment, while this focused patch fixes that path and preserves explicitly conflicting-ID handling.

Priority: P1
Reviewed head: b1a73fdda482ffa2b2ba58a2537b5369abf57c52
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported repair with direct-path terminal proof and targeted boundary coverage; maintainer confirmation is needed only for the public compatibility choice.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes after-fix terminal output from an unmocked local OpenAI-compatible SSE server consumed through the real direct-provider fetch path, with a stated pre-fix failure and post-fix result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes after-fix terminal output from an unmocked local OpenAI-compatible SSE server consumed through the real direct-provider fetch path, with a stated pre-fix failure and post-fix result.
Evidence reviewed 6 items Current-main behavior: Current main still assigns a direct-mode function name only when the stored name is empty, so a later fragment cannot replace it.
Changed owner boundary: The branch distinguishes an omitted continuation ID from an explicitly conflicting ID before updating the resolved block name.
Direct and managed callers: The standalone provider calls the assembler with direct mode, while the managed transport calls the same owner without that mode.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs packages/ai/src/providers/openai-completions.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130537-eMzug2/target

 ✓  unit  packages/ai/src/providers/openai-completions.test.ts (68 tests) 178ms

 Test Files  1 passed (1)
      Tests  68 passed (68)
   Start at  05:25:33
   Duration  2.18s (transform 1.48s, setup 991ms, import 651ms, tests 178ms, environment 0ms)

[test] passed 1 Vitest shard in 13.89s

Assertions:

  • NOT OBSERVED expect_output: replaces the stored name when an index-resolved continuation omits the id — command exited successfully; expected output was not observed in the captured pane
  • PASS expect_output: Test Files

How this fits together

OpenAI-compatible completion chunks are assembled into assistant tool calls before OpenClaw dispatches them. The shared assembler serves both the standalone direct provider and the managed transport.

flowchart LR
A[OpenAI-compatible SSE chunks] --> B[Shared stream assembler]
B --> C[Resolve tool-call identity]
C --> D[Update name and arguments]
D --> E[Assistant tool-call output]
E --> F[Tool dispatch]
Loading

Decision needed

Question Recommendation
Should the direct provider’s public stream contract treat an idless, index-resolved later function-name snapshot as a continuation that replaces the earlier name? Accept corrected continuation semantics: Merge the patch so a resolved same-ID or idless-index continuation publishes its latest nonempty name, while an explicit conflicting ID retains the existing first-identity protection.

Why: The patch is technically focused and source-proven, but it intentionally changes observable standalone-provider output from the previously preserved first snapshot.

Before merge

  • Resolve merge risk (P1) - This changes the published direct-stream result for same-ID and idless index-resolved continuations: latest nonempty names now win instead of the first fragment.
  • Resolve merge risk (P1) - The local checkout lacked the pinned SDK source and GitHub DNS was unavailable, so the claimed SDK accumulator implementation was not independently inspected; the PR’s real local-SSE proof remains sufficient for the observed OpenClaw behavior.
  • Resolve merge risk (P1) - Production changes are +9 lines, primarily the identity predicate and explanatory comment; the behavior is contained, but repository policy normally prefers net-neutral bug fixes.
  • Complete next step (P2) - A maintainer must accept the direct-provider compatibility correction; no mechanical repair remains.
Agent review details

Security

None.

PR surface

Source +9, Tests +167. Total +176 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 1 +9
Tests 2 167 0 +167
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 177 1 +176

Review metrics

Metric Value Why it matters
Production versus test delta production +9/-1; tests +167/-0 The runtime change is one identity predicate with explanatory comments; added tests cover both caller modes and conflicting-ID preservation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #127601
Summary: This PR is a focused candidate fix for the direct-provider stale-name bug tracked by the canonical issue.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the corrected stream contract (recommended)
    Merge after confirming that direct-provider consumers should receive the latest nonempty name for a resolved continuation, including when the later frame omits its ID.
  2. Preserve the existing direct output
    Pause or close this PR if first-fragment naming is an intentional public contract that must remain unchanged.

Technical review

Best possible solution:

Adopt the latest-nonempty-name rule for an already resolved direct tool call while retaining first identity only for an explicitly conflicting supplied ID.

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

Yes: current main’s direct-mode guard at packages/ai/src/transports/openai-completions-stream.ts:613 retains the first nonempty name; the supplied two-frame same-index stream is a high-confidence source reproduction.

Is this the best way to solve the issue?

Yes, subject to maintainer acceptance of the corrected direct-stream contract: the shared owner distinguishes absent identity evidence from an explicitly conflicting ID without changing argument assembly or managed-mode behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 95c318669520.

Labels

Label justifications:

  • P1: A fragmented direct-provider tool call can otherwise be emitted under a stale name and fail or target the wrong available tool.
  • merge-risk: 🚨 compatibility: The patch intentionally changes observable direct OpenAI-compatible stream output for existing same-ID and idless-index continuations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from an unmocked local OpenAI-compatible SSE server consumed through the real direct-provider fetch path, with a stated pre-fix failure and post-fix result.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from an unmocked local OpenAI-compatible SSE server consumed through the real direct-provider fetch path, with a stated pre-fix failure and post-fix result.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the related merged shared-stream refactor and owns the current-main lines that establish the direct-mode behavior. (role: shared stream feature owner; confidence: high; commits: f8e5674cc36f, 7c6a79828a0a; files: packages/ai/src/transports/openai-completions-stream.ts, packages/ai/src/providers/openai-completions.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the intended direct-provider continuation contract before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-27T00:51:40.106Z sha ff49b54ea6e71da03548a814515b492f7ce29957 :: needs real behavior proof before merge. :: [P1] Allow idless index-resolved continuations to replace the name
  • reviewed 2026-08-27T01:58:12.364Z sha 5edebe0bdc53027dec6c3dfc3da43fce1dd2a38a :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T02:26:47.282Z sha 5edebe0bdc53027dec6c3dfc3da43fce1dd2a38a :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T03:06:36.293Z sha 5edebe0bdc53027dec6c3dfc3da43fce1dd2a38a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T04:48:57.291Z sha b1a73fd :: needs maintainer review before merge. :: none

@SunnyShu0925
SunnyShu0925 force-pushed the fix/openai-streamed-function-name-127601 branch from ff49b54 to 5edebe0 Compare August 27, 2026 01:51
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
The direct OpenAI Chat Completions provider froze a streamed tool-call
function name on the first nonempty fragment. processCompletionsStream
now replaces the stored name whenever the delta is not an explicitly
conflicting id: a continuation that re-uses the established index but
omits its id is treated as a continuation (the block was already
resolved by index or id above), matching the pinned OpenAI SDK
accumulator, while a present-and-differing id keeps the first name to
preserve the first-tool-identity contract.

Fixes openclaw#127601
@SunnyShu0925
SunnyShu0925 force-pushed the fix/openai-streamed-function-name-127601 branch from 5edebe0 to b1a73fd Compare August 27, 2026 04:42
@obviyus

obviyus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Maintainer dependency check: I inspected the installed pinned [email protected] source from the dependency-ready root install. node_modules/openai/lib/ChatCompletionStream.js:451-475 resolves tool calls by index, assigns id only when present, and replaces functionSnapshot.name for every nonempty fn.name. This confirms the PR contract: a later same-index frame with no ID replaces the stale name; only OpenClaw direct mode adds the explicit conflicting-ID guard.

@obviyus

obviyus commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks @SunnyShu0925!

@obviyus
obviyus merged commit 6c10672 into openclaw:main Aug 27, 2026
321 of 325 checks passed
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus My pleasure!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
)

Use the latest nonempty function-name snapshot for a resolved tool call so fragmented direct OpenAI-compatible streams do not publish stale tool names. Preserve the first tool identity when a later fragment supplies an explicitly conflicting ID.

Co-authored-by: SunnyShu0925 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct OpenAI Chat Completions freezes a stale first streamed function name

2 participants