fix: pick deterministic conversion strategy for union receivers - #12283
fix: pick deterministic conversion strategy for union receivers#12283Diwak4r wants to merge 3 commits into
Conversation
|
@Diwak4r is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
|
|
Hi @Diwak4r, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
Related Issues
Proposed Changes:
_get_conversion_strategyresolves the strategy for aUnionreceiver by collecting the strategies of every member into a set and, when neitherWRAPnorUNWRAPis among them, falling back tostrategies.pop(). Because enum members hash by identity,set.pop()is non-deterministic across processes (ASLR): the same sender/receiver pair could resolve to different conversion strategies on different runs.Example: converting a
ChatMessagetostr | list[str]could resolve to eitherCHAT_MESSAGE_TO_STRorWRAP_CHAT_MESSAGE_TO_STRdepending on the process.This PR replaces the
set.pop()with a deterministic scan of the receiver's union members in declaration order, returning the strategy of the first member that yields one. The chosen strategy now honors the order in which the user declared the union members.How did you test it?
Added regression assertions to
test_types_are_compatible_with_conversion:ChatMessage->str | list[str]resolves toCHAT_MESSAGE_TO_STRChatMessage->list[str] | strresolves toWRAP_CHAT_MESSAGE_TO_STRUnder the previous code, the first assertion would flip between the two strategies at random across processes; both now always pass.
Ran the full
test_type_utils.pyandtest_recursive_splitter.pysuites: 1122 tests pass.Notes for the reviewer
The existing WRAP/UNWRAP preference loop is unchanged; only the fallback selection is now deterministic.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.