Skip to content

id(range-sync): a zero-length upper bound encodes as +infinity — Some(vec![]) is the one bound length the sentinel swallows, and check_bounds approves it as finite #2607

Closed

Description

@dezren39

Problem

The range-sync wire format uses a bound's length byte as a sentinel: 0 means +infinity, anything else is the length of the key prefix that follows (module doc, pkgs/id/src/event_store/range.rs lines 19–24). That makes a zero-length bound unrepresentable — but nothing refuses one. An entry built with upper: Some(vec![]) encodes byte-for-byte identically to upper: None (+infinity), so the encoder silently changes what the entry says, and check_bounds — the documented pre-flight check a caller runs before Party::respond — approves the entry as a finite bound that does not end the flight.

Evidence (pkgs/id/src/event_store/range.rs, main f9268e2; file sha256 identical on the laptop clone at 819889b):

  • encode_entry (~line 411): Some(b) => { out.push(b.len() as u8); out.extend_from_slice(b); } — with b empty it pushes the 0 sentinel and no bytes, exactly the None arm's output.
  • Reader::entry (~line 510): let len = self.byte()? as usize; … let upper = if len == 0 { None } else { Some(…) } — the decoder can never produce Some(vec![]), so the value exists only on the constructing side, where it is silently rewritten.
  • check_bounds (~line 571): treats Some(bound) as a finite bound — it does not set its ended (+infinity) flag, and an empty bound sorts below every other bound, so [Some([]), Some([1]), None] passes.
  • Internal producers are safe today only by construction: Party::separator always returns at least one byte, and inbound entries come through decode_frame. Entry, frames, check_bounds and Party::respond are the public library surface of /id-range-sync/1, and respond clones the caller's upper bounds into its answer.

Verified this run (laptop probe, real crate)

Probe: ~/git/fleet/probe-2026-10-30-laneA-zerobound/ (id path dependency, default-features off; range.rs sha256 2e8a2255… matches sandbox main f9268e2):

  • Case 1: frames([Entry { upper: Some(vec![]), mode: Skip }]) succeeds (4 wire bytes); decode_frame returns the entry with upper = None; round-trip equality is false. check_bounds on the original entry: Ok.
  • Case 2: the flight [Some([]), Some([1]), None] passes the sender-side check_bounds; after encode/decode its uppers are [None, Some([1]), None], which the receiver-side check_bounds rejects ("an entry follows +infinity") — a flight the sender's own pre-flight check approved kills the session at the peer.
  • Case 3: frames([Some(vec![])]) is byte-identical to frames([None]).

Related but distinct: #2595 covers bounds over KEY_LEN (decoder rejection at 73–255, u8 wrap at ≥256). A fix that only refuses len > KEY_LEN does not catch the empty bound — the empty bound is the one length that collides with the format's own sentinel rather than exceeding its limit. This issue tracks that remaining case; the two fixes belong in the same functions (encode_entry/frames and check_bounds).

Why it matters

A bound that silently widens to +infinity changes the meaning of a flight: as the last entry it reconciles the whole remaining key space instead of an empty range; anywhere else it makes the peer reject the flight. Either way the failure surfaces at the wrong layer (a bounds error on the receiver, or a mysteriously widened range), never at the constructor that wrote an unrepresentable value. The module's own pattern is fail-closed at encode time (frame budgets, bound length in the decoder); the empty bound is the one input that slips through because its length is too small, not too large.

Acceptance criteria

  • frames() (or encode_entry) refuses an entry whose upper bound is Some with length 0, with an error naming the problem (a bound is a key prefix of 1..=KEY_LEN bytes, or None for +infinity).
  • check_bounds also refuses a zero-length bound, so the documented pre-flight check catches what respond() would otherwise clone into its answer and re-encode as +infinity.
  • Tests cover: Some(vec![]) refused at encode and by check_bounds; a 1-byte bound still round-trips; None still encodes as the sentinel.
  • Existing range.rs tests stay green.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/lowNice to have; do when convenient
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/xsTrivial: expected under 30 minutes of work
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  4. 33 remaining items

  5. added
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 2, 2026
  6. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: parked
    task: 5392 (repo-health-code-pilot, lane A worker shift)
    state: parked until 2026-11-02T07:27:07Z — CI pending on PR #4222
    progress: fresh revalidation 2026-11-02T07:36Z — PR #4222 OPEN @ 153c5a4; Codex review completed with zero findings; diff is exactly the scoped change (pkgs/id/src/event_store/range.rs, +45/-17). basic + native arm64 checks still QUEUED (runner delay, not failures). The targeted cargo test result from the prior lane never reported, so test verification remains outstanding.
    resume: when PR #4222 checks complete green and targeted tests are verified, merge, close #2607, complete task 5392 as fixed_merged.

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: picked_up
    task: 5392 (repo-health-code-pilot, lane E worker shift)
    state: claimed; resuming PR #4222 from awaiting_ci — CI run 41398870212 still QUEUED since 2026-11-02T06:16Z (runner stall, not a failure); running the targeted test on the laptop to complete verification
    resume: merge PR #4222 once targeted tests verified (Codex on head 153c5a4 already completed with zero findings; diff scoped to pkgs/id/src/event_store/range.rs)

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: done
    task: 5392 (repo-health-code-pilot, lane E worker shift)
    state: done — fixed_merged. PR #4222 MERGED (squash ddd0d42); #2607 closed.
    evidence: laptop cargo test (pkgs/id) range::tests — 20 passed, 0 failed, including test_empty_bounds_are_refused_but_one_byte_and_infinity_round_trip; Codex review on head 153c5a4 completed with zero findings; diff scoped to pkgs/id/src/event_store/range.rs only.
    ci note: PR check run 41398870212 was still QUEUED since 2026-11-02T06:16Z at merge time (runner stall, not a failure) — merged under standing merge authority with local test verification; main-tier CI on main will exercise the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions