Repository navigation
Conversation
`semcode lore -b nvme_tcp_queue --limit 0` aborts with "user-provided comparison function does not correctly implement a total order". Any result set that mixes Date headers that parse with ones that do not can trigger this panic. `sort_emails_by_date()` compares parsed dates when both Date headers parse and raw strings otherwise, which is not transitive. With A = "Tue, 01 Jan 2030 00:00:00 +0000", B = "U-not-a-date" and C = "Wed, 01 Jan 2020 00:00:00 +0000", it says A < B and B < C by string but C < A by date. Rust's sort panics when it detects such a comparator. Sort on a key instead: emails whose date parses come first in time order, the rest follow by raw header, and ties break on the raw header and then on `message_id`. Same-second emails now come out in the same order on every run, whatever order the query returned them in. The function's signature and its five callers are unchanged. The key is computed once per email, so each Date header is parsed once rather than on every comparison. The newest-first sort in `dig` was already a total order; its same-instant ties now break on `message_id` too. Both new tests fail on the old comparator. One sorts the A/B/C triple from all six input orders. The other sorts 2,000 emails, a third of them with unparseable dates and most sharing a timestamp, from two fixed permutations, and checks the order and that both permutations give the same result.
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.
semcode lore -b nvme_tcp_queue --limit 0aborts with "user-provided comparison function does not correctly implement a total order". Any result set that mixes Date headers that parse with ones that do not can trigger this panic.sort_emails_by_date()compares parsed dates when both Date headers parse and raw strings otherwise, which is not transitive. With A = "Tue, 01 Jan 2030 00:00:00 +0000", B = "U-not-a-date" and C = "Wed, 01 Jan 2020 00:00:00 +0000", it says A < B and B < C by string but C < A by date. Rust's sort panics when it detects such a comparator.Sort on a key instead: emails whose date parses come first in time order, the rest follow by raw header, and ties break on the raw header and then on
message_id. Same-second emails now come out in the same order on every run, whatever order the query returned them in. The function's signature and its five callers are unchanged. The key is computed once per email, so each Date header is parsed once rather than on every comparison.The newest-first sort in
digwas already a total order; its same-instant ties now break onmessage_idtoo.Both new tests fail on the old comparator. One sorts the A/B/C triple from all six input orders. The other sorts 2,000 emails, a third of them with unparseable dates and most sharing a timestamp, from two fixed permutations, and checks the order and that both permutations give the same result.