[api] Ensure both IO and exit code are gathered before calling back