Why LLM Code Reviews Take So Long and Keep Reconnecting
This article explains why code review tasks handled by large language models can vary in duration by an order of magnitude, and why long-running sessions often drop and reconnect. It breaks the problem into four bottlenecks—low context cache hit rate, poor token efficiency, unstable streaming connections, and coarse task orchestration—and then covers practical fixes: stabilizing the prompt prefix, constraining output with a JSON schema, sharding and pipelining the review, and adding engineering-side resilience. It closes with evaluation advice based on four benchmark metrics and a short summary.
1. The Symptom: Why the Same Review Task Varies by an Order of Magnitude
In day-to-day development, teams increasingly hand code review to AI coding tools. A typical anomaly: code changes of similar size take wildly different amounts of time under different model configurations. Some return a verdict in a few minutes; others are still streaming output after ten-plus minutes; in extreme cases, tens of minutes pass without convergence, accompanied by repeated connection drops and retries.
This is rarely caused by a single factor. It is usually the combined effect of four things: inference throughput, context reuse, output redundancy, and link stability. Separating them is the only way to apply the right fix.
2. Four Core Bottlenecks
2.1 Low Context Cache Hit Rate
Code review inputs contain a lot of repeated content: repository docs, directory structure, coding conventions, dependency lists, and prior review comments. If the inference side cannot effectively reuse the already-computed results of these prefixes, every request reprocesses the full context, and both time-to-first-token and overall latency rise sharply. A low cache hit rate is one of the most common root causes of long runtimes.
2.2 Poor Token Efficiency
Token efficiency here means “effective output needed to complete the task / total tokens consumed.” Inefficient models tend to restate code repeatedly, explain obvious conclusions at length, and even confirm the same point multiple times, which inflates output length. A review’s conclusion should be a small set of structured items; once the output diverges, the runtime naturally stretches.
2.3 Streaming Output and Connection Stability
Long tasks require a streaming connection to stay open for a long time. Intermediate hop timeouts, load balancers reclaiming idle connections, and poor client retry strategies all create a “reconnect—start over” loop. If the server does not support resuming from a checkpoint or session persistence, a reconnect means recomputing the context, which makes the latency even worse.
2.4 Coarse Task Orchestration
Stuffing an entire repository into the model at once, or asking a single request to perform defect detection, convention checks, security scanning, and refactoring suggestions simultaneously, exceeds both the context window and the effective range of attention. The model ends up “losing sight of one thing while attending to another”—thinking for a long time without producing a usable conclusion.
3. Practical Optimization Methods
3.1 Stabilize the Prefix to Improve Cache Reuse
Putting invariant content first and variable content last is the general practice for improving cache hits:
[System conventions + coding standards + dependency notes] <- kept stable, good for prefix reuse[Files and diffs in this change] <- the part that changes each round[Output format constraints] <- fixed template
Also avoid repeatedly modifying the system prompt during a session, which invalidates the cache.
3.2 Constrain the Output Structure to Cut Redundancy
Use an explicit schema to constrain the output so the model produces only conclusions, not the process:
{"findings": [{"file": "src/a.ts", "line": 42, "severity": "high", "issue": "null pointer risk", "fix": "add a null check"}],"summary": "3 high-severity issues found in total"}
Pairing this with an instruction such as “output JSON only, no explanation” can significantly reduce token consumption.
3.3 Shard and Pipeline the Review
Split the task by file or by change block, scan high-risk directories first, then expand step by step. Set a timeout and a retry limit for each shard, and rerun failed shards individually instead of restarting the whole task.
3.4 Engineering-Side Resilience Design
- On the client, set reasonable connection timeouts, read timeouts, and exponential backoff retries;
- Enable session persistence, and have the server record intermediate stage results so runs can resume from a checkpoint;
- Feed logs and metrics into a general logging service plus monitoring and alerting, and observe time-to-first-token, output tokens per second, and reconnect counts;
- For very long tasks, switch to an asynchronous task queue plus object storage for intermediate artifacts, so a long-lived connection is not a single point of failure.
4. Evaluation and Selection Advice
Do not rely on marketing claims. Run small-scale benchmarks on your own codebase and record four metrics consistently: task completion time, cache hit rate, token cost per conclusion, and reconnect rate. Comparing the same set of samples side by side is the only way to reach a credible conclusion. If you use Baidu AI Cloud capabilities, you can combine its container platform for hosting inference services with its logging service and monitoring/alerting for observability, forming a “measurable—locatable—optimizable” loop.
5. Summary
Slow code reviews with frequent reconnects are fundamentally a combined problem of cache reuse, output efficiency, and link resilience. With stable prefixes, structured output, sharded orchestration, and engineering-level observability, most teams can bring runtimes back from tens of minutes to minutes, with stable and reproducible results.
