Skip to content

👺 Havoc: Prevent panic on jittered_ttl overflow#1807

Open
madmax983 wants to merge 1 commit into
trunk-devfrom
havoc-cache-jitter-overflow-257098097593059716
Open

👺 Havoc: Prevent panic on jittered_ttl overflow#1807
madmax983 wants to merge 1 commit into
trunk-devfrom
havoc-cache-jitter-overflow-257098097593059716

Conversation

@madmax983

Copy link
Copy Markdown
Owner

🧊 The Trigger:
Passing a very large Duration (e.g. Duration::MAX) to jittered_ttl with a fraction that results in a randomized jitter factor > 1.0.

📉 The Stack Trace:

thread 'integration::chaos_cache_jitter_proptest::test_jittered_ttl_no_panic' panicked at /rustc/4a4ef493e3a1488c6e321570238084b38948f6db/library/core/src/time.rs:964:23:
cannot convert float seconds to Duration: value is either too big or NaN

🧪 Reproduction:
Run the new proptest harness located at autumn/tests/integration/chaos_cache_jitter_proptest.rs. The fuzzer hits this edge case by feeding extreme ranges into jittered_ttl.

😈 Comment:
"You assumed Duration::mul_f64 was infallible and would never overflow when multiplying large durations by random jitter. You were wrong."


PR created automatically by Jules for task 257098097593059716 started by @madmax983

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 prevents potential panics in jittered_ttl due to overflow when multiplying a large Duration by a random jitter factor, and adds a property-based test to verify this safety. The feedback suggests using Duration::try_from_secs_f64 to perform a cleaner, safer, and more idiomatic checked conversion instead of manually checking against u64::MAX as f64 and suppressing the clippy::cast_precision_loss lint.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +291 to +297
#[allow(clippy::cast_precision_loss)]
let max_secs = u64::MAX as f64;
if base.as_secs_f64() * factor >= max_secs {
Duration::MAX
} else {
base.mul_f64(factor)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of manually checking for overflow against u64::MAX as f64 (which requires suppressing the clippy::cast_precision_loss lint), you can use Duration::try_from_secs_f64 directly. This is cleaner, safer, and idiomatic in Rust for performing checked float-to-Duration conversions.

    Duration::try_from_secs_f64(base.as_secs_f64() * factor).unwrap_or(Duration::MAX)

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.82%. Comparing base (14e6518) to head (f4e25c5).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           trunk-dev    #1807      +/-   ##
=============================================
- Coverage      86.82%   86.82%   -0.01%     
=============================================
  Files            273      273              
  Lines         202424   202427       +3     
=============================================
  Hits          175761   175761              
- Misses         26663    26666       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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