A search box sometimes shows yesterday’s selection. Type “oak,” then “elm,” and the field says “elm” while the results describe oak. Reading the two success handlers rarely settles the question. Either one looks reasonable on its own. What you need to know is which one wrote to the screen last.

The “AI Sandwich” puts a human-run experiment between two conversations with an assistant. In the first, ask where to observe the application. In the second, give the assistant what actually happened and ask it to account for the result. The middle step gives you both something more useful than another guess.

First pass: design the observation

Describe the symptom and one expectation you can test. Here the expectation is that results always belong to the most recent search. Ask the assistant to identify where a request gets its identity and where the visible result changes. A log at those two boundaries tells you more than a dump of the entire application store.

Give each request an identifier. Keep the active request and the request responsible for the displayed data as separate fields. An ordered trace from a single run might look like this:

seq  event       request  active  displayed
  1  started        A       A        —
  2  started        B       B        —
  3  committed      B       B        B
  4  committed      A       B        A

Row four is a concrete failure. A response from A changed the display while B was active. If every line only said “success,” the same trace would look uneventful.

Middle: run one repeatable experiment

In a local development build, start with an empty trace. Trigger two searches with known inputs and controlled response timing. Record the request start and the state before and after each commit. Track the loading flag if the symptom involves a spinner. If missing data is plausible, record a boolean such as hasResults and distinguish an empty list from a missing payload.

One lightweight browser collector is an array on window.appLogs. Append a fresh object of primitive values at each boundary so an object mutated later cannot rewrite your view of the past. In DevTools, inspect the array before copying the JSON for analysis. Event names, sequence numbers, and per-run request labels are enough for this case. The query text, headers, and full response bodies add no evidence about ordering.

For example, start a fresh collection before each run and call this helper immediately after each observed transition. Use locally assigned labels for the request arguments. The resulting JSON preserves the sequence even when several writes happen within a single millisecond.

window.appLogs = [];
function record(event, request, active, displayed) {
    window.appLogs.push({
        seq: window.appLogs.length + 1,
        event,
        request,
        active,
        displayed
    });
}

Second pass: make the explanation predict something

Give the assistant the expectation, reproduction steps, and trace together. Ask: “Which is the first transition that violates the expectation? Which earlier event makes that transition possible? What should I see if I reverse the response order?” A useful answer points to a specific row and makes a prediction you can disprove.

Test the proposed change at the write boundary. If only the current request may commit, the late A response should still arrive, the trace should mark it as ignored, and the display should keep B. Reverse the completion order as a second test. Watch loading and error state as well as the result: a stale response that clears a spinner can still mislead the person waiting.

Turn the failing order into a repeatable regression test and remove the temporary collector. The interactive guide lets you run both orders and inspect the effect of a commit guard, one event at a time.