I'm not sure if this should be wrapped in a call into session_btree.c. It's probably a layering violation, and definitely ugly.