UsageEvents::DumpWriteBufferCronWorker throws ActiveRecord::InvalidForeignKey when namespace was deleted

Summary

When Ai::UsageEvent was registered but namespace got deleted shortly after buffer worker throws an error

PG::ForeignKeyViolation: ERROR:  insert or update on table "ai_usage_events_202508" violates foreign key constraint "fk_rails_1a85bb845c"
DETAIL:  Key (namespace_id)=(xxxx) is not present in table "namespaces"

Logs: https://log.gprd.gitlab.net/app/r/s/1QhMy

Proposal

Events with invalid namespace_id should be properly filtered out.

Edited by 🤖 GitLab Bot 🤖