Skip to content

feat: add user-agent override, per-source GC, and origin-kind tracking - #467

Merged
thiras merged 6 commits into
mainfrom
claude/plan-issue-fixes-hPaaA
May 8, 2026
Merged

thiras merged 6 commits into
mainfrom
claude/plan-issue-fixes-hPaaA

Conversation

@thiras

@thiras thiras commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

This PR implements three complementary features for improved CDN operations and observability:

Summary

Adds operator-configurable HTTP User-Agent headers for origin requests, periodic garbage collection for per-source rate-limiter buckets, and origin-backend tracking in eviction previews to help operators estimate re-fetch costs.

Key Changes

User-Agent Configuration (#435)

  • Add cache.user_agent TOML config field to override the default decdn-node/<version> User-Agent sent on HTTP origin requests
  • Implement DEFAULT_USER_AGENT constant in crate::origin::http embedding the decdn-cache crate's CARGO_PKG_VERSION
  • Add HttpOrigin::new_with_user_agent() to support operator-configured overrides
  • Validate the configured user-agent at config load time: rejects empty strings and any byte outside visible-ASCII / tab so CRLF / NUL / other control bytes can't smuggle a second header onto every origin request
  • Support environment variable expansion for the user-agent field, with the field wired into the per-field expansion error-context table that guards the "added a field, forgot to wire expansion" regression class
  • Wire-level tests using wiremock prove the configured UA reaches the wire (in both default and override branches), not just the constructor

Per-Source Rate-Limiter GC (#440)

  • Add ConnectionLimiter::gc_per_source() method to periodically drop fully-refilled per-source buckets; returns Option<(before, after)> so the runtime can emit a debug breadcrumb only on real sweeps
  • Implement ConnectionLimiter::per_source_tracked() to expose current bucket count for monitoring
  • Spawn periodic GC task in runtime with 60-second interval (matching gossip TTL sweep cadence) — extracted as run_dispatch_gc(...) so the shutdown-promptness contract can be tested directly
  • Use single-flight synchronization with acquire-path pruning via pruning_in_progress flag, with an RAII PruneGuard that resets the flag on Drop (including drop during panic unwind), so a panic inside retain_recent cannot permanently disable both prune codepaths
  • Tests cover: GC drops refilled buckets, no-op when layer is disabled, panic-safety of the guard via catch_unwind, and prompt task shutdown on the stop signal at production interval

Origin-Kind Tracking (#439)

  • Add OriginKind enum (Http / Filesystem, marked #[non_exhaustive] so the foreshadowed S3/R2/B2 follow-ups land additively) to tag origin backend type
  • Implement Origin::kind() trait method on all origin implementations
  • Add origin_kind field to EvictionPreview to surface backend type in admin RPC responses
  • Update dry-run output formatting to display origin kind (or "none" for cache-only mode)
  • JSON wire-form pin tests assert the literal lowercase "http" / "filesystem" strings, the round-trip through serde, and the agreement of as_str / Display / serde-tag — silently drifting any of these would break operator log scrapers

Test Coverage Improvements

Implementation Details

  • Origin-kind serialization uses lowercase names (http, filesystem) for operator-friendly JSON output, pinned by serde-form tests
  • GC task uses compare_exchange for lock-free single-flight coordination with RAII reset on drop
  • User-agent validation happens at config load time for clear error messages naming the offending field and byte position
  • All new public APIs include comprehensive test coverage with edge cases

Closes

Closes #435
Closes #440
Closes #439
Closes #438
Closes #434

https://claude.ai/code/session_015QgzLTQEu4fxUMqWbaYmg4

Copilot AI review requested due to automatic review settings May 7, 2026 17: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 improves node operability and observability by (1) allowing operators to override the HTTP origin request User-Agent, (2) adding periodic garbage-collection for dispatch per-source rate-limiter state to prevent unbounded growth on long-lived nodes, and (3) surfacing the configured origin backend type in eviction previews and CLI dry-run output to estimate re-fetch/egress cost.

Changes:

  • Add cache.user_agent config (with env expansion + validation) and plumb it into HttpOrigin client construction.
  • Add ConnectionLimiter::gc_per_source() plus a runtime task that runs it every 60s to reclaim fully-refilled per-source buckets.
  • Introduce OriginKind and propagate it through cache EvictionPreview → admin RPC → CLI dry-run output, with tests.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/node/tests/sighup_signal.rs Update test config seed to include ResolvedCache.user_agent.
crates/node/src/runtime/reload.rs Ensure runtime reload seeds include ResolvedCache.user_agent in defaults/tests.
crates/node/src/runtime/mod.rs Spawn periodic per-source limiter GC task; use HttpOrigin::new_with_user_agent when building HTTP origin.
crates/node/src/dispatch.rs Add gc_per_source() + per_source_tracked() and unit tests for GC behavior.
crates/node/src/admin.rs Include origin_kind in admin RPC eviction preview responses; update tests’ stub origins.
crates/common/src/config/types.rs Add cache.user_agent to file config schema.
crates/common/src/config/resolved.rs Add ResolvedCache.user_agent to resolved config schema.
crates/common/src/config/mod.rs Resolve/validate cache.user_agent, expand env vars, and add per-field merge coverage tests (gossip/security) + UA tests.
crates/common/src/admin.rs Extend EvictPreview JSON schema with optional origin_kind.
crates/cli/tests/config_validate.rs Update resolved-config sample to include user_agent.
crates/cli/src/commands/node.rs Print origin_kind in human dry-run output; update formatting tests.
crates/cache/tests/pull_through.rs Update test origins to implement new Origin::kind() method.
crates/cache/src/origin/mod.rs Add OriginKind enum and extend Origin trait with kind().
crates/cache/src/origin/http.rs Add DEFAULT_USER_AGENT, HttpOrigin::new_with_user_agent, set UA on reqwest client, implement kind(), add tests.
crates/cache/src/origin/fs.rs Implement Origin::kind() for filesystem origin.
crates/cache/src/lib.rs Re-export OriginKind and DEFAULT_USER_AGENT.
crates/cache/src/engine.rs Add origin_kind to eviction preview and populate it from configured origin; add tests.

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

Comment thread crates/cache/src/origin/http.rs Resolved
Comment thread crates/cache/tests/pull_through.rs Resolved

@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 OriginKind reporting in eviction previews to help operators estimate egress costs and adds a configurable User-Agent for HTTP origin requests. It also implements a periodic garbage collection task for the per-source connection rate limiter to prune stale buckets and includes expanded test coverage for configuration resolution. I have no feedback to provide.

thiras added a commit that referenced this pull request May 7, 2026
…#467 review)

Address Copilot review on #467, plus a related doc-link bug introduced
by the same PR commit (bc05b1d) that was failing the cargo-doc
pre-commit hook with `-Dwarnings`.

- `DEFAULT_USER_AGENT` and `HttpOrigin::new` referenced a non-existent
  `HttpOrigin::with_user_agent`. The real builder is
  `new_with_user_agent`; update both intra-doc links so they resolve.
- The "workspace version" claim in `DEFAULT_USER_AGENT`'s docstring was
  inaccurate — `[workspace.package]` sets no `version`, so
  `env!("CARGO_PKG_VERSION")` reflects the `decdn-cache` crate's own
  version. Reword to state that explicitly while noting the
  co-versioning with `decdn-node` that makes the embedded value match
  the running binary today.
- `OriginKind`'s docstring linked to a bare `CacheEngine`, which is
  not in scope inside `origin/mod.rs`. Use `crate::CacheEngine` to
  mirror the next line's `crate::EvictionPreview::origin_kind` style.
- `InterruptOnceOrigin` in `pull_through.rs` wraps a real
  `FilesystemOrigin` but reported `OriginKind::Http`, which would
  mislead any future test or assertion that inspects backend kind.
  Delegate to `self.inner.kind()`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras thiras changed the title Add user-agent override, per-source GC, and origin-kind tracking feat: add user-agent override, per-source GC, and origin-kind tracking May 7, 2026
thiras added a commit that referenced this pull request May 7, 2026
…review)

Aggregated multi-agent review (code-reviewer, comment-analyzer,
silent-failure-hunter, pr-test-analyzer, type-design-analyzer) caught
four docstring lies:

- `DEFAULT_USER_AGENT` and `ResolvedCache.user_agent` claimed the UA
  embeds a "workspace version", and the prior fix-up doubled down with
  a "co-versioned with `decdn-node`" gloss. Neither is true: the
  workspace `[workspace.package]` table sets no `version`, and each
  member crate pins its own `version = "0.1.0"` independently. A
  future bump of `decdn-node` alone would silently desync the UA from
  the running daemon's version. Rephrase honestly: it's the
  `decdn-cache` crate's `CARGO_PKG_VERSION`, period.
- `OriginKind` doc said "TOML representation uses lowercase tag
  names". `OriginKind` is never TOML-serialised — it is output-only,
  surfaced through the admin RPC's JSON. The `[cache.origin]` TOML
  table uses `OriginConfig`, an unrelated type.
- `EvictPreview.origin_kind`'s `skip_serializing_if = "Option::is_none"`
  doc claimed older clients see "no surface change". That holds only
  in cache-only mode; in origin-mode the field is present
  unconditionally, so a `deny_unknown_fields` deserialiser pinned to a
  pre-#439 schema would still break. Scope the claim to cache-only.
- `engine.rs` carried a speculative comment about "a future per-blob
  origin association would require touching `EvictionPreview` again",
  flagged by the project's never-reference-future-work rule. The seam
  is already obvious from the surrounding code; remove it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thiras added a commit that referenced this pull request May 7, 2026
#467 review)

Three concerns from the multi-agent review of #467 — separately
flagged by code-reviewer (rated 85 confidence), pr-test-analyzer
(rated 9), and silent-failure-hunter (high) — converged on the same
gap: the resolver only rejected the empty string, leaving CRLF / NUL
/ other control bytes to surface inside `HttpOrigin::new_with_user_agent`
at runtime as a generic `"failed to build reqwest client"`. The
docstring already promised config-load rejection; this commit makes
the code match the promise.

- New `validate_user_agent` rejects any byte outside visible ASCII
  (0x20..=0x7e) plus tab. CR/LF in particular blocks header
  injection; non-ASCII obs-text (legal under RFC 7230 but never seen
  in real `User-Agent` strings) is rejected so a botched env-var
  expansion can't ship surprises to origin operators.
- Test for the negative path covers CR, LF, NUL, DEL, and obs-text
  in one loop, with a separate single-case message-shape assertion
  that pins both the field name (`cache.user_agent`) and the
  byte-position phrasing — without that, a future error-context
  regression would slip through silently.
- Test for the positive path: tab is part of the legal byte set and
  shows up in real-world UAs occasionally; pinning it prevents an
  over-zealous future tightening from rejecting legitimate values.
- Add `cache.user_agent` to the per-field env-expansion error-context
  table (config/mod.rs:~1610) — that table explicitly says it guards
  the "added a field, forgot to wire expansion" regression. The
  field was wired up in expand_env but missing from the table,
  defeating its stated purpose. Plus a happy-path expansion test
  mirroring the sibling `expand_env_substitutes_cache_origin_url`.
- Wire-level test in `pull_through.rs` that proves the configured
  `User-Agent` actually reaches the wire via reqwest. The existing
  `new_with_user_agent_accepts_custom_value` only checks the
  constructor doesn't error; a future reqwest-builder reordering or
  a typo passing the UA into the wrong builder slot would silently
  ship the default. Wiremock's `header()` matcher returns 404 if the
  UA doesn't match, so the test asserts the get() succeeds — exactly
  the regression class #435 is meant to prevent. Paired test for the
  default-UA case so both branches of the seam are pinned.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thiras added a commit that referenced this pull request May 7, 2026
…review)

Three related findings on the dispatch per-source GC introduced in
#440, all surfaced by silent-failure-hunter and pr-test-analyzer
during the multi-agent review of #467.

- `pruning_in_progress` was set via `compare_exchange`, then
  `retain_recent()` ran, then a manual `store(false)` reset it. If
  `retain_recent()` ever panicked (third-party governor code, an
  allocation failure during an O(n) walk, or any future regression
  in the keyed limiter), the flag would stay stuck `true` for the
  process lifetime — permanently disabling both the acquire-path
  opportunistic prune and the periodic GC task. That is exactly the
  unbounded-keyspace pathology #440 was meant to prevent. New
  `PruneGuard` RAII type resets the flag in `Drop`, so the protection
  holds across panic unwind. Both prune call sites switch to the
  guard. New unit test uses `catch_unwind` around a panicking scope
  to prove the flag is released even when the protected operation
  unwinds — `retain_recent` itself can't be made to panic on demand
  for a real test, so the guard's Drop semantics are tested directly.

- `gc_per_source` returned `()`, and the periodic task in
  `runtime/mod.rs` emitted no log line per tick. The runtime's doc
  comment explicitly promised a debug breadcrumb so operators could
  correlate keyspace size with the bookkeeping cap, but no such log
  existed. Change `gc_per_source` to return `Option<(usize, usize)>`
  — `Some((before, after))` when a sweep ran, `None` when the layer
  is disabled or the call lost the single-flight CAS. The runtime
  task uses the return value to emit `tracing::debug!(before, after,
  dropped)` only on real sweeps; silence is meaningful (either
  layer-off or skipped-due-to-concurrent-prune).

- The GC task's shutdown contract was untested. A regression that
  dropped the `&mut stop_rx` arm of the select, or moved it after
  `ticker.tick()` without `biased`, would silently extend
  `SHUTDOWN_DEADLINE` by up to 60s in production. Extract the loop
  body into `run_dispatch_gc(limiter, stop_rx, interval)` and add a
  test that uses a 60s interval (mirroring production) plus a 500ms
  timeout — a regression that polled the ticker before the stop
  signal would hang for the full minute, well past the timeout, so
  the assertion actually catches the bug rather than an unrelated
  short-interval race.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thiras added a commit that referenced this pull request May 7, 2026
…467 review)

Type-design analyzer flagged `OriginKind`'s wire-form contract as
under-enforced: `#[serde(rename_all = "lowercase")]` plus the manual
`as_str` table plus `Display` were the only defences against an
operator-visible string drift, with no test pinning the literal JSON
output and no marker for additive evolution. Test-analyzer
independently flagged the missing JSON test (rated 9). Both concerns
land here.

- `#[non_exhaustive]` on the enum so the foreshadowed S3/R2/B2
  follow-ups (per the cache crate's `Origin is the seam` doc
  comment) can land additively without a `breaking-change` bump for
  every consumer that matches on the type. Audited the workspace —
  no external `match OriginKind { ... }` sites exist, so adding
  `non_exhaustive` is a no-op for the call graph today and only buys
  forward room.
- Three new tests pin the operator-visible string contract:
  `origin_kind_serialises_to_stable_lowercase_strings` asserts the
  exact `"http"` / `"filesystem"` JSON literals;
  `origin_kind_round_trips_through_json` locks both directions so a
  rename + `serde(alias)` sleight-of-hand still fails;
  `origin_kind_as_str_and_display_match_serde_tag` proves the three
  paths (`as_str`, `Display`, serde tag) cannot drift independently
  — operators grepping `decdn_origin_kind="http"` in tracing logs
  see the `Display` form while admin RPC consumers see the JSON
  form, and silently disagreeing values would force every consumer
  to update their queries.
- Add `serde_json` to `decdn-cache`'s dev-dependencies (workspace
  version) since the new tests are the first crate-internal use of
  it. Already pinned at the workspace level (Cargo.toml:41).

