Operator bpy.ops.rigidbody.object_add.poll() failed, context is incorrect
Just in case this is useful for somebody in the future, here's what seems to work for me:

import bpy
from bpy.app.handlers import persistent  

@persistent
def load_handler(dummy):
  obj = bpy.data.objects['obj']
  obj = C.scene.objects.active
  obj.select = True
  bpy.ops.rigidbody.object_add()
  obj.rigid_body.type = 'PASSIVE'

bpy.app.handlers.load_post.append(load_handler)
bpy.ops.wm.open_mainfile(filepath=task_path+ str(x) +".blend")