anantbhandarkar/make-it-right/mir-backend-beam
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (BEAM runtime tier). Erlang VM / BEAM reliability footguns shared across every BEAM-based backend (Phoenix, Nerves, Broadway, pure Erlang/OTP) — distinct from the generic backend gates and from any one framework's mechanics. Covers: let-it-crash + supervision tree design (restart strategies, max_restarts escalation, poison-message crash-loops and why a catch-all handle_info does NOT stop them), unbounded mailbox growth and real backpressure (a GenServer.call timeout does not shed load; GenStage/Broadway; OTP 28 priority messages are not backpressure), hot GenServer as a serial bottleneck and when to use ETS / :counters / :persistent_term instead, blocking handle_call timing out callers, per-process heap isolation and refc-binary retention, distributed Erlang hazards (netsplits, :global, pairwise ordering, :erpc), what Elixir's set-theoretic type checker does and does not catch, and VM-level security (binary_to_term, atom exhaustion, distribution cookie/EPMD, :os.cmd vs System.cmd, OTP TLS/term-decoding advisories, Hex supply chain). TRIGGER when the backend runtime is Elixir or Erlang — sits between mir-backend (generic) and the framework module (mir-backend-beam-phoenix). SKIP for Python, Node, Go, JVM, Rust, .NET, Ruby, PHP runtimes (each has its own mir-backend-<runtime> tier), and for Phoenix / LiveView / Ecto / Plug library mechanics — those load mir-backend-beam-phoenix, not this.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-beamSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-beam.
/mir-backend-beam · Make It Right (BEAM runtime)
The middle tier. mir-backend decides what is correct (any language). The framework module (e.g. mir-backend-beam-phoenix) knows the library's mechanics. This tier owns what's true for all BEAM backends because they run on the Erlang VM — the process model, message-passing concurrency, and fault-tolerance primitives that Phoenix, Nerves, Broadway, and plain Erlang all inherit.
Runtime assumed: Elixir 1.20 on OTP 27–29; syntax examples are Elixir, the notes hold for Erlang directly. Verified 13 Aug 2026: Elixir 1.20.3 is the current stable line (1.21 is unreleased, in development on main); OTP 29.0.5 (4 Aug 2026) is the current major, with 28.5.0.5 and 27.3.4.16 as maintained lines. Elixir 1.20 requires OTP 27+ and supports up to OTP 29; Elixir 1.19 required OTP 28.1+ to run on the OTP 28 line. If the project is on OTP 26 or older, that is a Gate 4 risk row — the July 2026 security batch below was not backported below 27.3.4.15. Load order: mir-backend → mir-backend-beam → <framework module>.
The BEAM footguns AI walks into (framework-agnostic)
1. Let-it-crash + supervision — design the tree, don't rescue everything
A crashed worker is restarted by its supervisor without taking down the rest of the system. AI undermines this by wrapping every operation in try/rescue, converting a clean crash into a swallowed error that leaves the process alive with invalid state.
- Let unexpected errors crash. A restart resets state cleanly. A rescued exception that keeps executing with invalid state is harder to detect and harder to recover from.
- Pick the restart strategy deliberately.
:one_for_one(worker failures are independent),:rest_for_one(a failure restarts that child and every child started after it — use for ordered startup dependencies),:one_for_all(all children are interdependent). - Know where the escalation ends.
Supervisordefaults tomax_restarts: 3withinmax_seconds: 5. Exceed that and the supervisor itself terminates and escalates to its supervisor. At the top of the tree that stops the whole application. A crash-loop is therefore not "contained" — it is a delayed outage.
A catch-all `handle_info/2` does not fix a poison message. This is the most common wrong fix AI writes. A catch-all clause only handles messages that match no other clause. A message that matches your real clause and then raises inside it still crashes the process.
Be precise about why that loops, because the fix depends on it: the crashed process and its mailbox both die — OTP does not hand the old mailbox to the restarted process. The loop comes from the source. An unacknowledged broker message is redelivered to the restarted consumer; a producer that retries re-sends. An in-process sender that fired once and moved on will not.
What actually stops the loop, in order of preference:
| Where the message comes from | Fix | |
|---|---|---|
| A broker (SQS, RabbitMQ, Kafka) via Broadway | Let it crash, then use handle_failed/2 to set the ack action for failed messages (Broadway.Message.configure_ack/2, e.g. on_failure: :reject on RabbitMQ). handle_failed/2 only shapes the message before acknowledgement — the broker still has to have the dead-letter route configured (an SQS redrive policy, a RabbitMQ DLX). Both halves, or it is redelivered forever | |
| A job queue (Oban) | Set max_attempts on the worker; after the last attempt the job moves to discarded and stops being fetched | |
| Another process in your own app | Validate at the boundary and drop or park the bad message explicitly. That is a validation decision with a log line and a metric — not a rescue |
Use significant: true on a child plus auto_shutdown: on its supervisor when a child terminating normally should bring the subtree down. Otherwise a "finished" worker leaves an empty supervisor running forever.
2. Unbounded mailbox growth — and why a call timeout is not backpressure
Every process has a mailbox. If a GenServer receives faster than it processes, the mailbox grows without bound: memory climbs, GC gets more expensive because the mailbox is scanned, and tail latency rises for everyone queued behind.
- Monitor `Process.info(pid, :message_queue_len)` and alert on sustained growth. Call
Process.set_label/1(Elixir 1.17+) ininit/1so a runaway process is identifiable in:observerand in crash reports instead of showing up as a bare pid. - `GenServer.call/3` gives you flow control — the caller blocks until the server replies, which throttles the producer. But a `call` timeout does not shed load. The caller gives up; the message stays in the server's mailbox and is still processed. Under overload, timeouts hide the queue instead of draining it. If you need to shed, cap concurrency at the entry point (a pool with a bounded checkout timeout) rather than relying on
calltimeouts. - `cast/2` is only appropriate when losing the message is acceptable (best-effort metrics) or the producer is rate-limited elsewhere. Never use it for work that must be bounded.
- For pipelines, use GenStage (demand-driven producer/consumer), Broadway (queue consumption with backpressure, batching, retries and failure handling built in), or Flow.
- Selective receive is O(n) in mailbox length. A
receivethat waits for a specific pattern scans from the front of the queue. A long mailbox makes every such receive slow, which makes the mailbox longer. - `Process.flag(:message_queue_data, :off_heap)` on processes that legitimately hold big mailboxes keeps the messages out of the process heap so GC does not copy them.
OTP 28 priority messages are not a backpressure mechanism. OTP 28 added them (EEP 76): a priority alias from :erlang.alias([:priority]), sends via :erlang.send/3 with the priority option, and a priority option on :erlang.monitor/3 and :erlang.link/2. They exist so a control message (shutdown, health probe) can jump an already-long queue. The Erlang docs are explicit: you "very seldom need to resort to usage of priority messages", and "receiving processes have not been optimized for handling large amounts of priority messages." Enabling them also means the message queue order no longer reflects the order signals arrived. Do not reach for them to fix a queue that is growing — fix the demand.
3. Hot GenServer = serial bottleneck — use ETS, :counters, or :persistent_term
A GenServer processes one message at a time. Routing high-read traffic through one process serializes it. Under load, callers time out and the mailbox grows.
- Many readers of shared data (config, a registry, a rate-limit snapshot) should not go through a GenServer. Let the GenServer own the ETS table for writes; let readers hit ETS directly.
- ETS is not transactional.
:ets.lookupfollowed by:ets.insertis a read-modify-write race between concurrent processes. For counters use:ets.update_counter/3(atomic), or:counters/:atomicsfor a fixed set of counters with no table lookup at all. - An ETS table dies with its owning process. If the owner is a GenServer that crashes, the table and everything in it are gone — and the restarted GenServer creates an empty one. Set
heir:if the data must outlive a restart, or accept the loss explicitly.
:persistent_term is for global data that is read constantly and written almost never — reads are a direct memory access with no table lookup. Every `:persistent_term.put/2` is expensive (it scans processes holding references to the old value). Write it once at boot; never per request.
Do not put a compiled `Regex` in a compile-time position on OTP 28+. OTP 28 replaced PCRE with PCRE2 and changed the compiled-regex representation, so a regex that was compiled at build time no longer works at runtime. Elixir 1.19 made regexes-as-struct-field-defaults an error for exactly this reason; module attributes holding regexes break the same way. Build it in Application.start/2 and stash it in :persistent_term. While you are there: OTP 28 also changed the re module's default character encoding from Latin-1 to ASCII — patterns that used to match non-ASCII input now need unicode passed explicitly.
4. Long work in handle_call blocks callers and times out
GenServer.call/3 defaults to a 5000 ms timeout, and a timeout exits the caller (exit(:timeout)) unless it is caught. In a supervised worker that means the caller crashes too. Meanwhile the server is still chewing on the slow message and will eventually try to reply to a dead process.
- Do the work in the caller if it does not need the server's state.
- Delegate to a supervised task and reply out of band with
GenServer.reply/2. - Use a pool (
NimblePool,poolboy) so many workers run in parallel.
If the task can crash before replying, the caller still waits the full timeout. Either wrap the reply so every path replies, or monitor the task and reply {:error, :crashed} from the :DOWN handler.
5. State is isolated per process — no shared memory
Processes share nothing. Each has its own heap; sending data copies it. That is what makes crash isolation safe, and it has consequences:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-beam/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-beam)