Manage tern protocol for query.end