Context Drift: How to Stop AI Agent Rules from Contradicting Each Other

    Context drift happens when project rules, skill files, and documentation fall out of sync, causing AI coding agents to silently pick one conflicting answer without flagging the issue. This article explains how context drift differs from context rot, why models silently choose sides, and how to treat the problem as an engineering concern through a single source of truth, layered rules, upfront conflict detection, mandatory conflict reporting, versioning, and regression testing. A practical acceptance checklist is included.

    1. It Started with an Acceptance Detail

    Two documents described the refund window differently: one said 14 days, the other said 30 days. You handed the project materials to an AI coding tool and asked it to answer customer questions based on the docs. It quickly returned a specific number. As the reviewer, what you really care about is not the number itself, but whether the tool realized it had read two conflicting answers at the same time.

    The hidden nature of this problem is that the output looks completely “normal.” The answer is fluent, well-formatted, and confident, with no errors and no warnings. But correctness is not the same as consistency. A seemingly successful answer may simply be the model making a silent choice between two candidate facts.

    A developer relations practitioner ran a set of coding sandbox experiments on a personal technical blog: when the task instructions contradicted the overall project rules, the model followed the task instructions 95% to 100% of the time; across 110 runs that did not ask the model to report conflicts, it proactively pointed out the discrepancy to the user zero times. It is worth emphasizing that these findings are limited to two specific models, specific tasks, and a specific sandbox environment, and cannot be directly generalized as a universal rule for all tools. Still, they are enough to reveal a class of engineering risk.

    2. Two Different “Context Problems”

    People who have been using AI to write code for a long time usually get into the habit of starting new sessions. Plans that have piled up in the context include some that were already disproven, yet the model picks them up again, so you compress the history, clear the noise, and reopen the conversation. This kind of problem can be called context rot: the longer the session, the more noise accumulates, and the more the answer quality suffers.

    This article discusses a different phenomenon: context drift. The rule file in the project root has already changed the refund window to 14 days, a skill description for a customer service task still says 30 days, and the docs directory still holds a description from three months ago. Skill files are the operating instructions the model reads when it receives a specific task. Even if you just opened a blank session, these files will still give different answers.

    The key differences can be contrasted as follows:

    • Trigger timing: rot appears in the later stages of a long session; drift can appear in the very first turn of a new session.
    • Source of noise: rot comes from the buildup of historical messages; drift comes from project materials losing sync with each other.
    • User perception: rot shows up as going off-topic or repeating ineffective solutions; drift shows up as a smooth answer that only gives one version.
    • Where to start troubleshooting: rot is handled by clearing history and restating the task; drift requires locating the conflicting source text and confirming which one is still valid.

    Creating drift does not require anyone to make a big mistake. Updating a rule file, adding a skill description, or migrating documentation—any routine iteration can quietly make multiple materials diverge.

    3. Why the Model “Silently Picks a Side”

    From an engineering perspective, silently picking a side is not an anomaly but the result of several factors stacking up.

    First, instruction hierarchy naturally has priority. System-level constraints, project-level rules, task-level instructions, and the user’s current-turn question form an implicit priority chain. When a task instruction conflicts with the overall rules, the “closer” instruction often wins, which is consistent with the experimental observations.

    Second, there is no defined action for reporting conflicts. If the workflow does not require the model to output “I found a contradiction, please confirm,” it will only deliver a conclusion. The default behavior is the path of least resistance: give an answer rather than throw a question back.

    Third, retrieval is fragmentary. The model usually only gets a few recalled fragments and cannot see the full set of materials, so it is hard to tell whether this is the only fact or just one version.

    Fourth, acceptance criteria only look at the result. If acceptance only checks “whether an answer appears,” the conflict gets masked by the correctness of the result.

    An illustrative rule priority can be expressed like this:

    1. Priority from high to low:
    2. 1. Safety and compliance constraints
    3. 2. Explicit instructions from the user's current turn
    4. 3. Task-level operating instructions (skill files)
    5. 4. Project-level overall rules
    6. 5. Historical docs and comments
    7. Conflict handling: same-level conflicts must be reported; silent selection is not allowed

    4. Governance: Turning Drift into a Detectable Engineering Problem

    1. Establish a Single Source of Truth

    The same fact is allowed only one authoritative definition; all other places reference it rather than copy it. For example, centralize parameters such as deadlines, thresholds, and switches in one configuration, and have docs and skill descriptions obtain values through references, avoiding multiple copies evolving on their own.

    2. Layer Rules and Use Namespaces

    Layer by “global—module—task” and make clear the scope each layer may override. Lower layers are forbidden from rewriting upper-layer hard constraints on their own and may only refine within the constraint space.

    3. Move Conflict Detection Upfront

    Before generating an answer or code, run a consistency check first: extract key entities and values, compare across sources, and if a discrepancy is found, halt and output a conflict list.

    1. [Conflict] Refund window
    2. Source A: project overall rules = 14 days
    3. Source B: customer service skill description = 30 days
    4. Source C: historical doc (three months ago) = 30 days
    5. Suggestion: use the project overall rules as authoritative, pending confirmation to unify the other sources

    4. Make Reporting the Default Action

    Write a fixed requirement into the system constraints: when encountering a same-level or cross-level contradiction, the model must first report the conflict location, both values, and a suggested resolution, then wait for confirmation, and must not pick a side on its own.

    5. Version and Timestamp

    Give every rule and document a version number, effective time, and owner. Outdated content is automatically down-weighted or marked as pending review, reducing the chance that a “three-month-old description” continues to take part in decisions.

    6. Regression-Consistent Testing

    Turn key facts into assertions and include them in continuous integration: after modifying any source, automatically run a consistency check and output a diff report to prevent iteration from introducing divergence again.

    5. Acceptance Checklist

    • Can you list all sources that involve the same fact and their values?
    • Are there parameter copies that were duplicated rather than referenced?
    • When a conflict occurs, does the tool proactively report it instead of silently giving an answer?
    • Is there a version, effective time, and owner?
    • Is there automated consistency validation and regression test coverage?

    6. Conclusion

    The essence of context drift is not a model capability problem but a knowledge management problem. Only by converging facts into a single source, writing conflict reporting into the workflow, and making consistency a regression-testable check can AI coding tools work stably and auditably in multi-source material environments. Combined with common cloud capabilities such as configuration management, logging services, and monitoring alerts, conflict detection and tracing can be further automated, turning governance from manual experience into a sustainable engineering practice.