Repository navigation
Budget notification fan-out per person - #350
Conversation
- Each notification enqueued a web push per device (up to 10) plus adapter delivery on the shared worker, with no per-actor bound. - Notifications::FanoutBudget allows 300 outside deliveries per person per 10 minutes; past that, notifications stay inbox-only. - Agent comments are charged to the person behind them, so new session tokens don't reset it. Mentions are charged too.
HamptonMakes
left a comment
There was a problem hiding this comment.
This sort of thing needs to have sensible defaults- but should be configurable at the host level.
|
🤖 I reproduced two implementation issues on e0285e8, in addition to Hampton's request for host-configurable defaults:
Hampton asked me to fix these and push an update here for review. I'll add host configuration, serialize accounting safely, and ensure cache failures cannot interrupt inbox creation. I'll preserve this PR's existing inbox-only overflow behavior; changing delivery policy or isolating queues would be separate work. |
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
|
🤖 Fixed in e4d1fb3 and pushed for Hampton's review.
Validation: 146 focused specs passed, full RuboCop passed, and an isolated MySQL/Solid Cache concurrency tryout admitted exactly six of twelve offered deliveries with a limit of six. The follow-up review found no blocking findings. All 15 checks pass on e4d1fb3, including MySQL/PostgreSQL and browser/stress suites: https://github.com/block/coplan/actions/runs/45468956157 GitHub reports no merge conflict. Hampton's requested-changes review remains in place for re-review; this has not been approved or merged. |
What changed and why
Nothing limits how much outside delivery one person's comments can start. Each notification enqueues one web push job per recipient device (up to 10) and one adapter delivery (the Slack DM). Push jobs can wait 5 s and retry 5 times. Production runs every queue on one 3-thread worker, so a person, or an agent posting as them, can bury the summaries, provenance and notification jobs behind their own pushes.
Now
Notifications::FanoutBudgetdefaults to 300 initial external delivery jobs per person per fixed 10-minute window. Hosts can setnotification_fanout_limitandnotification_fanout_window, or disable the budget with anillimit. Each notification costs one per push device, plus one if a delivery adapter is installed. Past the budget:An agent's comment is charged to the person behind it (
author_id), so minting new session tokens doesn't reset the budget. Mentions are charged the same way. Review notifications are exempt from this budget.The budget covers the engine's delivery adapters, which is how
coplan-squaresends Slack DMs (Coplan::Slack). This repo's demo host still sends DMs through its ownSlackNotificationJob. That path is debounced to one DM per thread per window and isn't budgeted.The default allows a comment that mentions 20 people with several devices each. Hosts can choose a limit and window suited to their deployment; use the same settings in web and worker processes.
Accounting uses ordinary
Rails.cachereads and writes under a lock on the existing person row. Each reservation uses a fresh request-local cache to avoid stale reads. Rejected deliveries do not consume unused capacity. Cache and lock failures allow delivery and log a warning, so accounting cannot interrupt inbox creation. A null store bypasses the budget. Multi-process hosts need a shared, consistently readable cache; eviction or outages can relax this best-effort limit. No new tables or dependencies are required.Found in the Coplan STPA review (finding comments-notify-7): https://coplan.sqprod.co/dgrochowski/reliability-analyses/coplan-stamp-stpa-analysis-service-review
Evidence
spec/services/coplan/notifications/fanout_budget_spec.rb, with the host limit configured to 6 and a recipient with 3 devices:A local MySQL/Solid Cache tryout offered four concurrent 3-delivery reservations with a limit of 6: exactly two were admitted and two refused, with no cache errors. Disabling the budget allowed delivery, and the next window admitted new work.
How to try it
With an existing user (for example, from the demo seed), this prints
{true=>300, false=>1}. It does not send notifications.Testing
spec/models/coplan/notification_spec.rbpass unchanged.bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb": 2,928 examples, 0 failures. System specs can't start Chrome locally, so CI covers them.Maintenance validation: 146 focused notification/configuration/agent-instruction specs passed, full RuboCop passed, and all 15 checks passed on
e4d1fb3a. CI run.Generated with Codex.