Support Wait command & delayed screenshots; sanitize screen-element history; Groq image payload serialization and tests#100
Conversation
There was a problem hiding this comment.
Pull Request Review Summary
This PR implements Wait command support, delayed screenshots, screen element history sanitization, and Groq serialization fixes. The changes are well-structured overall with good test coverage.
Critical Issues Found
- Integer overflow risk in Wait command delay calculation that could cause negative delays
Changes Reviewed
- ✅ Wait command implementation and parsing
- ✅ Delayed screenshot execution with cancellation support
- ✅ Groq API client serialization improvements with proper polymorphic types
- ✅ Unit test coverage for new functionality
- ✅ Gradle configuration for unit tests
The implementation correctly handles delayed screenshots, command queue integration, and cleanup. Please address the overflow 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.
| pendingScreenshotDelayMillis = command.seconds | ||
| .coerceAtLeast(0L) | ||
| .coerceAtMost(Long.MAX_VALUE / 1000L) * 1000L |
There was a problem hiding this comment.
🛑 Logic Error: Integer overflow risk when multiplying seconds by 1000. If command.seconds equals Long.MAX_VALUE / 1000L (9223372036854775), multiplying by 1000 causes overflow to negative value. The coerceAtMost check happens before multiplication, allowing the overflow.
| pendingScreenshotDelayMillis = command.seconds | |
| .coerceAtLeast(0L) | |
| .coerceAtMost(Long.MAX_VALUE / 1000L) * 1000L | |
| pendingScreenshotDelayMillis = command.seconds | |
| .coerceAtLeast(0L) | |
| .coerceAtMost(Long.MAX_VALUE / 1000L - 1L) * 1000L |
Motivation
Description
Waitcommand (Command.Wait) and parsing support inCommandParserwith aWait(n)pattern, and updated the UI to display wait commands viaPhotoReasoningScreen.ScreenOperatorAccessibilityServicewithpendingScreenshotDelayMillis,pendingDelayedScreenshotRunnable,executeTakeScreenshotCommand()andcancelPendingDelayedScreenshot(), and ensuredclearCommandQueue()cancels pending delayed screenshots.PhotoReasoningScreenElementHistoryPolicyto sanitize chat messages by keeping only the latest relevantScreen elements:sections and replacing older ones with a "no longer relevant" marker, then wired it into multiple places inPhotoReasoningViewModel,PhotoReasoningHistoryBuilder,PhotoReasoningMessageMutations, and chat persistence logic.ScreenCaptureApiClients.ktby addingServiceGroqRequest,ServiceGroqMessage, and polymorphic sealedServiceGroqContenttypes (ServiceGroqTextContent,ServiceGroqImageContent) whereimage_urlis serialized as an object containingurl.testOptions.unitTests.isReturnDefaultValues = trueinapp/build.gradle.kts.CommandParserTestnow includes aWaitparsing test,PhotoReasoningScreenElementHistoryPolicyTestto validate sanitization behavior, andScreenCaptureApiClientsTestto verify Groq request JSON shape.Testing
app/src/test:CommandParserTest,PhotoReasoningScreenElementHistoryPolicyTest, andScreenCaptureApiClientsTestwhich exercisedWaitparsing, history sanitization, and Groq serialization respectively, and all tests passed.ScreenOperatorAccessibilityServiceduring unit/integration checks and did not regress existing command execution paths.Codex Task