Skip to content

docs(server): document star count lost-update race in PatchStarCount (REL-04) - #2368

Open
wilfredmulenga wants to merge 2 commits into
mainfrom
rel-04-note-star-toggle-race
Open

docs(server): document star count lost-update race in PatchStarCount (REL-04)#2368
wilfredmulenga wants to merge 2 commits into
mainfrom
rel-04-note-star-toggle-race

Conversation

@wilfredmulenga

Copy link
Copy Markdown
Contributor

Summary

A compliance scan (issue #96) flagged REL-04: PatchStarCount in server/internal/adapter/internalapi/server.go reads starredBy and starCount, mutates them in memory, then writes the whole thing back. Nothing covers this span with a transaction, and there is no optimistic lock or atomic update such as $addToSet or $inc. If two users star or unstar the same project at nearly the same instant, the second write can overwrite the first, so one user's star can disappear while starCount stays out of sync.

Decision

Rather than switching to an atomic update right now, this change adds a comment at the write call documenting the race for anyone reading this code later. The reasoning is that it is unlikely in practice for two different users to star the exact same project within the same narrow window at the same time, so the risk is judged low relative to the cost of reworking this path.

This is a comment-only change. No behavior changes.

Test plan

  • Ran go build ./... from server/ to confirm the code still compiles.
  • No functional change, so no new tests were added.

Compliance scan issue #96 flagged REL-04: PatchStarCount reads
starredBy/starCount, mutates them in memory, then writes the result
back with no transaction and no atomic update. Two near simultaneous
stars or unstars on the same project could let one write silently
overwrite the other.

Adding a comment instead of an atomic fix for now, since it is
unlikely in practice for two different users to star the exact same
project within the same narrow race window at the same time.
Copilot AI lite review requested due to automatic review settings August 5, 2026 21:01
@github-actions github-actions Bot added the server label Aug 5, 2026

Copilot AI left a comment

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.

Pull request overview

This PR documents a known lost-update race in PatchStarCount where starredBy/starCount are read, mutated in memory, and then written back without an atomic update across concurrent requests.

Changes:

  • Added an inline NOTE comment warning about the read-modify-write lost-update risk at the UpdateProjectMetadataByAnyUser call site.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/internal/adapter/internalapi/server.go Outdated
@wilfredmulenga wilfredmulenga changed the title Document star count lost-update race in PatchStarCount docs(server): document star count lost-update race in PatchStarCount Aug 5, 2026
…mment

Copilot review on #2368 flagged that "compliance scan issue #96" reads as
a reearth-visualizer issue reference, but #96 in this repo is unrelated
(Google Sheets import). Reword to avoid the confusion.
@wilfredmulenga wilfredmulenga changed the title docs(server): document star count lost-update race in PatchStarCount docs(server): document star count lost-update race in PatchStarCount (REL-04) Aug 17, 2026
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.

2 participants