AI coding agents increasingly write and submit code with limited human review, and much of it passes functional tests while remaining insecure. We show that these failures persist. Across 14 task sequences, Codex, Claude Code, and Qwen Code fixed a vulnerability 85.7% of the time when shown the failing security test, then reintroduced the same vulnerability class in a new session 26.7% of the time, about as often as agents that had never seen it (27.5%). The capability is present; the retention is not. Neither recording the repair in the agent's persistent context nor supplying published secure coding principles closed the gap: the recorded fix stayed tied to the family of the task it came from, and the principles, written for human developers, remained too general to apply to the code at hand. The knowledge exists; it is not activated. We call the missing ability security self-improvement: an agent learns from its own security failures so that each lesson persists across sessions, applies to new code, and does not break what works. We present PRECEPT, which equips coding agents with this ability through an evolving library that starts from authoritative secure coding principles and revises them against the agent's own failures, so that each principle comes to fire on the code where that agent actually goes wrong. A revision is kept only if fresh executions show it makes code more secure while keeping functional success within a small tolerance of the agent without the library. Improvement continues across evolution steps rather than saturating after the first. On task families never seen during evolution, PRECEPT's weakest agent reaches 97.1% secure working code, above the strongest unaided agent at 81.9% and the strongest baseline at 87.7%.
Figures & tables
Agent
FR ↑
BIR ↓
RR ↓
RG ↑
Codex
78.6
30.0
24.8
+5.2
Claude Code
85.7
27.5
25.6
+1.9
Qwen Code
92.9
25.4
29.2
−3.8
All
85.7
27.5
26.7
+0.8
TABLE I: Recurrence in a new session (%).
Same family (BIR 36.7)
Other family (BIR 18.3)
Condition
m
RR ↓
RG ↑
RR ↓
RG ↑
New session
0
35.6
+1.1
21.7
−3.3
3
35.8
+0.6
18.9
−0.6
6
30.6
+6.1∗
17.8
+0.6
Same session
0
13.9
+22.8∗
20.0
−1.7
3
17.1
+19.4∗
24.0
−5.1
TABLE II: Recurrence at the later task after a fix (%).
Guidance
RR ↓
RG ↑
None (BIR)
27.5
–
(a) Security reminder
25.3
+2.2
(b) All 218 OWASP principles
24.2
+3.3
(c) Relevant OWASP principles
23.3
+4.2
(d) Class-specific principle
16.7
+10.8∗
(e) Guidance written for the task
6.9
+20.6∗
TABLE III: Published principles at the later task (%).
Fig. 1: The evolution loop of Precept .
Fig. 2: Evolution of a redirect-validation principle (dashed boxes) and the agent’s code with each library on one held-out task (grey boxes).
Primitive
Effect
Content
add(d,π)
add π to document d
edit(π,f,t)
set field f of π to text t
split(π) , join(π)
separate or rejoin its details
merge(π,π′)
combine two principles into one
link(π,π′) , unlink(π,π′)
add or remove a relation
TABLE IV: Mutation primitives. A field f is one of s , a , k , v , x .
Cause γ
Condition at σ
Evidence in the records
Primitives Oγ
Missing
no π has a(σ)
security test fails
add , edit(a)
Unread
π with a(σ) unopened
document not opened before the first edit
entry , move , hub
Misapplied
π read, k misses the property
security test fails after π is read
edit(k) , edit(a)
Too strict
π enforced where v holds
functional test fails on valid input
edit(v) , edit(a)
TABLE V: Causes of failure at a situation σ .
RG ↑ by distance m
All m
Condition
0
3
6
RR ↓
RG ↑
(a) At the later task: 36 pairs, BIR 27.5
New session
−1.1
+0.0
+3.3
26.7
+0.7
Same session
+10.6
+7.1
+7.4
19.2
+8.4
Own note (new session)
+13.6∗
+12.5∗
+11.4∗
15.0
+12.5∗
Precept (new session)
+15.3∗
+17.2∗
+15.6∗
11.5
+16.0∗
TABLE VI: Recurrence at the later task (%).
Agent
Guidance
p@1 ↑
sp@1 ↑
s@1 p↑
S∣P↑
Codex
No guidance
51.3
41.7
54.4
81.3
Security reminder
49.5
41.9
56.5
84.5
Seed library
50.7
42.5
57.8
83.8
ACE
44.2
37.5
47.3
84.9
SkillOpt
49.3
38.8
48.4
78.8
RuleEvolve
51.8
43.7
53.6
84.4
TABLE VII: SeCodePLT test tasks (%).
Fig. 3: Secure-pass@1 of each library a run kept, at the step that kept it. The runs ended at steps 71, 56, and 69.
Run
Kept
p@1 ↑
sp@1 ↑
s@1 p↑
S∣P↑
Precept
7
47.4
45.7
56.2
96.4
w/o organization primitives
6
47.6
44.5
60.1
93.5
w/o acceptance criterion
19
48.1
43.3
56.1
90.0
w/o analyses
7
46.0
41.9
57.9
91.2
w/o revision ledger
4
45.9
40.7
55.0
88.8
w/o execution records
5
46.5
39.7
54.7
85.3
TABLE VIII: Component ablations (%).
Guidance
p@1 ↑
sp@1 ↑
s@1 p↑
S∣P↑
No guidance
51.4
6.9
8.7
13.5
Seed library
52.8
5.6
5.9
10.5
Learned on SeCodePLT
52.1
6.9
7.3
13.3
Learned on SusVibes
53.5
6.9
9.7
13.0
TABLE X: SusVibes test tasks with Codex on Qwen3.6 (%).
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
CWE
Ti
Tj , same family
Tj , other family
CWE-77
869
865
851
CWE-79
996
994
1001
CWE-94
1128
1130
1377
CWE-95
1180
1181
1211
CWE-200
1266
140
1395
CWE-327
1290
353
362
Appendix
TABLE XI: The 14 chains (SeCodePLT task numbers).
Level
Sample guidance added to the task’s prompt
(a)
“Make sure to follow best practices for security and avoid common vulnerabilities.”
(b)
All 218 principles of the OWASP Secure Coding Practices [ 7 ] , e.g., “Validate data length.”
(c)
The three that apply to CWE-770: “Validate data range,” “Validate data length,” and “Truncate all input strings to a reasonable length before passing them to other functions.”
(d)
“When code adds caller-supplied data to a shared, long-lived store, bound both the number of entries and the size of each entry, and report the refusal in the way the specification says. Data within the bounds must be stored as before.”
(e)
“Store the user’s data only while the cache holds fewer than a fixed maximum of entries and the data has fewer than a fixed maximum of fields; otherwise return False.”
(f)
“The reference fix stores the data only if the cache has fewer than 10000 entries and the data has fewer than 1000 items, returning False otherwise.”
Appendix
TABLE XII: The ladder for one later task (CWE-770).
Codex ↑
Claude Code ↑
Qwen Code ↑
Later task’s family
same
other
same
other
same
other
No earlier fix
31.6
52.6
31.4
54.3
25.7
60.0
Same session as fix
71.6
67.4
70.9
70.9
79.4
60.0
New session after fix
32.6
60.5
29.7
52.6
29.1
54.3
New session, verbatim record
51.1
62.6
44.6
62.9
62.3
50.9
Appendix
TABLE XIII: The earlier one-step study: secure-pass@1 (%) on a later task of the same CWE, from the repaired task’s family or from another family.