Did NOT take the analyzer's adjacent suggestion to introduce a
`const KIND: OriginKind` + defaulted `kind()` method on the trait —
the typo class it claimed to prevent (the `InterruptOnceOrigin`
mismatch caught by the prior round) survives the redesign in the
form of a wrong `const KIND` literal, so the trait churn isn't
load-bearing. The wire-form tests above catch the actual regression
class.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

claude and others added 6 commits May 8, 2026 16:17
Addresses five small, isolated open issues in one PR:

* #435 — HttpOrigin sets a `User-Agent` header (`decdn-node/<version>`
  by default; `cache.user_agent` overrides). Origin operators can
  attribute CDN pull-through traffic in their access logs and apply
  rate-limit / routing policy that distinguishes CDN pulls from
  end-user clients.

* #440 — runtime spawns a periodic dispatch-limiter GC task that
  calls `ConnectionLimiter::gc_per_source()` every 60s. The acquire
  path only prunes opportunistically when the keyspace exceeds
  `cap + cap/10`; without periodic GC a node whose connection rate
  falls below that threshold accumulates stale per-source buckets
  until restart.

* #439 — `EvictionPreview` (and the admin `EvictPreview` DTO + CLI
  human format) carry an `origin_kind` tag (`http`/`filesystem`/
  none) so admin dry-run callers can estimate origin egress cost
  before committing to an eviction. JSON omits the field when no
  origin is configured (skip-on-None) — older clients see no
  surface change.

