一键导入
rate-limiting
Use when working with per-model daily request counters, rate limit errors, the America/Los_Angeles reset logic, or RPD quota enforcement.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when working with per-model daily request counters, rate limit errors, the America/Los_Angeles reset logic, or RPD quota enforcement.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when selecting a Gemini model, checking rate limits or quotas, configuring the gemini-rust crate, or debugging model name mismatches.
Create new Kiro skills (Agent Skills). Use when asked to create a skill, write a SKILL.md, add a new workflow to .kiro/skills/, or package agent instructions as a reusable skill.
Use when creating a release, bumping the version, tagging a commit, or working with the GitHub Actions release workflow for rs-summarizer.
Use when editing or creating Askama HTML templates, adding template variables, fixing compile-time template errors, or working with HTMX attributes in templates.
Use when working with tokio::spawn background tasks, the summarization pipeline, task state transitions, or the mark_error/mark_summary_done pattern.
Use when building, running, linting with clippy, formatting with rustfmt, or running cargo commands for the rs-summarizer project.
| name | rate-limiting |
| description | Use when working with per-model daily request counters, rate limit errors, the America/Los_Angeles reset logic, or RPD quota enforcement. |
rs-summarizer implements per-model daily request counters to prevent exceeding Gemini API quotas. Counters reset at the start of each calendar day in America/Los_Angeles timezone.
Rate limiting state lives in AppState (shared across all requests):
pub struct AppState {
pub model_counts: Arc<RwLock<HashMap<String, u32>>>,
pub last_reset_day: Arc<RwLock<Option<NaiveDate>>>,
// ...
}
File: src/services/rate_limiter.rs
pub struct RateLimiter;
impl RateLimiter {
/// Returns true if request is allowed, false if rate limited.
pub async fn check_rate_limit(
model: &ModelOption,
model_counts: &Arc<RwLock<HashMap<String, u32>>>,
last_reset_day: &Arc<RwLock<Option<NaiveDate>>>,
) -> bool;
/// Increment counter after spawning a task.
pub async fn increment_counter(
model_name: &str,
model_counts: &Arc<RwLock<HashMap<String, u32>>>,
);
}
maybe_reset_counters() is called on every check_rate_limit():
last_reset_daylast_reset_dayfn today_la() -> NaiveDate {
let utc_now = chrono::Utc::now();
let la_time = utc_now - chrono::Duration::hours(8);
la_time.date_naive()
}
Note: Uses fixed UTC-8 offset (PST approximation). For DST-aware handling, chrono-tz could be added.
// In process_transcript():
let allowed = RateLimiter::check_rate_limit(&model, &app.model_counts, &app.last_reset_day).await;
if !allowed {
return Html("<p>Rate limit exceeded...</p>".to_string());
}
// After spawning task:
RateLimiter::increment_counter(&input.model, &app.model_counts).await;
Each ModelOption has rpd_limit (requests per day). The counter is compared against this:
let current_count = counts.get(&model.name).copied().unwrap_or(0);
current_count < model.rpd_limit // true = allowed
src/services/rate_limiter.rs — Rate limiter implementationsrc/state.rs — ModelOption.rpd_limit fieldsrc/routes/mod.rs — Check + increment in process_transcript()test_rate_limit_error_display (port 4453) verifies the rate limit UI end-to-end: creates a model with rpd_limit=1, submits once (exhausts limit), submits again, and asserts "Rate limit exceeded" is shown with no polling partial. Run with: cargo test --test integration_browser test_rate_limit_error_display -- --ignored