Feature/idempotent session sync - #3
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Resolve the API contract mismatch and add coverage for partial or empty acknowledgements.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds deterministic client session IDs and acknowledgement handling for idempotent session uploads.
Changes:
- Renames the upload identifier to
clientSessionId. - Marks sessions sent based on accepted server IDs.
- Updates the API DTOs and synchronization tests.
The API response currently conflicts with the documented endpoint contract (critical, 3 votes), and partial or empty acknowledgements lack test coverage (critical, 2 votes).
File summaries
| File | Summary |
|---|---|
app/src/main/java/com/harshit/crossdevicetracker/SessionUploadMapper.kt |
Maps local IDs to client session IDs. |
app/src/main/java/com/harshit/crossdevicetracker/SessionUploadDto.kt |
Defines the client session ID field. |
app/src/main/java/com/harshit/crossdevicetracker/SessionSyncService.kt |
Processes accepted sessions; needs partial/empty acknowledgement tests. |
app/src/main/java/com/harshit/crossdevicetracker/SessionApi.kt |
Uses the acknowledgement response type, which conflicts with the documented endpoint contract. |
app/src/main/java/com/harshit/crossdevicetracker/AcceptedTimeLogsResponse.kt |
Defines the acknowledgement response model. |
app/src/androidTest/java/com/harshit/crossdevicetracker/SessionSyncServiceTest.kt |
Updates synchronization tests and fake API responses. |
Review details
Suppressed comments (1)
app/src/main/java/com/harshit/crossdevicetracker/SessionSyncService.kt:40
- A 2xx response with no body or an empty acknowledgement is treated as a permanent failure for every session in the batch.
markSessionFailedremoves records fromgetPendingSessions()(the query only selectsPENDING), so a missing acknowledgement does not leave these sessions retryable even though it does not prove that the server rejected them. Keep them pending and stop/report a protocol error, or only mark sessions failed when the server explicitly identifies rejected IDs.
if (acceptedIdSet == null || acceptedPendingCount == 0) {
val errMsg = "Successful sync response did not accept any pending session ids"
for (session in pendingSessions) {
sessionRepository.markSessionFailed(session.id, errMsg)
}
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @Header("Authorization") authToken: String, | ||
| @Body sessions: List<SessionUploadDto> | ||
| ): Response<Unit> | ||
| ): Response<AcceptedTimeLogsResponse> |
Comment on lines
+32
to
+36
| val acceptedIds = response.body()?.acceptedClientSessionIds | ||
| val acceptedIdSet = acceptedIds?.toHashSet() | ||
| val acceptedPendingCount = acceptedIdSet?.count { id -> pendingSessions.any { it.id == id } } ?: 0 | ||
|
|
||
| if (acceptedIdSet == null || acceptedPendingCount == 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.