Skip to content

Introduce MistralRequestCoordinator and queued auto-screenshot handling#72

Closed
Android-PowerUser wants to merge 4 commits intofix-compilation-errors-in-mainactivity.kt-h8jilxfrom
tackle-mistral-ai-rate-limit-issue-wst5gm
Closed

Introduce MistralRequestCoordinator and queued auto-screenshot handling#72
Android-PowerUser wants to merge 4 commits intofix-compilation-errors-in-mainactivity.kt-h8jilxfrom
tackle-mistral-ai-rate-limit-issue-wst5gm

Conversation

@Android-PowerUser
Copy link
Copy Markdown
Owner

Motivation

  • Centralize and harden Mistral API request coordination and retry/cooldown logic to replace duplicated ad-hoc implementations.
  • Prevent excessive parallel Mistral requests from auto-screenshot flow by serializing and queueing screenshot-triggered calls.

Description

  • Add a new coordinator network/MistralRequestCoordinator.kt that encapsulates key cooldowns, adaptive retries, parsing of Retry-After and x-ratelimit-reset headers, and selection of API keys via execute(...) returning MistralCoordinatedResponse.
  • Replace custom request/retry/cooldown code in ScreenCaptureApiClients.callMistralApi to use MistralRequestCoordinator.execute(...) when executing HTTP calls.
  • Replace the large ad-hoc Mistral retry and key-cooldown loop in PhotoReasoningViewModel.reason(...) with a call to MistralRequestCoordinator.execute(...) and remove redundant key bookkeeping logic.
  • Add queuing for auto screenshot-triggered Mistral requests in PhotoReasoningViewModel by introducing QueuedMistralScreenshotRequest, enqueueMistralAutoScreenshotRequest, dispatchMistralAutoScreenshotRequest, and releaseAndDrainMistralAutoScreenshotQueue to ensure only one in-flight Mistral auto-request and latest-wins queuing.
  • Wire the queue drain to the existing finally block so queued screenshot requests are drained after each Mistral call completes.

Testing

  • Built the app and run unit tests with ./gradlew assembleDebug and ./gradlew test, and the build and unit tests completed successfully.
  • Manually exercised the Mistral call paths in debug runs to validate coordinator selection and that auto-screenshot requests are queued and subsequently dispatched (no automated UI tests were added).

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

The PR successfully introduces MistralRequestCoordinator to centralize Mistral API request coordination with adaptive retry logic and cooldown management. The queuing mechanism for auto-screenshot requests prevents excessive parallel requests. The implementation is clean and well-structured.

Key Changes:

  • ✅ New MistralRequestCoordinator encapsulates cooldowns, retry logic, and header parsing
  • ✅ Replaced ad-hoc retry logic in both ScreenCaptureApiClients and PhotoReasoningViewModel
  • ✅ Added queuing for auto-screenshot-triggered Mistral requests with latest-wins strategy
  • ✅ Proper integration with finally blocks for queue draining

The changes are well-implemented and ready for merge. No blocking issues found.


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.

@Android-PowerUser Android-PowerUser deleted the tackle-mistral-ai-rate-limit-issue-wst5gm branch April 9, 2026 11:12
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