AI GAME GENERATOR · SCORE SETTLEMENT
Why Does One Game Round Submit Its Score Twice?
Give each round one stable ID and count its result once. Keep that ID when retrying a submission. Disable repeated clicks for clarity, and enforce one settlement per round in persistent server storage.
If your AI game generator produces a game that adds the same result twice, separate the completed round from the attempts to deliver its result. A timeout can leave the client uncertain even after a result was accepted. Duplicate event handlers can also trigger two submissions. Find which happened before changing the game rules.
A retry should not create a second result
Idempotence means that repeating an operation has the same intended effect as performing it once. It does not mean every response or log entry must be identical. MDN’s explanation of idempotence also notes that POST is not guaranteed to be idempotent. Sending a score through POST therefore does not, by itself, prevent duplicate settlement.
A three-request score ledger
I ran an isolated, sequential JavaScript model with two completed rounds and three delivery attempts. The first round, round-1842, scores 120. Its first attempt is labelled timeout_after_send to represent a lost acknowledgement; the model assumes the result already reached the accumulator. A second attempt carries exactly the same round ID and score. A new round, round-1843, scores 80.
The timeout is a scenario label, not an observed network failure. No real game, production leaderboard, competitor endpoint or player account was contacted. This model measures only how two local accumulation rules handle the recorded request sequence. It does not establish how any commercial generator implements score storage.
Count every delivery
120 + 120 + 80 = 320
The first round contributes twice.
Count each round once
120 + 0 + 80 = 200
The retry contributes no new points.
What the local comparison proves
The first accumulator adds every received score. The second keeps a Set of previously accepted round IDs, adds a score only for a new ID, and records the retry as ignored_duplicate. Both accept the new round. The saved request and result logs show each running total, making the extra 120 points traceable to one specific delivery.
This Set is a teaching device. It is lost when the process restarts and does not coordinate multiple servers. The experiment has no simultaneous requests, database failures or crash recovery. Calling it a complete production fix would go beyond the evidence. Its useful result is narrower: round identity separates a retry from a genuinely new round in this sequence.
Define the identity before asking for a patch
Assign the round ID when a round begins, then retain it with that round’s pending result. A retry must reuse the existing identity. Generating a new ID every time the submit button is pressed defeats this rule: the receiver sees apparently different rounds. Starting a genuinely new round should produce a new identity.
Do not use the score itself as the identity. Two legitimate rounds can each earn 120 points. Deduplicating by score would incorrectly discard the second one. A production key also needs the correct scope, such as the authenticated player, game and server-recognized round. The receiver must validate ownership and the result; a client-supplied ID is not proof that points were earned.
Store acceptance and its effect together
For a real service, make recording acceptance and applying the score one atomic operation. If the service records the ID first but crashes before applying the score, a later retry could be discarded without awarding points. If it awards points first but crashes before recording the ID, a retry could award them again. Persistent storage and a transaction or equivalent atomic design address this gap.
Store enough outcome information to answer a duplicate retry without adding another score. If the same scoped round ID arrives with a conflicting result, flag the conflict instead of silently treating different data as equivalent. Define how long accepted identities remain available; a short retention window can reopen duplicates after the record expires. These are design requirements, not behaviors exercised by the small model above.
A focused prompt for your AI game generator
Work in a copy of my project. Preserve controls, artwork and score rules. Trace the round-complete handler and score submission path. Separate round identity from request attempts. Reuse one round ID for retries; create a new ID only for a new round. In an isolated local test, deliver a 120-point round twice and a distinct 80-point round once. Show the request ledger and verify a total of 200. Explain how production storage makes settlement atomic and persistent, and list any untested restart or concurrency behavior. Do not send test scores to the public leaderboard.
Keep the before-and-after logs with the patched build. A disabled button improves feedback, but the acceptance rule belongs where the score is stored. After the basic local case passes, plan separate staging checks for simultaneous arrivals and restart recovery. Report those checks only when they have actually run; this article has not run them.
Where a database constraint helps
PostgreSQL’s constraint documentation describes uniqueness across a combination of columns. Such a constraint can enforce a scoped round identity, but a constraint alone is not the entire settlement workflow. Choose appropriate non-null identity fields and include the score effect in the same atomic operation.
Duplicate-score questions
Can I fix this by disabling the submit button?
That can reduce accidental clicks. It does not settle uncertain retries, duplicate handlers or concurrent arrivals at storage. Keep a visible pending state and enforce acceptance once at the receiver.
What if the acknowledgement never arrives?
Keep the pending round identity. Query its status or retry using that same identity according to your service’s contract. Do not assume a timeout means nothing was saved.
Is this the same as preventing cheating?
No. Accepting a round once and validating whether its score is legitimate are separate responsibilities. Both may be needed.