Skip to content

Chapter 0 · agent-neuron · Lab

The idea in one alert

A burst of inputs, a cheap check on each, and one costly step. The idea: the rule for when that step runs isn’t in a controller. It sits on the neuron that runs it.

The problem

In the recording, forty invented alerts come in for five services, all in under six seconds. That’s a burst.

Cheap checks look at every alert, but one step is costly, and in the recording it’s a stand-in that waits 500 ms where a call to a model would go. You want the cheap checks to agree that something’s wrong first. Only then should it run.

Then the burst keeps going, and a newer alert for the same service makes the older work pointless. Its answer would be about input that’s already been replaced. So the rule has two parts. When to act, and when to stop.

The common answer

A common answer is a controller in the middle. Every detector reports to it. It counts the flags for each alert, keeps a timer for each, starts the costly step when enough have agreed, and cancels the step when something newer arrives.

It works. But every rule sits in one place, and that place has to know about every detector, every timer and every cancellation. Changing a rule or adding a detector means changing the controller. That’s the cost.

// a sketch, invented for this page
const flags = new Map();   // alert -> detectors that flagged it
const timers = new Map();  // alert -> its expiry timer
const running = new Map(); // service -> the call in flight

function onFlag(alert, detector) {
  const seen = flags.get(alert.id) ?? new Set();
  seen.add(detector);
  flags.set(alert.id, seen);
  if (!timers.has(alert.id)) {
    timers.set(alert.id, setTimeout(() => forget(alert.id), WITHIN_MS));
  }
  if (seen.size >= THRESHOLD) {
    clearTimeout(timers.get(alert.id));
    cancel(running.get(alert.service));
    running.set(alert.service, startCostlyStep(alert));
  }
}

function onAlert(alert) {
  dropFlagsFor(alert.service);        // older flags are stale
  cancel(running.get(alert.service)); // older work is stale
}
Sketch, inventedFigure 1. I invented this sketch of a central controller for this page. It isn’t code from the recordings.

The rule on the box

In the alternative I’m testing, the costly neuron’s wrapper carries the rule: how many different senders must agree, how long a flag may wait, and that newer input for the same key makes older work stale. The rule sits on the box that acts.

A network is a small JSON file. Neurons in one list, the links between them in another.

On the costly neuron the rule is two lines: a threshold of 2 and a window of 500 ms. What the file doesn’t hold is replaces, the key that says what makes work stale. The source sets it on every alert (here, the service name). It travels with the signal.

Each detector looks at an input, then answers or stays quiet, and knows none of this. The counting, the waiting and the cutting all happen in one place. The costly neuron.

Illustration, invented dataFigure 2. The network behind the recordings, with signals running left to right (top to bottom on a phone): a source, three cheap detectors, the costly neuron with its rule written on it, and a composed neuron that gives one verdict. The alerts are invented.
{
  "neurons": [
    …
    {
      "id": "hypothesis",
      "run": [ … ],
      "threshold": 2,
      "within": 500
    },
    …
  ],
  "links": [
    …
    { "from": "logs", "to": "hypothesis" },
    { "from": "deploys", "to": "hypothesis" },
    { "from": "metrics", "to": "hypothesis" },
    …
  ]
}
ExcerptFigure 3. The costly neuron, shortened, as the network file writes it, and the links that reach it. The numbers are read from the recording. The alerts are invented.

One alert, step by step

Alert 1, for gateway, opens the recording. Start there.

  1. At 2 ms, all three detectors get it at once.
  2. Logs stays quiet at 14 ms, deploys flags it at 17 ms and metrics flags it at 27 ms.
  3. The earlier flag waits. It’s the later one, from metrics at 27 ms, that makes two different detectors agree. So the costly step starts.
  4. The step takes 500 ms, and at 152 ms alert 2 comes in, also for gateway. So the work for alert 1 is stale.
  5. In the recording, the call is cut at 178 ms, 151 ms after it started. No answer from it gets passed on.
  6. Alert 2 goes through the same steps. Two calls in this burst were cut. The call for alert 3 had no newer gateway alert behind it, and it finished at 830 ms. Only its result goes on to the diagnosis neuron.

What it did

The costly step didn’t start once for every flag. Across forty alerts it started 17 times. 10 of those calls were cut as stale. 7 finished.

The same alerts started 52 calls at a threshold of 1, where one flag is enough. At 3 it was 0.

Hold that against three things. The alerts are invented, and they come in bursts. So the waste is built in.

By construction, the recordings that reach a verdict reach the same one. So they show when work starts and stops. They don’t show whether an answer is right.

One run on one machine, played back: that’s each recording.

Agreement, the next chapter, plays all three recordings on one clock and goes through what they do not show.

Each recording is a separate run at its own threshold, on the same invented alerts.
ThresholdAlertsCalls startedCut as staleFinished
140523121
24017107
340000
Recording, invented dataFigure 4. The same forty invented alerts, recorded once at each threshold: three recordings.

Any program fits

The contract is small: the wrapper hands a program one JSON value on its input, and reads one JSON value from its output. If the program prints nothing, it has nothing to say. Nothing gets passed on.

In the recordings, two of the detectors are shell scripts, and one is a few lines of JavaScript. Any other program that can read and write JSON would do. The language doesn’t matter.

Give a neuron a threshold above one and it’s handed a little more. The input that crossed it, and the inputs that agreed with it.

import json, sys

alert = json.load(sys.stdin)
if alert.get("severity") == "crit":
    print(json.dumps({"service": alert["service"]}))
# printing nothing means quiet
Sketch, inventedFigure 5. A Python detector, in the shape the contract describes. It’s invented for this page.

Why neuron, and what is not built

Neuron is a loose name, and it isn't a model of the brain. What it stands for here is connective tissue between programs: a box with many inputs. It acts when its own rule says so.

The name hints at two things that aren’t built: connections that strengthen and weaken, and a network that works out which ones matter. Here, in every recording, each detector counts the same.

Unix pipes join programs that read and write text too, but in a line, one into the next. Here the joins make a graph: many into one, one into many. And the rule for when to act is set on each box.

I’m testing whether the rule for when to act belongs on each neuron’s wrapper, not in a central controller. That’s the question.

The same alert storm is one command away: npm run demo:network. It needs Node, no Rust, and it never makes a network request. The code is public:

overfocus/agent-neuron