Improve Mistral rate-limit handling and add cooldown probe scripts#69
Conversation
There was a problem hiding this comment.
Summary
This PR enhances Mistral rate-limit handling by increasing the minimum interval from 1.1s to 1.5s and adding support for server-provided rate-limit headers (Retry-After and x-ratelimit-reset). The cooldown probe scripts provide valuable testing capabilities.
Critical Issues Found
Security & Functionality Blockers:
- Hardcoded API key in probe script creates immediate security vulnerability (CWE-798)
- Missing
osmodule import causes script to crash on execution - No validation for required API key leads to authentication failures
Recommendation: Address the security vulnerability immediately by using environment variables for API keys. The probe scripts cannot function without these fixes.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| import time | ||
| from typing import Tuple, List | ||
|
|
||
| MISTRAL_API_KEY = "zsEegAJFadHH4uooe2lW0HVNmy1rpqGT" |
There was a problem hiding this comment.
🛑 Security Vulnerability: Hardcoded API key exposed in repository. This key grants access to your Mistral API account and will be permanently visible in git history, leading to unauthorized usage and potential account compromise.1
| MISTRAL_API_KEY = "zsEegAJFadHH4uooe2lW0HVNmy1rpqGT" | |
| MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY", "") |
Footnotes
-
CWE-798: Use of Hard-coded Credentials - https://cwe.mitre.org/data/definitions/798.html ↩
| import json | ||
| import subprocess | ||
| import time |
There was a problem hiding this comment.
🛑 Crash Risk: Missing import for os module causes NameError when accessing environment variable. Script will fail immediately on execution.
| import json | |
| import subprocess | |
| import time | |
| import json | |
| import os | |
| import subprocess | |
| import time |
| if __name__ == "__main__": | ||
| step_delays = list(range(100, 3001, 100)) |
There was a problem hiding this comment.
🛑 Crash Risk: Missing validation for required API key will cause authentication failure. Script proceeds with empty string when environment variable is not set, resulting in 401 Unauthorized errors from Mistral API.
| if __name__ == "__main__": | |
| step_delays = list(range(100, 3001, 100)) | |
| if __name__ == "__main__": | |
| if not MISTRAL_API_KEY: | |
| raise ValueError("MISTRAL_API_KEY environment variable must be set") | |
| step_delays = list(range(100, 3001, 100)) |
…o fix-compilation-errors-in-mainactivity.kt-esbisz
a772205
into
codex/analyze-technical-debt-and-complexity-o6bm9p
Motivation
Description
PhotoReasoningViewModelby increasing the baseMISTRAL_MIN_INTERVAL_MSfrom1100to1500and adding an overloadedmarkKeyCooldownthat accepts anextraDelayMsto apply server-requested delays.parseRetryAfterMsandparseRateLimitResetDelayMsto extractRetry-Afterandx-ratelimit-resetheaders and use the larger of these values to schedule the next allowed key use.maxAttemptsfrom available keys, updated retry/failure messages and error conditions to referencemaxAttempts, and resetstopExecutionFlagat the start ofreason().scripts/mistral_cooldown_probe.pyandscripts/mistral_cooldown_probe.shto measure minimal cooldown delays in two modes (based on last token time and based on request start), usingcurlagainst the Mistral endpoint.Testing
./gradlew assembleDebugand the build completed successfully../gradlew testand existing tests passed../gradlew checkand no new lint errors were reported; the new probe scripts were added but not executed in CI.Codex Task