Sub topic 14
Common failure modes and reviewing suggestions safely
This chapter assumes you know how a completion request is built from the prefix, the suffix and related context. It also assumes you have seen ghost text and next edit suggestions (NES) in an editor. Both features predict text, and a prediction can be wrong in ways that look right.
Where suggestions go wrong
Failures fall into a few groups. Knowing the group tells you where to look.
| Failure | Typical cause | What you see |
|---|---|---|
| Plausible but wrong logic | The model matches common patterns, not your requirements | Code that compiles and fails on edge cases |
| Invented API | The model guesses a function or parameter that does not exist | Import errors, or a call to a method that was never defined |
| Stale or missing context | Related files were not in the prompt, or edit history was truncated | Wrong variable names, wrong style, duplicated helpers |
| Boundary errors | Post-processing did not remove overlap with the suffix | Doubled brackets, repeated lines |
| Partial NES | The model predicted some call sites but not all | A rename applied in three places and missed in a fourth |
| Latency artifacts | A slow response arrives after the cursor moved | A suggestion that no longer fits the line |
Why they look convincing
A completion model is trained to produce likely text, not verified text. Ghost text is also rendered in your own file, in your own style. That makes errors easy to accept without reading them.
Here is a realistic case. You type the signature and the model fills in the body:
def average(values: list[float]) -> float:
return sum(values) / len(values)The code reads cleanly. But average([]) raises ZeroDivisionError. Your requirements may call for returning 0.0 or raising a clearer error. The model had no way to know which.
NES-specific risks
A next edit suggestion changes code away from your cursor. You are less likely to be looking at that region when you press Tab. Two habits reduce the risk:
- Read the diff the editor shows before accepting, not just the jump target.
- After accepting a multi-site edit, search for the old name to confirm that no site was missed.
The diff example in this tutorial renamed w and h to width and height at the call site. If another file also calls area(w=..., h=...), a suggestion limited to the current file leaves that caller broken.
A review routine
Use the same routine for both feature types, and scale the effort to the size of the suggestion.
Partial acceptance helps here. Take the first correct line or word, then write the risky part yourself.
Safety and settings
Some failures are about data, not correctness. Suggestions may contain hard-coded secrets copied from context, code that resembles licensed source, or insecure patterns such as string-built SQL. Treat suggested code like code from an unknown contributor:
- Run your normal tests and linters on it.
- Review it in version control with
git diffbefore committing. - Use your tool's settings to exclude sensitive files, and to enable public-code matching filters if your team requires them.
Handling a bad suggestion
Dismiss it with Escape, then keep typing. If a tool repeatedly suggests wrong things in a file, check what context it sees. Missing related files and stale edit history are common causes, and fixing the context is cheaper than correcting each suggestion.
Exercise
An NES renames w to width in a function definition and updates one call in the same file. Name two checks you should do before committing.
Show answer
Read the displayed diff to confirm every change is intended, and search the whole project for remaining uses of the old name or keyword arguments (for example w=) in other files. Then run the tests.
Exercise
Why can a completion that compiles and reads cleanly still be unsafe to accept?
Show answer
The model predicts likely text and does not verify behavior. It can miss edge cases such as an empty list, use an API that does not exist, or reproduce an insecure pattern. Only review and tests confirm correctness.