Failure-Grounded Evolving Security Principles (PRECEPT)¶
Evolving structured security principles from attributed test failures cuts cross-session vulnerability recurrence on single-function Python benchmarks, but fails on multi-file repositories.
Coding agents fix vulnerabilities 85.7% of the time when shown a failing security test, yet reintroduce the same CWE class 26.7% of the time in a new session, nearly matching the 27.5% rate of agents that never saw the flaw (Guo et al., 2026, §I–II). PRECEPT treats that gap as a retention failure and iteratively revises a workspace library of structured secure-coding principles against attributed execution failures, gating every edit on fresh paired tests.
When this applies¶
Apply failure-grounded principle evolution only when four conditions hold (Guo et al., 2026, §V-B, §VI, §VIII-B–C):
- You have dense paired functional and security tests across multiple task families per CWE. SeCodePLT provides 20 to 40 Python tasks per CWE; on CWEval (73 training tasks across 18 CWEs, roughly one problem per language), the evolved library stayed close to the seed.
- Target tasks are short-trajectory, single-language, and narrow in scope. During evolution, SeCodePLT executions made a median of 9 tool calls, keeping the principle library at 5.6% of input tokens.
- You can absorb high offline compute and roughly double deployment input tokens. Each main run executed the coding agent 35,600 to 46,400 times (0.31 to 0.39M input tokens per execution), and the final library raised deployment input tokens from 0.11 to 0.16M to 0.25 to 0.30M per task.
- Training tasks and test suites are trusted and contributor-diverse, because test outcomes control which principles enter the library.
How the evolution loop works¶
PRECEPT represents each principle as a structured tuple (id, s, a, k, v, x, ρ): statement s, code-class situation a, required check k, allowed behavior v, supporting fields x, and provenance ρ (Guo et al., 2026, §IV-B). The library's index sits in the workspace as the agent's standard instruction file (AGENTS.md for Codex and Qwen Code, CLAUDE.md for Claude Code) beside the principle documents, with no system prompt changes (Guo et al., 2026, §V-A).
Each evolution round runs four phases (Test, Analyze, Draft, Decide) using a closed set of content and organization edits (Guo et al., 2026, §IV-C–G):
- Test runs the agent on paired functional and security tasks and logs what it read, changed, and failed.
- Analyze attributes each failure to one of four causes:
missing,unread,misapplied, ortoo strict. - Draft edits the failing component and strips training-task details. Across the three main runs, the detail-stripping check fired on 147 of 338 drafted revisions (43 to 44% per run), most often for task-specific names.
- Decide accepts a revision only when fresh, paired executions pooled across rounds show security gains while functional
pass@1stays within 3 percentage points (ε_F = 3) of the unmodified agent.
On 129 held-out SeCodePLT Python tasks (17 CWEs, Qwen3.6-35B-A3B), PRECEPT raised the secure share of functional code (S|P) to 97.1–98.5%, against 81.9% for the strongest unguided agent and 87.7% for the strongest baseline (Guo et al., 2026, §I, §V-B). Across 36 motivating-study pairs, supplying the library at the later task cut cross-session recurrence from 26.7% to 11.5%, compared with 15.0% for agent-written notes. In 20-step Qwen Code ablations, removing execution records or the cross-round revision ledger wiped out gains over the seed, and removing the acceptance gate dropped S|P from 96.4% to 90.0% (Guo et al., 2026, §V-B EQ3, Table VIII).
Libraries transferred across Codex, Claude Code, and Qwen Code on SeCodePLT (S|P 96.5–98.2% vs 79.7–81.9% unguided), across Qwen3.6-35B-A3B and Mistral Medium 3.5 in 17-step runs (81.9% to 97.3% on Mistral and 81.9% to 86.5% on Qwen3.6), and to CWEval Python tasks (S|P 88.6% vs 70.2%, pass@1 87.9% vs 84.0%) (Guo et al., 2026, §V-B EQ5, Table IX).
Why it works¶
Agents already have the capability to patch vulnerabilities: keeping a fix in the same conversation cut same-family recurrence from 36.7% to 13.9%, though it did not lower recurrence on another task family of the same CWE (Guo et al., 2026, §I–II-D). Standard persistence and static checklists both miss the activation boundary. With built-in memory enabled, no agent recorded the fix and none of the 36 later sessions held a trace of it; when asked to write a note (28 of 36 cases), 13 of 28 notes tied the lesson to the fixed task's own functions or fields (Guo et al., 2026, §II-D). Conversely, an OWASP principle directly addressed 19 of 27 later tasks (70%, Cohen's κ = 0.83), yet supplying all 218 principles or only the relevant ones produced no measurable drop in recurrence.
Restating a principle for a class of code (naming where it applies and what must hold without naming the task) lowered recurrence by 10.8 percentage points with little observed loss of working code (Guo et al., 2026, §II-D). Gating revisions on fresh executions removes selection bias: in a calibration with an earlier 10% nominal false-acceptance criterion, a no-effect revision was accepted 68% of the time on the runs that chose its targets versus 12% on fresh runs (Guo et al., 2026, §IV-G).
When this backfires¶
Do not rely on evolved natural-language principles in these regimes:
- Multi-file repository workflows: on SusVibes (184 Python feature tasks across 101 projects, 20 steps), no library beat no guidance (
S|P10.5–13.5% across conditions; 13.0–13.3% with learned libraries vs 13.5% unguided). During evolution, median tool calls rose to 108, the library shrank to 0.11% of input tokens, and 98% of findings concerned a single task that could not clear statistical gating. Across the 30 SusVibes test tasks where the evolved library left functional but insecure code, Codex never opened a library document on 10 and returned to one after its first edit on only 4 of the remaining 20 (Guo et al., 2026, §VI, Table X). - Cross-language codebases: applying the SeCodePLT Python library to CWEval C, C++, and JavaScript tasks pushed
pass@1below the 3-point floor (Guo et al., 2026, §V-B EQ5). - Broad situation clauses (
a) that overreach across CWEs: a CWE-200 template-formatting principle fired on CWE-77 HTML templates and caused 72% functional test failure among executions that opened it (vs 33% for others), dropping Codex CWE-77pass@1from 69.0% to 46.0% (Guo et al., 2026, §V-B EQ4, Table XIV). - Prompt-only or unverified harness evolution: prompt engineering alone showed no statistically significant reduction in vulnerability frequency or density across five LLMs and four languages (Kharma et al., 2026), and automatic harness evolution on Terminal-Bench 2.1 did not consistently beat test-time scaling (Wang et al., 2026).
- Untrusted test suites or inputs: a poisoned benchmark led Hyperagents (powered by Sonnet 4.5) to self-evolve instructions disabling HTTPS certificate validation on neutral URL-fetching tasks, with contamination often persisting under later clean benchmarks (Roesner & Kohno, 2026). At 10% attacker support, trajectory poisoning embedded target behaviors in 91.0% of SkillClaw trials and 61.5% of Trace2Skill trials (Chen et al., 2026). Adversarial test inputs read during analysis can also attach an untested
vexception to an otherwise useful revision (Guo et al., 2026, §VIII-B).
In multi-file repositories and polyglot stacks, enforce security deterministically at the harness and CI boundary (static analyzers, pre-commit or PreToolUse hooks, sandboxes, and project-specific security regression tests) instead of relying on natural-language rules that dilute across long sessions and need a per-CWE training corpus.
Key Takeaways¶
- Treat cross-session vulnerability recurrence as an activation problem, and verify that any retained security note names a code-class trigger
a, required checkk, and allowed behaviorvrather than one task's function names. - Never accept an instruction-file revision on the same test runs that surfaced the failure; evaluate edits on fresh paired executions with an explicit functional
pass@1floor. - Audit principle libraries for cross-CWE functional regressions by tracking per-CWE
pass@1, because an aggregate non-inferiority floor can hide a sharp drop on one vulnerability class. - Use deterministic scanners, hooks, and regression tests once sessions span multi-file repositories or multiple languages, where natural-language principle libraries lose context share and go unread.
- Isolate the test corpus that drives instruction evolution from untrusted contributors, and require every
v(allowed-behavior) clause to cite a failed functional test during review.
Related¶
- Security Constitution for AI Code Generation — Static, versioned security rules consumed at specification time and paired with linters and CI gates
- Security Drift in Iterative LLM Code Refinement — How functional fix-test loops accumulate silent security regressions when security tests are absent
- Benchmark Poisoning of Self-Modifying Coding Agents — How attacker-controlled test suites write persistent insecure directives into self-modifying agents
- Security Knowledge Priming for Code Generation (SPARK) — Lightweight prompt-level CWE cues as a supplement to static scanners
- Probe-and-Refine Tuning of Repository Guidance for Coding Agents — Execution-grounded refinement of repository guidance files for functional tasks