Source-linked AI summary

Towards Effectively Leveraging Execution Traces for Program Repair with Code LLMs

Mirazul Haque, Petr Babkin, Farima Farmahinifarahani, Manuela Veloso

arXiv:2505.04441v1cs.LGcs.SE

TL;DR

LLM-based APR often focuses on static code rather than runtime behavior, leaving execution traces underexplored as prompt information. This paper evaluates trace-augmented prompts across datasets and GPT models, finding inconsistent gains that decline with trace complexity, while LLM-optimized traces perform more consistently.

  • Problem

    LLM-based APR largely relies on static code analysis, although debugging can require understanding program runtime behavior.

    Source: §1 · p. 1
  • Method

    The authors augment APR prompts with execution traces and evaluate trace representations across datasets and GPT models.

    Source: §1 · pp. 1–2
  • Results

    Trace prompts do not consistently outperform trace-free prompts, effectiveness declines with longer and more assignment-heavy traces, and LLM-optimized prompts yield more consistent repair results.

    Source: §1 · pp. 1–2
  • Takeaways & Limitations

    LLM-optimized trace prompts provide more consistent repair performance without heuristically limiting trace complexity.

    Source: §1 · p. 2, §6 · p. 8

    The fine-tuning comparison used a small training dataset; the authors plan to test larger datasets and models.

    Source: §5.1 · p. 8

Abstract

from arXiv · show

Large Language Models (LLMs) show promising performance on various programming tasks, including Automatic Program Repair (APR). However, most approaches to LLM-based APR are limited to the static analysis of the programs, while disregarding their runtime behavior. Inspired by knowledge-augmented NLP, in this work, we aim to remedy this potential blind spot by augmenting standard APR prompts with program execution traces. We evaluate our approach using the GPT family of models on three popular APR datasets. Our findings suggest that simply incorporating execution traces into the prompt provides a limited performance improvement over trace-free baselines, in only 2 out of 6 tested dataset / model configurations. We further find that the effectiveness of execution traces for APR diminishes as their complexity increases. We explore several strategies for leveraging traces in prompts and demonstrate that LLM-optimized prompts help outperform trace-free prompts more consistently. Additionally, we show trace-based prompting to be superior to finetuning a smaller LLM on a small-scale dataset; and conduct probing studies reinforcing the notion that execution traces can complement the reasoning abilities of the LLMs.

1 Introduction

The paper addresses LLM-based APR’s limited attention to runtime behavior by adding execution traces to repair prompts. It studies when traces help, how complexity matters, and which trace representations perform more consistently.

1 Introduction

  • LLM-based APR relies on static code analysis, while debugging complex issues can require understanding runtime behavior such as variable and control-flow changes.Execution traces provide diagnostic information beyond static analysis.Source: §1 · p. 1
  • Adding execution traces does not consistently outperform trace-free prompts, and longer traces with more variable assignments are less effective.The paper evaluates trace prompts against failing-test-only and trace-free chain-of-thought prompts.Source: §1 · p. 1
  • Among three trace representations, LLM-optimized prompts provide the most consistent repair results.The alternatives are collated traces and a representation selected according to the LLM’s confidence.Source: §1 · p. 2
  • Two follow-up studies compare trace-based prompting with fine-tuning and probe LLMs on trace-understanding tasks.The fine-tuning comparison is inspired by TraceFixer.Source: §1 · p. 2

2 Related Work

Prior work used execution information in training and explored LLM-generated explanations, but the paper identifies a gap in studying execution traces as prompts for pretrained LLMs.

2 Related Work

  • Prior work used compiler and test diagnostics for self-supervised APR training, and execution traces for pretraining code models on execution-related tasks.Examples include SelfAPR, TRACED, and program-state prediction pretraining.Source: §2 · p. 2
  • TraceFixer improved APR by 13% on synthetic bugs over a code-only baseline but struggled with real bugs.The cited work’s authors note potential generalization limitations.Source: §2 · p. 2
  • Self-Debug uses LLM-generated code explanations in a chain-of-thought approach to program generation.The paper distinguishes this training-free approach from prompting a pretrained LLM with actual execution traces.Source: §2 · p. 2
  • The authors state that, to their knowledge, prior work had not studied placing execution traces in prompts to pretrained LLMs.This is the paper’s stated distinction from the related work it discusses.Source: §2 · p. 2

3 Analyzing the Impact of Execution Traces on Program Repair

The study evaluates trace prompts against trace-free baselines across three APR datasets and two GPT models. Trace benefits vary by configuration, while longer or more assignment-heavy traces are associated with weaker repair outcomes.

3.1 Set Up

  • The evaluation uses Refactory, RunBugRun, and HumanEval-Java, with GPT-3.5 Turbo and GPT-4; traces log runtime state changes tied to code lines.The datasets span student Python bugs, sampled Python submissions, and synthetic bugs in Java-adapted HumanEval problems.Source: §3.1 · p. 3
  • Prompt comparisons measure Correct Fix Accuracy (CFA) and Correct Program Accuracy (CPA), with one prediction per test-case-specific prompt.CFA counts fixes passing all test cases; CPA counts programs with at least one correct fix.Source: §3.1 · p. 3, §3.2 · p. 4

3.2 RQ1. Are prompts with execution traces more effective at program repair than prompts without traces?

  • Trace prompts do not consistently outperform error-only prompts: GPT-4 benefits on two datasets, while GPT-3.5 does not appear to benefit on RunBugRun.On Refactory, error-only prompts outperform trace prompts for both models on fix and program accuracy; HumanEval-Java results vary by model and metric.Source: §3.2 · p. 4

3.3 RQ2. How does trace complexity affect the effectiveness of trace-based prompts?

  • For HumanEval-Java and RunBugRun, failing fixes have higher median trace lengths and variable modifications; Refactory has shorter median traces for failing fixes.Median variable modifications are one in Refactory versus five in RunBugRun, suggesting variable changes may matter to trace effectiveness.Source: §3.3 · p. 5, Figure 2 · p. 5
  • Longer execution traces are associated with a lower chance of generating a correct fix.The analysis considers trace length and the number and type of variable state changes.Source: §3.3 · p. 5

4 Impact of Modified Traces

Section 4 evaluates modified trace representations and routing strategies. LLM-optimized prompts are the most consistent, while confidence- and length-based selection show weaker or limited benefits.

4.1 Modified Traces

  • Some traces exceed 10,000 entries, and trace prompts are truncated in 5% of Refactory cases and almost 10% of RunBugRun cases.The passage reports these extreme traces in all datasets and for both correct and failing fixes.Source: §4.1 · p. 5
  • Collated traces place trace entries inline with matching code lines, while OPT uses GPT-4-32k to condense traces and confidence-based selection falls back to OPT for low confidence.Confidence is measured on a 1–5 Likert scale; scores below 3 trigger the fallback.Source: §4.1 · pp. 5–6

Trace-length Based Prompt Selection (TRL

4.2 RQ3 Results.

  • OPT ranks among the top three prompting techniques for CPA across all dataset/model pairs, leads CFA in three of six, and is second-best for CFA in the other three.Table 2 reports the RQ3 quantitative results for Correct Fix Accuracy (CFA) and Correct Program Accuracy (CPA).Source: §4.2 · p. 6, Table 2 · p. 7
  • Confidence-based selection performs comparatively better for GPT-4 but worse for GPT-3.5, and remains unreliable for GPT-4 because it performs significantly worse than OPT on average.The authors infer that GPT-4 provides significantly better confidence scores than GPT-3.5.Source: §4.2 · p. 6
  • Length routing yields the best CPA only for GPT-3.5 on HumanEvalJava, and changing N has limited impact on CFA and CPA.The authors find no strong evidence that routing by trace length is significantly beneficial.Source: §4.2 · p. 7
  • Collated prompts do not improve over trace prompts; inline loop traces can stretch prompts, while LLMs struggle to track variable changes across iterations and truncation can exclude original problem content.The authors suggest unfamiliarity with inline state-change comments as one possible explanation for the lack of improvement.Source: §4.2 · p. 7

5 Additional Studies

The additional studies compare trace-based prompting with fine-tuning a smaller model and probe how well LLMs manipulate or generate execution traces. Prompting outperformed fine-tuning in the reported comparison, while probing suggests real traces can provide information not easily inferred by GPT-4.

5.1 Trace-based prompting compared to finetuning a smaller model.

  • The deepseek-coder-1.3b-instruct model was fine-tuned on buggy programs, failing-test results, and execution traces from HumanEval-Java and RunBugRun.For each dataset, 80% of problems were used for training and the rest for testing.Source: §5.1 · p. 7
  • All prompting techniques outperformed the fine-tuned model on CPA and CFA in the reported test comparison.The comparison used the same test programs for prompting-based techniques; the authors suggest limited training data may be one reason for the fine-tuned model’s lower scores.Source: §5.1 · p. 7, Figure 4 · p. 8

5.2 Probing Studies of Trace Understanding

  • The probing studies used GPT-4 on Refactory and Geeks-for-geeks programs to test trace collation and trace prediction, reporting exact-match rates.They distinguished traces for working and failing programs; outputs were compared with ground-truth traces or collated trace/programs after light post-processing.Source: §5.2 · p. 8
  • Trace-collating accuracy was 88% on reference Refactory programs, fell by nearly ten percent on failing programs, and reached 45% on Geeks-for-geeks.The authors note that the latter dataset also eliminates the possibility of prompt leakage.Source: §5.2 · p. 8
  • Zero-diff trace prediction did not exceed 50% on reference Refactory programs, was halved for failing programs, and was 15% on Geeks-for-geeks.The authors conclude that real traces can contribute information not yet easily inferred by strong LLMs such as GPT-4.Source: §5.2 · p. 8

6 Conclusion

The conclusion reports that trace prompts do not consistently beat error-based prompts, with effectiveness varying by dataset and model. LLM-optimized traces were more consistently beneficial, while longer, more complex traces reduced effectiveness.

  • Trace-based prompts did not consistently outperform error-based prompts, and their effectiveness varied with dataset and LLM.LLM-optimized traces offered more consistent improvements without limiting trace complexity heuristically.Source: §6 · p. 8
  • Longer traces and more variable assignments reduced trace-prompt effectiveness.Source: §6 · p. 8
  • LLMs had limited capacity for trace generation, which the authors say explains the weaker Self-Debug baseline and highlights traces’ potential utility in code tasks.Source: §6 · p. 8

7 Disclaimer

The disclaimer states that the document is informational and disclaims responsibility for the information’s completeness, accuracy, and reliability. It is not investment research or advice, nor a recommendation or solicitation concerning financial products or transactions.

  • The document was prepared for informational purposes and is not a product of JP Morgan’s Research Department.Source: §7 · p. 9
  • It is not investment research or investment advice, or a recommendation, offer, or solicitation to buy or sell a security or financial product.Source: §7 · p. 9
  • JP Morgan disclaims warranties and liability for the information’s completeness, accuracy, or reliability.Source: §7 · p. 9

A Rationale behind prompt choice and other prompts considered.

The rationale favors error prompts over program-only prompts and uses a single failing test case after multiple failing cases failed to improve results. Few-shot examples are presented as problematic for trace prompts because of prompt length.

A.1 Trace Understanding Probing Studies Full Results and Qualitative Findings

A manual review of trace-related diffs finds recurring errors in variable modifications, function returns, exception predictions, and other trace details.

A.1 Trace Understanding Probing Studies Full Results and Qualitative Findings

  • Most discrepancies between ground-truth and LLM-collated or predicted traces involve added or deleted variable modifications.Source: §A.1 · p. 14
  • Within loops, the LLM tends to miss or add variable modifications, potentially reflecting limits in reasoning depth and memory.Source: §A.1 · p. 14
  • For trace prediction from scratch, function returns are the second most erratic behavior, with errors in value or placement in execution flow.Source: §A.1 · p. 14
  • Other observed discrepancies include unreliable exception predictions, formatting changes, removal of untaken branches, extra commentary, and hallucinated literals.Source: §A.1 · p. 14
Loading 2505.04441v1…