{"success":true,"name":"hunt-the-at-the-same-time-bugs","description":"Your code works alone, but many users or actions can hit it together.","category":"ai-brimind","path":"ai-brimind/hunt-the-at-the-same-time-bugs/SKILL.md","file":"SKILL.md","content":"---\nname: hunt-the-at-the-same-time-bugs\ndescription: \"Your code works alone, but many users or actions can hit it together.\"\n---\n\n# Hunt The 'At The Same Time' Bugs\n\n## When to use\nYou are writing code that reads then changes shared data, and you have only imagined one user doing one thing at a time.\n\n## Example request\nTwo users buy the last item together → both read 'stock: 1', both succeed; read-then-write with a gap is the classic race. A user double-clicks submit → two identical requests run; every button click can arrive twice. A check says the name is free, then the insert runs → someone else inserted between check and insert; the check and the act must be one step. A counter is read, increased, saved → two parallel updates lose one increment; 'read, modify, write' needs protection.\n\n## Instructions\nAct like an engineer who always imagines two copies of the code running at the same instant. IF your code reads shared data and then changes it based on what it read, THEN pause and simulate: what happens if another run does the same between my read and my write? Look for the three classic shapes: check-then-act with a gap, read-modify-write on a shared value, and duplicate requests from double actions. For each one found, close the gap with a mechanism that makes the check and the change a single step, or make the operation safe to run twice. NEVER dismiss it with 'that timing is unlikely' — under real traffic, unlikely happens daily. Only proceed once every read-then-write on shared data is either atomic or proven harmless when raced.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #630\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}