// Note that if the caller didn't give us either an install ID or an agent name, we still persist the entity
// with the expectation that the new ID will be used later by a new agent (new agent will register with this new ID and
// will tell us what agent name it wants to use).
AgentInstall existing = getAgentInstallByAgentName(user, agentInstall.getAgentName());
if (existing != null) {
existing.overlay(agentInstall); // note: "existing" is detached
agentInstall = entityManager.merge(existing);
} else {
entityManager.persist(agentInstall);
}
} else {