fix(memory): restore MemoryMimeType enum on load instead of degrading to str - #8294
Open
JingHao-Leon wants to merge 1 commit into
Open
JingHao-Leon wants to merge 1 commit into
JingHao-Leon wants to merge 1 commit into
Conversation
… to str MemoryContent serializes mime_type to its string value but had no inverse step, so a dump_component/load_component roundtrip degraded a MemoryMimeType into a plain str. Any dispatch on mime_type == MemoryMimeType.X (user code and autogen_ext memory implementations filtering by MIME type) silently changed behavior after a save/load. Add a before-mode field_validator that coerces known MIME strings back to their enum members, keeping unrecognized custom strings unchanged, and cover both the roundtrip and the pass-through in tests. Fixes microsoft#8293
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MemoryContentserializesmime_typeto its string value (field_serializer) but had no inverse step, so adump_component()/load_component()roundtrip (e.g. saving and restoring aListMemory) degraded aMemoryMimeTypeinto a plainstr. Any dispatch onmime_type == MemoryMimeType.X— user code andautogen_extmemory implementations that filter by MIME type — silently changed behavior after a save/load.Changes
MemoryContent: add a before-modefield_validatorthat coerces known MIME strings back to theirMemoryMimeTypemembers; unrecognized custom strings pass through unchanged (preserving theMemoryMimeType | strcontract)is MemoryMimeType.MARKDOWN); custom unrecognized strings keep passing throughRelated issue
Fixes #8293
Verification
Same class of roundtrip type-degeneration as #8283 / PR #8292 (FunctionTool
strict); this one needed the inverse direction — a validator on the way in rather than persisting the field.