Skip to content

fix(anthropic): dynamic image downscaling on append busts prompt prefix cache #4532

Description

@jiaoyun286

Client or integration

Codex App

Area

Provider adapter

Summary

In OpenCodex 2.53.0, the Anthropic adapter dynamically calculates image downscaling tiers based on relative recency (initialPosition in anthropic-image-normalize.ts).

When a session appends a new image, earlier images in conversation history are pushed into lower resolution tiers (e.g. dropping from 2000px to 1024px) and re-encoded. This mutates past request bytes and completely invalidates Anthropic's prompt prefix cache, causing substantial token waste and cache misses on subsequent turns.

Expected behavior: Once an image is normalized and sent within a conversation, its encoded bytes/tier should remain immutable across future turns.

Reproduction

  1. Send an initial turn with 6 images through the Anthropic adapter. Note the encoded base64 hash/size of Image 1.
  2. In the next turn, append a 7th image to the session.
  3. Inspect the outgoing Anthropic payload:
    • Observed: Image 1 dropped from Tier 1 (2000px) to Tier 2 (1024px); its base64 payload mutated, breaking the prefix cache.
    • Expected: Image 1 retains its initial resolution and base64 encoding; prefix cache remains intact.

Version

2.53.0

Operating system

macOS 15.2

Provider and model

anthropic / claude-5-sonnet, openAi / gpt-6,googel / gemini-3.8-flash

Logs or error output

Affected files:
- src/adapters/anthropic-image-codec.ts (tier configs: 6 @ 2000px, 14 @ 1024px, older @ 700px)
- src/adapters/anthropic-image-normalize.ts (line 132 recalculating initialPosition dynamically)
- src/adapters/anthropic.ts (calling normalization per request)

Screenshots and supporting files

No response

Redacted configuration

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingproviderProvider adapters, OpenAI-compat presets, upstream API quirks

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions