Skip to content

fix(core): reject future feature-flag cache timestamps - #234

Merged
BunsDev merged 1 commit into
mainfrom
fix/feature-cache-clock
Oct 15, 2026
Merged

BunsDev merged 1 commit into
mainfrom
fix/feature-cache-clock

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 15, 2026

Copy link
Copy Markdown
Member

Summary

The remote feature-flag cache no longer overflows when its stored fetched_at is in the future; such a cache is treated as stale.

Context

  • Related request: Coven Code surface-reduction goal, unit 37 ("cache clock safety" in the surface inventory ledger).
  • Scope: crates/core/src/feature_flags.rs (cache validity only).
  • Non-goals: the public FeatureFlagManager API, the 10 s HTTP timeout, and the stale-cache fallback on API errors are unchanged. No network request or user cache was touched.

Changes

  • Cache age was now - fetched_at. A future timestamp, from a clock rollback or file contents, overflowed, which is a panic in debug builds (reproduced with the extracted expression at u64::MAX).
  • The private validity method takes now explicitly and uses checked_sub, so a future timestamp is never fresh (+1 net production line).
  • Deterministic tests cover exact TTL, just-fresh, epoch, u64::MAX, a future timestamp and zero TTL.

Validation

  • RED: 3 focused tests passed and 1 failed (future-timestamp subtraction).
  • cargo test --locked -p claurst-core --lib feature_flags: 4 passed, 0 failed.
  • cargo fmt --all -- --check, cargo check --workspace --locked, cargo clippy --workspace --all-targets --locked -- -D warnings: pass on this branch (current main).
  • git diff --check: clean.
  • cargo test --workspace: hosted Rust CI. Source: 669 core tests passed; integration assembly 2,078 passed.
  • Independent final review accepted.

PR Readiness

  • Diff is limited to the intended file.
  • Generated files were not edited by hand.
  • User-facing docs: not needed.
  • No secrets, credentials, local paths, or unrelated logs are included.
  • Remaining risks: none.

The cache freshness check subtracted fetched_at from the current time,
which overflows (and panics in debug builds) when the cached timestamp
is in the future, for example after a clock rollback or an edited cache
file. Pass now explicitly to the private validity check and use
checked_sub so a future timestamp is treated as stale. The public API
and the stale-cache fallback on API errors are unchanged.

Coven-Harness: Claude Code / claude-opus-5-5
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Oct 15, 2026 8:25am UTC

Request Review

@BunsDev
BunsDev merged commit 9b9afea into main Oct 15, 2026
6 checks passed
@BunsDev
BunsDev deleted the fix/feature-cache-clock branch October 18, 2026 08:31

This branch was successfully deployed

1 active deployment
Preview — f64fc304 Deployed Oct 15, 2026 by vercel[bot]
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.

1 participant