The answer is no, there is no automatic way to handle that in OptiX
You either need to gather all hits inside the anyhit program like before and then sort them in the raygeneration program or march along the ray direction in order using closesthit programs in an iterative fashion like a path tracer.
See some previous discussion about related topics. Basically read all my replies in these threads and all their links:
[url]distinguish objects when closest hit program occured - OptiX - NVIDIA Developer Forums
If you have coplanar faces which are not distinguishable by front/back facing side like in the last link of the above post, then you would need to implement some sort of instance ID plus primitive ID check which would allow to shoot a ray without epsilon offset and ignore the self-intersection. That’s obviously a little more expensive.
Since for CSG and coplanar faces you really need to find both hits in order which is not possible with a single ray using closest hit approach (you get only one hit and that might not be the volume you’re currently in), the anyhit gathering sounds more feasible.
Ways to identify geometry instances:
[url]https://devtalk.nvidia.com/default/topic/1025193/optix/pick-ray/post/5328261/#5328261[/url]
More robust self intersection avoidance idea:
[url]https://devtalk.nvidia.com/default/topic/913414/optix/how-can-optix-solve-the-problem-of-z-fighting-/post/4792621/#4792621[/url]