fix(tasks): correct enum variant ordering for deserialization #634
+21
−18
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.
Move CustomRequest and CustomResult to end of their respective untagged enums to ensure specific task variants match before catch-all custom types. Add deny_unknown_fields to GetTaskInfoResult to prevent matching arbitrary JSON objects.
Fixes issue where tasks/get, tasks/list, tasks/result, and tasks/cancel incorrectly deserialized as CustomRequest instead of their typed variants.
Motivation and Context
Fixes deserialization bug where task-related requests (tasks/get, tasks/list, tasks/result, tasks/cancel) were incorrectly matching CustomRequest instead of their specific typed variants. This occurred because serde tries untagged enum variants in order, and CustomRequest accepted any method string.
The bug prevented proper routing of task requests in gateways and servers that deserialize into ClientRequest/ServerResult enums.
How Has This Been Tested?
Breaking Changes
None. This is a bug fix that corrects deserialization behavior without changing the public API.
Types of changes
Checklist
Additional context
The fix involves two changes:
This ensures serde's untagged enum deserialization tries specific variants before falling back to custom types.