Skip to content

perf: reduce image memory overhead across lifecycle - #10117

Open
w31r4 wants to merge 5 commits into
masterfrom
perf/image-memory-lifecycle
Open

w31r4 wants to merge 5 commits into
masterfrom
perf/image-memory-lifecycle

Conversation

@w31r4

@w31r4 w31r4 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Problem

Image handling had a second byte-budget path beside the latest master model-image pipeline. Historical images could be materialized as their full stored bytes, while legacy inline image URLs could bypass request-level preparation. The duplicated policies increased transient memory use and made provider behavior inconsistent.

Change

  • Reuse the mainline model-image pipeline for provider inputs: reject known inputs larger than 64 MiB before decoding and keep each prepared image strictly below 512 KiB.
  • Continue honoring the existing provider_settings.image_compress_options.max_size setting.
  • Store new local-agent conversation images as content-addressed durable references and materialize only images selected for the active request.
  • Prepare legacy inline image URLs request-locally when they are selected, without rewriting persisted history.
  • Route OpenAI, OpenAI Responses, Anthropic, Gemini, Coze, Dify, and DeerFlow model-image paths through the same preparation policy.
  • Keep Satori outbound image serialization byte-preserving instead of applying model-input compression to platform messages.
  • Retain the mainline GIF, animated WebP, and APNG montage handling, transparency preservation, original-file ownership, and cleanup behavior.
  • Remove the duplicate image_budget implementation and the old per-context encoded-byte options. No new runtime dependency or streaming transport is added.

Compatibility

  • Existing durable image references remain readable.
  • Existing inline history remains readable and is not rewritten during normal requests.
  • The existing max_size configuration remains the only image preparation setting used by this change.
  • Invalid or unavailable historical media becomes a bounded placeholder; resource-exhaustion and oversized-input errors remain visible to the caller.

Validation

  • Focused regression suite: 790 passed.
  • Final image and lifecycle subset after cleanup: 241 passed.
  • uv run ruff format .
  • uv run ruff check .
  • git diff --check

The tests were run in the WSL checkout. Native Windows and macOS runs are left to CI or the maintainer test environment.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @w31r4, your pull request is larger than the review limit of 150,000 diff characters

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 17, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
astrbot-docs b20759f Commit Preview URL

Branch Preview URL
Sep 19 2026, 11:33 AM

@w31r4
w31r4 force-pushed the perf/image-memory-lifecycle branch from 533d64e to 843f171 Compare September 17, 2026 11:13
@w31r4
w31r4 force-pushed the perf/image-memory-lifecycle branch from 843f171 to b20759f Compare September 19, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant