unregisterAgent()/terminateAgent() removed an agent from state/topology/bus/consensus but left it in AgentPool and agentDomainMap. A later assignTaskToDomain() could return that removed id, while getAgent() was undefined and its task_complete was dropped. Detach from the domain pool before cancellation so release cannot hand the agent new work, and stop deleting agentDomainMap before unregisterAgent().