Skip to content

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

Closed
arkyu2077 wants to merge 1 commit into
openclaw:mainfrom
arkyu2077:pr-factory/issue-98825
Closed

arkyu2077 wants to merge 1 commit into
openclaw:mainfrom
arkyu2077:pr-factory/issue-98825

Conversation

@arkyu2077

Copy link
Copy Markdown
Contributor

Summary

  • normalize tool-result inputs before extracting text so replay can handle single objects and other non-array payloads
  • preserve plain string tool results instead of iterating them character-by-character and falling back to media placeholders
  • add regression coverage for plain-string and single-object tool result replay

Fixes #98825.

Testing

  • npm test -- src/llm/providers/tool-result-text.test.ts

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 10:01 PM ET / 02:01 UTC.

Summary
The PR widens the shared tool-result replay text helpers to accept non-array inputs and adds helper-level regression tests for plain-string and single-object content.

PR surface: Source +16, Tests +15. Total +31 across 2 files.

Reproducibility: yes. Source inspection shows current main iterates raw helper input, and existing transcript/restart tests show toolResult content can appear as strings; I did not run tests because this review is read-only.

Review metrics: 1 noteworthy metric.

  • Public helper inputs: 2 widened. Both re-exported provider-transport helpers now accept non-array content, so caller behavior and plugin-facing semantics should be checked 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 issue; a separate draft PR targets the same root but is not a safe supersession target because it has unresolved review and proof blockers.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Normalize non-array content before provider media/image checks and add provider-path regression coverage.
  • [P1] Update the PR body with redacted terminal output, logs, or a linked artifact showing after-fix replay behavior in a real setup.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only a unit-test command is listed; there is no after-fix runtime output, log, terminal proof, or linked artifact showing real tool-result replay behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Actual provider replay is still not fully covered: OpenAI, Google, and Mistral callers use array methods on the original content after helper extraction.
  • [P1] The external PR lacks after-fix real behavior proof, so maintainers cannot verify the replay path outside helper-level tests yet.

Maintainer options:

  1. Fix the provider replay boundary first (recommended)
    Normalize non-array content once for text extraction, media placeholders, and image checks, then add at least one provider-path regression test that would fail on current main.
  2. Pause until contributor proof is added
    Wait for the contributor to add redacted terminal output, logs, or linked artifact proof showing the after-fix replay behavior in a real setup.

Next step before merge

  • [P1] Needs contributor code repair plus redacted real behavior proof before maintainer merge review; ClawSweeper should not take over while the external proof gate is missing.

Security
Cleared: No concrete security or supply-chain regression was found; the diff only changes a TypeScript replay helper and colocated tests, with no dependency, workflow, secret, or build-script changes.

Review findings

  • [P2] Normalize before caller media checks — src/llm/providers/tool-result-text.ts:189
Review details

Best possible solution:

Normalize non-array tool-result content at a shared replay boundary used by text extraction and media/image checks, add provider-path regression coverage, and require redacted real behavior proof before merge.

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

Yes. Source inspection shows current main iterates raw helper input, and existing transcript/restart tests show toolResult content can appear as strings; I did not run tests because this review is read-only.

Is this the best way to solve the issue?

No. Normalizing only inside extractToolResultText is too narrow because provider callers still use the original content for media/image checks; a shared normalized boundary or caller normalization is the safer fix.

Full review comments:

  • [P2] Normalize before caller media checks — src/llm/providers/tool-result-text.ts:189
    The helper now accepts non-array content, but provider replay callers still call .some or .filter on the original msg.content immediately after extraction. If the string or single-object content from the linked issue reaches those paths, replay can still fail before preserving output; normalize the content at the shared replay boundary or update the callers and add provider-path coverage.
    Confidence: 0.84

Overall correctness: patch is incorrect
Overall confidence: 0.84

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 313560d5b98e.

Label changes

Label justifications:

  • P2: This is a bounded LLM replay bugfix PR with limited blast radius, but it still has a blocking provider-path correctness gap.
  • merge-risk: 🚨 message-delivery: The diff changes provider-bound tool-result replay text, and actual non-array content can still fail or suppress useful tool output in caller paths.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only a unit-test command is listed; there is no after-fix runtime output, log, terminal proof, or linked artifact showing real tool-result replay behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +16, Tests +15. Total +31 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 4 +16
