R438 · Agent architecture › Memory and context

Pairwise precedence: an agent that documents which file wins, twice, and never the order

Read the original

coding-agentscontext-filesinstruction-followingconfiguration-precedencecontext-windowdocumentation-gapsvendor

Source: Pi's own documentation at docs.pi.dev — the home page, "How Pi works", "Configuration", "Settings" and "Compaction". Pi is "an extensible AI agent that works from your terminal", published by Earendil, Inc. and contributors. Scope note: this entry covers those five pages; the sessions, CLI, slash-commands and session-format pages are outside it, so every "not documented" below means not stated on those five.

The question worth asking of any agent harness

A developer writes a project rule — use this test runner, never touch that directory, prefer this style. Hours later the agent does something else. The useful question is not whether the model "forgot". It is mechanical: which instruction sources did the harness load, in what order, and which one wins when two disagree?

That question has a documented answer for some harnesses. For this one it has three answers and a gap, and the gap is where the interesting part lives.

What gets loaded

Instructions come from two distinct surfaces, and they behave differently.

Context files. In any directory, Pi recognises AGENTS.override.md, AGENTS.md, AGENTS.MD, CLAUDE.md or CLAUDE.MD, described as "User instructions applied across working directories". Discovery is broad: "Pi loads them from the agent directory, the working directory, and its parent directories", and "A context file applies whenever Pi runs in its directory or anywhere below it." The agent directory defaults to ~/.pi/agent and is relocatable via PI_CODING_AGENT_DIR.

System-prompt files. SYSTEM.md "Replaces Pi's default system prompt" and APPEND_SYSTEM.md "Adds instructions to Pi's system prompt", each available in the agent directory and, as .pi/SYSTEM.md and .pi/APPEND_SYSTEM.md, per project.

So a single run in a nested directory can inherit context files from the agent directory, the working directory, and every parent in between — a set whose size depends on where you happen to be standing.

The three precedence rules that exist

The documentation states precedence three times, each time for one pair:

  1. "For SYSTEM.md and APPEND_SYSTEM.md, the trusted project file takes precedence over the corresponding agent-directory file", with "Files with the same name are not combined."

  2. "An AGENTS.override.md replaces AGENTS.md or CLAUDE.md only in the same directory" — and, crucially, "It does not suppress context files from the agent directory or other directories."

  3. "Project settings override agent-directory settings", while "Resource lists are combined."

Rule 2 is the one to sit with. An override is local. It replaces its siblings in its own directory and leaves every inherited file standing. A developer reaching for the strongest-sounding filename in the tree gets a rule that wins where it lives and does not displace anything above it. That is additive accumulation dressed as an override — and it is the closest the documentation comes to describing how a deliberate rule ends up as one voice among several.

The orderings that are not documented

Against those three, here is what those five pages do not state:

So the harness documents three pairwise winners and no ordering. For a developer with files in a home directory, a repository root and a subdirectory, the resolved instruction set is not derivable from the documentation.

Compaction: where content does get dropped

One surface genuinely removes material, and it is documented in detail.

Auto-compaction fires when contextTokens > contextWindow - reserveTokens, with compaction.reserveTokens defaulting to 16384 and compaction.keepRecentTokens to 20000; the docs give a worked case — "For a model with a 1M context window, this override triggers compaction above 600K tokens". The mechanism: "Generate summary: Call LLM to summarize with structured format, passing the previous summary as iterative context when present", then rebuild "using summary + messages from firstKeptEntryId onwards". The replacement is for transmission only: "Compaction inserts a summary entry that replaces older messages in subsequent model requests", while "The original entries remain in the session tree."

The summary template has headings "Goal", "Constraints & Preferences", "Progress", "Key Decisions", "Next Steps" and "Critical Context", and under constraints a placeholder reading "[Requirements mentioned by user]". That is an instruction to a summarising model, not a guarantee. Whether user rules survive compaction is not documented — the diagram implies the system prompt persists, which would preserve context-file instructions, but no sentence says so. Two details worth knowing for anything that relies on transcript fidelity: "Thinking blocks are omitted" and "Tool results are truncated to 2000 characters during serialization."

The asymmetry is the point. A rule stated in a file lives in the system prompt and plausibly persists. A rule stated in conversation — "from now on, always..." — is ordinary message content, and its survival depends on a summarising model honouring a template placeholder.

The gap that makes the question unanswerable

Across those five pages, no debug flag, verbose mode, trace or request-dump command is documented. The commands named are /compact [instructions], /reload, /tree, /settings, /session (which "shows the next decision" for cache warming) and pi config. None prints the assembled request.

That is the finding. A developer who suspects their rule was outranked cannot check, because the harness documents neither the ranking nor a way to inspect what was sent. The claim and its refutation are equally unavailable. Pages outside this scope may document a dump — and if so, it belongs in the configuration page next to the precedence rules, where someone looking for it would be.

A trust detail that cuts the other way

Three statements, read together, describe a boundary worth noting. "Pi resolves project trust before loading project settings and resources", and separately, "After the trust decision and project-resource loading, Pi loads context files" — but "Context-file discovery does not require project trust."

So entering an untrusted repository still discovers its context files. Combined with "Project trust controls which project resources Pi loads, but it does not sandbox tool calls", the trust decision gates resources rather than instructions. A cloned repository carrying an AGENTS.md contributes instructions through a path the trust prompt does not cover, and /reload exists precisely because instructions are re-read on demand.

Failure modes

Assuming a filename implies precedence. AGENTS.override.md overrides within its directory only. Expecting it to silence an inherited rule is a documented mistake.

Writing a rule in conversation and treating it as durable. File-borne instructions and chat-borne instructions have different survival properties under compaction, and only the first is structurally protected.

Depending on which of two recognised filenames wins. A repository holding both AGENTS.md and CLAUDE.md — common when migrating between harnesses — has undocumented resolution. Keep one.

Debugging rule-following as a model problem. Before concluding the model ignored an instruction, establish which instructions were loaded. With no request dump, that means controlling the directory tree: run from a known location with a known file set.

Trusting a summary template as a retention policy. "[Requirements mentioned by user]" asks a model to carry constraints forward. It does not ensure it.

Treating an untrusted repository's instruction files as inert. Discovery does not require trust.

Review checklist

For any harness where instructions come from files:

Connections

See R438 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.