salch-cred 8b1ccb67d3 fix(agent): gate the 20-image eviction trigger on the request's dimensions
Mechanism: `agent/image_eviction_policy.outbound_image_retire_count` retired a
batch of 8 once a request carried more than 20 image blocks, for every provider
and every request. 20 is where Anthropic starts holding EVERY image in the
request to a stricter per-side cap -- it is not a count limit, so crossing it
only constrains a request that actually contains an image over that cap. Hermes
already embeds its own tool images well under it (`vision_analyze` and browser
screenshots at 1568 px, `computer_use` at 1456 px by default), and user uploads
are reserved and never rewritten. So on an all-tool-image request the 21st
screenshot crossed no provider constraint, and the batch retire rewrote a cached
prefix for nothing -- on the preserved-thinking models that also invalidates
every later thinking block (Anthropic's computer-use guidance now says to keep
screenshots at or under 2000 px and NOT to prune them client-side).

Seam: the block ceiling becomes conditional. `outbound_image_retire_count` takes
`many_image_safe` and derives `limit` from `outbound_image_block_limit()`, the
strict 20 unless every image in the request is within `MANY_IMAGE_DIMENSION_LIMIT`
(2000 px). Both passes classify from the same module so the #113517 invariant
holds: `context_compressor.evict_stale_outbound_tool_images` (OpenAI shape,
`image_url`) and `anthropic_message_convert._evict_old_screenshots` (wire shape,
`source.data`). Classification is header-only -- `image_max_side_from_data`
decodes just the leading base64 prefix, never a whole payload -- and fails
closed: a missing, unreadable or non-image source keeps today's strict 20.

`image_dimensions_from_bytes` moves into the policy leaf (which the wire
converter already imports and which must not import `tools/`) and is re-exported
from `tools/computer_use/backend.py`, so the tool layer's min-size guard and the
two send-path passes share one PNG/JPEG header reader.

Repro (real passes, pre-change code): 21 tool results carrying one 1568 px image
each -> `evict_stale_outbound_tool_images` returned 8 rewrites; 30 -> 16. Same
fixtures after the change -> 0, and 0 on the wire pass. A 20-carrier request
plus one 2001 px user upload still retires exactly `IMAGE_EVICTION_BATCH` (8),
byte-identical to before.
2026-10-16 14:21:39 -07:00
..
…
…