Tests 1 15 0 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 35 4 +31

What I checked:

  • Repository policy read: Read the full root AGENTS.md; no scoped AGENTS.md exists under src/llm, and the root review policy required checking callers, tests, related PRs, history, and proof rather than diff-only review. (AGENTS.md:29, 313560d5b98e)
  • PR widens helper inputs only: The diff adds normalizeToolResultBlocks and changes extractToolResultText/describeToolResultMediaPlaceholder to accept unknown input at the helper boundary. (src/llm/providers/tool-result-text.ts:189, ed4b5acf16da)
  • Current helper assumes arrays on main: Current main's extractToolResultText accepts readonly unknown[] and iterates the raw blocks value, so a raw string is walked character-by-character and primitive characters are ignored. (src/llm/providers/tool-result-text.ts:180, 313560d5b98e)
  • Provider callers still assume arrays: OpenAI Responses calls extractToolResultText(msg.content) but then immediately calls msg.content.some(...), so actual non-array content can still fail outside the patched helper. (src/llm/providers/openai-responses-shared.ts:415, 313560d5b98e)
  • Sibling provider callers share the invariant: Google and Mistral provider replay paths also call the shared extractor and then use filter/some on the original msg.content value for image/media handling. (src/llm/providers/google-shared.ts:282, 313560d5b98e)
  • Canonical message contract is still array-shaped: ToolResultMessage.content remains typed as (TextContent | ImageContent)[], so this PR is a defensive compatibility change for non-canonical or legacy shapes rather than a new primary data model. (packages/llm-core/src/types.ts:306, 313560d5b98e)

Likely related people:

  • obviyus: Live PR metadata shows obviyus merged the predecessor structured replay PR, and that PR includes follow-up commits by obviyus in the same provider replay/redaction surface. (role: recent area contributor and predecessor merger; confidence: medium; commits: b63e06f68aa0, c61e42978f43, 1ececc049f6e; files: src/llm/providers/tool-result-text.ts, src/llm/providers/openai-responses-shared.ts, src/llm/providers/openai-completions.ts)
  • snowzlmbot: snowzlmbot authored the merged predecessor PR that added the shared extractor and opened the canonical follow-up issue for this non-array replay gap. (role: feature contributor and canonical issue author; confidence: medium; commits: b63e06f68aa0, 524a4932a1ed, 0fe0e7ed62a3; files: src/llm/providers/tool-result-text.ts, src/llm/providers/tool-result-text.test.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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 2, 2026
@harjothkhara

Copy link
Copy Markdown
Contributor

I compared this against #98826 for #98825 after the latest CI run. This PR is the cleaner base only if it keeps #98826's direct output/content return out of the provider path: serializing single objects through the existing structured fallback preserves the current redaction, truncation, inline-data, and binary-field omission contract, while #98826's text-like-field branch bypasses that path.

Two concrete blockers remain here:

  • check-lint is failing on changed-file lines in src/llm/providers/tool-result-text.ts because readonly unknown[] | unknown collapses to unknown (typescript(no-redundant-type-constituents)). The CI log points at lines 137 and 192 in this PR head; changing both widened helper signatures to unknown should clear that local lint blocker.
  • The provider-boundary blocker is still the important correctness issue: OpenAI Responses, Google, Mistral, and OpenAI transport call extractToolResultText(msg.content) and then keep using the original msg.content.some / msg.content.filter path for media/image handling. A non-array value from bug(llm): tool-result replay can drop non-array output content #98825 can still fail outside the helper unless the normalized block list is shared with those callers or the caller boundary normalizes before text/media handling.

Best-fix verdict: acceptable base, not merge-ready. Compared with #98826, this branch is safer on the redaction contract, but it still needs the lint fix plus provider-path normalization/regression coverage before maintainers should treat it as the canonical #98825 fix.

Code/CI checked: src/llm/providers/tool-result-text.ts, src/llm/providers/openai-responses-shared.ts, src/llm/providers/google-shared.ts, src/llm/providers/mistral.ts, src/llm/providers/openai-completions.ts, packages/llm-core/src/types.ts, and the failed check-lint job log for run 28559878223 / job 84675215253.

@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
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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants