anantbhandarkar/make-it-right/mir-backend-beam

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

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-beam

SKILL.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. Supervisor defaults to max_restarts: 3 within max_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.

elixir
# Dangerous: a malformed item raises, the supervisor restarts the worker,
# the source redelivers the same message, and it crashes again — until
# max_restarts trips and the outage moves up the tree.
def handle_info({:process, item}, state) do
result = dangerous_work!(item) # raises on malformed item
{:noreply, %{state | last: result}}
end
# This clause does NOT help. {:process, bad_item} still matches the clause
# above. A catch-all only covers messages nothing else matched.
def handle_info(unknown, state) do
Logger.warning("unexpected message: #{inspect(unknown)}")
{:noreply, state}
end

What actually stops the loop, in order of preference:

Where the message comes fromFix
A broker (SQS, RabbitMQ, Kafka) via BroadwayLet 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 appValidate 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+) in init/1 so a runaway process is identifiable in :observer and 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 call timeouts.
  • `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 receive that 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.
elixir
# Unbounded: producer can flood the GenServer
GenServer.cast(worker, {:process, item})
# Flow-controlled: caller blocks until the GenServer is ready
GenServer.call(worker, {:process, item})
# Pipeline: Broadway controls demand, batching, and failure handling
defmodule MyPipeline do
use Broadway
def handle_message(_, message, _), do: message
def handle_failed(messages, _), do: messages # nack -> dead-letter
end

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.lookup followed by :ets.insert is a read-modify-write race between concurrent processes. For counters use :ets.update_counter/3 (atomic), or :counters / :atomics for 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.
elixir
# Bottleneck: every read is serialized through one process
def handle_call(:get_config, _from, state), do: {:reply, state.config, state}
# Scalable: write via the GenServer, read straight from ETS
def init(_) do
:ets.new(:config_cache, [:named_table, :public, read_concurrency: true])
{:ok, %{}}
end
def handle_cast({:update_config, config}, state) do
:ets.insert(:config_cache, {:config, config})
{:noreply, state}
end
def get_config, do: :ets.lookup(:config_cache, :config) # no process hop

: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.
elixir
# Dangerous: blocks the GenServer for the whole HTTP call
def handle_call({:fetch, url}, _from, state) do
{:reply, Req.get!(url), state}
end
# Safe: hand off to a supervised task, reply later.
# Task.start/1 is NOT the fix — it is unlinked and unsupervised, so a crash
# is silent and the caller just times out with no diagnostic.
def handle_call({:fetch, url}, from, state) do
Task.Supervisor.start_child(MyApp.TaskSup, fn ->
reply =
case Req.get(url) do
{:ok, resp} -> {:ok, resp}
{:error, e} -> {:error, e}
end
GenServer.reply(from, reply)
end)
{:noreply, state}
end

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-beam/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-beam)

Something wrong with this skill or its page? Tell us.