A support ticket landed on us with one sentence: "the record changed and nobody knows who did it."
We had the data. Our audit tables held every save and delete with the acting user attached. Our request logs held every call that came in. What we did not have was a way to say that this request caused those three rows.
So we did it by hand. Match on the user, narrow by timestamp, then guess. It worked for the obvious cases and fell apart exactly where it mattered: a background job running as the same service account, two tabs open, a retry. The reconstruction took an afternoon and the answer we gave was still hedged. That is the part that bothered us, because we were charging an afternoon to produce a maybe.
The fix was smaller than the investigation. We added a correlation id bound beside the ambient actor, in a module that imports nothing from the web framework: one context variable, a default of None, and a function that answers None when nothing is bound. Binding returns a token, and releasing restores whatever was there before. A background job can open its own block and name an id of its own, which is how the job path stopped being a blind spot.
Two details earned their keep.
First, the middleware binds only after the route map matches. An unaudited path never gets an id, so we are not stamping noise onto health checks.
Second, the order of release. Actor binds first, then correlation, then the view runs. On the way out, correlation is released before the actor. The request record is written while the binding is still live, so a view that raises still emits a record carrying the id of the saves it already made before it failed. Partial writes used to be the hardest thing to explain to a client. Now they are the easiest, because the half-finished request is labelled.
The audit record itself just gained a field that defaults to None and gets filled when the save and delete signals fire, and the serialized form exposes it on both record types. That last bit matters more than it sounds: the join survives being logged. You can answer the question from log aggregation without opening the database.
What changed in practice is the shape of the answer. "Who changed this" used to be an investigation. It is now a lookup: one id, and you have the request and everything it touched, including the parts that failed.
We shipped this in our open-source project model-audit, and it came directly out of years of payment and ledger work where "probably this request" is not an acceptable answer to a reconciliation question.
If you run audit trails in production, it is worth checking where you bind your correlation id, before or after the business logic can throw, and what your trail says about a request that died halfway.