Skip to content

fix(node,cache,dht): close the six #1806 review follow-ups - #1813

Merged
thiras merged 5 commits into
mainfrom
fix/1807-1812-review-followups
Aug 25, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/1807-1812-review-followups

Conversation

@thiras

@thiras thiras commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Six follow-ups from the review of #1806 (issue #1561), plus two rounds of review fixes. All six share one shape: a degradation path that repairs itself eventually but moves no metric, and in three cases silently shrinks what the node advertises.

#1807 — a faulted origin probe no longer drops the hash

rescan_origins resolved candidates through origin_size, whose per-origin error handling is swallow-and-advance — so a transport fault arrived as Ok(None), indistinguishable from an origin that genuinely does not hold the object. The issue's suggested Err arm does not exist: origin_size's only Err is NoOrigin. The rescan now walks the chain through a fault-aware primitive extracted from origin_probe_presence, bypassing its memo so a large enumeration cannot evict the live serve path's warm entries.

  • Only a retry-eligible fault carries an entry forward. A permanent one — a revoked ACL, a symlink escape — reads the same on every rescan, so carrying it would advertise content the serve path refuses until an operator intervened.
  • The index and its unresolved counts are one ArcSwap payload, published and read together. origin_held_hashes is deleted: a caller that can take the set without the counts is how the pairing gets lost, and the periodic rescan seed was doing exactly that.
  • Rescans are serialized. Carry-forward makes a rescan a read-modify-write spanning the whole walk, and both triggers spawn detached, so overlapping passes let the slower one publish a payload derived from a pre-empted index. A walk gets slower exactly when the origin is faulting, which is when a second pass is most likely to start on top of it.
  • Rescan probes get their own ceiling rather than cache.origin_probe_timeout_ms, which exists to stop a slow origin stalling the probe serve path. Borrowing it turns a merely slow origin into an all-fault rescan — and on a cold boot, where nothing can be carried forward, into a permanently empty announce set.
  • decdn_cache_origin_enumerate_failures_total covers the other leg: an origin whose listing fails contributes no candidates at all, so its hashes leave the announce set with no per-hash fault and nothing to carry.
  • The origin-only ownership probe counts its faults too, on decdn_dht_republish_seed_origin_probe_failures_total — the origin-side twin of the store-walk counter beside it.

Known limitation, filed as #1815: HttpOrigin::size maps every non-success status to Ok(None), so an HTTP 5xx reads as an authoritative absence and the republisher unschedules on it. Closing that means changing the Origin::size contract.

#1808 — a poisoned scheduler lock no longer wedges the republisher

Five real lock sites, not the seven the issue lists — schedule_with_offset and schedule_if_absent already funnel through with_slots. chain_projection's helpers were RwLock-only, so this adds with_lock, and routes all five plus the two routing-table sites in the same file through it.

All three helpers now clear the poison as they recover, so the warning is one line per panic rather than one per acquisition — these locks sit on a 1 Hz timer and the inbound Store path, where an ungated log is the flood dispatch's own poison gate exists to prevent. The rest of the routing-table sites are #1816.

#1809 — the sweep is cancelled at shutdown

run_republish takes a CancellationToken the runtime owns and cancels before the flush, replacing the oneshot. The worker's select! is biased on that token, so a sweep polled any time after the flush takes the cancel arm rather than observing the store it was walking disappear. Nothing joins the worker, so it may outlive the flush by a poll — it just cannot report anything once cancelled.

#1810 / #1812 — the registry resync

decdn_capacity_bond_registry_resync_failures_total at the warn!; decdn_capacity_bond_registry_last_resync_timestamp_seconds on success. The gauge is what catches the repair being skipped rather than failing, which emits nothing at all.

