Nathan Sobo
b091cc4d9a
Enforce 5MB per-image limit when converting images for language models ( #45313 )
...
## Problem
When users paste or drag large images into the agent panel, the encoded
payload can exceed upstream provider limits (e.g., Anthropic's 5MB
per-image limit), causing API errors.
## Solution
Enforce a default 5MB limit on encoded PNG bytes in
`LanguageModelImage::from_image`:
1. Apply existing Anthropic dimension limits first (1568px max in either
dimension)
2. Iteratively downscale by ~15% per pass until the encoded PNG is under
5MB
3. Return `None` if the image can't be shrunk within 8 passes
(fail-safe)
The limit is enforced at the `LanguageModelImage` conversion layer,
which is the choke point for all image ingestion paths (agent panel
paste/drag, file mentions, text threads, etc.).
## Future Work
The 5MB limit is a conservative default. Provider-specific limits can be
introduced later by adding a `from_image_with_constraints` API.
## Testing
Added a regression test that:
1. Generates a noisy 4096x4096 PNG (guaranteed >5MB)
2. Converts it via `LanguageModelImage::from_image`
3. Asserts the result is ≤5MB and was actually downscaled
---
**Note:** This PR builds on #45312 (prompt store fail-open fix). Please
merge that first.
cc @rtfeldman
---------
Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
2025-12-19 15:04:41 -05:00
..
2025-12-18 17:05:04 -05:00
2025-12-15 13:30:13 +00:00
2025-12-10 16:48:08 +00:00
2025-11-24 13:34:04 +01:00
2025-12-18 17:05:04 -05:00
2025-12-15 08:22:58 +01:00
2025-12-16 16:22:30 -03:00
2025-12-19 11:37:57 -08:00
2025-12-18 17:49:17 -03:00
2025-12-18 17:05:04 -05:00
2025-12-16 14:32:41 -05:00
2025-11-28 08:18:19 +01:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-15 08:24:57 +01:00
2025-12-15 04:07:44 +00:00
2025-11-07 22:27:14 +00:00
2025-11-27 14:08:43 +00:00
2025-11-11 12:55:19 +00:00
2025-11-27 13:46:43 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 12:54:57 +01:00
2025-11-20 12:18:50 +01:00
2025-12-19 19:08:49 +00:00
2025-12-16 05:10:33 +00:00
2025-11-24 13:34:04 +01:00
2025-12-16 01:22:41 +00:00
2025-12-15 20:53:50 -07:00
2025-11-06 09:16:45 +00:00
2025-11-10 23:00:55 -07:00
2025-10-17 18:58:14 +00:00
2025-12-13 00:56:06 +00:00
2025-12-17 21:43:42 +01:00
2025-12-17 01:59:34 +02:00
2025-12-17 16:51:16 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 16:51:16 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-16 21:44:39 +00:00
2025-12-17 21:43:42 +01:00
2025-12-02 16:15:18 -05:00
2025-10-17 18:58:14 +00:00
2025-11-19 12:34:41 +01:00
2025-12-08 19:57:02 +01:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-04 03:55:04 +05:30
2025-12-17 16:51:16 +00:00
2025-12-18 12:47:34 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 16:51:16 +00:00
2025-12-18 21:59:05 -05:00
2025-12-18 00:32:46 +00:00
2025-12-17 16:53:42 +00:00
2025-12-10 17:36:51 -08:00
2025-12-17 21:43:42 +01:00
2025-12-17 16:51:16 +00:00
2025-12-19 17:32:38 +00:00
2025-12-17 16:53:42 +00:00
2025-12-18 17:26:20 +01:00
2025-10-17 18:58:14 +00:00
2025-12-18 17:05:04 -05:00
2025-12-17 16:25:07 -08:00
2025-12-08 21:49:26 +01:00
2025-12-18 17:05:04 -05:00
2025-12-08 13:16:19 +00:00
2025-12-15 10:14:15 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 16:51:16 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 19:55:36 +00:00
2025-10-20 10:30:06 +00:00
2025-11-20 22:17:50 -07:00
2025-12-08 19:50:20 +01:00
2025-12-17 17:31:12 -05:00
2025-12-08 13:32:14 -05:00
2025-12-19 13:50:35 +00:00
2025-12-17 16:51:16 +00:00
2025-12-17 20:12:40 -06:00
2025-12-19 13:31:27 -03:00
2025-12-17 16:51:16 +00:00
2025-12-15 16:09:10 +01:00
2025-10-17 18:58:14 +00:00
2025-12-09 09:29:40 -08:00
2025-10-17 18:58:14 +00:00
2025-12-15 13:02:01 -03:00
2025-12-11 19:14:36 +00:00
2025-12-16 20:34:00 +02:00
2025-10-17 18:58:14 +00:00
2025-11-19 22:00:58 +00:00
2025-12-05 20:26:42 +00:00
2025-12-17 16:51:16 +00:00
2025-12-19 18:18:20 +00:00
2025-12-09 13:22:57 +01:00
2025-12-19 15:04:41 -05:00
2025-12-18 17:05:04 -05:00
2025-10-17 18:58:14 +00:00
2025-10-22 19:52:38 +00:00
2025-12-18 21:59:21 +00:00
2025-12-19 21:44:02 +05:30
2025-10-22 19:52:38 +00:00
2025-10-17 18:58:14 +00:00
2025-12-15 14:58:38 +01:00
2025-10-17 18:58:14 +00:00
2025-12-18 21:59:21 +00:00
2025-12-17 16:51:16 +00:00
2025-12-17 16:51:16 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-16 07:51:28 -03:00
2025-11-26 18:03:42 +01:00
2025-12-18 09:49:32 +00:00
2025-12-18 16:45:55 +01:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 16:53:42 +00:00
2025-12-15 12:06:17 +00:00
2025-11-11 16:10:47 +01:00
2025-12-17 16:51:16 +00:00
2025-12-11 15:49:10 -05:00
2025-11-24 13:24:26 -05:00
2025-12-17 16:51:16 +00:00
2025-12-18 11:45:26 -05:00
2025-10-17 18:58:14 +00:00
2025-12-10 12:10:43 -08:00
2025-12-17 16:51:16 +00:00
2025-12-12 11:16:17 +00:00
2025-12-19 19:08:49 +00:00
2025-12-17 16:53:42 +00:00
2025-12-19 10:12:01 +00:00
2025-12-03 21:56:39 +00:00
2025-12-19 14:59:01 -05:00
2025-12-17 16:53:42 +00:00
2025-12-17 16:51:16 +00:00
2025-12-15 13:30:13 +00:00
2025-11-27 13:46:43 +00:00
2025-12-19 17:06:16 +01:00
2025-12-17 16:53:42 +00:00
2025-12-12 06:32:30 -08:00
2025-12-09 09:29:40 -08:00
2025-11-03 19:25:15 +00:00
2025-12-15 08:25:50 +01:00
2025-12-04 14:42:26 +00:00
2025-12-18 17:21:41 +01:00
2025-10-17 18:58:14 +00:00
2025-12-16 10:48:14 -05:00
2025-12-19 13:31:27 -03:00
2025-12-01 09:12:31 +01:00
2025-12-19 21:44:02 +05:30
2025-10-27 10:13:26 -04:00
2025-11-21 08:28:17 -07:00
2025-11-07 22:27:14 +00:00
2025-12-18 11:45:26 -05:00
2025-10-17 18:58:14 +00:00
2025-12-08 21:38:24 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-11-20 01:52:13 -03:00
2025-11-03 19:25:15 +00:00
2025-12-15 08:25:50 +01:00
2025-12-17 21:43:42 +01:00
2025-10-17 18:58:14 +00:00
2025-11-20 12:18:50 +01:00
2025-11-24 13:34:04 +01:00
2025-12-16 08:26:29 +00:00
2025-12-04 15:37:32 -05:00
2025-12-09 09:08:59 +01:00
2025-11-07 11:36:05 +00:00
2025-11-24 13:34:04 +01:00
2025-12-17 15:53:22 -05:00
2025-12-19 09:39:58 -05:00
2025-12-12 14:28:25 +01:00
2025-12-04 03:55:04 +05:30
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-01 20:52:57 -07:00
2025-10-17 18:58:14 +00:00
2025-12-19 13:01:48 -03:00
2025-12-19 14:06:15 +01:00
2025-12-19 13:14:31 -03:00
2025-12-17 16:51:16 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-18 21:05:14 +02:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-19 15:31:16 +00:00
2025-11-07 22:27:14 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-10-17 18:58:14 +00:00
2025-12-17 11:53:48 -07:00
2025-12-19 16:21:56 +00:00
2025-12-19 18:18:20 +00:00
2025-12-19 11:18:36 +01:00
2025-12-08 16:38:34 +01:00
2025-12-19 00:21:46 -03:00
2025-12-18 16:38:47 +01:00
2025-12-13 11:06:30 -05:00
2025-12-10 17:36:51 -08:00
2025-12-06 17:56:49 +00:00
2025-11-07 22:27:14 +00:00
2025-12-17 16:14:57 +00:00
2025-12-05 17:23:06 +00:00