AI sinh code nhiều hơn, mà infrastructure loạn hơn: Bài học từ production khi CI/CD bị ngập commit rác
Khi AI agent đẩy hàng nghìn dòng code mỗi tuần, pipeline CI/CD, observability stack và review process phải thay đổi như thế nào. Phân tích thực tế từ góc nhìn DevOps/Platform Engineer.
· 5 min read

Ảnh: Alexis Lê-Quôc from New York, United States, BY-SA qua openverse (nguồn)
Sáng thứ Hai vừa rồi, on-call nhận alert: build queue chờ 45 phút, 120 PR mở cùng lúc, 80% do bot tự động tạo. Team mình mất 3 tiếng chỉ để merge 5 PR hợp lệ. Không phải bug, không phải incident — là lũy thừa của code AI sinh ra.
Con số 160 upvote trên Hacker News cho bài “AI coding agents generate more code, but not more software” không ngẫu nhiên. Mọi người đang cảm nhận áp lực tương tự: velocity giả tạo, review bottleneck, test flaky tăng gấp bội, mà business value không tăng tương ứng.
Vấn đề không phải ở code, mà ở throughput
Trước đây, một engineer trung bình push 3-5 PR/tuần. Giờ một dev + Copilot/Cursor/Windsurf đẩy 20-30 PR. Pipeline không scale theo tỷ lệ đó. GitHub Actions runner queue, SonarCloud quota, container registry storage, artifact retention — tất cả bị ép đến giới hạn.
Thực tế là: AI viết code nhanh hơn infrastructure xử lý được. Và infrastructure team (thường 2-3 người cho 50+ dev) thành bottleneck mới.

