For those wondering, we didn’t die mostly due to a well-placed Disintegrate. My “stick an immovable rod in its innards” was disappointingly low damage.
For those wondering otherwise, our best plan involved turning it into a regular worm, using an immovable rod with a hole drilled through the length of the staff, clicking the rod, then dispelling polymorph.
Given that they’re immune, you may as well always keep them poisoned, just in case.