Fix _logId() collision via per-instance counter in SyncRepository#7
Fix _logId() collision via per-instance counter in SyncRepository#7Copilot wants to merge 2 commits into
_logId() collision via per-instance counter in SyncRepository#7Conversation
Co-authored-by: Harsh4114 <71206223+Harsh4114@users.noreply.github.com>
_logId() collision via per-instance counter in SyncRepository
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR updates the bloc-like SyncRepository log ID generation to avoid collisions when multiple SyncLog entries are created within the same microsecond, aligning the approach with SyncManager’s timestamp + counter pattern.
Changes:
- Add a per-instance
_logCounterand append it to_logId()to ensure uniqueSyncLog.idvalues during rapid log creation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String _logId() { | ||
| final micros = DateTime.now().microsecondsSinceEpoch; | ||
| return 'sync_log_$micros'; | ||
| _logCounter += 1; | ||
| return 'sync_log_${DateTime.now().microsecondsSinceEpoch}_$_logCounter'; | ||
| } |
There was a problem hiding this comment.
Add a regression test covering the collision scenario this change fixes (multiple log entries created within the same microsecond). For example, create many logs in a tight loop (or stub DateTime) and assert all generated SyncLog.id values are unique and that markSyncing/markSynced updates the intended log rather than the first match.
_logId()relied solely onmicrosecondsSinceEpoch, making collisions possible when multiple log entries are created within the same microsecond (tight loops, tests, rapid sequential ops).Changes
SyncRepository: Added_logCounterfield and updated_logId()to append it to the timestamp, mirroring the pattern already used bySyncManager._generateOpId()💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.