SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2306.03438 · NeurIPS · 2023

Large Language Models of Code Fail at Completing Code with Potential Bugs

Tuan Dinh, Sheng Zha, George Karypis, Jinman Zhao, Samson Tan, Renato Negrinho, Leonard Lausen

arXiv · PDF · Open in the Atlas

Code that ran

10 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 2 failures of our instrument; 0 no recorded run), measured 2026-11-21; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2306.03438.json · badge: /api/ran/2306.03438.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
amazon-science/buggy-code-completion canonical (classifier label)
classifier basis: census
10 ran · 0 no recorded run
FunctionStatusWhere it lives
estimate_pass_at_k Ran
ran; our contract draft was wrong, not the code
amazon-science/buggy-code-completion/src/metrics/evaluation.py
code served (permissive licence) · get_code("af8375df02e6b247")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (3,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import itertools

# Test case 1: num_samples as int, num_correct as list
num_samples_1 = 100
num_correct_1 = [50, 75, 90]
k_1 = 10

# Test case 2: num_samples as list, num_correct as array
num_samples_2 = [100, 150, 120]
num_correct_2 = np.array([50, 75, 90])
k_2 = 5

# Using the first test case for ARGS
ARGS = {
    "num_samples": 100,
    "num_correct": [50, 75, 90],
    "k": 10
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family float, shape (3,) — shape (3,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
fix_bugs Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/baselines.py
code served (permissive licence) · get_code("7c23e2d4cbcc48a5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockFixer(nn.Module):
    """Mock fixer that takes text and returns a list with dict containing 'text' and 'prob'"""
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 1)
    
    def forward(self, text):
        # Return a list with a dict containing 'text' and 'prob'
        return [{'text': text + ' fixed', 'prob': 0.95}]

fixer = MockFixer()
text = "def foo():\n    pass\n\ndef bar():\n    pass"
threshold = 0.9

ARGS = {
    'fixer': fixer,
    'text': text,
    'threshold': threshold
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
generate_infill Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/infiller/infill_ops.py
code served (permissive licence) · get_code("950eb33619d6b1e2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.vocab_size = 50257
    
    def __call__(self, text, return_tensors=None):
        # Return a mock result object with input_ids
        class TokenizerOutput:
            def __init__(self):
                self.input_ids = torch.tensor([[100, 200, 300]])
        return TokenizerOutput()
    
    def decode(self, token_ids, clean_up_tokenization_spaces=False):
        # Return a mock decoded string
        return '<|endoftext|>Hello world'

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def generate(self, input_ids, do_sample=False, top_p=0.95, temperature=0.2, max_length=128):
        # Return mock generated token ids
        batch_size = input_ids.shape[0]
        seq_len = min(max_length, 10)
        return torch.randint(0, 50257, (batch_size, seq_len))

model = MockModel()
tokenizer = MockTokenizer()
input_text = "def hello():"
max_to_generate = 128
temperature = 0.2
device = 'cpu'

ARGS = {
    'model': model,
    'tokenizer': tokenizer,
    'input': input_text,
    'max_to_generate': max_to_generate,
    'temperature': temperature,
    'device': device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_prefix Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/configs.py
code served (permissive licence) · get_code("2e44494d83f1b2ef")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def get_prefix(method_name):
    if method_name == 'completion':
        return '_naive'
    return method_name

ARGS = {
    'method_name': 'completion'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_score Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/infiller/infill_line.py
code served (permissive licence) · get_code("5f28bf9a2c267875")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class SimpleTokenizer:
    """Minimal tokenizer that implements encode method."""
    def encode(self, text):
        # Return a list of token ids
        # The function accesses index [1], so we need at least 2 elements
        # Using simple hash-based ids
        hash_val = abs(hash(text)) % 1000
        return [0, hash_val % 100, hash_val % 50]

class FakeTokenizer:
    """Stand-in tokenizer with encode method."""
    def __init__(self):
        self.vocab_size = 50
    
    def encode(self, text):
        # Return indices, function uses index [1]
        # Create deterministic but varying outputs based on input
        base = sum(ord(c) for c in text) % 40
        return [0, base, (base + 1) % 50]

# Create a small tensor z with scores
# The function accesses z[temp_id].item()
# temp_id comes from tokenizer.encode(), so we need enough capacity
z = torch.randn(100)  # Large enough to handle token ids from tokenizer

# Create tokenizer
tokenizer = FakeTokenizer()

# Create string input
s = "hello"

ARGS = {
    "tokenizer": tokenizer,
    "s": s,
    "z": z,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_score_next_token Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/infiller/infill_line.py
code served (permissive licence) · get_code("0f6644c9346c9e3f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (1, 100) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.eos_token_id = 2
    
    def __call__(self, text, truncation=True, max_length=700, return_tensors='pt'):
        # Return a dict with input_ids and attention_mask
        # Simulate tokenization output
        input_ids = torch.randint(0, 100, (1, 5))
        attention_mask = torch.ones((1, 5), dtype=torch.long)
        return {
            'input_ids': input_ids,
            'attention_mask': attention_mask
        }

class MockCodeLM(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(10, 100)
    
    def generate(self, input_ids, max_length, pad_token_id, do_sample, temperature, return_dict_in_generate, output_scores):
        # Simulate generation with scores
        # Return dict with 'scores' key containing a list of score tensors
        batch_size = input_ids.shape[0]
        # Generate one score tensor for the next token prediction
        scores = [torch.randn(batch_size, 100)]
        return {
            'scores': scores
        }

tokenizer = MockTokenizer()
codelm = MockCodeLM()
prompt_test = "def hello"
device = 'cpu'

ARGS = {
    'codelm': codelm,
    'tokenizer': tokenizer,
    'prompt_test': prompt_test,
    'device': device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (1, 100) — shape (1, 100) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
infill Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/infiller/infill_ops.py
code served (permissive licence) · get_code("04df553e86fc42e4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from typing import List

torch.manual_seed(0)

class MockTokenizer:
    def __call__(self, text, return_tensors=None):
        # Return a simple mock that has input_ids attribute
        class TokenizerOutput:
            def __init__(self):
                self.input_ids = torch.tensor([[1, 2, 3, 4]])
        return TokenizerOutput()
    
    def decode(self, token_ids, clean_up_tokenization_spaces=False):
        # Return a string with BOS prefix and some content
        return '<|endoftext|>Some generated text with <|endofmask|>'

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def generate(self, input_ids, do_sample=True, top_p=0.95, temperature=0.2, max_length=256):
        # Return mock generated token ids
        batch_size = input_ids.size(0)
        return torch.randint(0, 100, (batch_size, max_length))

model = MockModel()
tokenizer = MockTokenizer()
parts = ["Hello ", "world", "!"]

ARGS = {
    'model': model,
    'tokenizer': tokenizer,
    'parts': parts,
    'max_to_generate': 128,
    'temperature': 0.2,
    'extra_sentinel': True,
    'max_retries': 1,
    'device': 'cpu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_sentinel Ran
ran; our contract draft was wrong, not the code
amazon-science/buggy-code-completion/src/infiller/infill_ops.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from dpfried/incoder, is pointer only (licence: NONE) · get_code("bd9a376893413836")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from dpfried/incoder, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

predict_next Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/infiller/infill_line.py
code served (permissive licence) · get_code("071fba8594f05055")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Stand-in tokenizer class
class StandInTokenizer:
    def __init__(self):
        self.eos_token_id = 50256
    
    def __call__(self, text, truncation=True, max_length=700, return_tensors='pt'):
        # Return a dict with input_ids and attention_mask
        input_ids = torch.randint(0, 1000, (1, 10))
        attention_mask = torch.ones_like(input_ids)
        return {
            'input_ids': input_ids,
            'attention_mask': attention_mask
        }
    
    def decode(self, token_id):
        return "token_word"

# Stand-in code language model
class StandInCodeLM(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(10, 1000)
    
    def generate(self, input_ids, max_length, pad_token_id, do_sample, temperature, return_dict_in_generate, output_scores):
        # Return a dict with 'scores' containing logits for the next token
        # scores is a tuple of tensors, one per generated token
        batch_size = input_ids.shape[0]
        scores = (torch.randn(batch_size, 1000),)
        return {
            'scores': scores
        }

# Stand-in operation class with start and end attributes
class StandInOp:
    def __init__(self):
        self.start = (3, 5)  # (line, column)
        self.end = (3, 10)   # (line, column)

# Build arguments
device = 'cpu'
infiller = StandInCodeLM()
tokenizer = StandInTokenizer()
op = StandInOp()
prompt = "def hello():"
code_lines = [
    "def hello():",
    "    x = 5",
    "    y = 10",
    "    return x + y"
]

ARGS = {
    'infiller': infiller,
    'tokenizer': tokenizer,
    'op': op,
    'prompt': prompt,
    'code_lines': code_lines,
    'device': device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
remove_code Ran
ran on a synthesized input
amazon-science/buggy-code-completion/src/baselines.py
code served (permissive licence) · get_code("a28c9b6d92999895")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

# Setup code for remove_code function

ARGS = {
    "prompt": '''"""
def hello():
    print("Hello world")
    x = input()
    print(x)
"""''',
    "data_name": "fixeval"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 1 later) and 8 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
estimate_pass_at_k 20 other papers
3 dated earlier, 17 later
2107.03374 (2021-07)
Evaluating Large Language Models Trained on Code
2207.14255 (2022-07)
Efficient Training of Language Models to Fill in the Middle
2210.14868 (2022-10)
Multi-lingual Evaluation of Code Generation Models
and 17 more not named here
make_sentinel 1 other paper
1 dated earlier
2204.05999 (2022-04)
InCoder: A Generative Model for Code Infilling and Synthesis

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-21.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large language models of code (Code-LLMs) have recently brought tremendous advances to code completion, a fundamental feature of programming assistance and code intelligence. However, most existing works ignore the possible presence of bugs in the code context for generation, which are inevitable in software development. Therefore, we introduce and study the buggy-code completion problem, inspired by the realistic scenario of real-time code suggestion where the code context contains potential bugs -anti-patterns that can become bugs in the completed program. To systematically study the task, we introduce two datasets: one with synthetic bugs derived from semantics-altering operator changes (buggy-HumanEval) and one with realistic bugs derived from user submissions to coding problems (buggy-FixEval). We find that the presence of potential bugs significantly degrades the generation performance of the high-performing Code-LLMs. For instance, the passing rates of CODEGEN-2B-MONO on test cases of buggy-HumanEval drop more than 50% given a single potential bug in the context. Finally, we investigate several post-hoc methods for mitigating the adverse effect of potential bugs and find that there remains a significant gap in post-mitigation performance. 3 * Equal contribution. † Work done while interning at Amazon Web Services. 3 Code and datasets are available at https://github.com/amazon-science/buggy-code-completion 37th Conference on Neural Information Processing Systems (NeurIPS 2023).

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2306.03438")
get_code_for_paper("2306.03438")
have("2306.03438")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2306.03438.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2306.03438.svg)](https://syntology.ai/paper/2306.03438)

Connect an agent — have() is free.