Skip to content

Increase Mistral cooldown, make retry handling configurable, and add cooldown probe scripts#68

Merged
Android-PowerUser merged 1 commit intocodex/analyze-technical-debt-and-complexity-o6bm9pfrom
fix-compilation-errors-in-mainactivity.kt
Mar 31, 2026
Merged

Increase Mistral cooldown, make retry handling configurable, and add cooldown probe scripts#68
Android-PowerUser merged 1 commit intocodex/analyze-technical-debt-and-complexity-o6bm9pfrom
fix-compilation-errors-in-mainactivity.kt

Conversation

@Android-PowerUser
Copy link
Copy Markdown
Owner

Motivation

  • Increase the enforced minimum interval between Mistral requests after observing that 1.1s was insufficient.
  • Remove hardcoded retry limits in favor of using the configured maxAttempts to avoid inconsistent retry behavior.
  • Ensure streaming/command execution can be restarted cleanly by resetting the stop flag when starting reason().
  • Add tooling to empirically probe Mistral cooldown behavior to determine safe inter-request delays.

Description

  • Bumped the Mistral per-key minimum interval constant from 1100L to 1500L (MISTRAL_MIN_INTERVAL_MS).
  • Replaced hardcoded retry/failure checks that assumed 5 attempts with logic that uses the configured maxAttempts and updated the related IOException and user-facing retry messages to reference the actual maxAttempts value.
  • Reset stopExecutionFlag at the start of reason() via stopExecutionFlag.set(false) to allow fresh runs after prior aborts.
  • Updated streaming/error handling messaging and added a safety Log.w when selectedKeyForResponse is null during streaming callbacks.
  • Added scripts/mistral_cooldown_probe.py and a wrapper scripts/mistral_cooldown_probe.sh to probe Mistral cooldown behavior using curl in both streaming and non-streaming modes.

Testing

  • Ran the Android build with ./gradlew assembleDebug and the unit tests with ./gradlew test, both of which completed successfully.
  • Linted and executed the new probe script locally to validate it runs (scripts/mistral_cooldown_probe.sh), and it produced delay measurements (script run is included as an auxiliary diagnostic tool).

Codex Task

Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR increases the Mistral API cooldown interval and makes retry handling configurable, which are positive improvements to API reliability. However, there is a critical security issue that must be resolved before merge.

Critical Issue (Blocks Merge)

  • Security: Hardcoded API key in mistral_cooldown_probe.py must be removed and replaced with environment variable

Changes Reviewed

  • ✅ Increased Mistral cooldown from 1.1s to 1.5s - appropriate adjustment based on observed behavior
  • ✅ Fixed hardcoded retry limits to use configured maxAttempts - improves consistency
  • ✅ Reset stopExecutionFlag at start of reason() - correctly enables clean restarts
  • ⚠️ New probe scripts added - useful for diagnostics but contain security vulnerability

Please address the security issue before merging.


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"
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.

🛑 Security Vulnerability: Remove hardcoded API key before merge. Hardcoded credentials in source code create security risks and can lead to unauthorized access if the repository is compromised1.

Replace with environment variable or configuration file that's excluded from version control.

MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY", "")

Footnotes

  1. CWE-798: Use of Hard-coded Credentials - https://cwe.mitre.org/data/definitions/798.html

@Android-PowerUser Android-PowerUser merged commit 606b1e2 into codex/analyze-technical-debt-and-complexity-o6bm9p Mar 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant