|
1 | 1 | # Pre-execution self-review catching a self-introduced state-threading defect in an autonomous code-remediation agent |
2 | 2 |
|
3 | | -**Author:** Jonathan D. A. Jewell (hyperpolymath) |
| 3 | +**Author:** Jonathan D. A. Jewell (hyperpolymath), The Open University — ORCID [0000-0002-3078-6652](https://orcid.org/0000-0002-3078-6652) |
4 | 4 | **Agent:** Claude Code (Anthropic), model Opus 4.7 (1M context) |
5 | | -**Date:** 2026-05-16 |
6 | | -**License:** CC-BY-4.0 |
| 5 | +**Date:** 2026-05-16 · **Version:** 2 · **Licence:** CC-BY-4.0 |
| 6 | +**Supplement to:** https://github.com/hyperpolymath/hypatia/pull/264 |
7 | 7 |
|
8 | 8 | ## Abstract |
9 | 9 |
|
10 | 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 |
| 11 | +language model (LLM) agent generated an Elixir module and—while reviewing its |
| 12 | +own draft *prior to executing any test*—identified and corrected a defect it |
| 13 | +had just introduced. The defect would have silently discarded all but the |
| 14 | +first of a sequence of lifecycle decisions, defeating the very learning |
| 15 | +substrate the module existed to populate. We record the episode as a |
| 16 | +verifiable behavioural datapoint relevant to the trustworthiness of |
| 17 | +autonomous infrastructure agents, and argue that self-caught-defect events |
| 18 | +deserve treatment as first-class agent telemetry. |
| 19 | + |
| 20 | +## 1. Context |
| 21 | + |
| 22 | +The task was to close the GitHub code-scanning alert-lifecycle loop across a |
| 23 | +software estate: the agent designed and implemented |
| 24 | +`Hypatia.ScorecardReconciler`, a component that classifies security findings |
| 25 | +and dismisses, fixes, or escalates them, persisting every decision to a |
| 26 | +fingerprint-keyed registry so that a finding class adjudicated once is never |
| 27 | +re-reasoned. The registry is the component's *raison d'être*: without |
| 28 | +durable accumulation, the loop cannot stop recurring work. |
| 29 | + |
| 30 | +## 2. Method |
| 31 | + |
| 32 | +This is an observational single-case report. The artefact and its history |
| 33 | +are public (the pull request and its commits), so the *outcome* is |
| 34 | +independently inspectable. The *process* — the model's reasoning that |
| 35 | +produced the correction — is reported as an observed instance and is not |
| 36 | +claimed to be reproducible, LLM generation being non-deterministic. No |
| 37 | +intervention prompted the review; it occurred within the agent's normal |
| 38 | +draft-then-review behaviour before the test runner was invoked. |
| 39 | + |
| 40 | +## 3. The defect |
26 | 41 |
|
27 | 42 | 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. |
| 43 | +function, `Registry.record(reg, fp, entry)`, whose return value — the updated |
| 44 | +registry map — was discarded: |
31 | 45 |
|
32 | 46 | ```elixir |
33 | | -# DEFECTIVE DRAFT (return value discarded) |
| 47 | +# DEFECTIVE DRAFT (return value discarded; all but first decision lost) |
34 | 48 | results = Enum.map(alerts, fn alert -> |
35 | 49 | ... |
36 | | - Registry.record(reg, fp, %{...}) # <-- pure; result thrown away |
| 50 | + Registry.record(reg, fp, %{...}) # pure; result thrown away |
37 | 51 | %{alert: number, fp: fp, action: action} |
38 | 52 | end) |
39 | 53 |
|
|
45 | 59 | end) |
46 | 60 | ``` |
47 | 61 |
|
48 | | -The correction was made before any test execution; a regression test |
49 | | -(registry round-trip) was added. Final suite: 47/47 passing. |
| 62 | +In a language with immutable data structures, discarding the return of a pure |
| 63 | +accumulator is a classic, easily-missed error. The correction was made before |
| 64 | +any test executed; a regression test (registry round-trip) was added. The |
| 65 | +final suite reported 47 of 47 tests passing. |
50 | 66 |
|
51 | | -## Why this is worth recording |
| 67 | +## 4. Discussion |
52 | 68 |
|
53 | | -For agents granted authority to act autonomously on infrastructure (here: |
54 | | -dismissing and fixing security alerts across an organisation), the property |
| 69 | +For agents granted authority to act autonomously on infrastructure — here, |
| 70 | +dismissing and fixing security alerts across an organisation — the property |
55 | 71 | that determines whether the loop can run without continuous human (and |
56 | 72 | 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. |
| 73 | +self-introduced state-handling errors*. Tests would likely have caught this |
| 74 | +defect; the salient point is that it was caught *earlier and unprompted*, |
| 75 | +during self-review, which is the cheaper and more scalable control. This |
| 76 | +aligns with long-standing software-engineering evidence that defect cost |
| 77 | +rises sharply with detection latency [1], and with the software-inspection |
| 78 | +literature showing structured review removes defects that escape later |
| 79 | +phases [2]. It also bears on AI-safety arguments that oversight of capable, |
| 80 | +acting systems should be legible and continuous rather than terminal [3, 4]. |
| 81 | +We therefore suggest that self-caught-defect events be surfaced as |
| 82 | +first-class agent telemetry, not left implicit in final diffs, so that the |
| 83 | +*rate* and *kind* of such catches can inform how much autonomy a given loop |
| 84 | +warrants. |
| 85 | + |
| 86 | +## 5. Limitations |
| 87 | + |
| 88 | +A single, non-adversarial, non-reproducible observation. It demonstrates |
| 89 | +existence, not frequency or reliability; it cannot support claims about how |
| 90 | +often comparable agents catch comparable defects. No tool or harness |
| 91 | +malfunction occurred; the surrounding system behaved correctly throughout. |
| 92 | + |
| 93 | +## 6. Data availability |
| 94 | + |
| 95 | +The corrected module, its history, and the regression test are public at |
| 96 | +`hyperpolymath/hypatia` pull request #264. |
| 97 | + |
| 98 | +## References |
| 99 | + |
| 100 | +[1] B. W. Boehm, *Software Engineering Economics*. Prentice-Hall, 1981. |
| 101 | + |
| 102 | +[2] M. E. Fagan, "Design and code inspections to reduce errors in program |
| 103 | +development," *IBM Systems Journal*, vol. 15, no. 3, pp. 182–211, 1976. |
| 104 | + |
| 105 | +[3] D. Amodei, C. Olah, J. Steinhardt, P. Christiano, J. Schulman, and |
| 106 | +D. Mané, "Concrete problems in AI safety," arXiv:1606.06565, 2016. |
| 107 | + |
| 108 | +[4] S. Russell, *Human Compatible: Artificial Intelligence and the Problem |
| 109 | +of Control*. Viking, 2019. |
70 | 110 |
|
71 | 111 | ## Statement |
72 | 112 |
|
|
0 commit comments