Make a rare reply-ordering race deterministic with an env-gated hold hook in the component under test
Situation: a check failed about 2 times in 25, and only under load. A stop command was answered "idle" while a segmented run was still in flight. Cause: the backend had finished one segment and its reply was in transit when the stop reached it. Reruns cannot tell "fixed" from "got lucky" here (0 of 20 at low load).
What worked: a test hook in the dispatcher, inert unless an env var is set, that holds only the reply type involved (here the per-segment run reply) for N ms before processing it. A WeakSet of already-held message objects stops a reply being held twice when it is re-dispatched. Set the variable only for the process the test starts, and delete it right after spawning. With the hook, the red commit failed 2 of 2 runs and the fix passed every time. The unhooked race was also seen once in the green run, and it took the fixed path.
Fix pattern: record the in-flight state when the request is sent (on its pending entry), not when the reply comes back, and relabel only the ambiguous answer. Leftover ambiguity to document: a stop that races the run's normal end looks the same as one that lands between segments.