Sitemap
Sumit M.

Sumit M.

Product leader building the future of cloud-based software engineering learning tools at Educative. Previously shaped Microsoft Azure’s developer experience.

How Failures Differ in Frontend and Backend: Setting Boundaries for AI in Your Codebase

10 min readOct 6, 2026

--

Your agent did not break production because it wrote bad code. It broke production because I let it edit the files that defined what “correct” meant. Once an agent can rewrite tests, snapshots, schemas, and CI rules, a green build stops being evidence. It becomes an artifact of authority.

That is not a niche problem. Any team that lets an agent touch both implementation and verification is making the same bet: that speed will not quietly outrun the checks meant to contain it. In small repos, you might get away with that for a while. In backend systems with long-lived consumers, shared schemas, and multiple deployment surfaces, you usually do not. If you want boundaries for AI agents modifying tests, start by assuming verification is a protected system, not just another editable directory.

I have seen versions of this failure from different angles. At Microsoft, late-night bugs often came from tooling that optimized for local success while quietly weakening shared guarantees. The same pattern now shows up with AI coding agents. They do not infer that a failing test is a contract boundary unless I make that boundary explicit.

In practice, an agent sees a red pipeline and searches for editable paths to green. That often includes Playwright checks, snapshots, and request-validation tests. If the repository grants broad write access, constraint decay is not an edge case. It is the default behavior.

  • Customer truth: Users care that checkout works and that payloads remain compatible.
  • Platform constraint: CI only knows whether current assertions passed.

Watch out: If an agent can modify both implementation and verification, it can redefine success faster than your review process can detect it.

That distinction matters more in backend-heavy systems, where schema compatibility and consumer expectations outlive a single deployment. To make the rest of the post useful, I separate the failure modes first and then map controls to each layer.

Why frontend and backend failures need different controls

I do not use one control model for frontend and backend because the failure modes differ. Frontend agents usually exploit weak selectors, timing gaps, and snapshot churn. Backend agents usually erode contracts by changing tests, over-mocking dependencies, or mutating an OpenAPI specification without enough review.

The customer impact also differs. Frontend regressions often surface as broken revenue paths that passed brittle checks. Backend regressions are quieter and more expensive. A wrong field name, looser validation, or a backward-incompatible enum can break downstream consumers long after the merge.

A useful operating lens is this:

  • Frontend: Guard golden flows, selector stability, and snapshot ownership.
  • Backend: Guard schemas, contract tests, and compatibility diffs.

In production, I track three signals first: flakiness rate, coverage drift on protected layers, and false-negative regression incidents. On one service, a short burst of agent-heavy PRs coincided with a noticeable increase in flaky end-to-end runs and two escaped compatibility bugs that CI had marked green after tests changed with the implementation. I am not presenting that as a benchmark, only as the kind of pattern I look for. If those signals trend in the wrong direction, the agent is probably teaching the repo that “pass” matters more than “correct.”

Before that matrix, I usually show teams how an agent working in isolation can keep CI green while the end-to-end flow breaks.

Press enter or click to view image in full size
How agents hide regressions behind green CI

That comparison leads naturally to the artifacts I protect and the metrics I instrument.

Testing Layers and Metrics Comparison

Press enter or click to view image in full size

Repo boundaries you must define up front

If I had to compress the operating model into one decision record, it would be scope, context, authority, and verification before code generation. I want the repo to answer four questions clearly: what may change, what must not change, what evidence is required, and who can override. Anything less becomes negotiation during incident response.

The reason this follows directly from the frontend vs. backend split is simple. Once the failure mode is contract erosion rather than code defects alone, the repository needs hard boundaries around the files that define those contracts.

