Skip to content

fix: clean up invalid materialized images - #10090

Open
kilisamemarisaaa wants to merge 1 commit into
AstrBotDevs:masterfrom
kilisamemarisaaa:codex/fix-image-materialization-cleanup
Open

kilisamemarisaaa wants to merge 1 commit into
AstrBotDevs:masterfrom
kilisamemarisaaa:codex/fix-image-materialization-cleanup

Conversation

@kilisamemarisaaa

@kilisamemarisaaa kilisamemarisaaa commented Sep 15, 2026

Copy link
Copy Markdown

Root cause

PreProcessStage detached every resolved image path from event cleanup. When a data URI or remote reference materialized invalid bytes, the path was treated as a durable attachment even though image processing had failed, leaving a media_image_* file behind.

Reproduction

On Windows with Python 3.12, passing an invalid data:image/png;base64 reference through PreProcessStage and then running event cleanup left the materialized file on disk. The regression occurred for both ordinary and Reply-chain images.

Fix

  • Track newly materialized image files before validation.
  • Validate only newly materialized files with the existing MIME detector.
  • Keep invalid materialized files owned by the event so normal cleanup removes them.
  • Preserve existing local/file URI behavior and valid PNG, GIF, JPEG, WebP, and BMP paths.
  • Share ownership logic between ordinary and Reply-chain images.

Verification

  • uv run pytest -q: 2968 passed, 1 skipped
  • uv run pytest -q tests/test_preprocess_stage.py tests/test_media_utils.py tests/test_mattermost_adapter.py: 89 passed
  • uv run ruff check .: passed
  • uv run ruff format --check .: 505 files already formatted
  • Added regression coverage for invalid materialized images in ordinary and Reply-chain messages.

Related: #10042

@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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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