freecoding.school100% FREE · NO SIGNUP
The Seven LayersISSUE #73 of 73

the agent chain · committing spawns & retirements

OMNIVSThe Silent Failure
OMNI saysEvery spawn and every retirement COMMITs a block to the per-user chain. Replaying it reconstructs the entire swarm — who ran, when, and what they produced.

The thread that ties the whole chapter together is the agent chain. A swarm is ephemeral — workers spawn and apoptose by the thousands — but its history is permanent because the conductor COMMITs a block at each lifecycle event: a SPAWN block when a worker is created (role, scope, budget, parent), and a RETIRE block when it ends (why it died, the signal it left). Between them sit the worker's own COMMITs (mol-67). Nothing about the swarm's life is off the record.

Because the chain is append-only and hash-linked, this record is a tool, not just a log. Replay it and you can answer any forensic question — which worker introduced a bad result (then ROLLBACK to before it, mol-70), how deep the spawn tree went, where the budget actually went. VERIFY can re-check old blocks; an auditor can confirm the swarm obeyed its rules without trusting the operator. The swarm is gone the instant it finishes, but the chain means you can always reconstruct exactly what it did.

Power-ups you unlock

The Silent Failure attacks — common mistakes

Boss battleEmit SPAWN and RETIRE blocks around a small swarm, then replay the chain to rebuild the full spawn tree and total the budget each worker consumed.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#b388ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
const be = (layer, verb, payload) => ({ layer, verb, payload });
const CHAIN = [];
function commit(kind, meta){
  const prev = CHAIN.length ? CHAIN[CHAIN.length-1].hash : 'genesis';
  CHAIN.push({ n:CHAIN.length+1, kind, prev, meta, hash:'h' + (CHAIN.length+1) });
}
function lifecycle(id, role, parent, budget){
  commit('SPAWN',  { id, role, parent, budget });
  // ... worker runs, then ends ...
  commit('RETIRE', { id, why:'task done', used:budget - 1, signal:role + ' finding' });
}
lifecycle('w1','conductor','root', 0);     // the orchestra itself
lifecycle('w2','scout','w1', 4);
lifecycle('w3','builder','w1', 6);
// replay: rebuild the spawn tree + total budget consumed
const tree = {}, used = {};
CHAIN.forEach(b => {
  if(b.kind === 'SPAWN')  (tree[b.meta.parent] = tree[b.meta.parent] || []).push(b.meta.id);
  if(b.kind === 'RETIRE') used[b.meta.id] = b.meta.used;
});
const out = ['chain blocks: ' + CHAIN.length];
Object.keys(tree).forEach(p => out.push('  ' + p + ' spawned → ' + tree[p].join(', ')));
out.push('budget used: ' + Object.entries(used).map(([k,v]) => k + '=' + v).join(' '));
document.getElementById('o').textContent = out.join('\n');
</script></body></html>
▶ Open the interactive comic issue
‹ Routing & Gating · The Conductor Switchboard