Repository navigation
fix(id): separate future clock skew from the presence TTL (#8865) - #8881
Conversation
Presence accepted a heartbeat stamped up to a full PRESENCE_TTL_SECS (75s) in the future and computed liveness, typing, roster, and pruning from that sender stamp, so a future-dated heartbeat stayed live for up to ~150s after receipt and roster last_seen could be future-dated. - Add MAX_FUTURE_SKEW_SECS = 10, documented separately from the TTL: heartbeats stamped further ahead are refused in update_at. - Expiry now runs from an effective stamp, min(sender ts, local receipt): an accepted future-dated heartbeat lives at most one TTL from receipt, a past-stamped one keeps its sender stamp so replay cannot extend it, and a redelivered future heartbeat keeps its earliest effective stamp. - Roster last_seen reports the effective stamp, never a future time. Tests: boundary at the skew allowance (expiry from receipt, typing and prune on the same basis), just beyond it (refused, including the old receipt+75 stamp), and redelivery keeping the first effective stamp. cargo test -p id --lib chat_presence: 22 passed.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 23 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fc5c55768
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| let before = entries.len(); | ||
| entries.retain(|_, entry| now.saturating_sub(entry.heartbeat.ts) <= PRESENCE_TTL_SECS); | ||
| entries.retain(|_, entry| now.saturating_sub(entry.effective_ts) <= PRESENCE_TTL_SECS); |
There was a problem hiding this comment.
Retain replay protection until the sender stamp expires
For an accepted future-dated heartbeat, pruning now deletes its replay protection while its sender stamp still passes the freshness check. For example, a heartbeat stamped 1010 and received at 1000 is pruned at 1076; replaying it at 1076 then inserts it with effective_ts = 1010, resurrecting the departed node through 1085 instead of preserving the receipt-based expiry at 1075. The periodic cleanup in commands/serve.rs calls this method, so this can occur during normal operation. Retain the entry or a replay watermark until the sender stamp itself exceeds the freshness bound, while continuing to calculate liveness from the effective stamp.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d7619c5 — thank you, this was a real hole in the first version.
Disposition: prune_at no longer prunes on the effective (receipt-clamped) stamp. An entry is now retained as a replay watermark until its sender stamp ages past PRESENCE_TTL_SECS — exactly the retention option the finding suggests — while liveness and typing continue to expire on the effective stamp. A replay inside that window is an equal-stamp tie that keeps the first effective stamp, so it cannot resurrect the node; once the watermark is pruned, the same replay fails the freshness bound.
New regression test replay_after_receipt_expiry_does_not_resurrect_a_future_dated_heartbeat covers the finding's exact scenario (stamp 1010 received at 1000, replay at 1076: still Offline, last_seen stays 1000; watermark pruned at 1086 and the replay then refused). cargo test -p id --lib chat_presence: 23 passed.
…r stamp expires (#8865) Codex P2 on PR #8881: pruning on the effective (receipt-clamped) stamp deleted replay protection while a future-dated sender stamp still passed the freshness bound, so a replay could resurrect the node past its receipt-based expiry. prune_at now retains an entry until its sender stamp ages past PRESENCE_TTL_SECS, while liveness/typing keep expiring on the effective stamp. New regression test covers replay-after-expiry, watermark retention, and freshness refusal after the watermark is pruned.
Fixes #8865. Queue task 15092 (repo-health-code-pilot, lane code-d).
Problem
Presence accepted a heartbeat stamped up to a full
PRESENCE_TTL_SECS(75s) into the future and computed liveness, typing, roster, and pruning from that sender stamp: receipt at now=1000 with ts=1075 stayed live through now=1150 (~150s after receipt), and rosterlast_seencould be future-dated.Change (
pkgs/id/src/chat_presence.rsonly)MAX_FUTURE_SKEW_SECS = 10, documented separately fromPRESENCE_TTL_SECS:update_atnow refuses a heartbeat stamped more than 10s ahead of the receiver's clock (the old bound was the full TTL). 10s is generous for NTP-disciplined clocks and well under one heartbeat interval.min(sender ts, local receipt time). Liveness, typing, roster, live-nodes, and pruning all compute age from the effective stamp, so an accepted future-dated heartbeat lives at most one TTL from receipt. A past-stamped heartbeat keeps its sender stamp as its basis, so re-delivery still cannot extend its life; a redelivered future heartbeat keeps the earliest effective stamp it earned.last_seenreports the effective stamp, so it is never future-dated.tsstill orders entries; stale and far-future stamps are refused).Tests
New boundary tests (oracle: expiry measured from receipt):
last_seen == receipt; prune on the same basis.cargo test -p id --lib chat_presence(frompkgs/id): 22 passed, including all pre-existing presence tests (u64::MAX rejection, out-of-order/replay, duplicate-delivery expiry). The changed file is rustfmt-clean.Note: a full
cargo test -p idbuild currently fails to compile the unrelated integration testtests/probe_attestation_sign.rs(callssign_claimwith 5 args; the function incrates/id-eventstakes 6) — that error is in files this PR does not touch and exists at the base commit; the lib itself compiles and its tests pass.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.