-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: preserve input image geometry under CUA sandbox and warn on oversized images #10071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a41f7ed
2d0ee97
7970b4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ | |
| ) | ||
| from .image_input import prepare_request_images | ||
|
|
||
| # Anthropic rejects images above 5 MB; OpenAI and Gemini allow roughly 20 MB. | ||
| _CUA_IMAGE_WARN_BYTES = 5 * 1024 * 1024 | ||
|
|
||
|
|
||
| class InternalAgentSubStage(Stage): | ||
| async def initialize(self, ctx: PipelineContext) -> None: | ||
|
|
@@ -243,9 +246,24 @@ async def process( | |
| settings = self.ctx.astrbot_config["provider_settings"] | ||
| enabled = settings.get("image_compress_enabled", True) is not False | ||
| options = settings.get("image_compress_options", {}) | ||
| max_size = normalize_model_image_max_size( | ||
| montage_max_size = normalize_model_image_max_size( | ||
| options.get("max_size") if isinstance(options, dict) else None | ||
| ) | ||
| max_size = montage_max_size | ||
| sandbox_cfg = settings.get("sandbox") | ||
| cua_pixel_mode = ( | ||
| settings.get("computer_use_runtime") == "sandbox" | ||
| and isinstance(sandbox_cfg, dict) | ||
| and sandbox_cfg.get("booter") == "cua" | ||
| ) | ||
| if cua_pixel_mode: | ||
| # CUA pixel tools read coordinates 1:1 on stills, so the | ||
| # still-image resize is lifted; compliant images pass through | ||
| # byte-exact since lossy re-encoding would shift colors. | ||
| # Montages are never used for coordinates and keep the | ||
| # configured cap, which bounds the 3x3 canvas. Oversized | ||
| # passthrough images warn below. | ||
| max_size = 1_000_000 | ||
|
piexian marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): CUA still images whose longest edge exceeds 1,000,000 pixels are still resized by Triggers: When a CUA input image has a longest edge greater than 1,000,000 pixels. Suggested fix: Use an explicit no-resize path for CUA stills, or otherwise validate that the configured sentinel cannot be reached by real inputs before claiming geometry is always preserved.
Comment on lines
+259
to
+266
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a CUA sandbox is configured but the selected chat provider lacks image support, this lifts the resize cap before Useful? React with 👍 / 👎. |
||
| quality = ( | ||
| options.get("quality") if isinstance(options, dict) else None | ||
| ) | ||
|
|
@@ -275,6 +293,7 @@ async def process( | |
| output_dir=output_dir, | ||
| prepared=prepared, | ||
| quote_image_ref=quote_image_ref, | ||
| montage_max_size=montage_max_size, | ||
| ) | ||
| await _process_quote_message( | ||
| event, | ||
|
|
@@ -341,7 +360,26 @@ async def process( | |
| quality=quality, | ||
| output_dir=output_dir, | ||
| prepared=prepared, | ||
| montage_max_size=montage_max_size, | ||
| ) | ||
| if cua_pixel_mode: | ||
| oversized = [] | ||
| for path in {p for p in prepared.values() if p}: | ||
| try: | ||
| size = Path(path).stat().st_size | ||
| except OSError: | ||
| continue | ||
| if size > _CUA_IMAGE_WARN_BYTES: | ||
| oversized.append(size) | ||
| if oversized: | ||
| logger.warning( | ||
| "CUA session sends %d image(s) larger than %d MB " | ||
| "(largest %.1f MB) without resize; this may exceed " | ||
| "provider image upload limits.", | ||
| len(oversized), | ||
| _CUA_IMAGE_WARN_BYTES // 1048576, | ||
| max(oversized) / 1048576, | ||
| ) | ||
| # apply reset | ||
| if reset_coro: | ||
| await reset_coro | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.