I think I found the cause.
Somebody was too cheap to buy a proper CAT pin and cotter pin. The double nut bangs against the transmission filler when trying to stop the engine.
This was the problem. After replacing the double nutted bolt with a pin that clears both the oil filler and the right brake the diesel shuts off reliably and as a bonus it also starts more reliably because the cylinders aren't soaked with diesel during warmup.
that persuading language comes naturally working on old shit.
"i reject your reality and substitute my own" - adam savage. i suspect my final words maybe "well shit, that didnt work"
instead of perfection some times we just have to accept practicality