Skip to content

feat(acp): forward image blocks in tool call results - #55766

Closed
David553 wants to merge 3 commits into
openclaw:mainfrom
David553:feat/acp-image-tool-result
Closed

David553 wants to merge 3 commits into
openclaw:mainfrom
David553:feat/acp-image-tool-result

Conversation

@David553

Copy link
Copy Markdown

Summary

  • extractToolCallContent() in the ACP event mapper previously only extracted type: "text" blocks from tool results, silently dropping image content blocks
  • ACP clients (Feishu, Discord, etc.) could not display images produced by tools (e.g. the Read tool reading PNG/JPG files) because image blocks were never forwarded
  • Added image block extraction with validation (data and mimeType must both be present), using the existing ImageContent type from @agentclientprotocol/sdk
  • No protocol changes needed — the ACP SDK already supports ImageContent in ToolCallContent

Test plan

  • Added unit tests for extractToolCallContent() covering:
    • Text-only extraction (existing behavior)
    • Image-only extraction
    • Mixed text + image blocks
    • Malformed image blocks (missing data/mimeType) are skipped
    • Empty content returns undefined
    • String input fallback
  • Manual verification: use ACP bridge with a Feishu/Discord client, have the agent read a PNG file, confirm the image is displayed in the client

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends extractToolCallContent() in the ACP event mapper to forward image content blocks from tool results to ACP clients (e.g., Feishu, Discord), in addition to the previously-supported text blocks. The change is minimal and well-tested.

Key changes:

  • Added an else if branch in extractToolCallContent() that handles type: "image" blocks, validating that both data and mimeType are strings before forwarding them as ImageContent.
  • Added comprehensive unit tests covering text-only, image-only, mixed, malformed (missing fields), empty content, and string-fallback cases.

Issue found:

  • The image-block validation checks typeof entry.data === "string" but doesn't guard against an empty string (""), unlike the text-block branch which uses .trim(). An image block with data: "" or mimeType: "" would be forwarded to clients as a valid image, likely causing rendering failures. The test suite also doesn't cover this edge case.

Confidence Score: 5/5

Safe to merge; the only finding is a minor edge-case validation gap that won't be triggered in normal usage.

The implementation is correct for all realistic inputs. The single P2 finding requires a malformed tool result (empty-string data or mimeType) to trigger, which does not occur in normal tool output. Tests are thorough for the documented cases. No breaking changes or protocol modifications needed.

No files require special attention beyond the minor validation gap in src/acp/event-mapper.ts.

Important Files Changed

Filename Overview
src/acp/event-mapper.ts Added image block extraction to extractToolCallContent(). Logic is correct for the happy path but allows empty-string data/mimeType values through, unlike the text-block branch which guards against empty strings.
src/acp/event-mapper.test.ts New unit tests cover text, image, mixed, malformed (missing data/mimeType), empty content, and string-fallback cases. Missing a test for empty-string data/mimeType values.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/acp/event-mapper.ts
Line: 375-388

Comment:
**Empty `data`/`mimeType` strings pass validation**

The text block branch guards against empty strings with `.trim()` (line 367), but the image branch only checks `typeof entry.data === "string"` and `typeof entry.mimeType === "string"`. This means an image block with `data: ""` or `mimeType: ""` would be forwarded to ACP clients as a valid image, likely causing rendering failures on the client side.

For consistency with the text-block handling, you should add emptiness guards:

```suggestion
    } else if (
      entry?.type === "image" &&
      typeof entry.data === "string" &&
      entry.data.length > 0 &&
      typeof entry.mimeType === "string" &&
      entry.mimeType.length > 0
    ) {
      contents.push({
        type: "content",
        content: {
          type: "image",
          data: entry.data,
          mimeType: entry.mimeType,
        } as ImageContent & { type: "image" },
      });
    }
```

The corresponding test case `"skips image blocks with missing data or mimeType"` only covers `undefined` values (absent fields), not empty strings — a test for `{ type: "image", data: "", mimeType: "image/png" }` should also be added.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(acp): forward image blocks in tool ..." | Re-trigger Greptile

