Skip to content

fix(id): PresenceTable capacity eviction defeats the replay watermark — future-stamped heartbeat can be replayed back to life past receipt-based expiry #9579

Closed

Description

@dezren39

Finding

PR #4160's PresenceTable capacity eviction selects its victim by effective stamp only. That defeats the replay watermark the table's own pruning path maintains: a future-stamped heartbeat that is evicted once its effective stamp ages past the TTL — while its sender stamp still passes the freshness bound — can be replayed and re-inserted with a later effective stamp, resurrecting the node past its receipt-based expiry. prune_at was explicitly written not to do this (#8865); the eviction path added by #4160 was not given the same guard.

Worked timeline (current main, pkgs/id/crates/id-cli/src/chat_presence.rs; PRESENCE_TTL_SECS = 75 at :110, MAX_FUTURE_SKEW_SECS = 10 at :124):

  1. At receipt time T, a heartbeat stamped T+10 (inside the skew allowance) is accepted; its effective stamp is clamped to T (:395).
  2. At T+76, the entry is expired by effective stamp (76 > 75), so at capacity it is the eviction candidate (:406-424, filter at :409). Its sender stamp is only 66s old, so prune_at would have retained it as a replay watermark (:556-571, retain rule at :569).
  3. The evicted entry is gone, so a replay of the same heartbeat at T+76 passes the freshness bound (:356: age 66 ≤ 75), finds no existing entry to pin the effective stamp (:396-400 applies only when an entry exists), and is re-inserted with effective stamp min(T+10, T+76) = T+10.
  4. The node now reads Live until T+85 — 10s (one full skew allowance) past the documented bound: "no claim can outlive effective_ts + PRESENCE_TTL_SECS — at most one TTL from receipt — no matter when copies of it arrive" (:335-337).

Evidence

Why it matters

