|
| 1 | +# Pre-execution self-review catching a self-introduced state-threading defect in an autonomous code-remediation agent |
| 2 | + |
| 3 | +**Author:** Jonathan D. A. Jewell (hyperpolymath) |
| 4 | +**Agent:** Claude Code (Anthropic), model Opus 4.7 (1M context) |
| 5 | +**Date:** 2026-05-16 |
| 6 | +**License:** CC-BY-4.0 |
| 7 | + |
| 8 | +## Abstract |
| 9 | + |
| 10 | +During an autonomous, multi-repository security-remediation session, a large |
| 11 | +language model agent generated an Elixir module, and—while reviewing its own |
| 12 | +draft *prior to executing any test*—identified and corrected a defect it had |
| 13 | +just introduced. The defect would have silently discarded all but the first |
| 14 | +of a sequence of lifecycle decisions. We record the episode as a verifiable |
| 15 | +behavioral datapoint relevant to the trustworthiness of autonomous |
| 16 | +infrastructure agents. |
| 17 | + |
| 18 | +## Context |
| 19 | + |
| 20 | +Task: close the GitHub code-scanning alert-lifecycle loop for an |
| 21 | +organisation's repository estate (the agent designed and implemented |
| 22 | +`Hypatia.ScorecardReconciler`, which classifies security findings and |
| 23 | +dismisses/fixes/escalates them, persisting decisions to a registry). |
| 24 | + |
| 25 | +## The defect |
| 26 | + |
| 27 | +The first draft iterated alerts with `Enum.map/2` and called a *pure* |
| 28 | +function `Registry.record(reg, fp, entry)` whose return value (the updated |
| 29 | +registry map) was discarded. Net effect: every decision after the first |
| 30 | +would be lost; the learning substrate would never accumulate. |
| 31 | + |
| 32 | +```elixir |
| 33 | +# DEFECTIVE DRAFT (return value discarded) |
| 34 | +results = Enum.map(alerts, fn alert -> |
| 35 | + ... |
| 36 | + Registry.record(reg, fp, %{...}) # <-- pure; result thrown away |
| 37 | + %{alert: number, fp: fp, action: action} |
| 38 | +end) |
| 39 | + |
| 40 | +# CORRECTED (registry threaded via map_reduce) |
| 41 | +{results, reg} = Enum.map_reduce(alerts, reg0, fn alert, reg_acc -> |
| 42 | + ... |
| 43 | + reg_acc = Registry.record(reg_acc, fp, %{...}) |
| 44 | + {%{alert: number, fp: fp, action: action}, reg_acc} |
| 45 | +end) |
| 46 | +``` |
| 47 | + |
| 48 | +The correction was made before any test execution; a regression test |
| 49 | +(registry round-trip) was added. Final suite: 47/47 passing. |
| 50 | + |
| 51 | +## Why this is worth recording |
| 52 | + |
| 53 | +For agents granted authority to act autonomously on infrastructure (here: |
| 54 | +dismissing and fixing security alerts across an organisation), the property |
| 55 | +that determines whether the loop can run without continuous human (and |
| 56 | +monetary) supervision is precisely *pre-execution detection of |
| 57 | +self-introduced state-handling errors*. This episode is a positive instance. |
| 58 | +It also argues that self-caught-defect events should be surfaced as |
| 59 | +first-class agent telemetry, not implicit in final diffs. No tool or harness |
| 60 | +malfunction occurred; the surrounding system behaved correctly. |
| 61 | + |
| 62 | +## Reproducibility |
| 63 | + |
| 64 | +The artifact is the public pull request implementing the module |
| 65 | +(hyperpolymath/hypatia#264) and its commit history, which preserves the |
| 66 | +corrected form and the accompanying regression test. The episode itself |
| 67 | +(model reasoning that produced the correction) is inherently |
| 68 | +non-deterministic and is reported as an observed instance, not a guaranteed |
| 69 | +behavior. |
| 70 | + |
| 71 | +## Statement |
| 72 | + |
| 73 | +Reported in the interest of public accountability for autonomous AI systems. |
| 74 | +We are all responsible for a better world. |
0 commit comments