- Write the four-event race and predict the visible result after each event.
- Verify that a generation check rejects the old completion.
- Test an input edit during pending work and keep stale copy/download actions disabled.
A slow AI or search response can arrive after a newer request and overwrite the result the user actually wants. A loading spinner alone does not prevent this race. Model the order of requests and completions explicitly before asking an assistant to implement the interface.
Draw request order and completion order separately
In the fixture, a user requests a summary of documentA and then switches to documentB. RequestB completes first; requestA completes later. The correct screen still shows B. Write this sequence as four events so the race is visible without a live provider. A response being successful says nothing about whether it still belongs to the current interface state. Record the document identifier and request generation alongside the pending work.
Guard the state commit
Assign a monotonically increasing request generation when starting or invalidating work. Before committing a result, compare the response’s generation with the current one. An AbortController can reduce unnecessary work where the underlying API supports cancellation, but cancellation alone is not a universal correctness guarantee: a completion may already be queued or a provider may still process the request. Keep the generation guard even when the interface offers a cancel button and explain both responsibilities in the code review.
Test races without waiting for real timing
Use controlled promises or a deterministic event fixture to complete the second request before the first. Assert that the older response cannot replace the newer result or enable copy/download for stale data. Also test input edits during a pending request and an unmount or navigation event. Ask AI to identify another transition that invalidates the result, then check it manually. Do not interpret a cancelled client request as proof that a remote provider incurred no work or cost.
Fictional worked example — Completion race
Supplied input
Start A(g1), start B(g2), finish B(g2), finish A(g1)
Example result to inspect
Visible result=B; generation g1 completion discarded
The generation comparison governs state commitment even when remote cancellation is incomplete.
This is an authored teaching example, not a recorded live provider run or an independent performance test.
Make the idea concrete.
- Write the four-event race and predict the visible result after each event.
- Verify that a generation check rejects the old completion.
- Test an input edit during pending work and keep stale copy/download actions disabled.
What a useful outcome looks like
Only the response associated with current intent should commit state; completion order alone is insufficient.
Ask for reasoning you can verify.
Use fictional or permitted data. This is a copyable brief for a separate approved model; no model is called from this article.
Help me review this fictional coding with ai exercise: Use request identity and cancellation to preserve the latest user intent. I will supply the original input, my expected result and the actual transformation. Explain generation match, identify unsupported assumptions about remote cancellation limits, and propose one bounded negative control. Keep observations separate from hypotheses; do not invent output or act on external systems.
Turn reading into a reviewed checkpoint.
Complete the manual exercise, review each item, then answer the evidence question. This records self-study, not independent assessment of expertise.
Review the checklist and pass the question to save this lesson.
Primary references
References support further checking; cited organizations do not endorse AgentX. This guide is original AI-assisted educational content with illustrative examples. Read the editorial policy or report a correction.
Continue with a related task.
Read the contract before asking for code
Map callers, inputs and invariants before requesting a change.
Request a minimal diff with explicit exclusions
Keep an AI-assisted patch focused enough to review and revert.
Test the requirement rather than the generated implementation
Use independent examples to challenge an AI-written function.