Agent Context Drift: Why Your Project Rules Need a Cleanup

    Context drift happens when project documents fall out of sync, causing coding agents to confidently return conflicting answers without flagging the discrepancy. This article explains how context drift differs from context rot, why agents silently pick one source instead of reporting conflicts, and how to treat context like code through a single source of truth, explicit precedence, metadata, and CI conflict checks.

    1. A Real Problem Exposed During Acceptance

    One external document states a 14-day refund window. Another says 30 days. You ask a coding agent to answer a customer based on the project documentation, and it quickly returns a number. As the reviewer, can you tell from that fluent answer whether the agent ever saw the other value?

    A developer relations practitioner published a set of comparison experiments on a personal technical blog. The setup was a coding sandbox with real repository files: the model could read documentation, write code, and run tests. The task instructions and the top-level project rules were deliberately made contradictory to observe how the model chooses. The findings had two layers. First, choice behavior: the model followed the task instructions in 95% to 100% of matching tasks. Second, and more concerning: across 110 runs that did not ask the model to report conflicts, it proactively mentioned the discrepancy to the user zero times.

    The boundary matters. These numbers come from two models, one specific task set, and a self-built sandbox, so they cannot be generalized into a universal rule for all agents. But the engineering problem they reveal is general: when knowledge sources lose synchronization, the agent does not throw an error. It simply returns an answer that looks reasonable.

    2. Context Drift Is Not Context Rot

    Anyone who uses coding agents long-term knows the habit of starting a new session. Approaches discussed earlier pile up in the context, a few of them are already dead ends, and the model picks them up and retries. Compressing history, removing distractions, and starting fresh all address the same issue, which can be called context rot: as a single session grows longer, noise drags down answer quality.

    The experiment targets a different kind of context problem. Suppose the general rules file in the root directory has updated the refund window to 14 days, while a skill instruction file for a customer support task still says 30 days, and the docs directory still holds a version from three months ago. Skill files, the operating instructions a model loads when it receives a specific task, stand on their own alongside the general rules and historical documents. Even in a brand-new blank session, these files produce different answers. This gradual loss of synchronization across sources is context drift.

    Dimension Context Rot Context Drift
    When it appears The longer the chat, the more old approaches interfere Can appear in the first turn of a new session
    Where the problem lives Noise accumulated inside the session Inconsistent materials across the project
    What the user sees Answers go off track, retrying what was already tried Fluent answers that give only one version
    Where to start debugging Clear message history and restate the task Locate the conflicting text and check which source is still valid

    The practical value of separating the two is that the remedies are completely different: context rot is handled through session management, while context drift requires going back to the repository for document governance. Restarting the session does nothing.

    3. How Drift Happens

    Creating drift does not require anyone to make a big mistake. One team updates the integration instructions while another team keeps its own maintained copy. A new hire finds only one of them in the task directory, follows it, and still delivers. Months later, the model faces two documents written with equal confidence, encountering exactly the information that was dropped during a human handoff.

    Common sources fall into a few categories:

    • Copy proliferation: the same fact is copied to multiple places, and an update covers only one of them.
    • Layer overrides: general rules, directory-level rules, and task-level skill instructions stack up, with precedence never explicitly declared in the files.
    • Version leftovers: old design documents, migration notes, and temporary patch notes are not marked as obsolete.
    • Generative contamination: summaries produced by the agent itself are written back into the documentation and become the “authoritative source” for the next round.

    4. Why “Choose Without Reporting” Is Dangerous

    Models tend to follow instructions that are more specific and closer to the current task, which is an advantage in most scenarios. The risk is that the model filters the conflict out as noise: the output carries no anomaly marker, and the reviewer loses the clue that would reveal the problem. In engineering terms, conflicts do not surface as failures; they enter deliverables as “confident wrong answers.” For externally visible information such as deadlines, prices, and compliance terms, the cost may land directly on the customer side.

    5. The Fix: Manage Context Like Code

    1. Single source of truth. Keep one authoritative definition for each critical fact and turn every other location into a reference. Copy-and-paste synchronization is not allowed.
    2. Explicit precedence. State the load order and override relationships in the rules file so that “who overrides whom” is a readable declaration rather than a guess by the model.
    1. # Project Rules (highest to lowest priority)
    2. 1. Skill instructions under the task/ directory
    3. 2. General rules in the root directory
    4. 3. Background documents under docs/ (may be outdated, reference only)
    1. Freshness metadata. Tag documents with an effective date, applicable scope, and invalidation conditions so expired content is automatically downgraded to background material.
    2. A conflict detection pipeline. Add consistency checks to continuous integration: extract critical facts into structured entries, compare them, and fail the pipeline as soon as a discrepancy is found.
    1. # Illustration: extract key facts and detect conflicts
    2. facts = extract_facts(repo_docs, keys=["refund_window_days"])
    3. conflicts = [f for f in facts if len({v.value for v in f.values}) > 1]
    4. if conflicts:
    5. fail_build(conflicts) # output file paths and line numbers for human review
    1. Change linkage. When a critical fact changes, a checklist requires updating every referrer; log services and monitoring alerts can track trends in “the same fact changing in multiple places.”
    2. Add one question at acceptance. Require the agent to list every relevant source it read and the value each one carried. Once more than one source appears, it must explicitly flag the discrepancy instead of silently choosing for the user.

    6. Rollout Pace

    Start with a pilot in a single repository: inventory the rules and skill files, mark duplicated facts, and wire in the consistency check. After two weeks, use the number of conflicts and the mean time to fix as metrics. Then expand to multiple repositories and cross-team collaboration, and bring rules-file review into the normal code review process. If you use cloud-hosted capabilities, object storage can hold baseline versions of the rules, a container platform can run the check jobs, and logging and monitoring services can track drift trends; general product categories are sufficient.

    The essence of context drift is a knowledge management problem amplified in the age of agents. Cleaning up sessions only eases rot. Only keeping project materials synchronized and making conflicts visible makes an agent’s fluent answer truly worth accepting.