Skip to content

👾 Havoc: Rate limit double-spend via time-warp race#1870

Open
madmax983 wants to merge 1 commit into
trunk-devfrom
havoc-rate-limit-time-warp-15972419132455313770
Open

👾 Havoc: Rate limit double-spend via time-warp race#1870
madmax983 wants to merge 1 commit into
trunk-devfrom
havoc-rate-limit-time-warp-15972419132455313770

Conversation

@madmax983

Copy link
Copy Markdown
Owner

🧊 The Trigger: Capturing Instant::now() outside the lock in MemoryStore::decide allows threads to write a stale last_refill time into the bucket, moving time backwards.
📉 The Stack Trace: N/A
🧪 Reproduction: Run RUSTFLAGS="--cfg loom_models" LOOM_MAX_PREEMPTIONS=2 RATE_LIMIT_LOOM_SHOW_BUG=1 cargo test -p autumn-web --test loom_models rate_limit_time_warp.
😈 Comment: "Time goes forwards, not backwards. Except when I pause your thread."


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

In MemoryStore::decide, Instant::now() is called outside the bucket
lock. A thread that stalls after capturing `now` but before acquiring
the lock can write its earlier timestamp to `last_refill`, overwriting
a later timestamp from a thread that executed quickly.

By changing `bucket.last_refill = now` to use `std::cmp::max`, we
ensure that `last_refill` strictly moves forwards, preventing the bucket
from generating spurious tokens due to time running backwards.

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 fixes a time-warp race condition in the rate limiter's MemoryStore by ensuring last_refill is only updated to a later timestamp, and adds corresponding loom tests to model this behavior and test concurrent channel snapshots. The review feedback suggests gating the new integration test module with #[cfg(feature = "ws")] to maintain consistency and avoid compiling an empty module when the feature is disabled.

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.

mod chaos_channels_loom;
#[cfg(feature = "ws")]
mod chaos_channels_proptest;
mod chaos_channels_snapshot_loom;

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

To maintain consistency with the other chaos_channels modules in this file, please gate chaos_channels_snapshot_loom with #[cfg(feature = "ws")]. Although the file itself has an inner attribute #![cfg(feature = "ws")], conditionally compiling the module at the declaration level avoids compiling an empty module when the ws feature is disabled.

Suggested change
mod chaos_channels_snapshot_loom;
#[cfg(feature = "ws")]
mod chaos_channels_snapshot_loom;

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