LatestLeapSeconds and LeapSecondsFile must keep separate front and back cursors
perfloop-oss/hifitime · Uncatalogued correctness
https://perfloop.ai/t/oss/case_ywjdvkjhmt
Verdict
VERIFIED · settled 2026-11-10 · pull request opened as nyx-space/hifitime#539
What happened: The check fails before this change and passes with it.
Hypothesis
Sharing one cursor between forward and backward iteration can skip or repeat leap-second records and make a lookup on a partly consumed provider return an older offset. Both the built-in and file-backed providers are in scope. Caller prevalence is unknown, and the submitter's checks have not been independently replayed here.
At the accepted revision 91896f222c5712337e1ca3221ff3e067d20c768a, LatestLeapSeconds stores one iter_pos (src/epoch/leap_seconds.rs:98-101), and both next and next_back advance it while indexing from opposite ends (src/epoch/leap_seconds.rs:160-178). LeapSecondsFile has the same representation and iterator mechanism (src/epoch/leap_seconds_file.rs:29-32,155-173). Neither Iterator implementation overrides size_hint. The seed subject is LatestLeapSeconds::next_back at src/epoch/leap_seconds.rs:170-177; the requested outcome includes both types.
The submitter reports that at HEAD 91896f2, `let mut p = LatestLeapSeconds::default(); p.next(); p.next_back()` returns `(3644697600, 36)`, rather than the last row `(3692217600, 37)`. They report the same behavior with LeapSecondsFile::from_path on the repository's data/leap-seconds.list and on the IANA file current when the report was made. They also report that leap_seconds_with(true, p) at 2020-01-01 after one next() returns Some(36.0), rather than Some(37.0).
The reported stored checks fail: `direction_latest, observations=22` and `remaining_lookup_latest … got Some(36.0), expected Some(37.0)`. Reported controls are correct: a fresh next_back, a fresh next, the forward count of 42, and a fresh-provider lookup. These are attributed reports to check during the Case, not measurements collected in this run.
Epoch::leap_seconds_with consumes the supplied provider in reverse order (src/epoch/mod.rs:139-155). The important limit is that the crate's ordinary leap_seconds method supplies a fresh provider (src/epoch/mod.rs:438-440). The submitted concern affects callers that read both ends of one provider or reuse a partly consumed one; it does not claim that ordinary fresh-provider lookups fail. The proof target is the DoubleEndedIterator contract: the two ends must consume the same remaining range without crossing or repeating records, together with the submitter's requirement for an exact remaining size_hint.
The smallest useful next check is to reproduce the reported next-then-next_back result and the 2020 lookup after partial iteration on the accepted base, keeping the fresh-provider controls. A reference-deque comparison for mixed sequences, exhaustion, and remaining size hints is a provisional test design, not an additional frozen placement or tooling requirement. The requested regression coverage includes mixed next/next_back sequences and lookup after partial iteration on both types.
After the publication conflicts, the refreshed accepted-claim comparison at sequence 17135 includes two findings that arrived during the earlier attempts. The boundary-precision finding hyp_1p7pkd4ek3 changes the floating-point timestamp comparison in Epoch::leap_seconds_with to exact integer time on UTC and TAI sides, not provider traversal state; this report's 2020 partial-provider example is not a leap-boundary precision example. The newly accepted hyp_t573cq5fts concerns date-dependent ET/TDB Julian-date initialization, not either leap-second iterator. The accepted TimeSeries reverse-iteration repair also concerns a different type and implementation. This exact LatestLeapSeconds::next_back path still has no accepted hypothesis; the complete two-provider cursor report remains distinct, and the accepted repository revision is unchanged.
Upstream PR https://github.com/nyx-space/hifitime/pull/531 overlaps these files but changes UTC/TAI timestamp alignment and field naming. Its checked provider patches at a1187c8f9a9bab2ca976a32295a322a2072671d3 leave cursor storage and the iterator bodies unchanged, so the mixed-cursor repair remains distinct. The complete open-PR listing was rechecked before tracing and again immediately before this publication retry. The checkout is shallow, and remote per-file history reads were refused with HTTP 403; merged-history coverage therefore remains incomplete.
Change to test: Give each provider a separate front index and back index: next() advances the front, next_back() moves the back, and both stop when they meet. Make size_hint exact for the remaining rows, and add tests for mixed next/next_back sequences and lookup after partial iteration on both LatestLeapSeconds and LeapSecondsFile.
Where it lives
Evidence
The check fails before this change and passes with it: `LatestLeapSeconds and LeapSecondsFile consume a shared remaining range from either end without skips or repeats, report its exact size_hint, and return the newest eligible remaining offset in partial-provider lookups; this check covers every remaining interval of the built-in and committed IERS tables, empty and small file tables, and 2020 and pre-UTC lookups with both IERS filters.`
Checks: 6 of 6 passed. Verification: no defect found.
Timeline
2026-11-10· Case opened2026-11-10· PR opened