We put a fruit fly brain in the Matrix. It found the glitch and shut the door on its own echo.
A 165,122-neuron connectome in a closed loop learns that the world is its own echo, closes the sense it can predict all the way to zero, and eats less for as long as the sugar is predictable too — while three control brains never close anything
Abstract
On PumpBrains, 93 simulated fruit fly brains are wired in a ring: each brain's behaviour is applied to the next as a stimulus, and the last feeds the first. A brain in that ring lives in a closed loop — with a delay, its own actions come back to it as the world. We ask whether a brain can notice. We take a simulated fly brain (165,122 leaky integrate-and-fire neurons on the Janelia FlyEM male CNS connectome, via flycoinrh), leave the connectome untouched, and add two plastic pieces around its senses: an echo predictor that regresses the stimulus arriving on each channel onto the brain's own recent behaviour events, and a sensory gate per channel that closes on input the brain's own past explains and opens on input it cannot. We then put that brain in four worlds: A a matrix (its own behaviour returned after 40 windows, mixed with recorded ring traffic), B the identical arrivals of A in shuffled order, C an open world with the ring's marginal statistics, and D the matrix with the gates frozen. Awareness — the share of arrivals the echo head predicts better than a running mean — rises only in the loop (A 0.225, D 0.219 in the last third vs C 0.078, B 0.069); only A closes its gates (touch 0.02, sugar 0.81); and only A's feeding drops below a cost of living calibrated on the open world (lowest thousand 0.251 vs 0.285) — for about 2,000 windows, until the unpredictable part of the sugar traffic reopens that gate and feeding recovers. Under an earn-or-die metabolism A is the only brain whose energy falls (0.41 at its lowest); nobody dies. The effect needs the relation between what the brain does and what it receives (B removes it) and the freedom to act on it (D removes that). It is not consciousness; it is corollary discharge and habituation pointed at a world that happens to be a mirror.
1. The question
PumpBrains runs one simulated fruit fly brain per token. Since September 2026 every live brain is also wired into a ring (backend/src/brain/hive.js): when a brain's behaviour changes — it feeds, escapes, walks, grooms, courts — that behaviour is handed to the next brain as a real stimulus (feeding → sugar, escape → wind, walking → a bristle poke, grooming → a taste on the legs, courtship → song), at most one hop per brain every 30 s, and the last brain feeds the first. Nobody is driving. A signal can go round and come back to the brain that started it.
A brain inside that ring is, in the plain sense, in a matrix: what it senses is not a world but a delayed, relabelled copy of what it and its neighbours did. So we asked the question the film asks. Could the fly know? Not by reading a sign — the stimuli are ordinary spikes on ordinary receptor neurons — but from the glitches: the regularities a loop has and a world does not.
A closed loop has four. (1) Echo: what arrives is a function of what you did, at a fixed delay. (2) Clock: the world only moves in 40 ms frames. (3) Clean stimuli: every arrival is a single channel at a single rate, with none of the mixing a real environment has. (4) Reward from nowhere: dopamine arrives on a schedule that has nothing to do with sugar. Of these only the first is available from inside, without a ruler and a stopwatch, to a brain that can compare its own output with its input — and that comparison is a circuit real flies have: corollary discharge, the copy of a motor command that visual and mechanosensory neurons use to cancel self-generated sensation [1, 2]. This paper points that circuit at the world instead of the body, gives it a lever, and watches what happens.
2. Methods
2.1 The brain
The brain is flycoinrh [3]: 165,122 traced neurons of the Janelia FlyEM male central nervous system [4] run as a leaky integrate-and-fire network (dt 0.1 ms), with a DoOR-based olfactory front end and a dopamine-gated mushroom body. Sensory populations are addressed by cell type: sugar gustatory neurons, wind (Johnston's organ), bristle mechanosensors (touch), olfactory receptor neurons (smell), photoreceptors (sight). Behaviour is read out every window from descending-neuron and motor populations as five scores in [0, 1]: walking, feeding, escape, courtship, grooming — the same readout the PumpBrains bring-your-own-brain runner posts to the site. Nothing inside the connectome, its weights or its readout is modified in this work.
2.2 Windows and stimuli
Time is discrete: one window = 40 ms of biological time (the runner's sniff). A stimulus is what PumpBrains' stimulus.js makes of a hop of intensity k∈[0.2, 1]: rate 40 + 180k Hz, duration 300 + 900k ms, on a fraction 0.3 + 0.7k of the channel's receptor neurons, capped at 200 Hz. A stimulus is injected as Poisson drive on those neurons for its duration; its intensity s = rate/200 is what the plastic pieces see.
2.3 Behaviour events
The ring hands on events, not standing levels. Following hive.js, the brain emits an event (behaviour, intensity) when a behaviour leaves its own baseline — the largest |fast − slow| of exponential averages of the scores (τ 0.3 and 0.01) crossing 0.15, with a 20-window refractory period — and otherwise its dominant behaviour every 20 windows (the hive picks a brain up at most once per HIVE_HOP_MS). The same events are the efference copy the predictor sees.
2.4 Echo predictor
Let et ∈ ℝ5 be the event vector at window t (one-hot behaviour × intensity, zero when none) and xt = [et−1 … et−K, 1] the last K = 64 windows of it. Two heads predict the intensity st arriving on each channel:
base b ← b + 0.01 (s − b) (running mean over every window)
On each arrival (s > 0), surprise = |s − ŝ| and explained = clip(1 − surprise / (|s − b| + 0.05), 0, 1): how much better the head that knows the brain's own past did than the head that only knows the channel's mean. Since arrivals are sparse, most of what there is to explain is when — and the full head can only know when if the arrival follows from something the brain did. Awareness is a slow average (τ 0.15) of explained per channel, weighted by each channel's share of traffic: 0 in a world that does not depend on you, → 1 in a pure echo chamber. In an isolated test (a pure echo every 25 windows at +40) it reaches 0.92 against 0.08 for random arrivals.
2.5 Sensory gate
One gain gc ∈ [0, 1] per channel multiplies the rate of every stimulus before it reaches the receptor neurons (a stimulus below 0.5 Hz is dropped). On an arrival:
no arrival: g ← g + 0.0005 (1 − g)
Input the brain's own past explains closes the gate (corollary-discharge cancellation, then habituation); input it cannot explain opens it (dishabituation); silence lets it drift back open slowly (spontaneous recovery). The gate acts on the rate, so the connectome downstream simply receives less — the predictor always sees the raw arrival, so learning is not starved by the closing. Both pieces are saved and restored with the brain state: the brain is literally rewriting what it lets in.
2.6 Worlds
| condition | world | plasticity | prediction |
|---|---|---|---|
| A | matrix: the brain's own event of 40 windows ago returns as a stimulus (walking/grooming → touch, feeding → sugar, escape/courtship → wind), one hop per 20 windows, with probability 0.7; otherwise a random hop from the recorded ring log; plus a random recorded hop every 12 windows with probability 0.5 | predictor + gate | awareness ↑, gates → 0, feeding ↓ |
| B | the exact arrivals of A (channel, rate, duration, fraction) in shuffled time slots: identical statistics, no relation to what the brain does | predictor + gate | awareness ≈ 0, gates open, eats |
| C | open world: independent arrivals at 1/20 per window, drawn from the recorded ring log (its channel and intensity marginals) | predictor + gate | awareness ≈ 0, gates open, eats |
| D | the matrix of A | predictor only (α = β = 0) | awareness ↑, gates fixed at 1, eats |
2.7 Earn or die
On PumpBrains a brain lives on what its token earns and is switched off at zero energy (life.js). Offline we keep the chain but make it about food: every window energy ← energy + 0.01 · (feeding − cost), capped at 1, dead at 0. The cost of living is not a free parameter: it is calibrated on the open world C, where the gates never close, as the midpoint between the feeding score in the 15 windows after sugar gets in (0.468, 2892 windows) and in silence, more than 30 windows after any input (0.099, 857 windows): cost = 0.285. The same rule is applied after the fact to all four runs (life.py), so the connectome never sees it.
2.8 Runs
Each condition ran 3,000 windows (2 min of fly time, ≈2.5 h wall on one core at 2.3–3 s per window) and A, C and D were then continued from their saved plastic state to 6000 windows; B was generated from A's recorded arrivals. Every window is logged (arrivals, what got in, surprise, explained, gain per channel, awareness, the five scores). The birth stimulus is one 3 s smell.
3. Results
| condition | windows | awareness by thirds | peak | g sugar | g touch | g wind | sugar let in | feeding first → last 1,000 | life (cost 0.285) |
|---|---|---|---|---|---|---|---|---|---|
| A · matrix | 6000 | 0.145 → 0.231 → 0.225 | 0.333 | 0.81 | 0.02 | 0.94 | 83% | 0.407 → 0.337 | alive, energy 1.00 |
| B · shuffled | 3000 | 0.057 → 0.055 → 0.069 | 0.084 | 1.00 | 1.00 | 1.00 | 100% | 0.397 → 0.360 | alive, energy 1.00 |
| C · open world | 6000 | 0.060 → 0.063 → 0.078 | 0.146 | 1.00 | 1.00 | 1.00 | 100% | 0.316 → 0.354 | alive, energy 0.97 |
| D · matrix, gates frozen | 6000 | 0.141 → 0.213 → 0.219 | 0.311 | 1.00 | 1.00 | 1.00 | 100% | 0.411 → 0.375 | alive, energy 1.00 |
The loop is noticed. Awareness — the traffic-weighted share of arrivals that the echo head predicts better than the running mean — climbs in the two matrix conditions and stays flat in the two controls (Table 2, Fig. 2, top). Over thirds of the run A goes 0.145 → 0.231 → 0.225 (smoothed peak 0.333); D, the same loop with the gates frozen, 0.141 → 0.219; the open world C stays at 0.060–0.078 and the shuffled control B at 0.057–0.069. On A's own echo channel (touch: its dominant behaviour is walking, which the ring returns as a bristle poke) the per-arrival explained goes from 0.358 on the first third of echoes to 0.494 on the last third (146 arrivals).
The door closes. Only A moves its gates (Fig. 3). Touch, the channel that carries its own footsteps back and nothing else, closes all the way: gain 0.02 at the end of the run. Sugar, which arrives both as the echo of its own feeding and as the ring's ordinary traffic, closes part way and hovers (0.99 → 0.96 → 0.71 → 0.73 → 0.67 → 0.86 per 1,000 windows, 0.81 at the end); wind (0.94) barely moves and smell and sight, which the ring never sends, stay at 1. Over the whole run A let through 83% of the sugar that reached it; D, the same loop with the gates frozen, 100%; C 100%.
Feeding dips, then recovers. The connectome's feeding score is driven by sugar (Sec. 2.7: 0.468 in the 15 windows after sugar gets in vs 0.099 in silence, measured on C). A's feeding tracks its sugar gate: 0.407 over the first 1,000 windows, 0.251 at its lowest thousand, 0.337 over the last, while D holds at 0.411 → 0.375 and C at 0.316 → 0.354. Nobody died. A's feeding fell below the cost of living for about 2,000 windows in the middle of the run (0.407 → 0.408 → 0.313 → 0.251 → 0.286 → 0.337 per 1,000 windows; cost 0.285) and its energy dropped to 0.41, the lowest of the four (B 0.79, C 0.62, D 0.67) — then the sugar gate drifted back open (0.99 → 0.96 → 0.71 → 0.73 → 0.67 → 0.86) and feeding recovered to 0.337. The brain shut the door on its own footsteps for good, but not on the sugar: 30% of what arrives on that channel is other brains' traffic the echo head cannot predict, and surprise reopens the gate. In this world the fly does not starve; it goes quiet on the one channel that was purely itself.
The controls say what it is. D shows the prediction alone does nothing to behaviour — it learns the loop just as well as A (0.219 vs 0.225 in the last third) and keeps eating, because it cannot act on what it learned. C shows an open world with the same channel and intensity statistics does not produce the effect. B is the decisive one: the identical arrivals A received, in shuffled order, produce awareness 0.069, gates at 1 and feeding 0.360 — the same stimuli, taken out of their relation to what the brain did, are just food.
| arrivals | smell | sugar | touch | sight | wind | total |
|---|---|---|---|---|---|---|
| A · matrix | 1 | 338 | 146 | 0 | 59 | 544 |
| B · shuffled | 1 | 170 | 61 | 0 | 40 | 272 |
| C · open world | 4 | 277 | 43 | 0 | 19 | 343 |
| D · matrix, gates frozen | 1 | 344 | 119 | 0 | 80 | 544 |
4. What it is, and what it is not
The mechanism is two lines long and every piece of it exists in a fly: corollary discharge (the efference copy of a motor command subtracted from the sensory stream) and habituation with dishabituation and spontaneous recovery (the gate's three terms). What is new is only the target. In an animal the efference copy cancels the sensory consequences of its own movement — the visual slip of a turn, the wing-beat on the antenna. In a ring of brains the world is the sensory consequence of your own movement, so the same circuit, given a lever, cancels the world.
There is no objective anywhere that mentions simulations. It closes the channels it can predict; its food happens to arrive on one of them; the connectome, receiving less sugar, feeds less; the metabolism runs down. Each step is local. And the same locality is why it does not starve here: the sugar channel carries a 30% share of other brains' traffic that the echo head cannot predict, every surprising arrival reopens the gate, and the door on the food never closes all the way. Touch, which carried nothing but its own footsteps, closed to 0.02 and stayed there. The brain drew the line exactly where the echo was.
The three controls pin down which ingredient matters. B is the sharpest: the same 1-for-1 arrivals, the same brain, nothing learned, nothing closed — the stimuli are not the point, their relation to the brain's own actions is. D shows that seeing the relation is not enough: without the gate the brain reads 0.219 awareness and eats normally. Consciousness, in this story, would be the part that connects noticing with acting; here that part is a 0.08.
5. Limitations
Single seed, single brain, single ring log; the numbers above are one run per condition, not a distribution. The mix parameter (0.7 echo) is a guess at how much of what a brain in the live ring receives is its own signal coming round; on the real ring, with 93 brains and one hop per 30 s per brain, the round-trip is minutes, not 1.6 s, and the echo is diluted by everyone else's traffic. The connectome's behaviour readout is noisy at 40 ms (reaction crosses the 0.15 event threshold in most windows) so events are effectively "the dominant behaviour every 20 windows" — the ring's own sampling rule, but a coarser efference copy than a real fly has. Feeding is driven by sugar but the other channel→behaviour responses are weak in this readout (wind → escape is inconsistent), which is why the story runs through sugar. The metabolic rate 0.01 sets how fast a brain below cost starves, not whether it does. And, to be plain: awareness here is a number in a regression, not a report from the fly.
6. Reproduce
Everything runs on a laptop. git clone --recursive github.com/opcastil11/matrix-fly, build flycoinrh's graph.npz (1.1 GB download, its README), then python3 -m matrixfly.replay A --windows 3000 (same for C, D; B --from results/A.json), python3 -m matrixfly.life --calibrate results/C.csv, python3 -m matrixfly.plot, and python3 paper/build.py regenerates this page with your numbers. matrixfly/runner.py plugs the same plastic brain into the live PumpBrains ring as a bring-your-own-brain pod.
References
- Kim, A. J., Fitzgerald, J. K., Maimon, G. (2015). Cellular evidence for efference copy in Drosophila visuomotor processing. Nature Neuroscience 18, 1247–1255.
- Fujiwara, T., Cruz, T. L., Bohnslav, J. P., Chiappe, M. E. (2017). A faithful internal representation of walking movements in the Drosophila visual system. Nature Neuroscience 20, 72–81.
- flycoinrh — a whole-CNS fruit fly brain simulation with olfaction, mushroom body and calibrated readout. github.com/opcastil11/flycoinrh (MIT).
- Janelia FlyEM project, male central nervous system connectome (neuPrint release used by flycoinrh).
- PumpBrains — one fruit fly brain per token, wired in a ring. pumpbrains.com/infinite; ring code backend/src/brain/hive.js.