For #1812: the recovery edge already exists in the poller, but WatcherHook is a bare Fn() with no access to the sink. LogSink gains on_recovered — sync, infallible, no-op by default — fired from a new pass placed before reconcile_routes, so a sink that clears its cadence clock re-reads on that same tick.

  • All five sinks use it, not just the registry. Slash, blacklist, fee-shares and rate-bounds each gate their reconcile on a clock stamped before the read, so all four deferred a further interval after exactly the outage that made them stale.
  • The forced re-read is floored at a fifteenth of each sink's cadence. A recovery edge fires whenever a route comes back from an errored tick, so a flapping endpoint would otherwise buy a full authoritative re-read per flap.
  • fail_whole_tick arms the edge too, so a shared head-read failure — the shape a whole-RPC outage takes — reaches every route.
  • ErasedSink's method defaults are removed. With one blanket implementation they were unreachable, and their only effect was to turn a forgotten forward into a silent no-op.

#1811 — coalesced sweeps

decdn_dht_republish_lag_sweeps_coalesced_total, a sibling per the reason-splits convention. Neither it nor the difference counts walks — the slot holds one queued position, so any number of lags behind a running worker collapse into one further pass. The ratio is what reads.

Review rounds

Two passes: a Copilot review, then five specialized agents (correctness, tests, silent failures, comment accuracy, type design). Everything was verified against the code before acting.

