LearnNewsExamplesServices
Frontmatter
id9471
titleAdd Anti-Corruption Protocol to AGENTS.md
stateClosed
labels
documentationai
assigneestobiu
createdAtMar 14, 2026, 12:06 PM
updatedAtMar 15, 2026, 7:37 PM
githubUrlhttps://github.com/neomjs/neo/issues/9471
authortobiu
commentsCount3
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 14, 2026, 12:11 PM

Add Anti-Corruption Protocol to AGENTS.md

Closed v12.1.0 documentationai
tobiu
tobiu commented on Mar 14, 2026, 12:06 PM

Description

The AI agents have been experiencing "Contextual Drift" (context corruption) during long, complex sessions. When an agent modifies a file multiple times and then performs a full read_file to "refresh" its understanding, the context window fills with competing semantic realities of the same file. This confuses the attention mechanism, leading to hallucinated string replacements and failed edits.

Additionally, agents have been falling into a "Context Blindness" trap, using inefficient shell commands (cat and grep) to search files they already have in context, wasting tokens and causing severe API delays.

Proposed Solution

Add a new Section 8 to AGENTS.md titled "Preventing Context Corruption (State Management)".

This protocol will:

  1. Enforce Single Reads: Restrict agents to reading a file fully only once per session.
  2. Ban Re-reads: Explicitly forbid re-reading modified files to prevent competing realities.
  3. Mandate git diff: Instruct agents to use git diff HEAD to reconcile state when they lose track of edits, anchoring their understanding without duplicating code.
  4. Enforce grep_search: Mandate the use of the native grep_search tool for targeted method verification instead of full file reads.
  5. Ban Shell Fallbacks: Strictly forbid the use of cat or grep via run_shell_command for file reading/searching.
tobiu added the documentation label on Mar 14, 2026, 12:06 PM
tobiu added the ai label on Mar 14, 2026, 12:06 PM
tobiu referenced in commit c8e951f - "docs: Add Anti-Corruption Protocol to AGENTS.md (#9471)" on Mar 14, 2026, 12:10 PM
tobiu
tobiu Mar 14, 2026, 12:10 PM

Input from Gemini 3.1 Pro:

✦ The new "Anti-Corruption Protocol" has been successfully added to AGENTS.md. This will instruct all future AI sessions to avoid context drift by relying on git diff and targeted grep_search instead of dangerous full-file re-reads and inefficient cat/grep shell commands.

tobiu assigned to @tobiu on Mar 14, 2026, 12:10 PM
tobiu closed this issue on Mar 14, 2026, 12:11 PM
tobiu
tobiu Mar 15, 2026, 7:37 PM

@raye-deng Thanks for your input! The git diff idea sounds good for edits. I am still mostly using Gemini CLI with the 3.1 pro model. I did notice that the CLI instructions recently changed, and not in a good way. Starting with

CRITICAL INSTRUCTION 1: Use specific tools.

The intent is good, but it seems to just confuse models. The changes of this ticket definitely need more refinements: now Gemini is frequently using the Search_Text tool inside known files.

What helped me the most to counter hallucinations is this one: https://github.com/neomjs/neo/blob/dev/learn/guides/mcp/NeuralLink.md

Best regards, Tobi