Ảnh: Raimond Spekking, BY-SA qua openverse (nguồn)
Noise trong observability stack
Không chỉ CI/CD. Logging, tracing, metrics cũng bị ngập.
- Log volume tăng 3-4x do AI sinh thêm debug statement, try-catch boilerplate, comment block dài dòng
- Trace sampling rate phải giảm từ 100% xuống 10% để Jaeger không OOM
- Alert fatigue: PagerDuty reo liên tục vì threshold cũ không còn phù hợp với baseline mới
- Dashboard Grafana load chậm vì cardinality explosion từ label tự động sinh (feature/xyz, task/abc, agent/claude-3.5)
Team mình đã phải rewrite PromQL query, thêm relabel_config drop label không cần thiết, tăng retention cho high-cardinality metric. Chi phí Datadog bill tăng 40% trong 2 tháng.
Supply chain risk: dependency hallucination là thực tế
Bài research của Anthropic về self-replicating AI (source 1) nghe như sci-fi, nhưng dependency hallucination đã xảy ra hàng ngày. AI import package không tồn tại, hoặc import version deprecated có CVE. Dependabot PR tăng 5x, nhưng 60% là false positive do lockfile bị AI edit sai.
Lần trước team mình mất 4 tiếng trace một production incident: AI sinh code import lodash-es thay vì lodash, bundle size tăng 200KB, CDN cache miss, latency p99 nhảy từ 120ms lên 800ms. PR review bỏ qua vì “chỉ đổi import”.
Giải pháp team mình áp dụng: gating ở layer infrastructure
Không thể cấm AI. Cần gating ở chỗ infrastructure kiểm soát được.
1. PR size limit enforced by GitHub Actions
# .github/workflows/pr-size-check.yml
name: PR Size Guard
on: [pull_request]
jobs:
size-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate diff
id: diff
run: |
FILES_CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | wc -l)
LINES_ADDED=$(git diff --numstat origin/${{ github.base_ref }}...HEAD | awk '{sum+=$1} END {print sum}')
echo "files=$FILES_CHANGED" >> $GITHUB_OUTPUT
echo "lines=$LINES_ADDED" >> $GITHUB_OUTPUT
- name: Fail if too large
if: steps.diff.outputs.files > 20 || steps.diff.outputs.lines > 500
run: |
echo "PR quá lớn: ${{ steps.diff.outputs.files }} files, ${{ steps.diff.outputs.lines }} lines"
echo "Hãy tách thành PR nhỏ hơn. Limit: 20 files, 500 lines."
exit 1
Kết quả: PR trung bình giảm từ 340 lines xuống 180 lines. Review time giảm 60%. Bot auto-split PR (dùng git-cliff + script) handle phần lớn.
2. Mandatory test generation gate
AI sinh code nhưng không sinh test. Team mình bắt buộc: coverage diff phải >= 0 cho file mới sửa. Dùng diff-cover + pytest-cov:
# Chỉ fail nếu coverage của file thay đổi < 80%
diff-cover coverage.xml --compare-branch=origin/main --fail-under=80
AI agent (Cursor/Windsurf) giờ được prompt: “Viết test trước, implementation sau”. Coverage thực tế tăng từ 62% lên 78% trong 6 tuần.
3. Dependency verification pipeline
Thêm step npm audit --audit-level=high và pip-audit cho mọi PR touch lockfile. Caching node_modules/venv bằng TurboRepo remote cache để không chậm pipeline.
- name: Audit dependencies
if: hashFiles('**/package-lock.json', '**/requirements.txt', '**/pyproject.toml') != ''
run: |
if [ -f package-lock.json ]; then npm audit --audit-level=high; fi
if [ -f requirements.txt ]; then pip-audit -r requirements.txt; fi
Block 12 CVE critical trong tháng đầu tiên.
4. Observability cost attribution
Tag mọi resource (log, metric, trace) bằng team, service, source (human/ai). Dùng OpenTelemetry resource detector tự động:
# otel_resource.py
from opentelemetry.sdk.resources import Resource, ResourceDetector
import os
class AISourceDetector(ResourceDetector):
def detect(self) -> Resource:
source = os.getenv("CODE_SOURCE", "human") # CI set giá trị này
return Resource.create({"code.source": source})
Grafana dashboard lọc code.source=ai thấy: AI-gen service p99 latency cao hơn 23%, error rate cao 1.8x. Data này dùng để negotiate resource allocation với management.
Human factor: OpenFatigue là thực tế
Bài OpenFatigue (source 2) chỉ ra developer burnout do review load. Team mình đo: engineer trung bình spend 11h/tuần review PR (tăng từ 4h). 3 người đã nghỉ trong 6 tháng.
Giải pháp không phải hire thêm reviewer. Là:
- Auto-merge cho PR < 50 lines, coverage pass, no security finding — 35% PR tự merge
- Review rotation schedule — mỗi người 2h/ngày, protected time
- AI-assisted review — dùng
github-scriptaction gọi LLM review style guide, naming convention, security pattern trước khi human xem
- name: AI Pre-review
uses: actions/github-script@v7
with:
script: |
const diff = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
mediaType: { format: 'diff' }
})
// Gửi diff đến LLM endpoint nội bộ, post comment nếu có finding
LLM catch 40% style issue, 15% bug tiềm ẩn (null check, race condition). Human reviewer focus vào architecture, business logic.
Kết luận: Infrastructure phải dẫn dắt, không phải chạy theo
AI coding agent ở đây để lâu. Fighting nó là thua. Infrastructure team phải:
- Thiết lập guardrail ở pipeline level — size limit, test gate, security scan. Không nhờ developer tự giác.
- Instrument mọi thứ để có data — cost attribution, latency comparison, error rate by source. Data nói chuyện với management hiệu quả hơn cảm tính.
- Automate toil — auto-split PR, auto-merge safe PR, AI pre-review. Giữ human review cho high-value decision.
- Capacity planning dựa trên token throughput — không còn plan theo headcount. Plan theo “AI-assisted PR/week”.
Team mình giảm build queue từ 45 phút xuống 8 phút. Review time từ 11h/tuần xuống 5h. Datadog bill ổn định. Quan trọng hơn: 0 người nghỉ do burnout trong 3 tháng qua.

Ảnh: Ndahiro derrick, CC BY 4.0 qua wikimedia (nguồn)
Infrastructure không phải support function. Là force multiplier. Khi AI nhân lên code volume 10x, infrastructure phải nhân lên leverage 10x. Cách duy nhất là codify guardrail vào pipeline, automate toil, và dùng data để drive decision.
Nếu team bạn đang đau đầu vì AI code flood — hãy bắt đầu từ một PR size limit workflow hôm nay. Small win tạo momentum cho những thay đổi lớn hơn.