Skip to content

refactor(crates): extract decdn-config-types leaf crate (#578) - #586

Merged
alpergundogdu merged 3 commits into
mainfrom
feat/578-config-types-leaf-crate
May 19, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
feat/578-config-types-leaf-crate

Conversation

@thiras

@thiras thiras commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #578. The decdn publisher CLI transitively linked the entire cache crate (iroh-blobs, AWS S3 SDK, async-compression) through cli → common → cache, directly defeating the binary-split goal documented in adr/appendix-binaries.md.

This extracts the config-vocabulary value types decdn-common actually needs into a new decdn-config-types leaf crate (deps: serde, url, anyhow only):

  • RetryPolicy (value type; the rand-using delay_for backoff math stays in decdn-cache)
  • DecompressMode, OriginKind, OriginUrl + parse_origin_url / redact_for_log
  • a new panic-free Hash newtype ([u8;32], lowercase-64-hex serde — byte-identical to iroh_blobs::Hash) + PinnedHashes / PinDiff
  • DEFAULT_USER_AGENT / DEFAULT_MAX_PROBE_HOLDS

decdn-cache re-exports every moved type, so decdn-node is essentially untouched; decdn_cache::Hash still means iroh_blobs::Hash (the blob-store hash). to_store_hash/from_store_hash shims bridge the two same-shaped 32-byte digests; the only conversion site is the node evict admin handler. The cache engine keeps its internal pinned set on the store hash and converts only on the cold open / SIGHUP path (hot is_pinned/eviction_candidates stay zero-cost).

This realizes the budget-gated remedy appendix-binaries.md already prescribed — no new ADR; existing ADRs and CLAUDE.md files reconciled to the now-true state.

Result

The production decdn binary (cargo tree -p decdn-cli -e normal) links none of iroh-blobs, aws-sdk-s3, aws-config, aws-smithy-*, aws-credential-types, async-compression. decdn-common is clean too. reqwest/iroh remain (via alloy / the direct iroh dep — not the cache, as intended). The dev-dep decdn-cache in cli is intentional (integration tests) and never reaches the release binary.

Verification

  • cargo build --workspace / cargo clippy --workspace --all-targets -- -D warnings / cargo fmt --all -- --check — all clean (anti-panic policy satisfied on the hand-rolled hex)
  • cargo nextest run --workspace — 892 passed, 0 skipped
  • Moved tests travel with their types; no net coverage loss (the deleted engine.rs diff test has an equivalent in the leaf)
  • New cross-crate wire-compat test pins the leaf Hash hex form byte-identical to iroh_blobs::Hash against the known BLAKE3("") vector + lossless store↔leaf round-trips
  • New RetryPolicy serde partial-section regression guard (#[serde(default)] / default_buffered_max_bytes)

Review

Ran the multi-agent PR review toolkit (code / comments / tests / silent-failures / type-design). One Critical (missing cross-crate wire-compat test) and four Important doc/test items were found and fixed in this branch; reviewers' consensus is a faithful realization of the approved plan with no remaining blocking issues. A pre-existing engine.rs poisoned-mutex silent fallback was identified as out of scope (not introduced here) and left as a noted future follow-up.

🤖 Generated with Claude Code

The publisher CLI (`decdn`) transitively linked the entire cache stack
(iroh-blobs, AWS S3 SDK, async-compression) via `cli → common → cache`,
defeating the documented binary-split goal in appendix-binaries.md.

Extract the config-vocabulary value types `decdn-common` needs
(RetryPolicy, DecompressMode, OriginUrl, OriginKind, a new panic-free
Hash newtype, PinnedHashes/PinDiff, DEFAULT_USER_AGENT,
DEFAULT_MAX_PROBE_HOLDS) into a new serde+url-only `decdn-config-types`
leaf crate. `decdn-cache` re-exports them so `decdn-node` is unchanged;
`decdn_cache::Hash` still means `iroh_blobs::Hash`, with
`to_store_hash`/`from_store_hash` shims and a single conversion site in
the node `evict` admin handler. The engine keeps its pinned set on the
store hash, converting only on the cold open/SIGHUP path.

`decdn-common` now depends on the leaf instead of `decdn-cache`, so the
production `decdn` binary links none of iroh-blobs / the AWS SDK
(verified via `cargo tree -p decdn-cli -e normal -i ...`). reqwest/iroh
remain via alloy / the direct iroh dep, not the cache.

Realizes the budget-gated remedy appendix-binaries.md already
prescribed; no new ADR. Docs reconciled: appendix-binaries.md,
architecture.md, cli/Cargo.toml, both CLAUDE.md files.

Verification: cargo build/clippy/fmt clean; cargo nextest run
--workspace = 892 passed. Includes a cross-crate wire-compat test
pinning the leaf Hash hex form byte-identical to iroh_blobs::Hash
against the known BLAKE3("") vector, and a RetryPolicy serde
partial-section regression guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 19, 2026 00:18

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

Extracts a new decdn-config-types leaf crate (deps: serde, url, anyhow) holding the config-vocabulary value types (RetryPolicy, DecompressMode, OriginUrl, OriginKind, a panic-free Hash newtype, PinnedHashes/PinDiff, DEFAULT_USER_AGENT/DEFAULT_MAX_PROBE_HOLDS). decdn-common now depends on this leaf instead of decdn-cache, so the publisher CLI (decdn) no longer links iroh-blobs/AWS SDK/async-compression. decdn-cache re-exports moved types and adds to_store_hash/from_store_hash shims between the leaf Hash and iroh_blobs::Hash; the engine converts at its public boundary (cold paths only).

Changes:

  • New leaf crate crates/config-types/ with moved types, tests, and a Hash newtype with hand-rolled hex codec byte-identical to iroh_blobs::Hash.
  • decdn-cache updated to import from leaf, re-export for source compat, store pinned set as store-hash internally, and convert at the public boundary; decdn-common switches to leaf dep.
  • Docs updated: CLAUDE.md, adr/architecture.md, adr/appendix-binaries.md, and inline rustdoc references; node evict handler converts via decdn_cache::to_store_hash.

Reviewed changes

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

Show a summary per file
File Description
Cargo.toml, Cargo.lock Register new decdn-config-types workspace member and update lockfile.
crates/config-types/Cargo.toml New leaf crate manifest (serde/url/anyhow only).
crates/config-types/src/{lib,retry,origin_url,origin_kind,decompress,hash,defaults}.rs Moved value types with tests; new panic-free Hash newtype + PinnedHashes/PinDiff.
crates/cache/Cargo.toml Adds dep on the new leaf crate.
crates/cache/src/lib.rs Re-exports leaf types; adds to_store_hash/from_store_hash; pins cross-crate hex/round-trip wire-compat.
crates/cache/src/engine.rs Removes moved types; engine pinned set stays on store hash; converts at boundary; recomputes PinDiff over store-hash sets.
crates/cache/src/retry.rs Removes moved RetryPolicy; keeps delay_for (needs rand); tests updated.
crates/cache/src/origin/{mod,http}.rs Re-exports moved types; removes duplicate redact_for_log/OriginUrl/DecompressMode/OriginKind definitions and their tests.
crates/cache/src/probe_hold.rs DEFAULT_MAX_PROBE_HOLDS re-exported from leaf.
crates/common/Cargo.toml Drops decdn-cache dep, adds decdn-config-types.
crates/common/src/{lib,admin,config/{mod,types,resolved,secret}}.rs Replace decdn_cache::* paths with decdn_config_types::*; docs updated.
crates/node/src/admin.rs Converts the leaf hash from parse_hash_arg to the store hash via decdn_cache::to_store_hash at the evict boundary.
crates/cli/Cargo.toml Comment update reflecting the new clean dependency tree (no code change).
CLAUDE.md, adr/architecture.md, adr/appendix-binaries.md Document the new 9-crate workspace, leaf-crate topology, and the realized remedy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.68% (was 89.59%, ▲ +0.08%) — 16110/17964 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.16% 1444/1550 ▲ +0.54%
crates/cache/src/lib.rs 100.00% 28/28 new
crates/cache/src/origin/http.rs 97.09% 200/206 ▲ +1.70%
crates/cache/src/origin/mod.rs 75.68% 28/37 ▼ 11.28%
crates/cache/src/retry.rs 84.51% 180/213 ▼ 2.40%
crates/common/src/admin.rs 69.57% 16/23 ● 0.00%
crates/common/src/config/mod.rs 96.19% 3860/4013 ● 0.00%
crates/common/src/config/secret.rs 95.59% 65/68 ● 0.00%
crates/config-types/src/decompress.rs 100.00% 9/9 new
crates/config-types/src/hash.rs 91.12% 154/169 new
crates/config-types/src/origin_kind.rs 100.00% 32/32 new
crates/config-types/src/origin_url.rs 92.91% 131/141 new
crates/config-types/src/retry.rs 100.00% 49/49 new
crates/node/src/admin.rs 95.85% 623/650 ● 0.00%
History
Commit Total Δ vs base
0e68dc7 89.64% ▲ +0.04%
8d77099 89.63% ▲ +0.04%
e933a74 (HEAD) 89.68% ▲ +0.08%

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new leaf crate, decdn-config-types, to house shared configuration value types such as RetryPolicy, OriginUrl, and Hash. This architectural change decouples decdn-common and the CLI from the heavy storage and network dependencies of decdn-cache, significantly reducing the CLI's binary size. The cache engine now includes conversion functions to bridge between the leaf Hash type and the internal iroh_blobs::Hash. Feedback was provided regarding the Display and Debug implementations for the Hash struct, suggesting a more efficient approach that avoids unnecessary string allocations by writing directly to the formatter.

Comment thread crates/config-types/src/hash.rs Resolved
thiras and others added 2 commits May 19, 2026 03:30
Display/Debug went through to_hex()'s String allocation on every call;
a frequently-logged type shouldn't allocate per format. Write `{:02x}`
straight to the formatter and delegate Debug to Display. Output is
byte-identical (lowercase zero-padded) to to_hex()/the serde form, so
the to_hex() + serde wire path is untouched and the cross-crate
wire-compat test (hash_bridge_tests) still pins it.

Addresses PR #586 review feedback (gemini-code-assist).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Commit 8d77099 made Display a second, independent hex impl while
to_hex() (the serde path) keeps the HEX-table impl. The two must stay
byte-identical (admin JSON-RPC uses serde→to_hex; tracing %hash uses
Display), but no test pinned that equivalence — hash_bridge_tests only
covers to_hex()↔iroh_blobs::Hash, and the prior comment/commit message
overstated that coverage.

Add display_and_debug_match_to_hex (asserts Display == to_hex() and
Debug == to_hex() over zero/0xab/leading-zero+0xff vectors) and correct
the Display comment to reference the real pin. Closes the untested
drift gap surfaced in PR #586 re-review.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras requested a review from alpergundogdu May 19, 2026 00:34
@alpergundogdu
alpergundogdu merged commit f513ad0 into main May 19, 2026
13 checks passed
@alpergundogdu
alpergundogdu deleted the feat/578-config-types-leaf-crate branch May 19, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK)

3 participants