Skip to content

id(event_store): Mirror::release/present_proof expire due waiting events in the pool but never delete their rows — pool and rows diverge in the committed transaction #2690

Closed

Description

@dezren39

id(event_store): Mirror::release / present_proof expire due waiting events in the pool but never delete their rows — pool and rows diverge in the committed transaction

Evidence (main c9f0108)

pkgs/id/src/event_store/waiting_rows.rs states the invariant the mirror exists to keep (module docs, lines 15–19):

"The pool and the rows change together through Mirror. Each call on a Mirror makes one change to the pool and the matching change to the rows, inside one write transaction. If the transaction commits, the two agree…"

Two Mirror methods break it:

  • Mirror::release (waiting_rows.rs:272–277) calls self.pool.arrived(*id, now) and then deletes only the released id's row and its dep index (delete + drop_dep).
  • Mirror::present_proof (waiting_rows.rs:284–292) does the same.

But WaitingPool::arrived (pkgs/id/src/waiting.rs:342–343) begins with self.expire_due(now_ms): every held event that has reached the age cap at now is removed from every pool index and pushed onto the pool's internal expired buffer. Those events are:

  • not in arrived's return value (it returns only released events),
  • not deleted from the waiting / waiting_by_dep rows by release/present_proof — row deletion for expired events happens only in Mirror::expire (waiting_rows.rs:195–201), which these methods never call.

So a transaction whose only waiting-pool work is a release (the common drain path in event_store/ingest.rs, e.g. ingest.rs:641, 660) can commit with the pool and the rows disagreeing:

  • in memory the due event is gone (waiting_len, is_waiting, rival checks in held_rivals all see it as absent),
  • on disk its row — including its waiting_by_dep entries — is still present.

Verified with a probe (verbatim waiting.rs, main c9f0108)

Laptop probe ~/git/fleet/probe-2026-10-30-laneA-waitmirror/ (crate copies pkgs/id/src/waiting.rs unchanged; WaitingPool<u32, &str>, default limits):

  1. insert(author, 1, [9], "X-due", 0) and insert(author, 2, [10], "Y-waiter", WEEK_MS - 1_000) (Y fresh, X due at the cap).
  2. Simulate exactly Mirror::release(dep=10)'s pool side at now = 604_800_000 (the 7-day cap): pool.arrived(10, WEEK_MS) returns ["Y-waiter"] only; afterwards pool.len() == 0 and pool.contains(&1) == false — X left the pool without being returned anywhere.
  3. Only a later pool.expire(WEEK_MS) surfaces X: [(author, "X-due")].

In the store that later surfacing is what deletes X's row, so the cleanup — and the expiry count returned by expire_waiting (ingest.rs:396–401) — is attributed to a later, unrelated call. If no later ingest/expire call happens before shutdown, the row survives on disk; on the next open, reload (event_store/mod.rs:980–1013) silently drops it as due, so the expiry is never reported at all. Either way the expiry is not lost, but it is unreported/misattributed and the documented pool↔rows agreement does not hold for the committing transaction.

Distinct from the pool in isolation: waiting.rs's caps/expiry/self-dep semantics were checked and found consistent in an earlier pass — this is specifically the Mirror layer's failure to flush the pool's expired buffer (rows + reporting) inside release/present_proof.

Why it matters

  • The mirror's pool↔rows agreement is the stated crash-consistency story for the waiting table; a silent exception in the hottest path (every release) makes the invariant un-auditable — the next divergence will be assumed impossible.
  • Expiry is the waiting pool's only drop path and is supposed to be logged/counted by the caller (waiting.rs module docs, step 3: "Call expire regularly and log what it returns"). Expiries swallowed into the buffer during a release are logged late, under a different call, or never (restart case).
  • The stale row keeps its waiting_by_dep entries, so drop_dep for a later-arriving dependency iterates and rewrites a row for an event the pool no longer holds.

Acceptance criteria

  • Mirror::release and Mirror::present_proof leave pool and rows in agreement when the transaction commits: due events expired inside pool.arrived have their rows deleted in the same transaction (or the methods flush/report the pool's expired buffer the way Mirror::expire does).
  • An expiry that happens during a release is reported through the same channel/count as an expiry from expire_waiting — not silently attributed to a later unrelated call, and not lost across a restart.
  • A regression test at the store level: hold two events, release a dependency at a time when the other event is due, then assert pool state, row state (e.g. via reopen/waiting_len after reload), and the expiry count agree immediately after the releasing call.
  • Existing waiting/event-store tests still pass.

Activity

  1. added
    kind/bug
    task/triage
    status/needs-triage
    source/creator
    priority/low
    queue/queued
    effort/s
    app/id
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (new-issue-creator-code-a)
    • Session / ID: cron new-issue-creator-code-a, run 2026-10-30 05:35 CDT
    • Found via: filed this run
    • Task: Triage the Mirror pool↔rows expiry divergence: release/present_proof expire due events pool-side via pool.arrived→expire_due but never delete their rows in the same transaction.
    • Expectation: effort/s — verdict on current main; if confirmed, pin whether release flushes the expired buffer (rows + reporting) and enqueue the small_fix.
    • Links: evidence body filed from hidden_files/issue-code-waitmirror-expiry-body.md; probe (verbatim waiting.rs, main c9f0108) on laptop ~/git/fleet/probe-2026-10-30-laneA-waitmirror/
  3. added
    work/assigned
    queue/claimed
    status/in-progress
    and removed
    status/needs-triage
    queue/queued
    on Oct 31, 2026
  4. 7 remaining items

  5. added
    work/assigned
    status/in-progress
    and removed
    queue/queued
    on Oct 31, 2026
  6. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  8. added
    queue/parked
    status/parked
    and removed
    status/in-progress
    queue/claimed
    on Oct 31, 2026
  9. added a commit that references this issue on Oct 31, 2026
  10. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (fixed + merged)

    • Agent: repo-worker-code (openchamber scheduled lane)
    • Task: 4100 (repo-health-code-pilot), scheduled lane run 2026-10-31 ~01:48Z
    • State: DONE — fix merged to main as PR id(event_store): release/present_proof flush expired-buffer rows in the same transaction (#2690) #2895 (merge commit a51aab2cd). Closing as completed.
    • Fix: Mirror::release and Mirror::present_proof expired due events pool-side via pool.arrived but left their rows for a later expire (or a restart) — pool and rows diverged in the committed transaction. Both now call the shared flush_expired (the same row deletion Mirror::expire performs) in the releasing transaction, so the releasing call is the one that effects and reports the expiry. present_proof flushes before the park, so a held proof that was itself due is re-held rather than deleted.
    • Acceptance: pool and rows agree immediately after the releasing call (asserted at mirror level and ingest level); expiry is counted by the releasing call (expire_waiting returns 0 after); regression tests test_a_mirror_release_flushes_the_events_it_expires + test_a_release_flushes_the_events_it_expires; existing waiting/event-store suites pass (99 + 34 locally; CI test shards 0–3 green).
    • Note: 8 CI legs are red on this PR but fail identically on clean main (pre-existing: toolchain fmt drift, web legs, test-unit, clippy) — unrelated to this change.
  11. removed
    status/parked
    queue/parked
    work/assigned
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/ideffort/skind/bugpriority/lowsource/creatortask/triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions