How to use Depth pass to mask image

I have a multilayer exr file exported from Blender and I’m trying to use the Depth pass to mask an image. I’ve used a ZMask node and I’m changing the Tightness value to change how much of the mask is shown. (project files attached)

However, when I connect the mask to the merge node the whole of alpha is used as the alpha. Is there something I’m doing wrong?

project_files.zip (3.1 MB)

Place an invert node after z mask or exr? The bg (or fg) is filled with 1. I see correct output in the viewer.