Skip to content

perf(ai): skip discarded text assembly for image tool results - #140409

Merged
steipete merged 1 commit into
mainfrom
codex/perf53-anthropic-image-text
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf53-anthropic-image-text

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Anthropic tool results containing images assemble an aggregate text result that the image branch never uses, then extract and sanitize each block again. Structured results also repeat serialization and redaction unnecessarily.

Why This Change Was Made

Move aggregate text extraction into its existing text-only consumer. Keep the image branch's per-block extraction, redaction, ordering, normalization and image budget unchanged. This removes one production line and needs no new API, cache, configuration or dependency.

User Impact

In the checksum-corrected R2 comparison, structured/resource image-result medians improved 45–52%, and 20-result histories improved 42–45%, across both orders on image-emitting paths. Provider and transport capability differences remain unchanged, including non-vision transport behavior.

All adverse observations remain: 47/128 medians, 50/128 means and 49/128 maximum batch means worsened. The provider-vision image-only case was +32% (+11.8 µs) forward, while its 64 KiB text/image case was +11.3%/+6.8% (+3.1/+2.0 µs). Peak process RSS increased slightly in both orders. These are payload-conversion measurements, not provider, Gateway, memory-reduction or native-image-codec claims.

Evidence

All 257 existing tests across provider, transport, generic extraction and image-budget suites passed. All 27 normal changed-file checks and fresh independent Codex review through P2 passed; no tests were weakened or added merely to assert a call count.

The fixed B0/C0/C1/B1 cohort calls the actual shared converter with real core redaction and image normalization. Its 64 cases cover all four provider/transport and vision/non-vision combinations. All 9,472 complete input/wire records match both independent fixture expectations and the other variants. All 2,048 retained batch means remain available; individual call timings were not separately recorded. Process closure, restored candidate bytes and selected runtime/source pins were independently verified. No provider request or real credential was used in this projection-only comparison.

R1 remains retained separately: its tiny PNG had an incorrect IDAT checksum, although the compressed data inflated and the actual MIME/normalization route accepted it. R2 corrected only three checksum bytes; file length, compressed pixels, cases, order and timing settings stayed unchanged. All three R2 chunk CRCs validate. R1's measurements and regressions are preserved and were not pooled into or replaced by R2. This proves fixture structure/checksum/inflation, not native codec rendering.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 20:05
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 4:19 PM ET / 20:19 UTC.

ClawSweeper review

What this changes

Avoids assembling unused aggregate text when converting image-bearing tool results into Anthropic request messages.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization: current main still performs the discarded extraction, and the patch introduces no blocking correctness finding. The maintainer-authored, protected PR should remain available for normal landing.

Priority: P3
Reviewed head: 1dbbded858e4e313732804c4a59636f2f12e72ee

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, maintainable optimization with existing behavioral coverage and appropriately bounded performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its captured body reports after-fix comparisons through the actual converter with real redaction and image normalization, matching output records and mixed timing results; it makes no live-provider or native-codec claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its captured body reports after-fix comparisons through the actual converter with real redaction and image normalization, matching output records and mixed timing results; it makes no live-provider or native-codec claim.
Evidence reviewed 8 items Verified introduced change: The pinned merge-base-to-head diff moves aggregate extraction into its sole consuming branch; the image loop, capability predicate, fallbacks, and image budget remain unchanged.
Current main still contains unnecessary work: Fetched main extracts aggregate text before deciding whether to emit images, then independently extracts each image-branch block. The requested optimization is therefore still absent from this main revision.
Extraction and redaction remain at the emitted-block boundary: Aggregate extraction calls the same block extractor retained in the image loop. Structured serialization still applies host secret redaction, binary-field omission, Unicode sanitation, and truncation before emitted text is produced.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Anthropic message converter prepares conversation history for both provider and transport requests. It converts tool output into text or ordered text-and-image blocks before the request is sent.

flowchart TD
  A[Conversation tool results] --> B[Anthropic message converter]
  B --> C{Images supported and present?}
  C -->|No| D[Extract aggregate text]
  C -->|Yes| E[Extract individual blocks and normalize images]
  D --> F[Anthropic request messages]
  E --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1. Total -1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 1 2 -1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 1 2 -1

Review metrics

None.

Technical review

Best possible solution:

Keep aggregate extraction local to the text-only branch while preserving the existing per-block image conversion and sanitation path.

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

Yes, source establishes the redundant work: an image-bearing tool result causes aggregate extraction whose value is discarded before per-block extraction repeats it. Timing measurements were not rerun.

Is this the best way to solve the issue?

Yes, moving the computation to its sole consumer is the narrowest repair and preserves both provider and transport output paths without adding another abstraction.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e1c1bc37c77f.

Labels

Label justifications:

  • P3: This is a bounded payload-conversion optimization with no intended output or configuration change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its captured body reports after-fix comparisons through the actual converter with real redaction and image normalization, matching output records and mixed timing results; it makes no live-provider or native-codec claim.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2dfd3c3 adds packages/ai/src/transports/anthropic-messages.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2dfd3c3daba9; files: packages/ai/src/transports/anthropic-messages.ts)

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 (1 earlier review cycle)
  • reviewed 2026-09-06T20:11:44.265Z sha 1dbbded :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 56316e4 into main Sep 6, 2026
194 of 195 checks passed
@steipete
steipete deleted the codex/perf53-anthropic-image-text branch September 6, 2026 20:22
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
…rol-ui

* origin/main:
  docs: remove the empty release-sections nav group (#140427)
  fix(tooling): omit Codex machine squash credit (#140420)
  chore(ui): refresh control ui locales (#140384)
  refactor(plugin-sdk): reuse native approval input contracts (#140415)
  fix: silent model WebSocket streams hang past the idle timeout (#140335)
  perf(ai): avoid unused text extraction for image results (#140409)
  fix(ui): distinguish failed GitHub status checks from disconnected accounts (#140333)
  refactor(cron): share runtime feedback schema fields (#140408)
  fix: avoid duplicate cloud worker teardown during recovery (#140377)
  fix(cli): show executable approval scope (#138386)
  refactor(ui): reuse shared requirement records (#140407)
  test(gateway): table-drive device token lifecycle checks (#140403)
  fix(chat): fence delayed history at terminal retirement (#140379)
  test(skills): compare large upload bytes natively (#140402)
  refactor(delivery): reuse the canonical rendered batch plan type (#140386)
  docs(start): repair the first-run path from landing page to first channel (#140390)

# Conflicts:
#	docs/.i18n/glossary.zh-CN.json
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

1 participant