Agents reference gateways but the migration was missing, causing ensure_main_agent() to fail on INSERT with UndefinedColumn error.