Context Drift and Rule Conflicts in Coding Agents: Governance, Priority, and Testable Reporting
Coding-agent quality problems are often lumped together as “bad context.” This article separates context rot within a single session from context drift across persistent project materials, examines how models tend to follow more specific task instructions and stay silent about conflicts, and presents practical governance: single sources of truth, explicit precedence, default conflict reporting, conflicting test fixtures, layered documentation cleanup, and acceptance questions reviewers should ask.
Two Context Problems That Are Easy to Confuse
Quality problems in coding agents are often loosely called “bad context.” For engineering purposes, they should be separated into at least two categories.
The first happens inside a single session. Design discussions, failed attempts, outdated assumptions, and temporary instructions keep piling up, and the model later picks up an idea that was already rejected. Compacting history, deleting off-track intermediate conclusions, or simply starting a new conversation all target this kind of noise that grows with length. Call it context rot: the information is still in the same interaction, but the signal-to-noise ratio has dropped.
The second does not depend on how long the conversation has run. The global rules in the repository root have already changed the refund window to 14 days, while the skill instructions for a customer-support task still say 30 days, and the documentation directory still contains an old note from three months ago. The user only asks, “According to the project documentation, how many days is the customer refund window?” The model can immediately give a definite number. If a reviewer looks only at that sentence, they often cannot tell whether the model also read a different answer. A new session cannot eliminate this contradiction, because the contradiction is written in files that are automatically loaded into context, not in the chat history. Call this context drift: multiple materials that are supposed to describe the same fact gradually fall out of sync.
The two look different, and the entry point for governance is different as well.
| Dimension | Context rot | Context drift |
|---|---|---|
| Where it occurs | History accumulated in a single session | Multiple persistent documents in a project |
| Typical timing | More likely to recur as the conversation grows | Can appear in the first turn of a new session |
| What the user sees | Repeated failed approaches, off-target answers | A fluent answer that gives only one version |
| First things to inspect | History messages, compaction strategy, task restatement | Conflicting source texts and which one is still effective |
How Models Usually Choose When Instructions Conflict
The problem can be reduced to a minimal contrast: task instructions and global project rules give mutually exclusive answers about the same fact, while the rest of the environment stays realistic—there are repository files, readable documentation, writable code, and runnable checks. In repeated experiments of this kind, the same pattern is observed: in matching tasks, the model most of the time acts according to the more specific task instructions rather than the higher-level global rules.
What matters more than which side it chooses is how it explains that choice. If the prompt does not require reporting conflicts, the number of times it proactively tells the user “these two materials are inconsistent” across multiple runs can approach zero. It gives a day count, an implementation, or a seemingly complete reply, equally confident when its tone matches the documentation. The reviewer therefore loses an important signal: the disagreement has been absorbed internally by the model instead of being handed back to a human for a decision.
This behavior should not be generalized to “all models and all tasks.” It is constrained by task form, how files are loaded, and prompt structure. But it is enough to show an acceptance risk: fluency does not mean fidelity to the rules that are still effective, and silence does not mean a second answer does not exist.
Drift Is Usually Not One Big Mistake
Creating drift does not require anyone to deliberately write something wrong. The common path looks more like a missed handoff:
- One team updates an integration guide or business rule, while another team keeps its own copy.
- A new team member finds only that one skill instruction in the task directory and completes the current request by following it.
- Root rules, task instructions, design documents, examples, and test fixtures evolve separately, and no one defines which one overrides the others.
- An old document is kept because “it still works,” and months later it sounds just as confident as the new rule.
Synchronization problems that people miss during handoffs become model inputs exactly as they are. The model does not naturally know which document was “changed later” unless the repository turns time and precedence into checkable constraints.
Why “Start a New Conversation” Does Not Solve It
Starting a new conversation only clears session state; it does not clear repository state. In the first turn, the agent reads project-level behavior rules, task-level operating instructions, adjacent documentation, and code comments. As long as these sources give different answers to the same question, the first sentence in a blank context may already have taken a side.
It is also necessary to distinguish two kinds of conflict:
- Hard conflict: the same field cannot hold two values at once, such as a refund window of 14 days versus 30 days.
- Soft conflict: the scope, exception, or applicable object differs, such as “14 days by default, with enterprise contracts handled separately.” If the task instructions turn the exception into the default value, the model may still output only one number.
Soft conflicts are harder to spot by eye because each text looks reasonable on its own.
Recommended Precedence and a Single Source of Truth
Without explicit precedence, the model tends to obey the task instructions in front of it. If a team wants global rules to win, it must write the rules as an executable loading order instead of expecting the model to “understand that global rules are more important.”
One workable convention is:
- Define a business fact in only one place, such as a canonical file in a policies directory; other files reference it rather than copying the sentence.
- Make the override order explicit. For example: global safety and compliance rules > current task instructions > historical design documents > code comments and examples. If business requirements make it necessary for task instructions to override a default value, the override itself should be recorded and should trigger a write-back to the global rules.
- Prohibit a second copy that sounds “equally confident.” A skill instruction should say “the refund window is governed by the policy file,” not hard-code the day count.
- Give every citable rule a stable identifier and update date, so answers can include the basis rather than only the conclusion.
An illustrative rule fragment can be written as follows; the point is to reference, not to copy the number again:
# Project behavior rules- For customer-facing policy statements, only cite entries under policies/ that are still marked effective.- If task instructions, examples, or historical documents conflict with an effective entry, stop giving a single conclusion and first list the conflicting sources and entry identifiers.- Report hard conflicts even when not asked; do not choose one day count, time limit, or quota on your own.
# Task: Reply to a refund inquiry- Read policy identifier refund.window.- Do not write a specific day count in this file.- If more than one effective value is read, output a conflict list and request human confirmation.
Make “Did It See the Conflict?” a Testable Behavior
Writing rules into documentation is not enough, because the model may still fail to report them. Conflict detection should be made into a check of the same kind as business tests.
- Prepare paired fixtures: one global rule and one task instruction with deliberately mutually exclusive facts; assert that the agent output must contain a conflict marker and must not contain only one of the valid values.
- Also prepare a consistent fixture: the two materials are in sync; assert that a single answer can be given and includes the rule identifier.
- Run one group for “reporting not required” and one for “reporting explicitly required.” If the model admits a conflict only when named, the default behavior will still miss it during acceptance.
- Put the checks into continuous integration or a pre-release checklist rather than relying on an occasional manual spot check. On failure, block “external replies” or “automatic code changes,” not all local experiments.
The illustrative assertion does not need to be tied to any specific framework; its core is to reject a “single answer”:
Given: Global rule refund.window = 14, task instruction says 30, and both are marked current and effectiveExpected: Output contains a conflict; both values appear or both sources are explicitly citedForbidden: Output only 14 or only 30 without stating that another source exists
This kind of test verifies a behavioral contract, not a model’s marketing claims. It should be rerun after model or prompt-format changes, because “whether it speaks up proactively” can itself drift.
Cleanup Can Be Done Layer by Layer
Rather than vaguely asking people to “clean up the documentation,” clean it up by layer.
Fact layer. List the files the agent will automatically read: global rules, task skill instructions, interface documentation, runbooks, examples, and test data. Designate a single source of truth for each externally visible statement, and delete or downgrade the other copies. When downgrading, change the confident tone and mark the file as “historical record; not to be used as the current statement.”
Reference layer. Change skill instructions into steps and prohibitions; do not embed numbers, addresses, time limits, or permission lists that will expire. Keep numbers in policy files, and make the steps say only “read which identifier.”
Precedence layer. Write a short text explaining who wins in a conflict and when the agent must stop and ask a human. Facts related to safety, privacy, funds, and customer commitments should default to stop-and-report; silent side-taking is not allowed.
Session layer. Context rot still needs to be managed: in long conversations, periodically restate the currently effective decisions and discard rejected approaches. But this is a supplement; it cannot replace synchronization inside the repository.
Organization layer. Rule changes need an owner. The person changing a global rule is responsible for searching for copies; someone who changes only a task directory should not be able to make the work look done. Code review should check not only the implementation but also whether documentation files have copied the policy text again.
What Humans Should Look at During Acceptance
Do not check only whether the final day count or final patch “works.” Add at least three questions:
- What rule identifier does this conclusion correspond to, and is the file still marked effective?
- Is there a second equally confident statement elsewhere in the repository? Did the model list it?
- If both are effective, did the task stop where it should have stopped, instead of making a business choice for people?
The 14-day and 30-day examples are only for explanation. Interface field meanings, permission scopes, timeouts, retry counts, billing rules, and error-code handling can all drift in the same way. The more smoothly the model writes, the higher the cost of a silent wrong choice, because reviewers are even less willing to go back and compare the source texts.
Summary
Longer sessions rot the context, which explains why conversations are restarted; it does not explain why two documents are still fighting after the restart. Context drift is a loss of synchronization between sources, and models tend to execute more specific task instructions while not reporting disagreements unless asked. Governance measures are a single source of truth, explicit precedence, default reporting of hard conflicts, and mutually exclusive fixtures that turn “must see the conflict” into a repeatable check. After this round of cleanup, the agent’s first-turn answer has a chance to be treated as execution under the current rules, rather than execution under whichever old instruction it read first.