Four claims in the first commit were wrong rather than imprecise, and are corrected: "running on stale sizes" (a size is immutable for a content address — the real cost is advertising content the origin dropped), "covers S3/R2 and the filesystem" (only HTTP's status path degrades; its transport faults do count), the gauge's "one interval after boot at the earliest" (falsified by the recovery edge in the same PR), and a test doc claiming the coalesced difference counts walks.

Filed rather than fixed here: #1814 (a panic discards a queued sweep pass — pre-existing #1806 behaviour), #1815, #1816.

Tests

Poisoned-scheduler round-trip; coalescing driven through the slot protocol; a cancelled sweep leaving the store unwalked; a faulted probe carried forward across a throttle window that then closes; an authoritative absence still evicting; a permanent fault not carrying; the blacklist filter on the announce set; the rescan's own counts reaching the seed; a whole-tick failure arming the recovery edge for every route; the resync floor; and a failed resync leaving the liveness gauge unstamped.

Verification

  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • cargo nextest run --workspace — 3006 passed, 0 failed
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace — clean
  • pre-commit run --all-files — all hooks pass
  • ADR rows, monitoring/prometheus-alerts.yml rules, and docs/runbook.md entries added alongside every new metric

Closes #1807
Closes #1808
Closes #1809
Closes #1810
Closes #1811
Closes #1812

🤖 Generated with Claude Code

https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU

Six degradation paths that repair themselves eventually but move no
metric, and in three cases silently shrink what the node advertises.

cache: `rescan_origins` resolved candidates through `origin_size`, whose
per-origin error handling is swallow-and-advance, so a transport fault
arrived as `Ok(None)` — indistinguishable from an origin that genuinely
does not hold the object. A throttled `HeadObject` window during a rescan
evicted those hashes from the origin-held index, and an origin-only node
that hit one at boot advertised a fraction of its content for a whole
rescan interval with every downstream signal green. The rescan now walks
the chain through the fault-aware primitive the serve gate uses, bypassing
its memo so a large enumeration cannot evict the live path's warm entries.
A faulted candidate keeps whatever the previous index held for it. Faults
count on `decdn_cache_origin_probe_failures_total` and reach both DHT seed
paths through `HolderSnapshot::origin_probe_faults`, the origin-held half's
counterpart to `store_error`.

dht: every `Mutex` site in `RepublishScheduler` swallowed poison, and
poison is sticky — one panic under a guard turned the scheduler into a
black hole for the process lifetime while every liveness signal stayed
green. All five sites, plus the two routing-table sites beside them, run
through a new `chain_projection::with_lock`, the `Mutex` analogue of the
existing `with_read`/`with_write`.

dht: the detached lag sweep held a `CacheEngine` clone and was never
cancelled, so a walk in flight when the runtime flushed the store took the
store-walk failure branch and fired an alertable counter on a clean
restart. The worker now selects against a token `run_republish` drops on
its way out.

dht: `decdn_dht_republish_lag_sweeps_coalesced_total` is the sibling that
makes `lag_sweeps_total` readable — the difference is the walks actually
started, and a coalesced rate tracking the lag rate one-for-one is the
signature of a slot that is never released.

node: the capacity-bond registry resync returns `Ok` on a failed read by
design (an `Err` would stall event pickup), which left a persistently
failing repair moving nothing. It now bumps a failure counter and stamps a
liveness gauge; the gauge is what catches the repair being *skipped*, since
the reconcile does not run at all while the route is errored.

node: that resync was cadence-driven only, and the cadence slips in exactly
the scenario that causes the drift. `LogSink` gains `on_recovered`, a sync
no-op-by-default seam the poller fires on the tick a route comes back —
before that tick's reconcile, so a sink clearing its cadence clock re-reads
immediately. All five watchers on the shared poller have it.

Tests: poisoned-scheduler round-trip, coalescing counter through the slot
protocol, a cancelled sweep leaving the store unwalked, a faulted probe
carried forward across a throttle window, the resync counter and gauge, and
the recovery edge firing once and before the reconcile.

Closes #1807
Closes #1808
Closes #1809
Closes #1810
Closes #1811
Closes #1812

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU
Copilot AI lite review requested due to automatic review settings August 24, 2026 21:20
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.97% (was 81.80%, ▲ +0.17%) — 67128/81891 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 92.12% 4291/4658 ▲ +0.24%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/client-pull/src/driver.rs 91.36% 856/937 ● 0.00%
crates/node/src/blacklist_watcher.rs 74.84% 928/1240 ▼ 0.18%
crates/node/src/chain_events/multiplexed_poller.rs 90.07% 1197/1329 ▲ +0.77%
crates/node/src/chain_events/resumable_watcher.rs 90.98% 222/244 ▼ 1.09%
crates/node/src/dht/capacity_bond_registry.rs 81.35% 689/847 ▲ +1.68%
crates/node/src/dht/chain_projection.rs 86.81% 79/91 ▲ +2.07%
crates/node/src/dht/chain_staker_set.rs 86.21% 100/116 ● 0.00%
crates/node/src/dht/publish.rs 91.29% 901/987 ▲ +5.03%
crates/node/src/fee_shares_watcher.rs 83.33% 135/162 ▼ 1.57%
crates/node/src/metrics.rs 94.51% 860/910 ▲ +0.05%
crates/node/src/rate_bounds_watcher.rs 58.56% 65/111 ▼ 1.63%
crates/node/src/runtime/mod.rs 48.16% 1154/2396 ▼ 0.02%
crates/node/src/slash_watcher.rs 59.38% 266/448 ▼ 0.40%
History
Commit Total Δ vs base
fdc58c9 81.90% ▲ +0.09%
9d3d81c 81.92% ▲ +0.12%
be8f3b8 81.94% ▲ +0.14%
a2a785f (HEAD) 81.97% ▲ +0.17%

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses six resilience and observability follow-ups across cache rescans, DHT republishing, and registry synchronization.

Changes:

  • Adds fault-aware origin rescans and failure metrics.
  • Hardens scheduler locks and lag-sweep cancellation/coalescing.
  • Adds registry recovery metrics, alerts, documentation, and changelog updates.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Reviewed change
monitoring/prometheus-alerts.yml Registry resync alerts
docs/runbook.md Operational remediation guidance
crates/node/src/runtime/mod.rs Boot-time resync and seed integration
crates/node/src/metrics.rs New node metrics
crates/node/src/dht/publish.rs Scheduler and sweep resilience
crates/node/src/dht/chain_staker_set.rs Resync observability documentation
crates/node/src/dht/chain_projection.rs Poisoned mutex recovery
crates/node/src/dht/capacity_bond_registry.rs Resync metrics and recovery
crates/node/src/chain_events/resumable_watcher.rs Recovery hook
crates/node/src/chain_events/multiplexed_poller.rs Recovery-edge tracking
crates/cache/src/metrics.rs Origin probe failure metric
crates/cache/src/engine.rs Fault-aware origin rescans
CHANGELOG.md Fixed-issue entries
adr/appendix-observability.md Observability catalog updates
Suppressed comments (6)

adr/appendix-observability.md:189

  • This subtraction does not yield the number of walks with the three-state slot. Multiple lag events can arrive while the worker is already queued; each increments coalesced, but they collapse into one queued rerun, so the difference counts only idle-slot claims and can undercount walks. Add a walk-start metric or document this as an event split rather than an exact walk count.
| `decdn_dht_republish_lag_sweeps_coalesced_total` | Counter | R | live | — | Lag events folded into a sweep that was already running or already queued. `lag_sweeps_total` minus this gives the walks actually started; a coalesced rate that tracks the lag rate one-for-one means the sweep slot is never released. |

crates/node/src/dht/chain_staker_set.rs:94

  • The forced recovery hook only starts an immediate re-enumeration; full_snapshot() can still fail on that tick, and the sink returns Ok(()) after stamping last_resync, deferring the next attempt for another cadence interval. Therefore the drift window is not bounded by poll recovery as this module text states; it is bounded by a successful recovery-time read (or a later cadence retry).
//! So the window a dropped change survives is bounded by the recovery of the
//! poll that dropped it, not by where the cadence happens to land afterwards.
//! The metrics above size that window; the two registry metrics report whether
//! the repair itself is working.

crates/node/src/dht/chain_staker_set.rs:94

  • This conclusion is too broad: on_operator_change intentionally returns Ok when nodeIdOf fails, so the route does not enter the errored state and on_recovered is never fired for that dropped change. That case still waits for the cadence resync; qualify the recovery bound to changes lost during a route-level outage.
//! So the window a dropped change survives is bounded by the recovery of the
//! poll that dropped it, not by where the cadence happens to land afterwards.
//! The metrics above size that window; the two registry metrics report whether
//! the repair itself is working.

crates/node/src/dht/publish.rs:393

  • origin_probe_faults is not a coherent snapshot of origin_held_hashes(): holder_snapshot reads the map, awaits iter_hashes, then reads this counter, while periodic and reload rescans can run concurrently. A snapshot can therefore retain an old fault-truncated map but observe a later successful rescan's zero count, causing lag_sweep to report healthy. Publish the map and fault count together, or version/lock them and read the pair atomically.
    HolderSnapshot {
        hashes,
        store_error,
        origin_probe_faults: cache.last_rescan_origin_probe_faults(),

crates/node/src/metrics.rs:399

  • The subtraction described here is not the number of walks started. If one worker is running and several more lag events arrive, all of them increment coalesced, but they collapse into at most one queued rerun; the difference therefore counts only lag events that acquired an idle slot and can undercount actual walks. Add a separate walk-start metric or remove the exact arithmetic claim from the dashboards/docs.
    /// `decdn_dht_republish_lag_sweeps_total` readable: subtracting this from it
    /// gives the number of walks actually started, and a coalesced rate that
    /// tracks the lag rate one-for-one is the signature of a sweep slot that is
    /// never released. Operator-visible name:

docs/runbook.md:497

  • This statement only holds when the watcher route actually transitions through errored/recovery. A nodeIdOf resolution error in on_operator_change is intentionally returned as Ok, so the route stays healthy and on_recovered is never called; active-staker drift can still wait for the 15-minute cadence. Qualify this as poll/watch outages rather than implying every registry repair failure gets same-tick recovery.
route forces a re-enumeration on the tick it comes back, so a stale gauge with a
healthy route means the reads themselves are failing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/metrics.rs Resolved
Comment thread crates/node/src/dht/publish.rs Resolved
Comment thread crates/node/src/dht/publish.rs Resolved
Comment thread crates/node/src/dht/publish.rs Resolved
Seven inline findings and four substantive suppressed ones, all verified
against the code first. Three were claims this branch introduced that are
not true.

cache: the origin-held index and the counts describing what the rescan
behind it could not resolve are now one `ArcSwap` payload. Published
separately, a seed could pair a fault-truncated index with a later rescan's
zero fault count and report a short announce set as healthy — the exact
failure the counts exist to expose, and reachable because the periodic and
reload rescans are detached.

cache: candidates dedupe on their own `seen` set. Keying off the index
being built meant a hash that resolved `Absent`, or faulted with nothing to
carry forward, was re-probed once per listing it appeared in — and counted
a fault per probe, so a duplicate inflated the very number the seed reads.

cache: `decdn_cache_origin_enumerate_failures_total` covers the rescan's
other leg. An origin whose listing fails contributes no candidates at all,
so its hashes leave the announce set with no per-hash fault and nothing to
carry forward. Counting only probe faults left that shrink silent, which is
what this whole change is about.

dht: the origin-only ownership probe counts its faults the same way. A
`Fault` there is skipped rather than announced — correct, since a blip must
not turn into an advertisement the serve gate would refuse — but skipping
is still a hash this node holds and does not announce, and on a remote
origin it dropped a node's own store-only content while the snapshot read
healthy.

dht: `run_republish` takes a `CancellationToken` the runtime owns and
cancels before the cache flush, replacing the `oneshot`. The previous shape
cancelled the sweep when the republisher returned, and nothing orders that
against the flush: the stop signal only reaches the sweep once the
republisher is next polled. The race was narrowed, not closed.

Docs corrected where they overclaimed: `lag_sweeps_total` minus coalesced
is not a walk count (the slot holds one queued position, so any number of
lags behind a running worker collapse into one further pass); the recovery
trigger bounds drift from a *poll* outage, not from a dropped `nodeIdOf`,
which returns `Ok` and never errors the route, and a recovery-forced read
can itself fail; a probe faults when one or more origins error and none
confirms, not when every origin errors.

`spawn_lag_sweep`'s "a request is never lost" now names the two paths that
discard a queued pass. Shutdown is deliberate. The panic path is not — it
is pre-existing #1806 behaviour and out of scope here, filed as #1814.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU
@thiras

thiras commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Also acted on four of the suppressed comments, since they were correct:

The coalesced arithmetic was wrong (appendix-observability.md:189, metrics.rs:399). The slot holds one queued position, so N lags arriving behind a running worker all count as coalesced and collapse into a single further pass — lag_sweeps_total − coalesced_total undercounts walks. The issue text made the same claim, so this was inherited rather than invented, but it was still wrong to ship. Reworded in the field doc, the ADR row, and CHANGELOG to describe the split and the ratio (coalesced climbing at the lag rate with the difference flat = a slot never released) rather than an exact walk count. No walk-start counter added — #1811 asked for the coalesced sibling specifically, and the ratio carries the diagnostic.

The recovery bound was overclaimed (chain_staker_set.rs:94 ×2, runbook.md:497). Both objections hold and they compound:

  • on_operator_change returns Ok on a nodeIdOf failure by design, so that drop never errors the route and never fires on_recovered — it still waits for the cadence.
  • A re-enumeration forced by recovery can itself fail, stamp the clock, and defer a further interval.

So the window closes on the first successful re-enumeration after recovery, not on recovery. Corrected in the module doc, the runbook entry, and the ADR prose, with the nodeIdOf case pointed at decdn_staker_set_watcher_resolve_failures_total as the signal that actually covers it.

The HolderSnapshot read was not a coherent pair (publish.rs:393) — same finding as the inline comment on engine.rs:1282, fixed the same way: one ArcSwap payload, one load.

Verification after the fixes: clippy --all-targets --all-features -D warnings clean, 3001/3001 tests pass, rustdoc with -D warnings clean, all pre-commit hooks pass.

Five review passes over the branch (correctness, tests, silent failures,
comments, type design). Everything below was verified against the code
before acting; three of the findings are things this branch introduced.

cache: rescans are serialized. Carrying a faulted candidate forward turned
a rescan into a read-modify-write spanning the whole walk, and both
triggers spawn detached — so two overlapping passes let the slower one
publish a payload derived from a pre-empted index, dropping whatever the
fresher pass found. A walk also gets slower exactly when the origin is
faulting, which is when a second pass is most likely to start on top of it.

cache: only a retry-eligible fault carries an entry forward. Every `Err`
was treated as waitable, so a revoked ACL or a symlink escape kept its
index entry for the process lifetime — the node advertising content the
serve path refuses on every request, which is a worse failure than the one
carry-forward exists to prevent.

cache: rescan probes get their own ceiling instead of borrowing
`cache.origin_probe_timeout_ms`. That knob is sized to stop a slow origin
stalling the probe serve path; a bulk walk under it turns a merely slow
origin into an all-fault rescan, and on a cold boot — nothing to carry
forward — into a permanently empty announce set.

cache: `origin_held_hashes` is gone. The whole point of pairing the index
with its unresolved counts is that a caller cannot take one without the
other, and the periodic rescan seed — the trigger that runs most often —
was still taking the set alone and reporting nothing.

node: the recovery-forced re-read is floored at a fifteenth of each sink's
cadence. A recovery edge fires whenever a route comes back from an errored
tick, so an endpoint that flaps rather than staying down bought a full
authoritative re-read per flap, aimed at an endpoint already failing.

node: all five sinks on the shared poller implement `on_recovered`, not
just the registry. Slash, blacklist, fee-shares and rate-bounds each gate
their reconcile on a clock stamped before the read, so all four deferred a
further interval after exactly the outage that made them stale — the
pathology the seam was added for. `ErasedSink`'s method defaults are gone:
with one blanket implementation they were unreachable, and their only
effect was to make a forgotten forward a silent no-op.

node: `notify_recovered_routes` no longer consumes the edge before it can
deliver it, and asserts on the unresolved-factory branch like both its
siblings. Clearing first meant an unresolved sink lost the recovery for the
whole outage rather than one tick.

node: the poison-recovery helpers clear the poison as they recover. Poison
is sticky and these locks sit on a 1 Hz timer and the inbound `Store` path,
so an ungated warn per acquisition is the flood `dispatch`'s own gate
exists to prevent.

node: the seed's ownership-probe faults get a counter. They were the one
leg this branch newly counted in the snapshot and metered nowhere, while
the store-walk leg beside them bumped one.

Docs: corrected four claims that were wrong rather than imprecise —
"running on stale sizes" (a size is immutable for a content address; the
real cost is advertising content the origin no longer holds), "covers
S3/R2 and the filesystem" (only HTTP's *status* path degrades; its
transport faults count), the gauge's "one interval after boot at the
earliest" (falsified by the recovery edge in the same PR), and a test doc
claiming the coalesced difference counts walks.

Tests: whole-tick failure arming the recovery edge for every route — the
only path that arms it for an RPC outage, and previously unpinned; the
resync floor; a failed resync leaving the liveness gauge unstamped; an
authoritative absence still evicting; a permanent fault not carrying
forward; the blacklist filter on the announce set; and the rescan's own
counts reaching the seed.

Not fixed here, filed instead: #1815 (an HTTP 5xx reads as an
authoritative absence, and the republisher unschedules on it) and #1816
(routing-table poison recovery now split between the republisher and the
query path).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Comment thread crates/cache/src/engine.rs Outdated
/// the origin is faulting, so without this two passes overlap and the slower
/// one publishes a payload derived from a pre-empted index, dropping
/// whatever the fresher pass found.
rescan_lock: tokio::sync::Mutex<()>,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0ada6bd. Serializing closed the read-modify-write hazard and left admission untouched — you are right that the waiters are the worse half, since they only accumulate when a walk is already outrunning the cadence, which is the origin-faulting case.

Took the coalesce option: the tokio::Mutex is replaced by the same three-state AtomicU8 slot protocol spawn_lag_sweep uses (RESCAN_IDLE/RESCAN_RUNNING/RESCAN_QUEUED, release by compare-exchange so a request landing mid-pass is never lost, RAII guard so a panic cannot strand it). A trigger that finds a pass in flight returns immediately instead of awaiting, and any number of them collapse into one rerun — which is all a rerun can be worth, since the next pass re-derives everything from scratch.

Test concurrent_rescans_collapse_into_one_rerun fires four triggers against a deliberately slow origin and asserts at most two passes, then that a later trigger still runs.

Comment thread crates/node/src/dht/publish.rs Outdated
let mut hashes: HashSet<decdn_cache::Hash> = cache.origin_held_hashes().into_iter().collect();
let report = cache.origin_held_snapshot();
let mut hashes = report.hashes;
let mut origin_probe_faults = report.probe_faults;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0ada6bd. The counter doc drew the distinction and the code then fed it the merged number, so with relay_foreign_namespaces = true — no ownership probes at all — a rescan fault still moved it.

HolderSnapshot now carries three separate fields: rescan_probe_faults and rescan_enumerate_failures (inherited from the index, describing a pass that may be as old as the rescan cadence) and ownership_probe_faults (measured by this walk). Only the last is recorded on decdn_dht_republish_seed_origin_probe_failures_total. is_degraded() still spans all of them, and the warnings name their source so an operator can tell "one stale rescan" from "the origin is unreachable right now".

