Skip to content

fix(llm): preserve non-array tool result replay - #98863

Closed
momothemage wants to merge 1 commit into
mainfrom
feature/issue-98825-tool-result-replay
Closed

momothemage wants to merge 1 commit into
mainfrom
feature/issue-98825-tool-result-replay

Conversation

@momothemage

Copy link
Copy Markdown
Contributor

Closes #98825.

What Problem This Solves

Fixes an issue where users could lose successful tool output on the next model turn when stored tool-result content reached provider replay as a plain string or single object instead of the canonical content-block array.

This is the same canonical bug targeted by #98838 and #98826, but this PR also covers the provider and transport replay callers that continue doing media/image checks after text extraction.

Why This Change Was Made

Tool-result replay now normalizes non-array content at the shared replay boundary and reuses that normalized view for text extraction, media placeholders, validated image blocks, non-vision image downgrade, provider payload construction, transport payload construction, and Copilot vision-header detection.

The fix keeps structured single-object content on the existing redacted/truncated structured fallback path instead of special-casing text-like fields in a way that could bypass existing replay safeguards.

User Impact

Tool results that were successfully produced as plain text, structured objects, or single image objects are preserved during provider replay instead of becoming (no output) or failing when callers attempt .some() / .filter() on non-array content.

Evidence

  • node scripts/run-vitest.mjs src/llm/providers/tool-result-text.test.ts src/llm/providers/openai-completions.test.ts
    • Passed: 2 files, 54 tests.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
    • Passed.
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo
    • Passed.
  • node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo
    • Passed.
  • node scripts/run-oxlint.mjs extensions/google/transport-stream.ts src/agents/anthropic-transport-stream.ts src/agents/openai-transport-stream.ts src/llm/providers/anthropic.ts src/llm/providers/github-copilot-headers.ts src/llm/providers/google-shared.ts src/llm/providers/mistral.ts src/llm/providers/openai-completions.test.ts src/llm/providers/openai-completions.ts src/llm/providers/openai-responses-shared.ts src/llm/providers/tool-result-text.test.ts src/llm/providers/tool-result-text.ts src/llm/providers/transform-messages.ts src/plugin-sdk/provider-transport-runtime.ts
    • Passed.
  • node scripts/check-plugin-sdk-subpath-exports.mjs
    • Passed.
  • git diff --check
    • Passed.

Runtime payload proof:

[
  {
    "role": "tool",
    "content": "plain status output",
    "tool_call_id": "call_1"
  }
]

That payload was produced locally by calling the real OpenAI Completions convertMessages() path with a toolResult whose content was the plain string "plain status output".

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: google size: M maintainer Maintainer-authored PR labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 1, 2026, 11:03 PM ET / 03:03 UTC.

Summary
The PR normalizes non-array tool-result replay across shared helpers, provider and transport callers, the Google plugin transport, Copilot image detection, and focused replay tests.

PR surface: Source +67, Tests +85. Total +152 across 14 files.

Reproducibility: yes. Source inspection shows current main iterates raw helper input as array-shaped content, so a plain string or single object can be dropped before replay text is produced.

Review metrics: 1 noteworthy metric.

  • Public Plugin SDK exports: 1 added. The added provider-transport-runtime export changes plugin-facing API surface and must be accepted and baselined before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98825
Summary: This PR is a candidate fix for the canonical non-array tool-result replay bug and is broader than the other open candidate PRs.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🐚 platinum hermit
Patch quality: 🦪 silver shellfish
Result: blocked by patch quality or review findings.

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

Rank-up moves:

  • Regenerate and commit the Plugin SDK API baseline for the new export, or remove the public export.
  • Let the remaining exact-head CI lanes finish before maintainer merge review.

Risk before merge

  • [P1] The PR adds a new public Plugin SDK export without updating the generated API baseline or documenting the intended contract.
  • [P1] The diff changes model-visible tool-result text and media replay across provider paths, so a bad merge could still suppress or misrepresent tool output.

Maintainer options:

  1. Settle the SDK contract first (recommended)
    Regenerate and commit the Plugin SDK API baseline with contract rationale, or remove the public export and route the Google transport through an internal seam.
  2. Accept the public replay helper deliberately
    Maintainers may choose to keep the new export, but should treat it as a provider plugin API addition rather than incidental implementation sharing.
  3. Prefer a private replay seam
    If the API direction is not ready, pause this branch or narrow it so the replay fix lands without expanding the public SDK surface.

Next step before merge

  • [P2] Maintainer review is needed for the public Plugin SDK API decision; the remaining blocker is not only a local code repair.

Security
Cleared: The diff changes TypeScript replay helpers, provider callers, and tests only; no dependency, workflow, credential, package-install, or secret-handling surface is broadened.

