Skip to content

[Bugfix][Wheel] Preserve PIL image state in structured transfer - #3412

Open
zxpdemonio wants to merge 1 commit into
kvcache-ai:mainfrom
openanolis:cruz/fix-pil-codec
Open

zxpdemonio wants to merge 1 commit into
kvcache-ai:mainfrom
openanolis:cruz/fix-pil-codec

Conversation

@zxpdemonio

@zxpdemonio zxpdemonio commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The structured media codec previously serialized a PIL image as raw pixels only. GET could reconstruct the pixels, but it lost image state such as the original format, palette, EXIF, ICC profile, and other entries from Image.info. Encoded PNG and JPEG byte payloads also need to remain byte-exact rather than being decoded and re-encoded.

This PR adds a framed binary representation for PIL entries in structured non-tensor fields. It stores raw pixels and validated msgpack state as payload members, while the existing offsets continue to provide row-level partial reads. PNG/JPEG byte entries remain unchanged and byte-exact. The decoder restores the PIL mode, size, format, palette, and supported Image.info state, and preserves the existing raw-byte fallback when Pillow is unavailable.

The implementation keeps image state out of the bundle manifest/catalog, reuses the existing structured codec and chunk planning paths, and retains BufferPool owners for zero-copy-compatible decoded images until release_result() is called.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

python3.12 -m pytest -q mooncake-wheel/tests/test_structured_object_store.py
python3.12 -m py_compile mooncake-wheel/mooncake/structured_object_store.py mooncake-wheel/tests/test_structured_object_store.py
git diff --check origin/main...HEAD

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Result: 99 passed, 29 skipped. The skipped tests require a working Torch/CUDA runtime; the test host has a pre-existing Torch/CUDA shared-library mismatch. Manual coverage included PNG/JPEG encoded-byte preservation, common PIL modes, palette images, EXIF/ICC state, partial row reads, malformed state rejection, missing-Pillow fallback, and BufferPool owner release.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

Python formatting was intentionally not run to avoid unrelated formatting churn in the existing Python files. py_compile and git diff --check pass.

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

Codex was used to inspect the existing structured codec, implement the focused fix, review failure and lifecycle paths, and run the validation matrix. The submitter reviewed the final diff and test results.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant