Skip to content

fix(cache): a present but unsized origin object is no longer memoised as an absence - #2867

Closed
yigitdot wants to merge 5 commits into
mainfrom
worktree-fix-2827-origin-size-tristate
Closed

yigitdot wants to merge 5 commits into
mainfrom
worktree-fix-2827-origin-size-tristate

Conversation

@yigitdot

@yigitdot yigitdot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Origin::size had one answer, Ok(None), for two different facts: the origin does not hold the object, and the origin holds it but cannot state a byte size (a stored-compressed object with Content-Encoding, or a 200 without Content-Length). The probe path reads that answer as authoritative absence: the memo caches Absent, the origin-only serve gate declines the node's own content, and the republish walk drops the hash — so a compressed remote origin silently reads as absent everywhere, while the engine docs claimed Ok(None) was reserved for a genuine 404.

size() now answers a tri-state OriginSize { Known, Unsized, Absent }. A present-but-unsized object memoises PresentUnsized and is admitted at the serve gate (the pull path already serves it through the whole-blob fallback, unchanged). A genuine 404 still reads as Absent, and the chain walk prefers a sibling origin's size over an unsized answer.

Probe coverage needs a size to sign, and a blob's length is immutable under its BLAKE3 hash — so an unsized hold is announced and probe-answered whenever anything else states the length: a size the previous rescan index holds, or the blob a pull landed complete in the local store (serve_audit). Only a hold nothing ever sized stays unannounced (counted and logged); the serve gate still admits it.

Caller-by-caller:

  • Serve gate (dispatch.rs): PresentUnsized admits — refusing the node's own content is the defect being fixed; the pull path serves it whole-blob.
  • Probe handler, origin-only branch: consults the rescan index first, then the live presence probe; a PresentUnsized answer takes the store's size for a complete local hold, else answers has_blob: false.
  • Republish walk (holder_snapshot): announces a PresentUnsized hash when the store holds the blob complete; skips it otherwise — uncounted, nothing is degraded.
  • Rescan index (resolve_candidates): sizes a PresentUnsized candidate from the previous index, else from the complete stored blob; a never-sized hold drops out, counted in unsized_drops, which warns on change and logs debug while steady.
  • Probe memo: a clean PresentUnsized stands for the positive TTL; one established while a sibling origin faulted (or the walk overran) stands only for the fault TTL, so the sibling that may state the size is re-probed promptly.
  • origin_probe_size: stays the size-only collapse (PresentUnsized/Absent/Fault → None); size-aware callers use origin_probe_presence plus serve_audit.
  • origin_size (range-pull scoping): Known returns the size; Unsized/Absent advance the chain — signature unchanged (Option<u64> out), the whole-blob fallback stays silent.
  • The trait default stays Absent so NodeOrigin and custom origins never read as holding content they cannot confirm.

Out of scope (noted, not done): making size() answer Err(Permanent) for DecompressMode::Strict/unsupported encodings — fetch already fails there; aligning size is a separate nicety.

Closes #2827
Closes #2869

🤖 Generated with Claude Code

… as an absence

Origin::size had one answer, Ok(None), for two different facts: the
origin does not hold the object, and the origin holds it but cannot
state a byte size (a stored-compressed object with Content-Encoding, or
a 200 without Content-Length). The probe path reads that answer as
authoritative absence: the memo caches Absent, the origin-only serve
gate declines the node's own content, and the republish walk drops the
hash.

size() now answers a tri-state OriginSize { Known, Unsized, Absent }. A
present-but-unsized object memoises PresentUnsized under the positive
TTL and is admitted at the serve gate; it stays out of the announce set
and the rescan index because origin-sourced probe coverage needs a size
to sign. A genuine 404 still reads as Absent, and the chain walk
prefers a sibling origin's size over an unsized answer. The whole-blob
pull fallback (origin_size) is unchanged.

Closes #2827

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 14:19

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-code-quality

github-code-quality Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main f238ccf worktree-fix-2827-or... abf115e +/-
77% 77% 0%
View coverage of the 9 most impacted files.
File main f238ccf worktree-fix-2827-or... abf115e +/-
crates/cache/sr.../origin/http.rs 95% 94% -1%
crates/node/src...ndlers/probe.rs 86% 85% -1%
crates/node/src/dht/publish.rs 78% 78% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/cache/src/origin/s3.rs 86% 86% 0%
crates/cache/src/origin/fs.rs 73% 73% 0%
crates/cache/sr...origin_probe.rs 96% 96% 0%
crates/client/src/lib.rs 89% 90% +1%
crates/protocol/src/framing.rs 92% 93% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 12, 2026 21:46 UTC

…escans

Review follow-ups on the OriginSize tri-state:

- probe_origin_chain keeps its findings outside the walk future, so a
  timeout that fires after an origin confirmed an unsized hold answers
  PresentUnsized, not Fault — the serve gate no longer refuses a
  known-present object because a slow sibling overran the ceiling. The
  sibling's fault (or the overrun) rides along as the probe cause and
  logs at warn without changing the memoised presence.
- resolve_candidates carries a previously-sized index entry forward when
  the origin's answer degrades to unsized: presence is confirmed and a
  hash's length cannot change, so the carried size signs the same
  coverage. Hashes no pass ever sized are counted and warned about
  (servable but not announced) instead of dropping silently.
- The memo stores OriginPresence directly; the isomorphic Presence enum,
  its From impl and the dead Presence::size() are gone.
- Doc reconciliation: the fetch-only trait default's consequences under
  the origin-only gate, the announce walk's two skip kinds, and stale
  Ok(None) wording.
- New tests: walk continues past Unsized to a sized sibling, timeout
  keeps the hold, rescan carry-forward, holder_snapshot skips unsized
  without a fault, the origin-only gate serves an unsized backend hash
  end to end, S3 HeadObject without Content-Length is Unsized.

Co-Authored-By: Claude Fable 5 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

Review pass (five-agent: code, comments, tests, errors, types) landed in 86e1186:

  • Bug fix: a walk timeout firing after an origin had already confirmed an unsized hold used to answer Fault (memoised; serve gate refused InternalError). The walk's findings now live outside the timed future, so the overrun keeps the confirmation, and a sibling origin's fault rides along as the logged cause instead of being dropped.
  • Rescan: a previously-sized index entry is carried forward when the origin's answer degrades to Unsized (presence confirmed, size immutable), so turning on bucket compression no longer silently un-announces content; never-sized holds are counted and warned about per pass.
  • Simplification: the memo now stores OriginPresence directly — the isomorphic Presence enum and both mappings are gone.
  • Docs: reconciled the fetch-only trait default with the Absent contract, split the announce walk's two skip kinds (deliberate unsized vs counted fault), fixed stale Ok(None) wording.
  • Tests: walk-continues-past-Unsized, timeout-keeps-the-hold, rescan carry-forward, holder_snapshot skips unsized without a fault, an end-to-end loopback serve of an unsized backend hash, and S3 HeadObject-without-Content-Length → Unsized.

2509 cache+node tests, clippy --all-targets -D warnings, fmt and the doc gate all pass.

@alpergundogdu

Copy link
Copy Markdown
Contributor

Review

The sized / unsized / absent split is a real improvement, and the pull path already serves a blob without a known size. Eight findings below; the first two are bugs.

Bugs

1. Origin-only node denies and leaves unannounced blobs it holds (crates/node/src/dht/publish.rs:600, crates/node/src/handlers/probe.rs:609)
holder_snapshot only walks hashes already in the local store, so for every PresentUnsized hash the store knows the exact size. Skipping them because there is "no size to sign coverage from" is wrong. The origin-only probe branch answers from origin_probe_size alone, so it says has_blob: false for the same blobs.
Scenario: origin-only node, S3 origin storing objects with Content-Encoding: gzip. A client fetches H once, H lands complete in the store. The DHT sweep skips H and the probe answers has_blob: false, so clients rank the node out although it holds H and the dispatch gate would admit it.
Fix: in both places, treat PresentUnsized as owned and take the size from the store when the blob is complete there. Skip only when the store does not hold it.

2. Unsized hold plus a sibling fault is memoised under the positive TTL (crates/cache/src/engine.rs:2293)
If origin A answers Unsized and sibling B (which may hold the object with a size) faults or the walk overruns, the chain returns PresentUnsized and the memo keeps it for origin_probe_ttl_sec. Before this PR the same chain gave Fault under the short fault TTL and was re-probed soon.
Scenario: chain [http (gzip), s3 (sized)], s3 returns a 503 or a slow HEAD on the first probe. For the whole positive TTL origin_probe_size answers None, although a retry seconds later would return Present(size).
Fix: when probe.cause is Some, memoise PresentUnsized under the fault TTL. Use the positive TTL only for a clean walk.

Smaller issues

3. Rescan sizes an unsized hold only from the previous index (crates/cache/src/engine.rs:2081)
On the first pass after a restart (empty previous index) a hash whose blob is complete in the store still counts as an unsized_drop.
Fix: fall back to the store's size for a complete stored blob before counting a drop.

4. The unsized-drop warning repeats on every rescan (crates/cache/src/engine.rs:44)
A compressed origin is a steady state, so report_rescan_pass warns at default level on every interval forever. That buries the real fault warning beside it.
Fix: warn when the count changes from the previous pass and log at debug otherwise, or expose it as a gauge next to origin_enumerate_failures.

5. The PR description does not match the rescan code, and the probe disagrees with the index (crates/cache/src/engine.rs:1866)
The description says the rescan skips PresentUnsized. The code keeps a size from the previous index and drops only hashes never sized. On an origin-only node the probe never reads that index: it goes to origin_probe_size, gets PresentUnsized, and answers has_blob: false. The hash is announced but probe-denied, the reputation cost the PR says it avoids.
Fix: have the origin-only probe branch consult origin_held_size before origin_probe_size, and update the description.

Cleanups

6. The PresentUnsized result is built in two places (crates/cache/src/engine.rs:2264)
probe_origin_chain builds it inside the walk and again in the timeout arm, so the precedence rule (Present > PresentUnsized > Fault > Absent) lives twice.
Fix: let the walk return Option<u64> (Some on Known) and only update the hoisted any_unsized / cause / any_transient. Then classify once after the timeout with an overran: bool.

7. Comment narrates history (crates/node/src/handlers/client/dispatch.rs:573)
"Four-way outcome (#1766 split presence from fault; #2827 split sized from unsized)" describes changes, which the repo's present-tense rule in CLAUDE.md rules out.
Fix: "Four-way outcome (#1766, #2827): ..." and keep the rest.

Open question

8. The serve gate admits what the probe and announce deny (crates/node/src/handlers/probe.rs:609)
Clients choose a node by probing first, so on an origin-only node a cold, never-cached unsized object is still never selected, and the newly admitted serve path is not reached in practice. The user-visible part of #2827 persists for discovery.
Options: document that origins must not store objects compressed, or read the size from the store once a whole-blob pull has landed it (this also covers 1 and 3).

🤖 Generated with Claude Code

…nes sooner

Review follow-ups on the Origin::size tri-state (#2827), closing #2869:

- the origin-only probe branch consults the rescan index, then the live
  presence probe, and sizes a PresentUnsized answer from the complete
  local blob (serve_audit), so announce, probe and serve agree
- holder_snapshot announces a store-complete unsized hold; the rescan
  sizes one from the previous index, else the store, before counting a
  drop — a restart no longer drops warm unsized holds
- a PresentUnsized established during a degraded walk (sibling fault or
  overrun) memoises under the fault TTL so a blipped sized sibling is
  re-probed promptly instead of being shadowed for the positive TTL
- the unsized-drop warn fires on a count change and logs debug while
  steady, so a compressed origin does not warn every rescan interval
- probe_origin_chain gathers in the walk and classifies once after the
  timeout, so the presence precedence lives in one match

Co-Authored-By: Claude Fable 5 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

All eight findings addressed in 3b458a1; 1/3/8 fold issue #2869 into this PR (the description now carries Closes #2869).

  1. Fixed — the origin-only probe branch (handlers/probe.rs) now consults origin_held_size, then origin_probe_presence, and sizes a PresentUnsized answer from the store via serve_audit when the blob is complete there; holder_snapshot announces a store-complete unsized hold the same way. Your S3-gzip scenario now probes has_blob: true with the store's length once H lands. Pinned by origin_only_probe_advertises_a_store_complete_unsized_hold (warm + cold cases) and holder_snapshot_announces_a_store_complete_unsized_hold.
  2. Fixed — a PresentUnsized whose walk carried a cause (sibling fault or overrun) is memoised via a new OriginProbeMemo::insert_degraded under the fault TTL; a clean walk keeps the positive TTL. Pinned by degraded_unsized_hold_expires_on_the_fault_ttl (engine) and degraded_insert_expires_on_the_fault_ttl (memo).
  3. Fixed — resolve_candidates falls back from the previous index to serve_audit before counting a drop, so a restart keeps warm unsized holds. Pinned by rescan_sizes_an_unsized_hold_from_the_complete_store_blob.
  4. Fixed — the index keeps the pass's unsized_drops; the warn fires only when the count changes and logs at debug while steady. Faults still warn every pass.
  5. Fixed — the probe branch reads the index first (the carried size now answers probes), and the PR description is rewritten to match the code.
  6. Fixed — the walk returns the first Known size and only updates hoisted findings; the Present > PresentUnsized > Fault > Absent precedence is applied in a single match after the timeout.
  7. Fixed — (#1766, #2827).
  8. With 1/3 in place the gap narrows to a cold, never-pulled unsized object: still undiscoverable until the first direct fetch warms the store, which the probe branch comment now states. Documenting "don't store compressed" stays an operator note in the origin adapter docs (Content-Encoding ⇒ Unsized).

🤖 Generated with Claude Code

yigitdot and others added 2 commits November 13, 2026 00:31
…gin-size-tristate

# Conflicts:
#	crates/cache/src/lib.rs
…s from the store

Second review pass on the Origin::size tri-state (#2827):

- http/s3 size() resolve Content-Encoding exactly as fetch does:
  identity keeps the length (Known), a decodable encoding is Unsized,
  and one fetch rejects (br, or any non-identity under Strict, or a
  malformed header) is a permanent fault, so the origin-only gate no
  longer admits a hash whose pull always fails
- the relay probe's live-origin fallback sizes a PresentUnsized hold
  from a complete local blob, sharing one helper with the origin-only
  branch
- holder_snapshot counts a failed store audit of an unsized hold as an
  ownership probe fault instead of skipping it silently

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

Second review addressed in abf115e (on top of a merge of current main; the only conflict was the OriginSize re-export after S3 moved behind the s3 feature).

Warning 1 — encoding-aware size(): fixed. http.rs and s3.rs now resolve Content-Encoding with the same resolve_encoding as fetch: identity (or none) keeps the length → Known; a decodable encoding → Unsized; one fetch rejects (br, any non-identity under Strict, or a malformed header) → Err(Permanent). The origin-only gate no longer admits a hash whose pull always fails. OriginSize docs updated. Tests: size_identity_encoding_keeps_the_length and size_rejected_encoding_is_a_permanent_fault for both adapters.

Warning 2 — relay probe fallback: fixed. The relay live-origin fallback now sizes a PresentUnsized hold from a complete local blob, via a live_origin_size helper shared with the origin-only branch (which still reads the rescan index first, without a live probe on an index hit). Test: relay_probe_advertises_a_store_complete_unsized_hold_with_holds_disabled.

Suggestion — holder_snapshot swallowing serve_audit Err: fixed. A failed audit now counts toward ownership_probe_faults (debug-logged); a partial hold stays an uncounted skip. No dedicated test: the store cannot be made to fail a status read in-process.

Local: 2518 cache+node tests pass with s3; clippy (--all-targets --all-features), fmt, doc gate and hooks clean.

🤖 Generated with Claude Code

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closed: #2885 makes a {H}.sizeproof the origin's only statement of a blob size, and a node never serves or advertises an origin object it cannot prove the size of. A present-but-unsized object is therefore not served, so the unsized tri-state has no use.

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