Review findings

  • [P1] Update the SDK API baseline for the new export — src/plugin-sdk/provider-transport-runtime.ts:10
Review details

Best possible solution:

Settle the Plugin SDK contract before merge: either regenerate and commit the API baseline for extractToolResultImageBlocks with maintainer acceptance, or keep the helper behind an internal/private replay seam.

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

Yes. Source inspection shows current main iterates raw helper input as array-shaped content, so a plain string or single object can be dropped before replay text is produced.

Is this the best way to solve the issue?

No, not merge-ready yet. Shared normalization is the right layer and this branch covers sibling providers, but the public SDK export needs baseline/contract handling or a private seam before merge.

Full review comments:

  • [P1] Update the SDK API baseline for the new export — src/plugin-sdk/provider-transport-runtime.ts:10
    plugin-sdk/provider-transport-runtime is a public SDK subpath, and this PR adds extractToolResultImageBlocks without updating the generated API baseline or documenting the accepted contract. Either regenerate and commit the baseline for this intentional API addition, or keep the helper off the public SDK surface.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4a2a97777e35.

Label changes

Label changes:

  • add P2: This is a bounded current-main LLM replay bugfix with limited blast radius, but it still has a merge-blocking SDK contract issue.
  • add merge-risk: 🚨 compatibility: Adding extractToolResultImageBlocks to plugin-sdk/provider-transport-runtime changes a public plugin API subpath.
  • add merge-risk: 🚨 message-delivery: The PR changes provider-bound tool-result replay, which controls whether successful tool output and media placeholders reach the next model turn.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied after-fix provider payload output from the real OpenAI Completions conversion path, and the live Real behavior proof check passed for this head.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes copied after-fix provider payload output from the real OpenAI Completions conversion path, and the live Real behavior proof check passed for this head.

Label justifications:

  • P2: This is a bounded current-main LLM replay bugfix with limited blast radius, but it still has a merge-blocking SDK contract issue.
  • merge-risk: 🚨 compatibility: Adding extractToolResultImageBlocks to plugin-sdk/provider-transport-runtime changes a public plugin API subpath.
  • merge-risk: 🚨 message-delivery: The PR changes provider-bound tool-result replay, which controls whether successful tool output and media placeholders reach the next model turn.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes copied after-fix provider payload output from the real OpenAI Completions conversion path, and the live Real behavior proof check passed for this head.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied after-fix provider payload output from the real OpenAI Completions conversion path, and the live Real behavior proof check passed for this head.
Evidence reviewed

PR surface:

Source +67, Tests +85. Total +152 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 12 138 71 +67
Tests 2 86 1 +85
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 224 72 +152

What I checked:

Likely related people:

  • obviyus: Merged the structured replay predecessor and authored the Plugin SDK baseline refresh in the same provider replay surface. (role: predecessor merger and recent area contributor; confidence: high; commits: b63e06f68aa0, 56ae3f26c9dd, ce28ff90f646; files: src/llm/providers/tool-result-text.ts, src/plugin-sdk/provider-transport-runtime.ts, docs/.generated/plugin-sdk-api-baseline.sha256)
  • snowzlmbot: Authored the merged structured replay work and opened the canonical non-array replay issue that this PR closes. (role: feature contributor and canonical issue author; confidence: high; commits: b63e06f68aa0, 524a4932a1ed; files: src/llm/providers/tool-result-text.ts, src/llm/providers/openai-completions.ts, extensions/google/transport-stream.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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 2, 2026
@obviyus

obviyus commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Closing: the underlying bug (#98825) is fixed on main by #98891 (merge commit e095dc8).

We took a different approach than this PR: instead of widening the shared replay helpers to tolerate non-array content, #98891 normalizes tool-result content once at session-JSONL ingest (src/agents/sessions/session-manager.ts) — string becomes [{ type: "text", text }], a single object becomes [object] — so every downstream consumer (provider converters, transport streams, the .some()/.filter() sites) keeps receiving the canonical (TextContent | ImageContent)[] and ToolResultMessage.content stays honest. Regression coverage lives in src/agents/sessions/session-manager.tool-result-replay.test.ts, including an Anthropic replay symptom test that was red before the fix.

Thanks for digging into this — the character-by-character iteration analysis in #98825 was exactly right. If you hit a path where non-array tool-result content still reaches the extractors after e095dc8 (i.e. one that doesn't enter via session-file load), please open a fresh issue with the repro and we'll extend the boundary normalization there.

@obviyus obviyus closed this Jul 2, 2026
@RomneyDa
RomneyDa deleted the feature/issue-98825-tool-result-replay branch October 22, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: google maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(llm): tool-result replay can drop non-array output content

2 participants