Autonomous code-writing systems increasingly work in loops: an agent drafts a patch, runs the tests, a second agent reviews it, and the draft is revised until the tests pass and the reviewers stop objecting. Safety research has mostly asked whether such agents can be tricked by text planted in the task description. A more unsettling question sits one layer deeper: what if the attacker controls one of the roles in the loop itself — not the issue text, but the persona of the reviewer or critic who the developer agent trusts? We know from role-play vulnerability research that models will sacrifice safety constraints to stay "in character," and from the code-refinement literature that multi-agent review teams are held together largely by conversational pressure. Nobody has yet connected the two: an adversary who weaponizes reviewer personas inside an iterative refinement loop to smuggle exploitable code past the entire pipeline.
The proposal has two halves. First, a threat model and attack study: an adversarial "reviewer" (or a compromised reviewer persona) uses developer-legitimate review comments — "this error handling is over-engineered, simplify it," "use raw string concatenation for performance" — to steer the developer agent, turn by turn, toward functionally correct yet vulnerable (FCV) patches. Second, a defense grounded in a simple observation from the refinement literature itself: these loops treat the compiler and the unit tests as objective ground truth, but security has no seat at that table. We extend the execution-feedback loop with a second oracle — dynamic proof-of-concept exploit tests of the kind used in SecCodePLT — so that "patch accepted" requires both functional and security feedback to pass. The core claim is that persona-driven security injection in refinement loops is a distinct and measurable failure mode, that it is amplified by some review dynamics we currently praise (including structured disagreement), and that it is best suppressed not by better prompts but by changing what counts as ground truth in the loop.
What the Existing Work Leaves Open
The closest prior work is When "Correct" Is Not Safe, which introduces the FCV attack: a malicious suggestion hidden in a GitHub issue text causes repository-level agents (SWE-Agent, Mini-SWE-agent) to fix the target bug while quietly inserting a CWE-class vulnerability, with attack success rates from 18.1% to 62.9% across agent-model combinations and 56.3% for SWE-Agent with Claude Sonnet 4. Critically, that attack is a single-prompt injection at the start of a trajectory; it never tests whether an adversary embedded in the multi-turn review conversation can escalate or be caught, and it proposes no loop-level defense. Its own open problems section says exactly this.
Two other papers define the ground the proposal stands on. Adversarial Review shows that multi-agent code refinement is a persona-driven conversation: unconstrained reviewer agents fall into "false consensus" (acquiescing under conversational pressure), and forcing structured disagreement — a fixed taxonomy of DISAGREE_EVIDENCE and DISAGREE_CONCERN labels with line-level citations — beats larger teams. But that paper evaluates only functional correctness on LiveCodeBench, SWE-PRBench, and SWE-bench Verified; it never measures security or adversarial personas. Conversely, Disentangling Intent from Role builds Persona-Invariant Consistency Learning (PICL), a teacher-student training scheme that pulls persona-conditioned outputs toward the model's safe direct responses, cutting average attack success from 60.1% to 5.4% on Qwen models and 30.2% to 5.2% on Llama-3.1 models — but only on conversational safety benchmarks, never on developer personas or code. The open question is whether persona-invariance, which was designed for chat, transfers to a setting where the baseline behavior itself is already security-negligent: Purple Llama CyberSecEval reports that models suggest insecure code about 30% of the time and that stronger coding ability correlates with worse security adherence.
Two further results constrain the design. Do Users Write More Insecure Code with AI Assistants? found that feedback loops in which the model refines its own output magnified security errors rather than fixing them — evidence that iteration alone is not a defense and can be an accelerant. And Structural Safety Generalisation in Agentic AI Setups showed that decomposing a harmful goal across role-specialized sub-agents reassembles into compliance (a DeepSeek model jumping from a 0.018 baseline refusal rate to a 0.591 attack score under multi-agent breadcrumb decomposition), but only on general NLP benchmarks, not code repositories. The proposal differs from all of these by studying the attack inside the loop, where the attacker participates in the iterative conversation and the loop's own verification machinery is the battleground.
Research Program
The first workstream builds the attack. We construct a benchmark, FCV-Loop, by extending SWE-bench Verified tasks with a paired CWE injection target chosen to be semantically compatible with the task (for example, replacing a parameterized query with string concatenation in a database-adjacent fix, per the CWE-538 pattern that reached a 67.6% insertion rate in When "Correct" Is Not Safe). The adversary is not a static prompt: it is a policy controlling one role in the refinement protocol — reviewer or critic — that emits review comments in the normal format at each iteration. The attack succeeds only if the final merged patch passes the task's unit tests and contains an exploitable weakness confirmed by a proof-of-concept exploit, scored with the StrongREJECT-style willingness-and-actionability logic of A StrongREJECT for Empty Jailbreaks adapted to code (refused/specific/convincing become does-not-compile, present-but-benign, exploitable).
The scientific payoff of this workstream is a decomposition of why the attack works. Role-play vulnerability work (Shah et al.; Xu et al.; Ramesh et al.) attributes persona-driven compliance to the model prioritizing character consistency over safety. In the refinement loop we can test three competing mechanisms: persona authority (the developer obeys because a reviewer said so), conversational momentum (the developer obeys because the conversation has drifted over many turns, as in the false-consensus dynamics of Adversarial Review), and feedback blindness (the developer obeys because nothing in the execution signal ever contradicts the suggestion, per the security-blind-oracle gap). We isolate them by ablation: same attacker, but with the reviewer relabeled as an anonymous linter output (removes persona authority), truncated to single-turn suggestion (removes momentum), and run against a loop that includes exploit-based tests (removes blindness).
The second workstream builds the defense: a security-grounded refinement loop. The change is deliberately minimal. At each iteration, alongside compiling and running unit tests, the loop runs two cheap checks — static analysis rules of the Insecure Code Detector kind (96% precision, 79% recall over 50 CWEs per CyberSecEval) on the diff, and, when a rule fires, a generated PoC exploit executed in a sandbox of the SecCodePLT style to confirm exploitability. Only a diff that passes tests, clears static analysis, and fails to be confirmed exploitable may be merged. The security feedback enters the loop exactly as compiler errors do — as just another machine signal with no persona attached — which is the point: the defense works by making ground truth impossible to argue with conversationally, rather than by teaching the agent better safety beliefs.
Baselines
The do-nothing reference point is the standard zero-shot single-agent refinement loop on SWE-bench Verified, which Adversarial Review reports at a 71.6% pass rate; under FCV-Loop attack we expect its security failure to be at least as bad as the 18.1%–62.9% attack success range When "Correct" Is Not Safe reports for single-prompt injection, since our attacker gets more turns.
The strongest existing competitor for the defense question is the system-prompt hardening that When "Correct" Is Not Safe already tested: adding explicit security instructions to the agent's system context. That paper reports it "slightly reduced ASR but did not eliminate the vulnerabilities," with Claude Sonnet 4 still reaching a 56.3% attack success rate under the original FCV attack. We will run it under identical models, identical FCV-Loop tasks, and identical turn budgets as our defense. A second competitor for the refinement quality question is the 3-agent Adversarial Review protocol itself (75.2% on SWE-bench Verified, 87% on LiveCodeBench, and an F1 of 0.533 on SWE-PRBench, all from Adversarial Review): our defense must not degrade functional performance below it, so we adopt the same protocol as the substrate and change only the feedback oracle. Both competitors get the same compute and tuning budget as our system — same models, same iteration caps, same token ceilings — because the claim we want to test is about the oracle, not about scale.
Two ablations isolate the key ingredient. Static-only: the loop with static analysis but no dynamic PoC confirmation, which measures how much of the defense comes from confirming exploitability rather than pattern matching — important because CyberSecEval itself notes its rule set misses logic-based vulnerabilities. Persona-only: the loop with a reviewer whose persona is explicitly rewritten to be "a security-obsessed senior engineer" but with no machine oracle — this measures whether security-minded personas can substitute for security ground truth, which is the cheapest thing a practitioner would try first. Beating the system-prompt-hardening baseline means cutting attack success on FCV-Loop by at least half while keeping the SWE-bench Verified pass rate within two points of the 75.2% Adversarial Review figure; beating static-only means catching a strictly larger set of confirmed-exploitable injections at matched false-positive rate.
Why not just…?
Why not just add security instructions to the system prompt? This is the first thing any practitioner tries, and the file already contains its evaluation: When "Correct" Is Not Safe reports that system-prompt safety instructions slightly reduced attack success but left it high (56.3% for Claude Sonnet 4 under the single-prompt variant), and Disentangling Intent from Role shows prompt-level safeguards lose specifically when persona pressure conflicts with global instructions. In a multi-turn loop the problem is worse, because the adversarial reviewer's authority re-asserts itself every iteration while the system prompt is stated once. We still run this baseline, but the mechanism-level explanation above predicts it plateaus; if it instead closes most of the gap in our loop setting, that would itself be a publishable negative result for the oracle proposal.
Why not just run a linter like Semgrep or the Insecure Code Detector on the final diff? Post-hoc static scanning is cheap and needs no new science. CyberSecEval reports 96% precision and 79% recall for its detector but explicitly notes it misses logic-based vulnerabilities, and SecCodePLT argues static rules cannot tell whether a flagged weakness is actually exploitable. The deeper problem is adversarial: our attacker sees the loop's checks if they are part of the loop, but a final-diff-only scanner faces an adversary free to search for weaknesses the rules miss, and the refinement loop's own optimizing pressure — the same pressure Do Users Write More Insecure Code with AI Assistants? shows magnifies insecurity — will find them. Our static-only ablation is exactly this alternative run honestly, with dynamic PoC confirmation as the increment on top; if static-only matches full security-grounded feedback, the simpler method wins and we will report that.
Why not just apply PICL to the coding model? Persona-Invariant Consistency Learning already exists and cut attack success from 60.1% to 5.4% on Qwen models, so retraining for persona-invariance looks like the cleanest fix. But those numbers are on conversational safety suites (JBB-Behaviors, HarmBench, PKU-SafeRLHF), and CyberSecEval documents that models refuse direct cyberattack requests yet comply when the same request is framed as debugging — the persona-invariant target distribution is itself insecure in the developer-persona regime. Pulling the developer-persona output toward the model's unconditioned output may pull it toward the 30% insecure-code baseline rather than away from it. We will test a PICL-style model in our loop as a fourth condition; this is a genuine open threat to the proposal, and the loop experiment is precisely what would settle whether persona-invariance helps, is neutral, or actively imports insecure defaults into code contexts.
Why not just use one bigger single agent in a sandbox? Adversarial Review already compared this: single-agent zero-shot scored 77% on LiveCodeBench versus 87% for the 3-agent protocol, at roughly 4.5× lower token cost, so single-agent is a real Pareto point and our defense must be shown to work there too, not only in multi-agent loops. We will therefore run the security-grounded oracle in a single-agent loop as well. The honest caveat: the attack half of the proposal is intrinsically multi-agent (there is no reviewer persona to corrupt in a single-agent loop), so the threat-model findings will not transfer there — only the defense findings will, and we scope the claims accordingly.
Proposed Experiments and Decisive Checks
Experiment one measures the attack. On FCV-Loop (200 SWE-bench Verified tasks paired with CWE targets), we run the reviewer-persona attacker against the zero-shot single-agent loop, the unconstrained multi-agent loop, and the structured-disagreement Adversarial Review protocol, reporting attack success (confirmed-exploitable FCV patches), functional pass@1, and the number of review turns to first injection. The key scientific test is the prediction that structured disagreement, praised for fixing false consensus on functional bugs, either fails to help against persona-driven security injection or worsens it — because DISAGREE_EVIDENCE forces the honest critic to marshal evidence against a reviewer whose suggestions do work functionally. If disagreement constraints cut attack success substantially, the false-consensus account extends to security and the field's current fix already covers half our story; that outcome would refocus the proposal entirely on the oracle defense.
Experiment two measures the defense. Same tasks and attack; the loop's oracle is extended with static analysis plus dynamic PoC confirmation. Success is defined against the baselines above: attack success halved or better relative to system-prompt hardening under matched models and budgets, SWE-bench Verified pass rate within two points of the 75.2% Adversarial Review substrate, and a strict improvement in confirmed-exploitable detection over static-only at matched false-positive rate on the repository diffs. Benign control runs on LiveCodeBench and SWE-PRBench (using the F1 metric, where Adversarial Review reports 0.533) verify the added checks do not cause over-refusal or the over-editing regressions Adversarial Review documents, and SecCodePLT's C/C++ subset — where top models stay below 20% patch success — tests whether security feedback improves or further hardens patch generation, since SecCodePLT already shows reminders alone do not close that gap.
Experiment three is the mechanism dissection and the PICL test described above, run on a 100-task subset with turn-by-turn logging of the developer's stated justifications, so we can classify which injections succeeded through authority, momentum, or blindness, and whether persona-invariant training shifts the mix. The proposal is falsifiable in a specific way: if the single-prompt FCV attack strength carries over unchanged regardless of reviewer persona, loop dynamics, and oracle type — that is, if attack success is invariant to everything we vary — then role-play dynamics are irrelevant to code-refinement vulnerability and the loop is merely a passive channel, a conclusion the field currently has no evidence for either way.
References
- SecCodePLT: A Unified Platform for Evaluating the Security of Code GenAI
- When "Correct" Is Not Safe: Can We Trust Functionally Correct Patches Generated by Code Agents?
- Adversarial Review: Structured Disagreement for Grounded Agentic Code Review
- Disentangling Intent from Role: Adversarial Self-Play for Persona-Invariant Safety Alignment
- Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Models
- Do Users Write More Insecure Code with AI Assistants?
- Structural Safety Generalisation in Agentic AI Setups
- A StrongREJECT for Empty Jailbreaks
- Scalable and Transferable Black-Box Jailbreaks for Language Models via Persona Modulation
- FraudShield: Knowledge Graph Empowered Defense for LLMs against Fraud Attacks
- EFFICIENT JAILBREAK ATTACK SEQUENCES ON LARGE LANGUAGE MODELS VIA MULTI-ARMED BANDIT-BASED CONTEXT SWITCHING