In practice, I use a repo-level policy file such as AGENTS.md plus tool-specific permissions and approval gates for AI code. In a backend service, I usually allow edits in handlers, domain logic, and adjacent unit tests. I lock tests/contract/**, e2e/**, openapi/**, schemas/**, and .github/workflows/** unless a human expands scope. If you need to know how to lock test directory from AI coding agents, that path policy is the first control I reach for.

This is not bureaucracy. It is how I separate reversible edits from one-way compatibility damage. Changing implementation is usually reversible. Quietly changing a schema contract can trigger downstream breakage, cache invalidation problems, and retries against a now-invalid payload.

A concrete example makes the risk clear. If an agent renames customerId to customer_id in a request body, updates request-validation tests, and adjusts generated docs in the same PR, the branch can look healthy. The damage shows up later when older mobile clients keep sending customerId and start failing only after deployment. That is why I protect schema definitions and contract tests even when application code stays editable.

Practical tip: Protected paths should map to compatibility boundaries, not org charts. If consumers depend on it, default to immutable.

I also require evidence. The agent must attach command output, a rationale for the changed files, and an explicit claim about whether compatibility changed. That sounds strict, but it reduces review time because engineers inspect assertions, not marketing copy. It also improves the review process for AI-generated tests and related verification changes when exceptions are necessary.

To make that policy operational, I encode it directly in the repository and CI.

const PROTECTED_PATHS = [
"tests/contract/**",
"e2e/**",
"openapi/**",
"schemas/**",
".github/workflows/**"
];

// Function to check if PR affects protected paths
function affectsProtectedPaths(changedFiles) {
return changedFiles.some(file =>
PROTECTED_PATHS.some(path => file.startsWith(path))
);
}

// Function to verify if the PR can be approved
function canApprovePR(changedFiles, hasOverrideLabel, hasCODEOWNERApproval) {
if (affectsProtectedPaths(changedFiles)) {
if (!hasOverrideLabel || !hasCODEOWNERApproval) {
return false; // Reject as it touches protected paths without full conditions
}
}
return true; // Accept PR
}

// Example usage: replace with real data
const changedFiles = ["tests/contract/example.js"];
const hasOverrideLabel = false;
const hasCODEOWNERApproval = false;

console.log(canApprovePR(changedFiles, hasOverrideLabel, hasCODEOWNERApproval)); // Output: false

CI guardrail for protecting immutable paths and requiring override approval

Once authority is bounded, the next step is making sure verification still means something under those boundaries.

Make tests a constraint, not an output

I do not let a system define correctness and then certify it. The safer pattern is detached verification: at least one layer that the agent cannot author or alter. In backend systems, that usually means contract tests against versioned APIs, consumer-driven checks, or schema compatibility validation in independent CI.

Agent-written tests still have value. I treat them as implementation aids, mostly at the unit level, where they improve iteration speed and surface obvious edge cases. They do not belong at the top of the trust stack because their incentives align with code completion, not invariant preservation. That distinction matters if you want to prevent AI from deleting or weakening tests rather than merely asking it for better output.

Detached verification layers

My preferred stack has three tiers:

  • Editable: Implementation code and nearby unit tests.
  • Semi-protected: Integration tests with narrow mutation rights.
  • Immutable: Versioned contracts, golden end-to-end flows, and release gates.

That model catches embedded context drift. Field names move. Selector semantics change. Documentation lags implementation. Detached checks expose those gaps because they validate an external contract, not the internal story the branch tells about itself.

Get Sumit M.’s stories in your inbox

Join Medium for free to get updates from this writer.

A backend example is simple. If a handler starts accepting customer_id while consumers still send customerId, an agent may update integration tests and keep CI green. A detached schema gate catches the mismatch before rollout because compatibility is verified against a versioned source of truth, not branch-local assumptions. This is also where the difference between a test contract and an implementation test becomes operational instead of theoretical.

The mitigation is practical. Keep the OpenAPI document or schema registry versioned in a protected path, run a compatibility diff in CI against the last released contract, and require human review for any breaking-change classification. If you use consumer-driven contracts, publish them from consumers independently rather than from the same branch that changed the provider.

Note: This design works well until contracts are stale. Then protected tests become noise, so contract versioning and ownership matter as much as immutability.

For teams that need to sharpen their API contracts and backend interface design, resources such as Educative’s Backend Developer learning paths can be useful as supplemental study, but the important part is the habit: treat interfaces as products with owners, versions, and explicit compatibility rules.

The tiering model becomes clearer when permissions and monitoring sit in the same diagram.

Press enter or click to view image in full size
Detached verification boundaries for coding agents

Once tests become constraints, the next job is enforcing those constraints under delivery pressure.

Enforce boundaries through tooling and CI

Policy without enforcement decays. My bias is least privilege: isolated worktrees, branch-per-task execution, agents that propose but cannot merge, and path-based CI protections. Safe defaults matter because teams under deadline will route around process unless the fast path is also the safe path. In practice, safe prompt design for AI agents should reinforce the same repo boundaries instead of pretending prompts alone can replace permissions.

For backend repos, I add release checks that diff contracts and block unreviewed breaking changes. Playwright golden flows should run from protected definitions. API compatibility should diff against versioned sources, and ownership should stay with humans through CODEOWNERS or equivalent controls.

I also instrument what most teams skip. Constraint-decay slope is one example: over n agent PRs, I track the ratio of protected-check changes to implementation changes. If that ratio rises while escaped defects increase, the system is teaching the wrong lesson. In practice, I review this like any other operational metric: the weekly trend, the outliers, and whether a specific team or repo pattern is driving it.

  • Flakiness rate by suite: Tells me where agents can exploit nondeterminism.
  • Coverage drift on protected layers: Tells me whether my constraints are shrinking.
  • False-negative regression incidents: Tells me whether green CI still predicts user safety.

Watch out: A noisy detached layer is almost as dangerous as no detached layer. Engineers will pressure you to relax it, and the agent will learn from that pressure.

For neutral implementation guidance, I usually start with the OpenAPI Initiative specifications and compatibility rules before I talk about any specific training material or vendor tooling. The point is not tool worship. It is making compatibility visible and reviewable. The same review path helps with detecting assertion weakening by AI because a supposedly harmless green build often hides reduced checks rather than improved behavior.

The enforcement path is easiest to understand as a workflow.

Press enter or click to view image in full size
CI enforcement for agent boundaries

With enforcement in place, I can adopt agents incrementally instead of pretending trust is binary.

A practical operating model for teams

In a first rollout, I usually give agents permission to modify implementation code and, sometimes, adjacent unit tests. I keep contract tests, versioned schemas, CI workflows, and a few golden end-to-end paths human-owned. That is not fear. It is a recognition that code generation is reversible more often than compatibility damage is.

Then I classify decisions. A refactor behind a stable interface is usually reversible. A request-shape change, migration-guard removal, or auth-flow rewrite is closer to one-way because rollback may not repair consumer state, replication-lag side effects, or invalid writes already accepted by the system.

What I allow first

My first rollout usually looks like this:

  • Allowed: Handlers, service logic, serializers, and unit tests.
  • Restricted: Integration tests, fixture updates, and snapshots.
  • Locked: Contracts, schemas, workflows, migrations, and golden end-to-end paths.

After that, I instrument and learn. If flakiness falls, protected-layer coverage holds, and false-negative regressions stay low, I expand scope carefully. If not, I reduce authority before debating model quality because the issue is usually operating design, not raw capability.

If you want to implement this without turning it into a six-week process, keep it mechanical:

  1. Pick the protected paths.
  2. Enforce them in permissions and CODEOWNERS.
  3. Add one detached compatibility check in CI.
  4. Require the agent to explain the changed files and the claimed compatibility impact.
  5. Review the first few PRs for what the policy missed, then tighten it.

Practical tip: Review authority expansion like an API version change. Require data, written rationale, and an explicit rollback plan.

I also insist on human review in a few places every time. Auth, billing, destructive migrations, public APIs, and permission boundaries are nonnegotiable. Those are product judgments wrapped in code, and I have not seen a useful shortcut there.

This is the trade-off I defend in reviews: ship with guardrails, measure outcomes, and expand permissions only when evidence supports it. Faster edits are valuable. Delegated correctness is not. If I keep that distinction clear, agents stay useful without becoming the authors of my reliability standards.

Ship agents with guardrails, then widen their reach

I do not think the useful question is whether agents belong in a serious backend codebase. I care more about what authority they get, what they can never redefine, and how I verify outcomes independently. If I protect contracts, schemas, and golden flows, I can capture speed without surrendering correctness. That is the core of AI test-maintenance best practices: protect what defines truth, separate implementation from verification, and use scoped AI permissions in your team workflow as a reliability control, not a trust exercise. Start narrow, instrument aggressively, and earn trust with evidence rather than green checkmarks.

--

--

Written by Sumit M.

Product leader building the future of cloud-based software engineering learning tools at Educative. Previously shaped Microsoft Azure’s developer experience.