core: Set z_pid cookie only when set_persistent is used. Fixes #701