Comment thread monitoring/prometheus-alerts.yml Outdated
Comment on lines +236 to +237
expr: rate(decdn_capacity_bond_registry_resync_failures_total[15m]) > 0
for: 30m

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0ada6bd. Attempts are exactly one REGISTRY_RESYNC_INTERVAL apart, so a 15m window is guaranteed to show a zero-rate gap on any poll or RPC delay, and for: 30m never survives it.

Now increase(decdn_capacity_bond_registry_resync_failures_total[1h]) > 0 with for: 15m — a 1h window always spans several attempts whatever the jitter. The reasoning is in the rule comment and in the ADR alert row, since the window is only correct relative to the attempt spacing.

decdn_staker_set_watcher_resolve_failures_total.

- alert: DecdnCapacityBondRegistryResyncStale
expr: (decdn_capacity_bond_registry_last_resync_timestamp_seconds > 0) and (time() - decdn_capacity_bond_registry_last_resync_timestamp_seconds > 1800)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 0ada6bd. Bootstrap runs bootstrap_registry — the same getRegisteredNodes read against the same contract — and seeded last_resync from it without stamping the gauge, so the guard suppressed the alert on exactly the node it exists to find.

bootstrap now stamps the gauge on that enumeration. The > 0 guard stays, but it now covers only the window before bootstrap completes rather than the whole life of a node whose resyncs never succeed. The field doc, the ADR row and the rule comment all previously said the gauge reads 0 until the first post-bootstrap resync; all three are corrected.

