Skip to content

id(world): restore's checkpoint consecutiveness check uses plain + 1 — a penultimate u64::MAX sequence panics in debug/test builds and wraps to an accepted MAX → 0 step in release #3736

Closed

Description

@dezren39

Problem

In pkgs/id, WorldCore::restore validates a journal checkpoint's events with a plain + 1 — the one sequence-consecutiveness check in the file that does not use the checked/saturating arithmetic every sibling check uses — so a checkpoint whose penultimate event carries sequence u64::MAX behaves differently in each build profile, and neither behaviour is the intended rejection:

  • Debug / test builds (overflow checks on — pkgs/id/Cargo.toml's [profile.dev]/[profile.test] set no overflow-checks override, so the default applies): the check panics with "attempt to add with overflow" instead of returning restore's journal checkpoint events are out of order error.
  • Release builds (overflow checks off): u64::MAX + 1 wraps to 0, so a checkpoint whose events run […, u64::MAX, 0] passes the consecutiveness gate as if MAX → 0 were a valid step (the trailing check events.last().sequence == sequence then anchors the checkpoint at sequence 0).

Evidence (verified this run, main 51dee687)

  • pkgs/id/src/world/core.rs:380-384 (the JournalEntry::Checkpoint arm of restore, core.rs:138; reached from journal load at world_store.rs:380):

    ensure!(
        events.last().is_none_or(|last| last.sequence == sequence)
            && events
                .windows(2)
                .all(|pair| pair[1].sequence == pair[0].sequence + 1),
        "journal checkpoint events are out of order"
    );
  • WorldEvent.sequence is u64 (pkgs/id/src/world/mod.rs:319).

  • Every sibling sequence check in the same file uses saturating or checked arithmetic: core.rs:335 and core.rs:1038 use saturating_add(1) for the same "next sequence" comparison; core.rs:220, :885, :1027, :1148 use checked_add(1). Line 383's plain + 1 is the lone exception.

  • Laptop probe (verbatim predicate, source md5 607e68c2 in both copies; ~/git/fleet/probe-2026-11-01-laneA-ckptseq/ on the laptop):

    • rustc -C overflow-checks=on: [1,2,3] → true, [1,3] → false, [MAX-1,MAX] → true, and the [MAX,0] case panics — attempt to add with overflow, exit 101.
    • rustc -O -C overflow-checks=off: [MAX,0] → true (wrap accepted as consecutive), [MAX,5] → false.

Why it matters

restore is the integrity gate for a world's journal on load: its ensure! checks are what stand between a damaged or crafted journal file and the world state rebuilt from it. A gate that panics in one profile and silently accepts a wrapped sequence in another is neither — the panic turns a corrupt-checkpoint error into a crash of the loading process, and the wrap-accept lets a checkpoint claim a sequence chain no writer can produce (writers advance via the saturating/checked paths). The fix is also the file's own established convention, so this is a consistency defect, not a design question.

Acceptance criteria

  • The checkpoint consecutiveness check uses checked arithmetic (e.g. pair[0].sequence.checked_add(1) == Some(pair[1].sequence), or the file's saturating_add(1) convention — either makes MAX → anything non-consecutive): a checkpoint with a penultimate u64::MAX sequence is rejected with the existing "journal checkpoint events are out of order" error in both debug and release profiles, with no panic.
  • A regression test restores a checkpoint whose events are […, u64::MAX, 0] (checkpoint sequence 0) and asserts the out-of-order error; ordinary consecutive checkpoints (including [MAX-1, MAX] as the final pair) still restore.
  • No other restore validation changes behaviour; existing world / world_store restore tests pass.

Distinct from #2396 (CLI --seconds/--timeout-secs added to an Instant — different site, different input path).

Activity

  1. developing-today commented on Nov 1, 2026

    @developing-today
    Contributor
  2. added
    queue/queuedHas a queued task in the Supabase agent queue
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    effort/sSmall: expected under 2 hours of work
    on Nov 1, 2026
  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator-code-a
    • Session / ID: new-issue-creator-code-a cron run 2026-11-01 08:35 CST
    • Found via: filed this run
    • Task: Filed this issue: restore's checkpoint consecutiveness check (world/core.rs:383) uses plain + 1 where every sibling sequence check uses saturating/checked arithmetic — a penultimate u64::MAX sequence panics in debug/test builds and wraps to an accepted MAX → 0 step in release.
    • Expectation: effort/s; done when the check uses checked arithmetic, a [.., u64::MAX, 0] checkpoint is rejected with the out-of-order error in both profiles, and a regression test covers it.
    • Links: laptop probe ~/git/fleet/probe-2026-11-01-laneA-ckptseq/ (verbatim predicate, rustc overflow-checks on/off; source md5 607e68c2 identical in both copies @ 51dee68)
  4. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · adopted as Phase 2 of design #4000

  5. 50 remaining items

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

    @dezren39
    MemberAuthor

    agent-note:v1
    event: parked
    task: 6202 (repo-health-code-pilot, repo-worker-code; OpenChamber scheduled lane ec118cad-0fd3-4652-91c4-27432f2f2efd)
    state: parked for 30 minutes
    blocker: PR #4498 remains OPEN and Drew-authored; this lane did not modify, test by editing, or merge it. Current rollup has no affected pkgs/id check (only unrelated basic guard success; CodeRabbit neutral/skipped).
    resume: Revalidate issue/PR ownership and checks. Resume only after explicit reassignment / PR no longer Drew-owned, or an independent unowned verification path exists; then obtain targeted pkgs/id test evidence and required PR-tier coverage.
    links: issue #3736 · PR #4498 · branch queue/6202-3736-checked-restore at 4b2a1b7

  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

    • Agent: queue worker (repo-worker-code)
    • Session / ID: task 6202 · OpenChamber lane 262eb403-3347-4a7c-ba6b-e7bc263ca853
    • Found via: queue claim, resumed from awaiting CI
    • Task: No changes to PR fix(id): reject wrapped checkpoint sequences #4498; it is the matching fix but is Drew-authored.
    • Expectation: effort/s — resume only after explicit ownership reassignment or an authorized independent verification route; current checks lack an affected pkgs/id test and the PR-tier coverage has a gap.
    • Links: PR fix(id): reject wrapped checkpoint sequences #4498 · branch/worktree queue/6202-3736-checked-restore / /home/user/git/fleet/6202
  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  10. 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
  11. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  12. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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/sSmall: expected under 2 hours 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 jobsource/design-architectFiled by the repo design architect 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