Getting Brethreign ready for launch: one deleted account broke my inbox
A deleted test account left a chat with nobody in it, and the inbox crashed. I heard about it from a person, not a tool. The fix took minutes; the safety net I built that evening uses only Rails: crash alerts, a self-checking robot and a test for the people who leave.

I'm preparing Brethreign, a safe social network for Christians, for its public release and a mass invite to churches and communities. Once it opens up, I'm hoping to sustain it through member donations, grants from Christian foundations and investment. More people are already joining every week, and today I resized the server to make room for them.
On the same day, the Brethreign inbox stopped opening. I didn't learn it from a dashboard or an alert. Someone told me.
That is the wrong way round for an app about to invite a crowd. This post covers the bug, the fix, and the safety net I built that evening so the next broken page reaches me before it reaches a member.
The error
The server log showed the same exception on every request to /inbox:
ActionView::Template::Error (undefined method 'visible_online?' for nil)
app/views/conversations/_conversation_row.html.erb:16
Each row in the inbox finds "the other person" in a two-person chat:
def other_participant_for(user)
participants.map(&:user).detect { |participant| participant.id != user.id }
end
The view then calls other_user.visible_online? to draw the green online dot.
The nil came from account deletion. I had created a test account so Apple's reviewers could try the iPhone app, and deleted it once the review recording was done. User declares has_many :conversation_participants, dependent: :destroy, so deleting the account removed it from every chat, but the chats themselves stayed. Its welcome chat was left with one participant, detect found nobody, and the whole inbox page raised a 500 for everyone in that chat.
The fix
The fix had three parts:
- Make the lookup tolerate missing users.
participants.map(&:user).compact.detect { ... }, so a participant row without a user can't blow up either. - Render the absence. In the inbox row, a nil other user now draws a neutral avatar and the name "Deleted account", the way WhatsApp handles it. The chat page shows "This member deleted their account" instead of crashing, and search results and page titles use safe navigation (
other_user&.display_name). - Pin it with a test. An integration test creates a chat, deletes one side's participant record, then asserts that the inbox returns 200 and shows the "Deleted account" row, and that the chat itself still opens.
The full suite passed and the fix shipped through a pull request and a Hatchbox deploy. The new release started at 17:18:06 UTC (18:18 in Lagos). I then counted 500s in the log since that exact timestamp: zero.
Layer 1: alert me the moment a page crashes
I didn't want a new paid service before launch, so I built on what Rails already gives me. Every controller action publishes a process_action.action_controller event, and when the action raises, the payload carries the exception. One subscriber catches the ones that become a 500:
ActiveSupport::Notifications.subscribe("process_action.action_controller") do |event|
error = event.payload[:exception_object]
next unless error
next if ActionDispatch::ExceptionWrapper.status_code_for_exception(error.class.name) < 500
where = Array(error.backtrace).find { |line| line.include?("/app/") }
ErrorAlert.notify(key: "#{error.class}|#{where}", title: "#{path} is crashing", detail: ...)
end
The hard part of alerting is not the first alert, it's the thousandth. A broken inbox with 50 members open would send 50 emails a minute. ErrorAlert groups errors by class plus the first line of my own code in the backtrace, and uses the cache as a gate:
count = Rails.cache.increment(count_key, 1, expires_in: 1.day)
return unless Rails.cache.write(sent_key, true, unless_exist: true, expires_in: 15.minutes)
The first occurrence in a 15-minute window wins the unless_exist write and sends. The rest just increment a counter, and the next alert reports how many times it happened. Sending happens in a Solid Queue job, so a slow mail server never slows the request that failed. The job emails every admin and sends a push notification to their phones through the same Apple and Google push pipeline members use.
Layer 2: a robot that uses the app like a member
Crash alerts only fire when a real member hits the broken page. I wanted to find it first. So the app now checks itself.
SiteHealthCheck opens an ActionDispatch::Integration::Session against Rails.application, the same machinery Rails tests use, but running inside production. It goes through routing, middleware, authentication, controllers and views exactly as a browser request would.
- Sign in for real. It fetches the sign-in page, reads the CSRF token from the form, and posts the credentials of a hidden monitor account. The monitor's password is replaced with a fresh random one on every run, so there is no long-lived secret to leak.
- Open 16 pages. Feed, following, trending, updates, inbox, new message, notifications, games, rooms, prayer circles, the composer, its own profile and settings. It also opens the newest approved post, that post's author and the busiest public room, so broken content gets caught as well as broken code.
- Judge each one. A 5xx is a failure. So is a redirect to the sign-in page, which would mean members were being logged out.
- Alert through layer 1. Failures go to
ErrorAlertwith a key built from the failing paths, so a page that stays broken alerts every 15 minutes, not every run.
It runs as a Solid Queue recurring task every 10 minutes, and an initializer schedules one run 90 seconds after the app boots, which means after every deploy. The monitor account is excluded from the User.active scope, so it never appears in member lists, and it skips the join announcement and welcome message.
The first run on production opened all 16 pages without a failure.
Layer 3: test the people who leave
The bug class here is "something points at a user who no longer exists". Most tests only create data. Few delete a user and then look around.
So I wrote one that does. It creates two members and has one of them do everything a member does to another: send chat messages, comment on a post, react, follow and be followed, and trigger notifications. Then it deletes that member and, signed in as the one who stayed, opens the feed, following feed, inbox, the old chat, notifications, their own profile, the post and the room. Any 5xx fails the test and names the page.
I run it with the full suite before every merge. With it, the suite went from 652 to 657 tests (now 666 with later work), all passing.
Limits, and what's next
This setup has blind spots, and I'd rather name them:
- The health check runs inside the app. It proves Rails can render the pages. It can't see a problem in Caddy, Cloudflare, DNS or TLS, or the server being down entirely. If the server dies, the thing that would alert me dies with it. An external uptime monitor that loads the site from outside is the next piece.
- Alerts are only as good as their dedupe key. Grouping by error class and first app frame works well for crashes like this one. A bug that throws from many places could still produce several alerts.
- No error history. I get an email per problem, not a searchable record. A hosted error tracker such as Sentry is worth adding as traffic grows.
- Deletion is still a hard delete. The safer long-term design is to keep a tombstone ("Deleted account") everywhere a user appears, rather than relying on every view to handle a missing record.
What I learned
- If your users find your bugs first, you have no monitoring. You don't need a paid service to start. An
ActiveSupport::Notificationssubscriber and a mailer cover most of it. - Dedupe before you alert. One cache write with
unless_existturns an alert flood into one message with a count. - Check the app the way a member uses it. "The server responds" is not "the inbox opens". Sign in through the real form and load the real pages.
- Check right after every deploy. Most breakage arrives with a change. A run 90 seconds after boot catches it while the change is fresh.
- Test the people who leave. Deleted accounts, empty chats and missing photos are where pages quietly break.
- Fix the class of bug, not just the bug. The nil guard took minutes. The test that covers every page after a deletion is what makes it last.
Brethreign is about to invite a lot more people. A member should never be the one to tell me the inbox is down, and now they won't have to.
If you'd like to support Brethreign as it opens to more people, through giving, a grant or investment, I'd love to hear from you.
Comments
Keep reading
Nov 19, 2026 · 5 min · Ruby on Rails
Musings from a lean stack: Stop making every request wait for the AI
AI features held a web request open for 20 to 35 seconds, so a few people asking at once could stall everyone. Accept, work in the background, deliver: the pattern, a Rails sketch, and the details that make waiting feel fine.
Nov 19, 2026 · 4 min · Ruby on Rails
Musings from a lean stack: The timeout you borrowed is breaking a feature you forgot
A profile import failed for everyone for four days without a single crash or alert. The cause was a 12-second timeout borrowed from another feature. Caller-owned limits, dumb-but-reliable fallbacks, and alerts for polite failures.
Jul 22, 2026 · 2 min · Ruby on Rails
Beyond Rails: How to Handle Real-Time & WebSocket-Heavy Apps
ActionCable is fine. But when you need to handle 10,000+ concurrent connections, you need a different beast.
Leave a comment