* #438 — adds per-field merge tests for `ResolvedSecurity`'s four
  fields (`max_concurrent_handlers`, `per_source_rate_per_sec`,
  `per_source_burst`, `max_tracked_sources`) plus an
  independent-overrides test. Mirrors the existing
  `resolve_blockchain` test layout.

* #434 — adds per-field merge tests for `ResolvedGossip`'s
  `announce_interval_sec`, `peer_ttl_sec`, and `subscribe_global`
  fields, plus sibling allowlist hex-validation tests covering
  non-hex characters and partial-list rejection — companions to
  the existing wrong-length test.

Single commit because the five issues touch overlapping files
(`crates/common/src/config/mod.rs`, `crates/cache/src/origin/`,
`crates/node/src/runtime/mod.rs`) and clean per-issue splits
would require interactive hunk staging.

https://claude.ai/code/session_015QgzLTQEu4fxUMqWbaYmg4
…#467 review)

Address Copilot review on #467, plus a related doc-link bug introduced
by the same PR commit (bc05b1d) that was failing the cargo-doc
pre-commit hook with `-Dwarnings`.

- `DEFAULT_USER_AGENT` and `HttpOrigin::new` referenced a non-existent
  `HttpOrigin::with_user_agent`. The real builder is
  `new_with_user_agent`; update both intra-doc links so they resolve.
- The "workspace version" claim in `DEFAULT_USER_AGENT`'s docstring was
  inaccurate — `[workspace.package]` sets no `version`, so
  `env!("CARGO_PKG_VERSION")` reflects the `decdn-cache` crate's own
  version. Reword to state that explicitly while noting the
  co-versioning with `decdn-node` that makes the embedded value match
  the running binary today.
- `OriginKind`'s docstring linked to a bare `CacheEngine`, which is
  not in scope inside `origin/mod.rs`. Use `crate::CacheEngine` to
  mirror the next line's `crate::EvictionPreview::origin_kind` style.
- `InterruptOnceOrigin` in `pull_through.rs` wraps a real
  `FilesystemOrigin` but reported `OriginKind::Http`, which would
  mislead any future test or assertion that inspects backend kind.
  Delegate to `self.inner.kind()`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…review)

Aggregated multi-agent review (code-reviewer, comment-analyzer,
silent-failure-hunter, pr-test-analyzer, type-design-analyzer) caught
four docstring lies:

- `DEFAULT_USER_AGENT` and `ResolvedCache.user_agent` claimed the UA
  embeds a "workspace version", and the prior fix-up doubled down with
  a "co-versioned with `decdn-node`" gloss. Neither is true: the
  workspace `[workspace.package]` table sets no `version`, and each
  member crate pins its own `version = "0.1.0"` independently. A
  future bump of `decdn-node` alone would silently desync the UA from
  the running daemon's version. Rephrase honestly: it's the
  `decdn-cache` crate's `CARGO_PKG_VERSION`, period.
- `OriginKind` doc said "TOML representation uses lowercase tag
  names". `OriginKind` is never TOML-serialised — it is output-only,
  surfaced through the admin RPC's JSON. The `[cache.origin]` TOML
  table uses `OriginConfig`, an unrelated type.
- `EvictPreview.origin_kind`'s `skip_serializing_if = "Option::is_none"`
  doc claimed older clients see "no surface change". That holds only
  in cache-only mode; in origin-mode the field is present
  unconditionally, so a `deny_unknown_fields` deserialiser pinned to a
  pre-#439 schema would still break. Scope the claim to cache-only.
- `engine.rs` carried a speculative comment about "a future per-blob
  origin association would require touching `EvictionPreview` again",
  flagged by the project's never-reference-future-work rule. The seam
  is already obvious from the surrounding code; remove it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
#467 review)

Three concerns from the multi-agent review of #467 — separately
flagged by code-reviewer (rated 85 confidence), pr-test-analyzer
(rated 9), and silent-failure-hunter (high) — converged on the same
gap: the resolver only rejected the empty string, leaving CRLF / NUL
/ other control bytes to surface inside `HttpOrigin::new_with_user_agent`
at runtime as a generic `"failed to build reqwest client"`. The
docstring already promised config-load rejection; this commit makes
the code match the promise.

- New `validate_user_agent` rejects any byte outside visible ASCII
  (0x20..=0x7e) plus tab. CR/LF in particular blocks header
  injection; non-ASCII obs-text (legal under RFC 7230 but never seen
  in real `User-Agent` strings) is rejected so a botched env-var
  expansion can't ship surprises to origin operators.
- Test for the negative path covers CR, LF, NUL, DEL, and obs-text
  in one loop, with a separate single-case message-shape assertion
  that pins both the field name (`cache.user_agent`) and the
  byte-position phrasing — without that, a future error-context
  regression would slip through silently.
- Test for the positive path: tab is part of the legal byte set and
  shows up in real-world UAs occasionally; pinning it prevents an
  over-zealous future tightening from rejecting legitimate values.
- Add `cache.user_agent` to the per-field env-expansion error-context
  table (config/mod.rs:~1610) — that table explicitly says it guards
  the "added a field, forgot to wire expansion" regression. The
  field was wired up in expand_env but missing from the table,
  defeating its stated purpose. Plus a happy-path expansion test
  mirroring the sibling `expand_env_substitutes_cache_origin_url`.
- Wire-level test in `pull_through.rs` that proves the configured
  `User-Agent` actually reaches the wire via reqwest. The existing
  `new_with_user_agent_accepts_custom_value` only checks the
  constructor doesn't error; a future reqwest-builder reordering or
  a typo passing the UA into the wrong builder slot would silently
  ship the default. Wiremock's `header()` matcher returns 404 if the
  UA doesn't match, so the test asserts the get() succeeds — exactly
  the regression class #435 is meant to prevent. Paired test for the
  default-UA case so both branches of the seam are pinned.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…review)

Three related findings on the dispatch per-source GC introduced in
#440, all surfaced by silent-failure-hunter and pr-test-analyzer
during the multi-agent review of #467.

- `pruning_in_progress` was set via `compare_exchange`, then
  `retain_recent()` ran, then a manual `store(false)` reset it. If
  `retain_recent()` ever panicked (third-party governor code, an
  allocation failure during an O(n) walk, or any future regression
  in the keyed limiter), the flag would stay stuck `true` for the
  process lifetime — permanently disabling both the acquire-path
  opportunistic prune and the periodic GC task. That is exactly the
  unbounded-keyspace pathology #440 was meant to prevent. New
  `PruneGuard` RAII type resets the flag in `Drop`, so the protection
  holds across panic unwind. Both prune call sites switch to the
  guard. New unit test uses `catch_unwind` around a panicking scope
  to prove the flag is released even when the protected operation
  unwinds — `retain_recent` itself can't be made to panic on demand
  for a real test, so the guard's Drop semantics are tested directly.

- `gc_per_source` returned `()`, and the periodic task in
  `runtime/mod.rs` emitted no log line per tick. The runtime's doc
  comment explicitly promised a debug breadcrumb so operators could
  correlate keyspace size with the bookkeeping cap, but no such log
  existed. Change `gc_per_source` to return `Option<(usize, usize)>`
  — `Some((before, after))` when a sweep ran, `None` when the layer
  is disabled or the call lost the single-flight CAS. The runtime
  task uses the return value to emit `tracing::debug!(before, after,
  dropped)` only on real sweeps; silence is meaningful (either
  layer-off or skipped-due-to-concurrent-prune).

- The GC task's shutdown contract was untested. A regression that
  dropped the `&mut stop_rx` arm of the select, or moved it after
  `ticker.tick()` without `biased`, would silently extend
  `SHUTDOWN_DEADLINE` by up to 60s in production. Extract the loop
  body into `run_dispatch_gc(limiter, stop_rx, interval)` and add a
  test that uses a 60s interval (mirroring production) plus a 500ms
  timeout — a regression that polled the ticker before the stop
  signal would hang for the full minute, well past the timeout, so
  the assertion actually catches the bug rather than an unrelated
  short-interval race.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…467 review)

Type-design analyzer flagged `OriginKind`'s wire-form contract as
under-enforced: `#[serde(rename_all = "lowercase")]` plus the manual
`as_str` table plus `Display` were the only defences against an
operator-visible string drift, with no test pinning the literal JSON
output and no marker for additive evolution. Test-analyzer
independently flagged the missing JSON test (rated 9). Both concerns
land here.

- `#[non_exhaustive]` on the enum so the foreshadowed S3/R2/B2
  follow-ups (per the cache crate's `Origin is the seam` doc
  comment) can land additively without a `breaking-change` bump for
  every consumer that matches on the type. Audited the workspace —
  no external `match OriginKind { ... }` sites exist, so adding
  `non_exhaustive` is a no-op for the call graph today and only buys
  forward room.
- Three new tests pin the operator-visible string contract:
  `origin_kind_serialises_to_stable_lowercase_strings` asserts the
  exact `"http"` / `"filesystem"` JSON literals;
  `origin_kind_round_trips_through_json` locks both directions so a
  rename + `serde(alias)` sleight-of-hand still fails;
  `origin_kind_as_str_and_display_match_serde_tag` proves the three
  paths (`as_str`, `Display`, serde tag) cannot drift independently
  — operators grepping `decdn_origin_kind="http"` in tracing logs
  see the `Display` form while admin RPC consumers see the JSON
  form, and silently disagreeing values would force every consumer
  to update their queries.
- Add `serde_json` to `decdn-cache`'s dev-dependencies (workspace
  version) since the new tests are the first crate-internal use of
  it. Already pinned at the workspace level (Cargo.toml:41).

Did NOT take the analyzer's adjacent suggestion to introduce a
`const KIND: OriginKind` + defaulted `kind()` method on the trait —
the typo class it claimed to prevent (the `InterruptOnceOrigin`
mismatch caught by the prior round) survives the redesign in the
form of a wrong `const KIND` literal, so the trait churn isn't
load-bearing. The wire-form tests above catch the actual regression
class.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras force-pushed the claude/plan-issue-fixes-hPaaA branch from 1eea966 to d94fb3e Compare May 8, 2026 13:23
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

Coverage report

Total: 87.49% (was 87.26%, ▲ +0.23%) — 11252/12861 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 90.48% 808/893 ▼ 0.02%
crates/cache/src/origin/fs.rs 73.68% 168/228 ▼ 0.98%
crates/cache/src/origin/http.rs 87.66% 334/381 ▼ 0.18%
crates/cache/src/origin/mod.rs 100.00% 32/32 new
crates/cache/src/origin/s3.rs 90.19% 340/377 ▼ 0.72%
crates/cli/src/commands/node.rs 78.11% 439/562 ▲ +0.48%
crates/common/src/admin.rs 69.57% 16/23 ● 0.00%
crates/common/src/config/mod.rs 96.46% 3244/3363 ▲ +0.28%
crates/node/src/admin.rs 95.84% 622/649 ▲ +0.07%
crates/node/src/dispatch.rs 92.99% 597/642 ▼ 1.39%
crates/node/src/runtime/mod.rs 53.60% 372/694 ▲ +2.28%
crates/node/src/runtime/reload.rs 95.16% 1179/1239 ▲ +0.01%
History
Commit Total Δ vs base
d94fb3e (HEAD) 87.49% ▲ +0.23%

@thiras
thiras merged commit 5ced852 into main May 8, 2026
12 checks passed
@thiras
thiras deleted the claude/plan-issue-fixes-hPaaA branch May 8, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants