{"slug": "the-agent-drifts-from-your-requirement-while-the-context-fills-up", "title": "The agent drifts from your requirement while the context fills up", "summary": "A developer argues that coding agents drift from their original brief as the context window fills with fetched files, terminal output and rejected edits, causing the agent to optimize for its most recent action rather than the stated requirement. The proposed fix is a small, fixed acceptance block pinned at the top of the task, a restatement pass that maps each bullet to a specific diff hunk before work is accepted, and trimming stale transcript material. The developer ties the approach to Powerduck's local-first, file-as-source-of-truth practice of keeping the contract in the repo rather than only in the prompt.", "body_md": "You ask for one behavior: add a validation that rejects a malformed id before the request reaches the handler. The agent reads the route, finds the schema file, runs a couple of searches, edits two other call sites to match a style it saw nearby, and finishes with a green test. The validation you asked for is missing; it optimized the last thing it touched and called the task done. The requirement did not disappear, it just got buried under the working material.\n\nA coding agent does not keep a clean memory of your request. It carries a running transcript: fetched files, terminal output, rejected edits, summaries of those edits. As that transcript grows, the original one-line brief sits farther from the tokens the model samples next, and each new decision leans on recent material more than on the opening instruction. Nobody tells the agent to pause and re-check acceptance, so the last successful action quietly becomes the objective.\n\nThis is not a model that forgot; it is a context that rotated. The brief was never restated, the acceptance criteria were never pinned, and the intermediate output was never trimmed. Drift looks like competence because the diff compiles and the tests that happen to exist still pass.\n\nThe cheapest anchor is a tiny block that never moves. Put it at the top of the task, in plain sentences the agent can quote back, and keep it separate from implementation notes. It should say what must change, what must stay unchanged, and the one check that proves it.\n\n```\nAcceptance for this task:\n- Reject a malformed id at the route boundary, before the handler runs.\n- Do not change existing valid-id behavior.\n- Prove it with one negative-case test that returns the expected error.\nEverything after this block is working material, not new requirements.\n```\n\nDo not trust a done that arrived from a long transcript. Before accepting the work, ask the agent to restate the acceptance block and point to the exact diff hunk that satisfies each bullet. When a bullet has no hunk, that is an open item, not a detail to skip. One restatement pass catches most drift because it forces the model to measure the final diff against the opening brief instead of against its last edit.\n\nTrim the transcript as you go too: drop early failed searches and superseded drafts rather than letting them ride along. A shorter, current context behaves like a focused engineer; a long muddy one behaves like someone reading from the middle of their notes.\n\nContext decays further when you stop and resume hours later. The new session opens cold, and without a handoff the agent reconstructs a goal from whatever is visible in the working tree. End a session with a short note: what was done, what is open, the acceptance block, and where the relevant files live. The next run starts from the anchor instead of re-deriving intent.\n\nThis is easier to hold when the anchor itself lives in the repo rather than only in the prompt. A checked-in contract or spec file the agent reads every session does not rot when the transcript does. That local-first, file-as-source-of-truth habit is the core of [Powerduck](https://www.powerduck.com/); the same instinct applies to keeping a task brief from drifting.\n\nDrift is invisible because the code still runs. The fix is not a bigger window; it is a fixed point the agent returns to, a periodic restatement, and a transcript that stays current instead of accumulating.", "url": "https://wpnews.pro/news/the-agent-drifts-from-your-requirement-while-the-context-fills-up", "canonical_source": "https://dev.to/jeff_pdc/the-agent-drifts-from-your-requirement-while-the-context-fills-up-2mdj", "published_at": "2026-10-23 22:27:35+00:00", "updated_at": "2026-10-23 22:39:52.356997+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "large-language-models", "developer-tools"], "entities": ["Powerduck"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/the-agent-drifts-from-your-requirement-while-the-context-fills-up", "markdown": "https://wpnews.pro/news/the-agent-drifts-from-your-requirement-while-the-context-fills-up.md", "text": "https://wpnews.pro/news/the-agent-drifts-from-your-requirement-while-the-context-fills-up.txt", "jsonld": "https://wpnews.pro/news/the-agent-drifts-from-your-requirement-while-the-context-fills-up.jsonld"}}