thiras and others added 2 commits August 25, 2026 01:58
Four unresolved threads, all verified against the code first, all defects
this branch introduced.

cache: the rescan slot coalesces instead of queueing. Serializing fixed the
read-modify-write hazard but not admission: both triggers fire detached, so
a walk that outran the cadence left one waiter per tick on the lock, and
those waiters then ran a backlog of obsolete passes back to back against an
origin already struggling. Triggers now collapse into a single rerun, which
is all a rerun can be worth — the next pass re-derives everything.

dht: `HolderSnapshot` keeps the rescan's probe faults separate from the
seed's own. Merging them meant a rescan fault moved
`decdn_dht_republish_seed_origin_probe_failures_total` even with
`relay_foreign_namespaces = true`, where the seed asks the origin nothing —
double-counting `decdn_cache_origin_probe_failures_total` and contradicting
the distinction that counter's own doc draws. `rescan_probe_faults` and
`rescan_enumerate_failures` describe a pass that may be as old as the
cadence; `ownership_probe_faults` describes this walk, and only it is
metered here.

node: the bootstrap enumeration stamps the registry's liveness gauge. It is
the same `getRegisteredNodes` read against the same contract, and without
it the staleness alert's `> 0` guard suppressed the alert forever on
exactly the node it exists to find — one where every later resync fails or
is skipped, leaving the gauge at zero.

monitoring: the resync failure alert measures `increase(...[1h])` rather
than `rate(...[15m])`. Attempts are one 15m interval apart, so a window of
that same length sees a zero-rate gap whenever a poll or RPC delay pushes
two increments further apart — resetting `for`, so a permanently failing
resync never fired it.

The degradation reporting both seeds do is now one method on
`HolderSnapshot`, taking a context string. It was three near-identical warn
blocks across two files, and adding a fourth degradation source meant
finding all of them.

Tests: four concurrent triggers collapsing into one rerun, with the slot
still claimable afterwards.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU
…lock

The re-open assertion measured wall-clock time against a 500 ms budget, so
it graded the runner's CPU speed as much as the driver's control flow. Under
coverage instrumentation the honest, sleep-free path took 550 ms and the test
failed while asserting nothing about the behavior it guards.

The clock is now paused: `tokio::time::sleep` is the only thing that advances
it, so a settle-wait costs a full `settle_backoff` of virtual time and the
fetch's CPU cost registers as zero. The budget is `settle_backoff` itself
rather than a hand-tuned millisecond count, which keeps the two in step.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FcG1aENT41wu3xQTbTkxpU
@thiras
thiras merged commit 43d27e0 into main Aug 25, 2026
25 checks passed
@thiras
thiras deleted the fix/1807-1812-review-followups branch August 25, 2026 02:04
alpergundogdu added a commit that referenced this pull request Aug 25, 2026
Three fixes surfaced by review of #1813:

- dht: run the lag-sweep walk in its own task and await the join, so a
  panic inside the store walk surfaces as JoinError::is_panic instead of
  unwinding through the worker. The worker then takes its normal release
  path, which consumes a queued sweep request rather than discarding it,
  and meters the panic on decdn_dht_republish_lag_sweep_panics_total
  (#1814).

- cache: classify HttpOrigin::size statuses instead of degrading every
  non-success to Ok(None): 404 stays an authoritative absence, 5xx/408/429
  surface as Transient faults, and other non-success statuses as
  Permanent — mirroring the S3 adapter's classify_head_object_error. An
  HTTP origin mid-outage now reads as Fault at every layer above, so the
  serve gate no longer signs an authoritative NotFound for it, the probe
  memo no longer caches it as an absence, and the DHT republisher no
  longer unschedules the hash. The due-time gate likewise treats a store
  query fault as unknown — the hash stays scheduled — instead of folding
  it into "no longer held" and unscheduling (#1815).

- dht: route every acquisition of the routing-table mutex through the
  poison-recovering with_lock — the FindNode/FindValue closest_to answer,
  the handler's note_peer_seen refresh, the bucket-refresh walk, and both
  bootstrap inserts — so a single panic no longer leaves the query path
  answering every lookup from an empty table while the republisher keeps
  working (#1816).

Closes #1814. Closes #1815. Closes #1816.


Claude-Session: https://claude.ai/code/session_01Vftbs9Ckm4hHbZrDW4ksgD

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants