ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection

arXiv:2608.20637 · cs.CR, cs.AI · Submitted 2026-08-21 · Read on arXiv

Listen

Radio episode about this paper

Transcript

Introduction to the show: ident: Security Radio. Generated commentary on the latest security and cryptography papers.

Nadia: I'm Nadia.

Elias: And I'm Elias, here with Priya.

Nadia: We're looking at the paper: "ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection".

Paper summary: Nadia: So we're talking about this paper called ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection. Essentially, static analysis tools like CodeQL use queries to find bugs in C and C plus plus programs. But these existing queries have problems with false positives and false negatives, meaning they either flag safe code as bad or miss actual vulnerabilities. ARQ is this agentic framework that automatically improves those CodeQL queries using evidence from synthesized programs.

Elias: That's the core thesis, Nadia. The main idea is that a synthesized program exposes a weakness in a query whenever its execution doesn't match what the query predicts it should find. If the program is actually vulnerable but the query stays silent, that's a false negative weakness; if it’s safe and the query still flags it as bad, that’s a false positive weakness. ARQ then uses an LLM-based loop to fix those weaknesses based on what those programs show.

Priya: So what does this actually mean for us looking at the data? If the synthesized program's execution disagrees with the query's verdict, it gives us ground truth that helps guide the refinement process. It’s using actual runtime behavior to correct the static analysis rules.

Nadia: Exactly. The paper shows they refine twelve official CodeQL queries using three different commercial LLMs, GPT-five point four, Claude-Sonnet-four point six, and Gemini-three point five-flash to see how effective it is in practice across different models and queries on the Juliet v1 point 3 and FormAI v2 datasets.

Elias: And they found that ARQ actually improved query performance in those evaluations when compared against the original CodeQL queries, although those gains depend on which underlying model you use, as Table one shows <ref:2608.20637#pg1>.

Priya: But we have to look at what they did beyond just those benchmark datasets. The paper validates ARQ on real, currently unresolved problems in widely used software by fixing three open GitHub issues related to UseAfterFree and identifying two previously undiscovered bugs in seven popular C plus plus projects like libpng and zlib.

Nadia: That’s a pretty big deal because it shows the framework works on actual codebases, not just theoretical examples. It also fixed three unresolved GitHub issues in the official CodeQL query repository that had been open for as long as twenty-seven months.

Elias: And they also looked at why this works by doing an ablation study to see if grounding the LLMs through Analyze and Oracle is necessary to reduce hallucinations in the LLM process. They found that without execution-grounded evidence, the agent sometimes hallucinates a weakness that doesn't actually exist, so running those tests is not just helpful—it seems necessary.

Priya: So, putting it simply, ARQ uses execution-driven reasoning where programs are synthesized to expose query failures, and then the LLM uses that disagreement as ground truth to repair the original query through iterative refinement.

Nadia: Right. The title of this paper is ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection by Chunyi Wang, Yunfei Ke, Junfeng Yang, Yun-Yun Tsai, and Penghui Li from Columbia University. It really highlights how we can use agentic frameworks to keep static analysis tools relevant as software evolves.

Elias: It suggests that an automated way to keep those queries updated through program synthesis and iterative LLM-guided reasoning could meaningfully reduce the maintenance burden on tools like CodeQL and help them stay effective as codebases and vulnerability patterns evolve.

Priya: The limitation they point out is that most query failures are never filed as bug reports, which means the framework relies on finding those specific failure modes through synthetic programs, which might not cover every real-world scenario.

Nadia: That's fair. So while ARQ shows promise for improving query accuracy and finding new bugs, we have to consider that the quality of the refinement really depends on how good those synthesized witness pairs are generated in the first place.

Elias: True. The efficiency of ARQ involves running this refinement loop over multiple iterations, with each iteration taking an average of four hundred thirty-three to six hundred ninety seconds depending on the model, so a full five iteration refinement can complete within an hour.

Priya: It's interesting that they focused on how the process works rather than just presenting a final, perfect query. They show you how it alternates between false negative and false positive witnesses until the budget is exhausted.

Nadia: It’s about making the static analysis queries more robust by treating them like something that can be actively refined, not just static rules you write once and forget about. That's what ARQ is aiming for.

Elias: So if you think a tool needs to stay effective as codebases change, automating the refinement of its detection queries using execution-grounded evidence is a practical strategy they’ve demonstrated here with ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection.

Conclusion: Nadia: So we're wrapping up this look at ARQ, which stands for Agentic CodeQL Query Refinement for C plus plus vulnerability detection by Wang and colleagues at Columbia University.

Elias: Yeah, it’s an agentic framework that uses execution-grounded evidence from synthesized programs to automatically fix the weaknesses in static analysis queries.

Priya: What they did is take existing CodeQL queries, which often have false positives or false negatives, and use this loop of generating test programs and getting feedback from those programs to actually improve the query itself.

Nadia: Exactly. The core idea is that if a program you run doesn't match what the query predicts it should find, that execution disagreement becomes a piece of ground truth to guide the refinement process.

Elias: It’s about using actual runtime behavior instead of just pure logic to determine if a vulnerability exists in code. This moves beyond just reading the source code and actually testing its behavior.

Priya: I'm interested in how they built that feedback loop, because they spent a lot of time on defining what constitutes a query failure, which is either a false positive or false negative against a specific program.

Nadia: Right, and then they ask the AI to generate pairs of programs that are similar but expose this failure. That pair acts as the witness showing where the query is weak.

Elias: And then they use that witness, that confirmed disagreement, to prompt an LLM to propose a better version of the original query. It’s a cycle where execution drives refinement and the LLM guides it.

Priya: So what this means for folks working on security tools is that you can use these AI agents to continuously keep your analysis queries current without having to manually write and test every single new edge case.

Nadia: It does suggest that automated, iterative refinement of static analysis queries could significantly lower the maintenance burden on tools like CodeQL as codebases change constantly.

Elias: It’s about keeping those detection rules effective as the vulnerability patterns in software evolve over time. But we still have to watch how well those synthesized programs actually capture all possible tricky scenarios.

Priya: That’s right, so while it tackles false positives and negatives effectively on test sets, we need to see if this level of automation holds up when applied to the really messy, real-world codebases.

Columbia University

cs.CR, cs.AI

Submitted: 2026-08-21

Updated: 2026-11-29

Code: https://github.com/github/codeql

License: http://arxiv.org/licenses/nonexclusive-distrib/1.0/

Importance score: 83/100

The gist: Static analyzers have widely adopted for vulnerability detection in C/C++ programs.<ref:2608.20637#pg1, However existing queries still suffer from false positives (FPs…

Key concepts

Execution-driven Reasoning
Instead of relying solely on text reasoning, ARQ executes synthesized programs to test a query's verdict. If the program's actual behavior contradicts the query's prediction, it reveals a weakness that can then be used to fix the query.
Witness Generation
The agent iteratively generates pairs of similar programs designed to expose flaws in the current query. These generated programs serve as 'witnesses'; when their execution results differ from what the query expects, they provide ground truth for refinement.
Oracle Function
The Oracle is a critical function that provides the definitive, correct result for a program's execution. This ground truth is essential because it allows the agent to detect and correct hallucinations—instances where an LLM incorrectly suggests a weakness that doesn't actually exist.

Terminology

Summary

Static analyzers have widely adopted for vulnerability detection in C/C++ programs. p. 0<ref:2608.20637#pg1, However existing queries still suffer from false positives (FPs, incorrectly flagging benign code as vulnerable) and false negatives (FNs, missing real vulnerabilities) >. p. 0 We present ARQ, an agentic framework that automatically refines C/C++ CodeQL queries using executiongrounded evidence from synthesized C/C++ programs. p. 0<ref:2608.20637#pg1, Our key insight is that a synthesized program exposes a query’s weakness whenever its execution disagrees with the query’s verdict >. p. 0 ARQ then runs an LLM-based refinement loop that repairs the query using these disagreements as ground truth. p. 0<ref:2608.20637#pg1, We demonstrate the effectiveness of ARQ by refining 12 official CodeQL queries using three commercial LLMs (GPT-5. p. 04, Claude-Sonnet-4. p. 06, and Gemini-3. p. 05-flash) >. p. 3

Pruning redundant reasoning tokens

The framework operates through an iterative process where an LLM proposes witness pairs that expose query failures.<ref:2608.20637#pg2>. This involves a cycle where the agent generates programs to expose weaknesses, executes them to confirm the weakness via Oracle, and then uses this evidence to update the query. p. 1<ref:2608.20637#pg4>.

How the training signal is built

The core mechanism for refinement relies on execution-driven reasoning where programs are synthesized to expose query failures.<ref:2608.20637#pg3, We define a query failure as a false positive or false negative that the query commits against a specific program p >. p. 2 The agent asks the LLM to generate a pair of witnesses w0 = (p0, c0q, c0o) and w1 = (p1, c1q, c1o), asking it to make p0 and p1 as similar as possible. p. 2<ref:2608.20637#pg4>. The Oracle function is critical as it produces ground-truth used to detect hallucinations. p. 2<ref:2608.20637#pg4>.

Where the gains come from

The effectiveness of ARQ is demonstrated by comparing its refined queries against original CodeQL queries on the Juliet v1.3 and FormAI v2 datasets. p. 0<ref:2608.20637#pg5>. Furthermore, ARQ successfully fixed three unresolved GitHub issues raised in the official CodeQL query repository that had remained open for as long as 27 months. p. 0<ref:2608.20637#pg5>.

Ablation Study

The study investigates whether grounding LLMs via Analyze and Oracle is necessary to reduce hallucinations in LLMs.<ref:2608.20637#pg7>. Manual inspection of agent transcripts shows why without execution-grounded evidence, the agent sometimes hallucinates a weakness that does not exist. p. 5<ref:2608.20637#pg7, Grounding LLMs via Analyze and Oracle through actual program execution is therefore not just beneficial—it is necessary >. p. 6

Efficiency

The efficiency of ARQ involves running the refinement loop over multiple iterations, with each iteration taking an average of 433–690 seconds depending on the model.<ref:2608.20637#pg8>. A full 5-iteration refinement completes within an hour. p. 6<ref:2608.20637#pg8>.

Conclusions

ARQ presents an agentic framework for automatically refining static analysis queries through execution-validated program synthesis and iterative LLM-guided reasoning.<ref:2608.20637#pg1>. Beyond these benchmarks, ARQ fixed 3 previously unresolved GitHub issues in the CodeQL repository and found 2 real, previously undiscovered bugs in 7 widely-used C/C++ projects. p. 6<ref:2608.20637#pg5>. Looking forward, ARQ’s core idea is not specific to CodeQL or to C/C++ <ref:2608. p. 620637#pg6>. The paper concludes that an automated way to keep queries up-to-date could meaningfully reduce the maintenance burden on tools like CodeQL and help them stay effective as codebases and vulnerability patterns evolve. p. 6<ref:2608.20637#pg6>.

--- Page 1 ---

ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection

Chunyi Wang ∗, Yunfei Ke ∗, Junfeng Yang, Yun-Yun Tsai, Penghui Li Department of Computer Science, Columbia University, New York, United States

--- Page 2 ---

1 Input query Q (DoubleFree.ql)

--- Page 3 ---

2 Preliminaries

--- Page 4 ---

2.1 Illustrative Example

We illustrate a buggy query DoubleFree.ql1 in GitHub’s official CodeQL query suite. p. 1<ref:2608.20637#pg4>. However, this query further requires the two sink calls to satisfy the rule, defaultSourceSinkIsRelated, which holds only when both calls lie within the same if branch. p. 1<ref:2608.20637#pg4>.

--- Page 5 ---

Figure 1: ARQ refining DoubleFree.ql. 1 the query under refinement. p. 0 2 the LLM proposes a pair of near-identical programs, tp. p. 1c and fn.c, that should disagree on the query’s verdict. p. 1<ref:2608.20637#pg5>. 4 guided by this confirmed witness (fn. p. 1c), the LLM proposes a refined query. p. 1<ref:2608.20637#pg5>.

--- Page 6 ---

1 I

--- Page 7 ---

  1. A double-free happens when a program calls free twice on the same pointer. p. 1 This corrupts the memory allocator’s internal bookkeeping and can be exploited to crash the program. p. 1<ref:2608.20637#pg7>.

--- Page 8 ---

1 1

--- Page 9 ---

2 void process buffer(char buffer)

3 char p = malloc(10);

4 free(p);

5 free(p); // double free

--- Page 9 ---

2 void use after free(char buffer).<ref:2608.20637#pg9>.

--- Page 9 ---

1 Listing 1: Simplified version of provided code in issue 16542.

--- Page 9 ---

2 module UseAfterFreeParam implements

FlowFromFreeParamSig.<ref:2608.20637#pg9>.

--- Page 10 ---

2.3 Key Ideas: Execution-driven Reasoning

Unlike purely LLM-based reasoning about a query’s correctness, ARQ executes programs and uses their runtime behavior to directly establish whether a vulnerability is present.<ref:2608.20637#pg4>.

--- Page 11 ---

3 ARQ Framework

We formalize the problem as follows.<ref:2608.20637#pg4>.

--- Page 12 ---

Algorithm 1: Adversarial Refinement Iteration. Input: Query Q, witness generation budget N, LLM refinement step T, regression tests Wr. p. 3 Primitives: Gen(Q) is a generation function that generates witness programs p for query Q. p. 3 Analyze(Q, p) and Oracle(p) are weakness detection functions. p. 2 Improve(Q, W) is a query refinement function. p. 2 Output: Refined query Q∗1 Wr←∅; 2 while T. p. 3<ref:2608.20637#pg4, do 3 T ← T − 1; // Phase 1: generate and validate 4 Wr, Wc = FIND_WITNESS(Q, N) // Phase 2: refine 5 Wr, Q′ = REFINE(Q, Wc) >. p. 3

--- Page 13 ---

9 Procedure FIND WITNESS(Q, N) found ← false; while N.<ref:2608.20637#pg4, do W ← Gen(Q); N ← N − 1; if ∀(p, cq, co) ∈ W: Analyze(Q, p) = cq ∧ Oracle(p) = co then found ← true; Wr ← Wr ∪ W; Wc ← W; break; if ¬found then return (Wr, ∅); no witness found >. p. 3 else return (Wr, Wc)

--- Page 14 ---

9 Procedure REFINE(Q, Wc) Q′ = Improve(Q, Wc); forall w ∈ Wr do p, cq, co ← w; c1 = Analyze(Q′, p); if c1!= co then W˜ ← W˜ ∪ w; if W˜ = ∅ then return (Wr, Q′); else Q' = Improve(Q', W̃); return (Wr, Q′)

--- Page 5 ---

4.1 RQ1: Query Performance Dataset. p. 4 We evaluate these CodeQL queries on Juliet v1. p. 43 (Black and Black 2018; Jr and Black 2012) and FormAI v2 (Tihanyi et al. p. 4 2025).<ref:2608.20637#pg5, We evaluate 12 CodeQL queries on the two datasets described above >. p. 4

--- Page 5 ---

Baselines. We compare only against the original CodeQL queries, not against IRIS (Li, Dutta, and Naik 2024) nor QLCoder (Wang et al. p. 4 2026).<ref:2608.20637#pg5, Both target Java: IRIS infers taint sources and sinks to feed a generic taint-analysis template, and QLCoder synthesizes a new query from CVE metadata; neither has a C/C++ implementation (CodeQL queries are language dependent), and neither refines an existing query the way ARQ does >. p. 4

--- Page 5 ---

Metric Ideally, as with most vulnerability detection tasks, we should evaluate both precision and recall.<ref:2608.20637#pg5, However, recall is not feasible to compute here >. p. 4 Precision = TP / (TP +F P). p. 0 Here, a true positive (TP) is a query detection on a sample that contains a genuine instance of the targeted vulnerability, and a false positive (FP) is a query detection on a sample that does not. p. 4<ref:2608.20637#pg5, Results Table 1 shows that ARQ generally improves query performance, though the exact gains depend on the underlying model >. p. 4

--- Page 5 ---

Table 1: True Positives, False Positives, and Precision aggregated over all included queries. Per-query break down is in technical supplement. p. 4 p. 4<ref:2608.20637#pg5, Table 1 also illustrates our concerns about the difficulty in evaluating CodeQL queries >. p. 4

--- Page 5 ---

4.2 RQ2: Real-World Impact Beyond the evaluations on Juliet and FormAI in § 4. p. 41, we validate ARQ on real, currently unresolved problems in widelyused software, where it matters most. p. 4<ref:2608.20637#pg6, Fixing GitHub CodeQL Issues The most direct application of ARQ is fixing known, unresolved problems in queries described by open GitHub issues2 >. p. 5 We selected the 3 most recent C/C++-query-related issues that have a minimally reproducible example, and all three happen to concern UseAfterFree. p. 5ql.<ref:2608.20637#pg6, ARQ fixed this by extending control-flow tracking to function argument usage using isNonThisParameterUse >. p. 5 Evaluating Queries on Open Source Projects. p. 5 We evaluated CodeQL queries and their refined counterparts on seven widely-used C/C++ projects (libpng, zlib, curl, redis, pcre2). p. 5<ref:2608.20637#pg6, The refined queries identified 2 previously undiscovered bugs that the original CodeQL queries do not detect >. p. 5

--- Page 5 ---

Table 2: Results for baseline, aggregated over the same query subset as Table 1. Per-query break down is in technical supplement.<ref:2608.20637#pg5, Table 2 also illustrates our concerns about the difficulty in evaluating CodeQL queries >. p. 4

--- Page 5 ---

4.3 RQ3: Ablation Study ARQ is based on the belief that we can reduce hallucinations in LLMs by giving them a source of ground truth. p. 5<ref:2608.20637#pg7>. ARQ consistently outperforms this pure-LLM baseline, showing the clear advantage of Analyze and Oracle. p. 5<ref:2608.20637#pg7>.

--- Page 5 ---

Table 3: Outcomes for all iterations per model.

--- Page 5 ---

4.4 RQ4: Efficiency. p. 6 As mentioned in § 3. p. 43, we delegated Algorithm 1 to coding agents. p. 6<ref:2608.20637#pg8>. Because programs used in witnesses are small, ARQ is not CPU-bound, so nearly all time is spent waiting on the LLM. p. 6<ref:2608.20637#pg8>. This demonstrates that execution-guided, example-driven query refinement is a practical and effective strategy for improving static analysis at scale without requiring manual specifications or labeled vulnerability datasets. p. 6<ref:2608.20637#pg1>.

--- Page 6 ---

5 Related Work

Pure LLM Vulnerability Detection LLMs have long been used for detecting vulnerabilities in code.<ref:2608.20637#pg9>. LLM-Assisted Static Analysis Studies about integrating LLMs with traditional static analysis tools for better vulnerability detection are rapidly emerging. p. 6<ref:2608.20637#pg9>.

--- Page 7 ---

LLM-Assisted Static Analysis Studies about integrating LLMs with traditional static analysis tools for better vulnerability detection are rapidly emerging.<ref:2608.20637#pg9>. Our approach refines the query using test programs generated independently from the application. p. 6 p. 6<ref:2608.20637#pg9>.

--- Page 9 ---

LLMs as Agents in Software Engineering Using LLMs as agents to interact with standard SWE tools (Yang et al. 2024) is not a new practice. p. 6 p. 6<ref:2608.20637#pg9>.

--- Page 10 ---

LLM-Assisted Static Analysis Studies about integrating LLMs with traditional static analysis tools for better vulnerability detection are rapidly emerging.<ref:2608.20637#pg9>.

--- Page 11 ---

LLM-Assisted Static Analysis Studies about integrating LLMs with traditional static analysis tools for better vulnerability detection are rapidly emerging.<ref:2608.20637#pg9>. Our approach refines the query using test programs generated independently from the application.<ref:2608.20637#pg9>.

--- Page 13 ---

LLMs as Agents in Software Engineering Using LLMs as agents to interact with standard SWE tools (Yang et al. 2024) is not a new practice.<ref:2608.20637#pg9>.

--- Page 14 ---

LLM-Assisted Static Analysis Studies about integrating LLMs with traditional static analysis tools for better vulnerability detection are rapidly emerging.<ref:2608.20637#pg9>.

Green — the paper says it, and the page is printed. Red — no passage carries it, so treat that sentence as unverified. The same check runs on your own text: check a summary against its source, $5.

Improvements for AI systems

  1. Improved Query Refinement Loop: The Agentic Framework automatically refines CodeQL queries using executiongrounded evidence from synthesized programs to expose false positives and false negatives, as shown in Algorithm 1. This loop runs iteratively, accepting or rejecting query updates based on whether the refined query passes all witness checks.

  2. Enhanced Witness Generation: The system generates pairs of near-identical witness programs (tp.c and fn.c) where only the control flow differs, encouraging LLMs to reason about vulnerable patterns rather than matching exact function names in p1. This pairing helps generate matched TN-FP or TP-FN pairs, ensuring the refinement loop alternates between addressing false positives and false negatives.

  3. Grounding via Execution Oracle: The system uses the executiongrounded evidence through functions like Analyze and Oracle to directly establish whether a vulnerability is present, addressing the challenge that most query failures are never filed as bug reports. This grounding is necessary because Without execution-grounded evidence, the agent sometimes hallucinates a weakness that does not exist.

  4. Robustness Against Regressions: ARQ incorporates regression testing by revalidating every refined query against a regression set Wr before accepting an update. This mechanism ensures that a fix for one weakness cannot silently break a case that was previously validated, preventing spurious reports from being introduced during refinement.

Sources

Related papers