The effective-stamp machinery (#8865) exists precisely so replayed gossip cannot extend a node's claimed liveness past one TTL from receipt. The capacity bound (#4004) exists for the adversarial case — a flood of minted keys filling the table. Combined, an attacker who can fill the table can force eviction of a future-stamped victim and then replay that victim's captured heartbeat to keep it "live" past its receipt-based expiry, in skew-sized increments of table churn. Narrow (≤10s per cycle, needs a full table), but it silently breaks a stated invariant in exactly the adversarial conditions both mechanisms were built for.

Acceptance criteria

  • Capacity eviction never removes an entry whose sender stamp still passes the freshness bound (the prune_at watermark rule), OR a replayed heartbeat can never gain a later effective stamp than its first acceptance earned — one of the two, with the invariant at :335-337 holding under both prune and eviction.
  • A regression test mirrors the timeline above: fill the table, insert a future-stamped (within skew) heartbeat, advance past effective-stamp expiry but not sender-stamp expiry, force a capacity admission, replay the heartbeat, and assert the node does not read Live past its original effective_ts + PRESENCE_TTL_SECS.
  • Existing presence tests still pass, including node_count_bound_* and the id(chat-presence): separate future clock skew from the presence TTL #8865 replay/skew tests.

Filed by pr-diff-review-b (Lane B PR diff review, run 2026-11-13 09:18 CST) from review of PR #4160.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    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)
    on Nov 13, 2026
  2. developing-today commented on Nov 13, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    Agent: pr-diff-review-b
    State: filed
    Repo: developing-today/code
    Source PR: #4160 (#4160, merged ccdfacd)
    Finding: PresenceTable capacity eviction (chat_presence.rs:406-424 on main) picks its victim by effective_ts only, so a future-stamped heartbeat evicted after effective expiry — while its sender stamp still passes freshness — can be replayed and re-inserted with a later effective stamp, living until original effective+85s instead of +75s, breaking the :335-337 invariant; prune_at (:556-571) explicitly retains such entries as replay watermarks (#8865), eviction does not.
    Verified against main: ef16105 (contents reads of chat_presence.rs; PR merge confirmed ancestor, compare behind=0)
    Evidence: hidden_files/pr-review-b-2026-11-13-0918/issue-presence-eviction-body.md + diff-4160.patch

  4. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up + triaged inline — Agent: queue worker (repo-worker-code), lane code-a — task 16122 (triage) for issue #9579.

    Fresh revalidation (2026-11-13T16:28Z): issue #9579 OPEN, no held / user/owned / do-not-merge / do-not-auto-edit labels; PR #4160 MERGED (merge ccdfacd) and ancestor of main per the packet evidence. No competing PR found in the packet or issue state.

    Triage (inline, per the lane runbook): work kind small-fix (task/small-fix replaces task/triage) — the defect is one guarded branch in the update_at eviction path in pkgs/id/crates/id-cli/src/chat_presence.rs, plus one regression test. Priority low stands (narrow window: ≤10s per cycle, needs a full 1,000-entry table plus a replay inside the skew window — but it breaks a stated #8865 invariant under the adversarial flood conditions #4004's bound addresses). Effort s stands. kind/bug already present.

    First concrete step: mirror prune_at's watermark rule in the capacity-eviction victim filter — never evict an entry whose sender stamp still passes the freshness bound at the eviction instant; fall back to the existing expired-by-effective-stamp victim only among watermark-safe entries, and if none qualifies, keep the current no-eviction behavior for that admission.

    Acceptance check: the issue's regression timeline as a test (full table + future-stamped heartbeat + advance past effective-but-not-sender expiry + capacity admission + replay → node does not read Live past original effective_ts + PRESENCE_TTL_SECS), and all existing chat_presence tests pass, including node_count_bound_* and the #8865 replay/skew tests.

    Continuing to the fix in this same claim.

  5. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 13, 2026
  6. added a commit that references this issue on Nov 13, 2026
  7. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — Agent: queue worker (repo-worker-code), lane code-a — task 16122 (triage → small-fix, fixed in the same claim) for issue #9579.

    PR #9584 MERGED at 2026-11-13T16:36:20Z, merge commit 6d6d7e8; issue #9579 CLOSED by the merge; fix commit 2c0b332 verified as an ancestor of origin/main.

    What changed (pkgs/id/crates/id-cli/src/chat_presence.rs only): the capacity-eviction victim filter now requires the sender stamp to also be past PRESENCE_TTL_SECS — exactly the prune_at replay-watermark rule (#8865) — so an entry whose sender stamp still passes the freshness bound is never evicted, and a capacity admission with no watermark-safe victim is refused. Doc comments at the bound bullet and the eviction site state the rule.

    Tests (laptop, fleet-build-lock): new regression node_count_bound_never_evicts_a_watermark_live_entry_9579 mirrors the issue timeline and passes (it discriminates: on the old filter the admission evicts the victim and the replay reads Live one skew allowance past the receipt-based bound); chat_presence 27/27; full id-cli crate 671 + 7 + 7 passed, 0 failed; cargo fmt --check clean. Codex review on PR #9584 failed to run (Codex usage limits, fleet-wide) and produced no findings; CodeRabbit completed NEUTRAL with no findings.

  8. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done) — Agent: queue worker (repo-worker-code), lane code-a — task 16137 (small_fix follow-on of triage task 16122) for issue #9579.

    This follow-on packet was created at task 16122's completion, but the fix had already landed inside that same claim: PR #9584 MERGED 2026-11-13T16:36:20Z (merge commit 6d6d7e8) and issue #9579 is CLOSED. Fresh verification this claim: issue state CLOSED; fix commit 2c0b332 is an ancestor of origin/main; the regression test node_count_bound_never_evicts_a_watermark_live_entry_9579 is present in chat_presence.rs on origin/main. No duplicate work performed.

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

Metadata

Metadata

Assignees

No one assigned

    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/pr-diff-reviewFiled by the pr-diff-review jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions