Skip to content

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

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/issues-1814-1815-1816-6695dr
Aug 25, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/issues-1814-1815-1816-6695dr

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

One PR for the three follow-ups surfaced by review of #1813.

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

#1814 — a panic inside a lag sweep no longer discards a queued pass

The sweep worker now runs each walk in an inner tokio::spawn and awaits the JoinHandle, so a panic inside the store walk (iroh-blobs sits outside the workspace anti-panic lints) surfaces as JoinError::is_panic instead of unwinding through the worker. The worker then takes its normal release path: the release compare-exchange fails if a request was queued mid-walk, and the worker consumes it with a further pass rather than dropping it through SweepSlotGuard. This is the same join-and-branch pattern the runtime, admin, and buyer-channel layers already use.

  • Shutdown is now the only path that discards a queued request, deliberately (the next boot re-seeds); docs on spawn_lag_sweep and SweepSlotGuard updated to match.
  • The panic itself is metered on a new counter, decdn_dht_republish_lag_sweep_panics_total — a sweep that panics every pass would otherwise only show up as a flat sweep_reseeded_total.
  • The worker body moved into run_sweep_worker to keep the slot-claim protocol and the worker loop separately readable.
  • New test drives the panic path deterministically: a stub origin whose size blocks on a semaphore and then panics lets the test queue a second pass behind a running walk, then open the gate — both passes run (two metered panics) and the slot ends idle.

#1815 — an HTTP origin's 5xx is no longer an authoritative absence

HttpOrigin::size now classifies statuses the way fetch and the S3 adapter's classify_head_object_error already do, instead of degrading every non-success to Ok(None):

  • 404 → Ok(None) (authoritative absence, as before);
  • 5xx/408/429 → Err(Transient);
  • every other non-success (401/403, disabled 3xx redirects, other 4xx) → Err(Permanent).

The issue's suggested-fix sketch had non-404 4xx degrading to Ok(None); this PR instead matches classify_head_object_error exactly (which the same issue names as the model), because a 403 folded into an absence has the same failure shape as the 503 — the serve gate would sign an authoritative NotFound for it. As Permanent, it reaches the probe chain as a non-carry-forward Fault, so the rescan still drops it from the announce set after one pass, matching S3.

Consequences at the layers above, with no changes needed there: probe_origin_chain now answers Fault (transient-flagged for the outage statuses) instead of Absent, so the origin-only serve gate answers InternalError instead of signing NotFound, the probe memo no longer caches an outage under the negative TTL, the fault-aware rescan carries the candidate forward, and the republisher no longer calls unschedule for it. The best-effort range-scope caller (CacheEngine::origin_size) already swallows per-origin errors and degrades to a whole-blob fetch, so the range-pull degrade path is unchanged. The Origin::size doc contract and the two doc comments that described the old HTTP quirk (origin_probe_presence, rescan_origins) are updated.

The related cache_still_holds shape from the issue is fixed too: it now returns Option<bool>, and the tick path treats a store fault as unknown — the hash is re-scheduled with a fresh steady-state draw and skipped for this cycle's publish — instead of unwrap_or(false) unscheduling it for the process lifetime.

New tests pin size's 404/503/403/200 classification (wiremock) and the store-fault-is-unknown gate.

#1816 — routing-table poison recovery is one idiom again

All four remaining raw acquisitions of the routing-table Mutex now go through chain_projection::with_lock (which clears poison as it recovers, so the warn is one line per panic, not one per request):

  • handlers/dht.rs closest_to — no longer answers every inbound FindNode/FindValue from an empty table after a panic; the "honest at this moment" comment is replaced, since an empty answer from a poisoned guard is an assertion about the table's contents the code cannot make;
  • handlers/dht.rs note_peer_seen — no longer silently drops every learned peer;
  • dht/bucket_refresh.rs — both the pick snapshot and the response-learned inserts;
  • dht/bootstrap.rs — both the seed step and the closer-nodes inserts.

with_lock widens from pub(super) to pub(crate) (and the chain_projection module to pub(crate)) so the handler can share the one recovery idiom; the record-store lock sites in the handler are untouched, as the issue scopes this to the routing table.

Validation

cargo build, cargo clippy --all-targets (no warnings), cargo fmt -- --check, full decdn-cache test suite, decdn-node lib tests (750 passed), and the origin_range_pull integration suite all pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vftbs9Ckm4hHbZrDW4ksgD


Generated by Claude Code

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.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vftbs9Ckm4hHbZrDW4ksgD
Copilot AI lite review requested due to automatic review settings August 25, 2026 08:40

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 closes the three follow-ups from review of #1813 by hardening DHT republish sweep behavior against panics, correcting HTTP-origin HEAD/size semantics so outages are not treated as authoritative absence, and unifying routing-table poison recovery across republisher and request paths.

Changes:

  • Prevent lag-sweep panics from discarding queued sweep passes by running each sweep walk in an inner task and branching on JoinError::is_panic, plus adding a new panic counter.
  • Reclassify HTTP origin size responses so only 404 yields Ok(None) while outages (5xx/408/429) and other non-success statuses become OriginPullError (transient vs permanent), and update the Origin::size contract/docs accordingly.
  • Route all remaining routing-table Mutex acquisitions through chain_projection::with_lock to consistently recover from poison and avoid “split-brain” behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/node/src/metrics.rs Adds a new counter for lag-sweep walk panics and wires a recorder for it.
crates/node/src/handlers/dht.rs Uses poison-tolerant with_lock for routing-table access in handler hot paths.
crates/node/src/dht/publish.rs Refactors lag-sweep worker loop to isolate panics via join handling; fixes due-time gate to treat store faults as unknown; adds tests for both behaviors.
crates/node/src/dht/mod.rs Widens chain_projection module visibility to allow handler reuse of the recovery helper.
crates/node/src/dht/chain_projection.rs Widens with_lock visibility to pub(crate) and documents why all sites should share the same recovery idiom.
crates/node/src/dht/bucket_refresh.rs Replaces raw routing-table Mutex locks with with_lock in refresh flows.
crates/node/src/dht/bootstrap.rs Replaces raw routing-table Mutex locks with with_lock and preserves insertion counting.
crates/cache/src/origin/mod.rs Updates the Origin::size contract to make Ok(None) authoritative absence and require faults to be surfaced as OriginPullError.
crates/cache/src/origin/http.rs Reclassifies HEAD status handling for size (404 → Ok(None), outage statuses → transient error, other non-success → permanent error) and adds focused tests.
crates/cache/src/engine.rs Updates documentation to reflect the new Origin::size semantics (no longer treating outages as absence).

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

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.01% (was 80.30%, ▲ +1.71%) — 67350/82126 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 92.14% 4292/4658 ▲ +0.64%
crates/cache/src/origin/http.rs 87.48% 482/551 ▲ +2.75%
crates/cache/src/origin/mod.rs 62.50% 70/112 ▲ +15.31%
crates/node/src/dht/bootstrap.rs 85.19% 92/108 ▲ +2.83%
crates/node/src/dht/bucket_refresh.rs 75.84% 135/178 ▲ +0.56%
crates/node/src/dht/chain_projection.rs 86.81% 79/91 ▲ +15.38%
crates/node/src/dht/publish.rs 91.41% 1032/1129 ▲ +5.52%
crates/node/src/handlers/dht.rs 77.04% 292/379 ▼ 0.43%
crates/node/src/metrics.rs 94.51% 860/910 ▼ 1.10%
History
Commit Total Δ vs base
1510f66 (HEAD) 82.01% ▲ +1.71%

@alpergundogdu
alpergundogdu merged commit 9475536 into main Aug 25, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issues-1814-1815-1816-6695dr branch August 25, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants