Skip to content

fix(tool-call-repair): preserve visible suffix when XML tool text is incomplete - #102240

Closed
qingminglong wants to merge 1 commit into
openclaw:mainfrom
qingminglong:codex/fix-tool-call-visible-suffix-stream
Closed

qingminglong wants to merge 1 commit into
openclaw:mainfrom
qingminglong:codex/fix-tool-call-visible-suffix-stream

Conversation

@qingminglong

@qingminglong qingminglong commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users could lose visible assistant text when a streamed response began with an oversized incomplete bracketed XML parameter block such as [read] and then continued with a normal visible answer.

Why This Change Was Made

The repair grammar now keeps optional missing </function> handling scoped to legacy [tool:name] XML blocks, while the stream normalizer recovers the visible suffix after incomplete plain [name] XML parameter text without leaking XML closing markers.

User Impact

Users now see the assistant's visible answer instead of receiving an empty completion when this malformed stream shape appears.

Evidence

  • Claim proved: an oversized incomplete [read] XML parameter prefix followed by visible text streams and finishes with only the visible suffix preserved.
  • Runtime proof at 1c9b82504a814992df8db26011f42648b13f7206: node --import tsx --input-type=module ran a redacted provider-returned stream through the real xAI provider wrapper path, importing wrapXaiProviderStream from extensions/xai/stream.ts and createAssistantMessageEventStream from src/llm/utils/event-stream.ts.
{
  "proof": "xai provider wrapper real path with local redacted provider stream",
  "eventTypes": ["text_delta", "done"],
  "textDelta": "Visible answer after an incomplete bracketed XML parameter block.",
  "finalContent": [
    {
      "type": "text",
      "text": "Visible answer after an incomplete bracketed XML parameter block."
    }
  ],
  "containsVisibleSuffix": true,
  "containsXmlParameterClose": false,
  "containsPlainToolPrefix": false
}
  • Focused regression at 1c9b82504a814992df8db26011f42648b13f7206: node scripts/run-vitest.mjs src/plugin-sdk/provider-stream-shared.test.ts passed with 67 tests passing.
  • Committed diff hygiene: git diff --check HEAD~1..HEAD passed.
  • Review proof: python .agents\skills\autoreview\scripts\autoreview --mode local passed with no accepted/actionable findings.
  • Observed result: both the runtime proof and focused regression emit a text_delta and done containing Visible answer after an incomplete bracketed XML parameter block. and do not include </parameter> or [read].

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 8, 2026, 12:35 PM ET / 16:35 UTC.

Summary
The PR narrows XML-ish plain-bracket parsing and adds visible-suffix recovery for incomplete over-cap [name] XML-parameter streams, with a provider-stream regression test.

PR surface: Source +86, Tests +44. Total +130 across 3 files.

Reproducibility: yes. Source inspection shows current main accepts the plain [name] XML-ish block as complete without </function>, and the PR regression exercises the over-cap stream shape that loses the visible suffix; I did not execute tests in this read-only review.

Review metrics: 1 noteworthy metric.

  • Message-scrubbing recovery path: 1 recovery path added. This path decides whether over-cap tool-looking assistant text stays suppressed or is re-emitted as visible message text.

Stored data model
Persistent data-model change detected: serialized state: src/plugin-sdk/provider-stream-shared.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #102240
Summary: This PR is the narrow current candidate for the plain-bracket incomplete XML visible-suffix repair; nearby tool-call repair PRs are foundational or adjacent rather than replacements.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh the branch against current main and keep exact-head CI green before merge.

Risk before merge

  • [P1] The PR changes stream suppression and re-emission logic; an overmatch here could hide or rewrite assistant-visible text.
  • [P1] The branch is mergeable but behind current main, so maintainers should review the final merge result and exact-head checks before landing.

Maintainer options:

  1. Land With Shared-Path Proof (recommended)
    Accept the message-delivery risk because the patch is scoped to the shared repair path and includes runtime wrapper proof plus a focused regression.
  2. Request Full Provider Replay
    Ask for a redacted live provider transcript or linked artifact that shows the malformed stream through a full OpenClaw run before merge.

Next step before merge

  • No automated repair is needed; the remaining path is normal maintainer review, exact-head CI, and acceptance of the message-delivery risk.

Maintainer decision needed

  • Question: Should maintainers accept this PR's shared stream-normalizer recovery for incomplete plain-bracket XML-ish tool text, given the message-delivery risk?
  • Rationale: Automation can verify the narrow code path, tests, and proof, but the changed suppression/re-emission boundary decides what assistant text users see.
  • Likely owner: steipete — Recent adjacent work and repair-package merge history make this the strongest available owner for the provider stream normalization boundary.
  • Options:
    • Land After Refresh (recommended): Accept the message-delivery risk under normal maintainer review after rebasing or otherwise refreshing exact-head checks.
    • Ask For Live Replay: Require an additional redacted full-provider replay artifact before merge if maintainers want stronger real-world assurance.

Security
Cleared: The diff changes parser/stream-normalizer logic and a regression test only, with no dependency, CI, lockfile, secret, permission, package, or code-execution surface changes.

Review details

Best possible solution:

Land the shared repair after maintainer acceptance of the message-scrubbing risk and fresh exact-head checks; avoid duplicating this behavior in individual providers or channels.

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

Yes. Source inspection shows current main accepts the plain [name] XML-ish block as complete without </function>, and the PR regression exercises the over-cap stream shape that loses the visible suffix; I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes. The shared tool-call-repair grammar and stream normalizer own this provider-visible repair before channel delivery, while provider- or channel-specific fixes would duplicate the invariant.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 534ace4d8a49.

Label changes

Label justifications:

  • P2: This is a normal-priority bug fix for a rare but user-visible assistant-text loss case in provider stream normalization.
  • merge-risk: 🚨 message-delivery: The PR changes message stream suppression and reclassification logic, so an overmatch could suppress or rewrite assistant-visible text.
  • 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 copied terminal JSON from a redacted runtime proof through the real xAI wrapper path showing the visible suffix emitted and XML markers absent.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied terminal JSON from a redacted runtime proof through the real xAI wrapper path showing the visible suffix emitted and XML markers absent.
Evidence reviewed

PR surface:

Source +86, Tests +44. Total +130 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 90 4 +86
Tests 1 44 0 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 134 4 +130

What I checked:

Likely related people:

  • fuller-stack-dev: Authored merged PR fix: promote serialized tool calls via repair package #87093, which added the tool-call-repair grammar, stream normalizer, and provider-stream regression surface this PR extends. (role: introduced shared repair package; confidence: high; commits: 3ea911558c45, e64271f1bb4b; files: packages/tool-call-repair/src/grammar.ts, packages/tool-call-repair/src/stream-normalizer.ts, src/plugin-sdk/provider-stream-shared.test.ts)
  • steipete: Authored merged PR fix(agent-core): ignore truncated tool calls #97140 on the adjacent provider/tool-call terminal boundary and is tied to the merged repair-package history. (role: recent adjacent contributor and merger; confidence: high; commits: 56259606d15f, 3ea911558c45; files: src/plugin-sdk/provider-stream-shared.ts, src/plugin-sdk/provider-stream-shared.test.ts, packages/tool-call-repair/src/stream-normalizer.ts)
  • vincentkoc: Current checkout blame for the central grammar and stream-normalizer lines points at recent commit 22ae651e9a; the shallow/grafted history makes this a weaker routing signal than the merged PR history. (role: current-line provenance; confidence: medium; commits: 22ae651e9ab5; files: packages/tool-call-repair/src/grammar.ts, packages/tool-call-repair/src/stream-normalizer.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-08T16:11:15.827Z sha 1c9b825 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-08T16:19:17.572Z sha 1c9b825 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-08T16:27:08.914Z sha 1c9b825 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 8, 2026
@qingminglong

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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 Jul 8, 2026
@steipete

Copy link
Copy Markdown
Contributor

Superseded by #104100, landed as 05ebaf41f6ee71729149ff83bf8c3ff8a37261a8.

The landed canonical scanner preserves visible suffix text after incomplete or oversized XML-ish tool syntax while bounding buffered events/bytes and keeping recognized incomplete syntax fail-closed. The exact malformed-stream cases, content-index preservation, terminal scrubbing, and live gateway behavior were covered in the 315-test focused matrix and exact-head proof on #104100. Thanks @wuqxuan for the original fix and regression evidence.

@steipete steipete closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. 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.

2 participants