Comment thread src/acp/event-mapper.ts
Comment on lines +375 to 388
} else if (
entry?.type === "image" &&
typeof entry.data === "string" &&
typeof entry.mimeType === "string"
) {
contents.push({
type: "content",
content: {
type: "image",
data: entry.data,
mimeType: entry.mimeType,
} as ImageContent & { type: "image" },
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Empty data/mimeType strings pass validation

The text block branch guards against empty strings with .trim() (line 367), but the image branch only checks typeof entry.data === "string" and typeof entry.mimeType === "string". This means an image block with data: "" or mimeType: "" would be forwarded to ACP clients as a valid image, likely causing rendering failures on the client side.

For consistency with the text-block handling, you should add emptiness guards:

Suggested change
} else if (
entry?.type === "image" &&
typeof entry.data === "string" &&
typeof entry.mimeType === "string"
) {
contents.push({
type: "content",
content: {
type: "image",
data: entry.data,
mimeType: entry.mimeType,
} as ImageContent & { type: "image" },
});
}
} else if (
entry?.type === "image" &&
typeof entry.data === "string" &&
entry.data.length > 0 &&
typeof entry.mimeType === "string" &&
entry.mimeType.length > 0
) {
contents.push({
type: "content",
content: {
type: "image",
data: entry.data,
mimeType: entry.mimeType,
} as ImageContent & { type: "image" },
});
}

The corresponding test case "skips image blocks with missing data or mimeType" only covers undefined values (absent fields), not empty strings — a test for { type: "image", data: "", mimeType: "image/png" } should also be added.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/acp/event-mapper.ts
Line: 375-388

Comment:
**Empty `data`/`mimeType` strings pass validation**

The text block branch guards against empty strings with `.trim()` (line 367), but the image branch only checks `typeof entry.data === "string"` and `typeof entry.mimeType === "string"`. This means an image block with `data: ""` or `mimeType: ""` would be forwarded to ACP clients as a valid image, likely causing rendering failures on the client side.

For consistency with the text-block handling, you should add emptiness guards:

```suggestion
    } else if (
      entry?.type === "image" &&
      typeof entry.data === "string" &&
      entry.data.length > 0 &&
      typeof entry.mimeType === "string" &&
      entry.mimeType.length > 0
    ) {
      contents.push({
        type: "content",
        content: {
          type: "image",
          data: entry.data,
          mimeType: entry.mimeType,
        } as ImageContent & { type: "image" },
      });
    }
```

The corresponding test case `"skips image blocks with missing data or mimeType"` only covers `undefined` values (absent fields), not empty strings — a test for `{ type: "image", data: "", mimeType: "image/png" }` should also be added.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bd9eac79b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/acp/event-mapper.ts Outdated
Comment on lines +376 to +378
entry?.type === "image" &&
typeof entry.data === "string" &&
typeof entry.mimeType === "string"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject empty image payloads in tool call content

The new image branch accepts any string values for data and mimeType, including empty strings, so a tool result like { type: "image", data: "", mimeType: "image/png" } is now forwarded as valid content. In that case ACP clients can receive an undecodable image payload, and because contents.length > 0, fallback text (text/message/error) is skipped entirely. This should validate non-empty (and ideally trimmed) strings before emitting an image content block.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7016f5a566

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/acp/event-mapper.ts Outdated
Comment on lines +377 to +380
typeof entry.data === "string" &&
entry.data.length > 0 &&
typeof entry.mimeType === "string" &&
entry.mimeType.length > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject whitespace-only image payload fields

The new image acceptance check only uses length > 0, so blocks like { type: "image", data: " ", mimeType: "image/png" } or { mimeType: " " } are treated as valid content even though they are not decodable/usable image payloads. In that case contents.length > 0 short-circuits fallback text (text/message/error), so clients can receive a broken image update with no human-readable fallback. Please trim and validate both fields before emitting an image content block.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the PR is a focused ACP mapper improvement that current main still lacks, but it is not merge-ready because the external branch has only unit-test proof and recent proof-check activity means it does not satisfy stale unproven close criteria.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes at source level: current main's ACP mapper only emits text content, and the translator uses that mapper for tool partial and final results. I did not establish a live ACP client reproduction in this read-only review.

Is this the best way to solve the issue?

Yes for the code layer: the event mapper is the shared ACP tool-result conversion boundary, and ACP SDK 1.1.0 already supports image content in tool-call content. It is not merge-ready until docs and real behavior proof cover the expanded surface.

Security review:

Security review cleared: No concrete security or supply-chain concern was found; the diff only changes ACP mapper logic and tests.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-27T12:04:09Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is mock_only and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Git history shows the initial experimental ACP bridge plus later refactors of the same event-mapper helpers used by this PR. (role: initial ACP feature and recent ACP mapper refactor contributor; confidence: high; commits: de3b68740aa9, 201697c20044, e42f11ed622d; files: src/acp/event-mapper.ts, src/acp/translator.ts, docs/cli/acp.md)
  • mbelinky: Merged ACP streaming work introduced the current tool-call content and location mapper surface that this branch extends. (role: ACP streaming feature contributor; confidence: high; commits: 8e3f3bc3cf47, 3c3474360be8; files: src/acp/event-mapper.ts, src/acp/translator.ts, src/acp/translator.tool-streaming.test.ts)
  • jacobtomlinson: Recent merged ACP terminal-title sanitization touched the same mapper and adjacent ACP client tests. (role: recent ACP mapper contributor; confidence: medium; commits: 464e2c10a5ed; files: src/acp/event-mapper.ts, src/acp/client.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 70f2bef6b4cf.

LibCaptain and others added 3 commits May 4, 2026 15:18
extractToolCallContent() previously only extracted text blocks from tool
results, silently dropping image content. This meant ACP clients (e.g.
Feishu, Discord) could not display images produced by tools like Read
when reading PNG/JPG files.

Add image block extraction alongside text blocks, with validation that
both data and mimeType are present. The ACP SDK already defines
ImageContent in ToolCallContent, so no protocol changes are needed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Address review feedback: add length > 0 guards for data and mimeType
to prevent forwarding undecodable image payloads to ACP clients.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@David553
David553 force-pushed the feat/acp-image-tool-result branch from 7016f5a to f0d66e2 Compare May 4, 2026 08:09
@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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 9, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed 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. labels Jun 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 10, 2026
@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. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Jul 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 2, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@David553 thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 22, 2026
@steipete

Copy link
Copy Markdown
Contributor

Closing per ClawSweeper review verdict duplicate_or_superseded (decision packet 2026-07-05T16:27:31.718Z). This item was part of the audited close backlog (openclaw/clawsweeper#920) stranded by an apply-lane defect, drained manually after re-verification. If this is wrong, reopen and ClawSweeper will re-review.

@steipete steipete closed this Jul 29, 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: S 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. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants