Blog

Why diff-only AI code review breaks your build

How diff-only AI coding agents miss dependencies and introduce bugs across your codebase

Alex Mercer

A developer submits a pull request, and the AI coding assistant reviews it with a suggestion for a cleaner implementation. The code looks better, the function more elegant, so the developer accepts and merges. Three hours later, the build breaks, the "cleaner" function changed a return type from User | null to User, breaking null checks in five services the AI never analyzed. The AI code assistant only saw the 50 lines that changed, not the 50,000 lines that depended on them.

This happens constantly with diff-based AI agents for coding. They analyze what changed without understanding how those changes ripple through your repository, suggesting improvements that look good in isolation but break dependencies three folders away. Our guide to AI code security covers the security side of AI-written changes.

TLDR

  • Diff-based AI code assistants analyze only changed lines, missing how modifications affect the broader codebase. 

  • Modern repository-aware AI agents for coding overcome this by analyzing entire repositories, understanding architectural patterns, catching cross-file dependency breaks, and learning project-specific conventions. 

  • Tools like cubic use repository-wide analysis to provide context-aware feedback.

The problem with diff-only code review

Most AI coding assistants work the same way: you open a pull request, the tool looks at the diff (the lines that changed), analyzes those lines, and provides feedback. This approach has a fatal flaw, code doesn't exist in isolation. Every function depends on other functions. Every change affects how other parts of the system work.

When coding agents only analyze diffs, they're reviewing code in a vacuum. They see the change but not the consequences. They see the improvement but not the breaking changes it introduces. The AI optimizes individual files without understanding the system those files belong to.

What diff-only AI coding agents miss

When AI agents for coding only analyze the diff, they miss critical dependencies that span your repository:

  1. Cross-file dependency chains: A function signature change breaks 15 call sites across different microservices, but the coding agent never sees those files. Your API returns Promise<User>, then someone changes it to Promise<User | null> based on an AI suggestion. Every consumer that awaits without null-checking now has a potential null reference bug. Diff-only AI code assistants can't trace these dependency chains.

  2. Architectural patterns and boundaries: Your codebase uses constructor-based dependency injection across 200+ service classes. But when the AI coding assistant only sees one new service file, it suggests direct instantiation with new DatabaseClient(). The AI doesn't know your architecture because it doesn't see the established patterns.

  3. Codebase-specific conventions: Your /api directory uses REST naming (getUserById), while /graphql uses GraphQL conventions (userQuery). AI-based code review tools analyzing only diffs apply inconsistent naming because they can't see these established conventions.

  4. Shared utility behaviors: Someone "improves" your parseDate utility to throw errors instead of returning null. The diff looks fine, but 20 files depend on the null-return behavior for graceful degradation. The AI approved the breaking change without seeing those dependencies.

Here's what this looks like in practice

Let's see an example of how diff-only review breaks production. The AI coding assistant saw this change and approved it:

// File: src/api/users.ts (CHANGED)

export function getUser(id: string): User {  // Changed from User | null

  const user = db.users.find(id);

  if (!user) throw new Error('User not found');

  return user;

}

The diff looked clean. Throwing errors is better than returning null, right? Better error handling, clearer control flow, the kind of improvement any AI code assistant would recommend. But the AI never saw these files:

// File: src/services/billing.ts (UNCHANGED - 3 folders away)

function chargeUser(userId: string) {

  const user = getUser(userId);

  if (user === null) {  //  Unreachable - getUser throws now

    logger.warn('User not found for billing');

    return;

  }

  processPayment(user.paymentMethod);

}



// File: src/background/notifications.ts (UNCHANGED)

function sendNotification(userId: string) {

  const user = getUser(userId);  // Uncaught exception crashes worker

  if (user === null) return;

  sendEmail(user.email, notification);

}



// File: tests/integration/user-flows.test.ts (UNCHANGED)

test('handles missing users gracefully', () => {

  const user = getUser('nonexistent');  // Test expects null, gets error

  expect(user).toBeNull();

});


Fifteen files across the codebase explicitly handled null returns. The AI-based code review tool only analyzed the diff and missed them all. Result: production incidents in billing, crashed background workers, and broken tests.

This is the fundamental problem with diff-only AI code assistants, they optimize individual files without understanding the system. Bug Bench tracks which AI models write the most type and compile errors in the code cubic reviews.

How repository-wide AI coding agents work

Repository-aware AI code review tools use several techniques to understand full repository context.

1. Checking each pull request against the whole codebase

cubic checks every pull request against your whole codebase and your team's rules, and flags changes that break code elsewhere, even in another repo. Separately, cubic's codebase scans run thousands of AI agents across the full repository in the background to find bugs and vulnerabilities in code that's already merged.

An example of what cubic might flag:

// You change this in src/core/auth.ts:

function validateToken(token: string): User {  // Changed from User | null

  // ... implementation

}



// cubic flags these issues in files you didn't touch:



// src/api/middleware/auth.ts

const user = validateToken(req.headers.auth);

if (!user) {  

  // cubic: Unreachable. validateToken now throws instead of 

  // returning null. Update error handling with try-catch.

  return res.status(401).send('Unauthorized');

}

2. Project-specific learning

If 95% of your API endpoints return errors as { error: { code, message } }, that is your standard, even if nobody wrote it down. cubic learns conventions like this from feedback on its review comments and from your senior engineers' past reviews, and you can write the rule yourself as a custom agent in plain English.

When you open a new PR with { errorMessage: "..." }, the AI flags it: "This doesn't match your API error format." Diff-only AI-based code review tools would approve it because they never saw your 200 other endpoints. They can't enforce consistency because they don't know what "consistent" means in your codebase.

cubic's AI wiki is a separate feature: it turns your repository into searchable documentation that people and coding agents can query.

Choosing repository-aware AI code assistants

Not all AI-based code review tools claiming "full repository context" actually deliver it. Here's how to tell the difference:

The breaking change test: Make a function signature change that breaks something three files away. Repository-aware tools flag it immediately because they already know the dependency graph. Diff-only tools miss it entirely.

The pattern learning test: Introduce code that violates an established pattern, direct database access when everything else uses the repository pattern. Repository-aware AI code assistants should flag this automatically because they've learned your conventions.

cubic reviews each pull request with the whole repository in view, can scan the codebase in the background for bugs that are already merged, and turns your senior engineers' past review comments into rules that run on every PR.

The shift from diff-based to repository-aware code review represents a fundamental evolution in what AI agents for coding can do for code quality.

Ready to see the difference repository-wide analysis makes?

Schedule a demo with cubic and watch AI coding agents analyze your entire codebase, not just the lines that changed.

Table of contents