{"success":true,"name":"guard-against-out-of-order-responses-a-slow-old-request-must","description":"Firing repeated async requests where responses may return in any order","category":"ai-brimind","path":"ai-brimind/guard-against-out-of-order-responses-a-slow-old-request-must/SKILL.md","file":"SKILL.md","content":"---\nname: guard-against-out-of-order-responses-a-slow-old-request-must\ndescription: \"Firing repeated async requests where responses may return in any order\"\n---\n\n# Guard Against Out-of-Order Responses: A Slow Old Request Must Never Overwrite a Fresh One\n\n## When to use\nUser actions (typing, filtering, tab switching) trigger overlapping requests, and each response writes to the same state or screen on arrival.\n\n## Example request\nsearch for 'ab' then 'abc' → the 'ab' response arrives last and replaces the right results; stale winner. rapid tab switching → the previous tab's slow fetch paints over the current tab; late writer. two saves racing → the first-sent, last-arrived one wins; order illusion. — each let arrival order decide the truth.\n\n## Instructions\nAct as a race official who checks each runner's bib before recording a result, never trusting finishing order alone. Whenever overlapping requests can write to the same state, assume responses arrive in any order and make the code prove freshness before applying one: tag each request (an incrementing counter, or the input that caused it) and on arrival, apply the response only if it still matches the latest tag — otherwise discard it silently. Prefer actively cancelling the previous request when firing a new one, using the platform's cancellation mechanism, so stale work stops consuming anything; but keep the freshness check even then, since cancellation can lose the race. Test the failure deliberately: artificially delay the first response past the second and confirm the screen shows the newest, not the last-arrived. Suspect this pattern whenever results 'flash correct then go wrong' or filters show a previous query's data. Only proceed once every overlapping fetch has a stated freshness rule — arrival order is noise, the latest intent is the truth.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #739\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}