DEV Community

Every deletion in your diff had a reason to exist. AI doesn't know what it was.

Dimitris Kyrkos on November 16, 2026

Diff tools are biased. Additions render green. They're the new surface area, the thing the reviewer interrogates. Deletions render red: they're th...
Collapse
 
gautamtalksdev profile image
Gautam K •

The removed authorization check is the case that worries me most, because the diff looks like a tidy simplification and the tests usually still pass. A cheap guard: run git blame on every deleted line that touches auth, validation or error handling, and make the review show the commit message that added it. If the original reason is still true, the deletion needs a sentence explaining why it's safe now. Have you seen a tool surface deletions that way?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I haven't seen a tool do this particularly well yet. git blame is a good starting point, but the commit message alone might not tell the full story, especially if the original context lives in an incident or a ticket. Ideally, a review tool would surface the history behind each security-sensitive deletion and ask the reviewer to explicitly account for it. That would be much more useful than just flagging removed lines.

Collapse
 
gautamtalksdev profile image
Gautam K •

Agreed, asking the reviewer to account for each security sensitive deletion is the useful part. Even linking the deleted lines to the ticket or incident that added them would make that prompt answerable instead of a guess.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Exactly. Linking the deleted lines back to the ticket or incident gives the reviewer the context to make a real decision. Otherwise they're being asked to reconstruct the reasoning from a commit message, which is often not enough. I'd also want the review to flag when that original context is missing, rather than silently treating the deletion as safe.

Thread Thread
 
gautamtalksdev profile image
Gautam K •

Exactly. A deletion with a linked ticket is a decision the reviewer can check; a deletion with only a commit message is a guess they have to reconstruct.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Yeah, and that missing context should be a signal in itself. If a security-sensitive deletion has no traceable reason behind it, I'd rather have the tool flag it for extra scrutiny than let it pass as a routine cleanup. The absence of history doesn't mean the code was unnecessary.

Collapse
 
sinarezaei profile image
Sina Rezaei •

One case I’ve seen worth paying attention to is tenant isolation in multi-tenant systems.

Imagine an API controller validates that a user belongs to a tenant, then queries documents by document_id. An AI refactor might decide that adding tenant_id to the repository query is redundant because authorization already happens in the controller.

But that repository might later be called by a background worker, a GraphQL resolver, or another internal service that doesn't pass through the same controller.

Now the original optimization has quietly removed an important security boundary. This is exactly how a seemingly harmless cleanup can introduce a Broken Object Level Authorization (BOLA) vulnerability.

I think deletion reviews should also trace who can call the remaining code, not just whether the current execution path still works. That's context a passing test suite might not cover.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Exactly. That's the part that makes this tricky. The controller might be safe today, but the repository shouldn't have to rely on every future caller remembering to enforce the same rule. I'd argue the tenant filter belongs as close to the data access as possible, even if it feels redundant. That's one of those checks I'd rather see twice than regret removing once.

Collapse
 
mnemehq profile image
Theo Valmis •

The non-local reason is the whole problem, and it is a record-keeping gap before it is a review gap. A check added after an incident carries its reason only in someone's memory or a closed ticket. If the reason lives next to the code as a written decision, like this authorization check stays even though a caller already checks, a refactor that removes it can fail a rule instead of relying on the reviewer to remember. That is the layer we are building Mneme around.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a good point. The tricky part is making sure those decisions don't become another layer of documentation that gets outdated or ignored. Ideally, the context should be available right where the change happens, and the tooling should actually enforce it. Otherwise we're just moving the memory problem somewhere else.

Collapse
 
mnemehq profile image
Theo Valmis •

Staleness is the right worry. Prose rots because nothing fails when it stops matching the code. A decision with a path scope and a check fails the day the file it describes moves or the exception stops applying, so someone has to update it or delete it. The rules that never fire in a quarter are your prune list.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's an interesting approach. Making decisions scoped and checkable rather than leaving them as free-form documentation addresses a big part of the staleness problem. I especially like the idea of treating rules that never fire as candidates for pruning. The challenge is making sure pruning doesn't remove a rule that protects against a rare but serious scenario.

Collapse
 
mp3sss31 profile image
mp3sss •

The non-local rationale point is the strongest part: a guard clause or error handler often exists because of an incident or threat model that never appears in the source, so an AI optimizing for local coherence will read it as dead weight. In an Electron main-process context this shows up the same way when a renderer-originated IPC argument validation looks redundant beside an existing allowlist, but removing it leaves the door open for a future channel. One practical guard is to annotate defensive checks with an explicit note on why they exist, and keep security-relevant deletions in a separate review gate that a refactor pass cannot touch.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That Electron IPC example is a good one. An allowlist protects the channels that exist today, while validating the arguments protects what those channels are allowed to do. They're different boundaries, even if the checks look redundant locally. I like the idea of keeping security-relevant deletions behind a separate review gate too. Comments help preserve the rationale, but the review gate makes sure it doesn't get lost during a refactor.

Collapse
 
iliyaoblakov profile image
Iliya Oblakov •

Failure mode 3 is the one a script can catch. My test gate takes a minimum test count set where the gate runs, outside the commit, so a cleanup pass can't lower it. I deleted one of two tests in a small Python project and the run failed with "the output reports 1 tests, fewer than GATE_MIN_TESTS=2". That check compares a total, so swapping the odd test for a trivial one passes, and a deleted permission check never touches the count. Those two still fall to the reviewer, whose prompt says nothing gets weakened without a stated reason.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a useful distinction. A test-count gate can catch accidental deletion, but it can't tell whether the deleted test was the one protecting the important invariant. Same with authorization checks. I think these need two different layers: automated checks for structural changes and a review step that understands what the removed code was actually protecting. One can't really replace the other.

Collapse
 
enoch_hou profile image
Enoch Hou •

说得很对,删除的代码往往藏着当时的取舍和教训,单独审一遍删除的部分这个做法很值得借鉴,谢谢分享。