DEV Community

WillCheah
WillCheah

Posted on Edited on Originally published at github.com

A 10-minute demo: break an AI agent's handoff on purpose

Agent-memory demos usually show what the agent remembers. This one shows the other half: whether the state it hands to the next session is consistent — and what happens when two files disagree.

You need Node.js 20+ and npm 7+. No API key, no model call, no install step.

1. Two lines

npx agent-handoff-cli init demo
cd demo && npx agent-handoff-cli check
Enter fullscreen mode Exit fullscreen mode

init prints the path it wrote to and the next step. check then prints:

PASS CORE_FILES       core files present
PASS HANDOFF_SCHEMA   frontmatter is valid
PASS HANDOFF_TIME     timestamps are ordered
PASS LEASE            PAUSED has no residual lease
PASS VERIFY_COMMAND   verification command recorded
PASS HANDOFF_BODY     8 sections and next action are present
PASS HANDOFF_FRESH    sections 4-6 are fresh (0 days)
PASS INDEX_MAP        INDEX is a map and its links resolve
PASS PROJECT_SYNC     derived status matches HANDOFF
PASS MEMORY_LINKS     memory index and links are closed
PASS SECRETS          no high-confidence secret pattern found
SKIP GIT_STATE        not a git repository
[ahp] 0 FAIL / 0 WARN / 11 PASS / 1 SKIP
[ahp] check passed
Enter fullscreen mode Exit fullscreen mode

The SKIP is honest: GIT_STATE needs a repository, and this directory is not one yet. Everything else is green.

2. What those seven files are

init writes seven files. Four are the contract:

File Role
AGENTS.md the entry point: boundaries and the handoff contract
INDEX.md the file map; no dynamic state
PROJECT.md durable decisions, plus a status block derived from HANDOFF.md
HANDOFF.md the current work unit, pause point, next action, and last verification

The other three are memory/MEMORY.md, one lesson body, and ahp.config.json (paths, statuses, freshness).

Only HANDOFF.md carries dynamic state. The status block in PROJECT.md is generated by ahp sync, which is why it cannot quietly drift from the handoff.

3. Break it

Open HANDOFF.md. Its frontmatter contains:

current_file: "none"
Enter fullscreen mode Exit fullscreen mode

and §3 contains:

## 3. Current working set
- Current file: none.
Enter fullscreen mode Exit fullscreen mode

Change only the frontmatter to current_file: "src/auth.ts" and run check again:

FAIL HANDOFF_BODY     current_file=src/auth.ts contradicts section 3 ("none")
[ahp] 1 FAIL / 0 WARN / 10 PASS / 1 SKIP
[ahp] check failed
Enter fullscreen mode Exit fullscreen mode

Look at what the gate did not do: it did not decide which value is true. It found two claims about the same fact that disagree, named both, and failed. That is the failure class this protocol is built for — a handoff that is structurally complete and internally contradictory.

4. Fix it

Change the value back to "none" and run check:

[ahp] 0 FAIL / 0 WARN / 11 PASS / 1 SKIP
[ahp] check passed
Enter fullscreen mode Exit fullscreen mode

A second failure worth trying: set status: "ACTIVE" and leave lease_until: "none". LEASE fails, because an active unit must own a future lease — otherwise two sessions can take it.

5. What this proves, and what it does not

It proves three things:

  • the four files agree with each other, or the check names the disagreement;
  • check is read-only: it creates, deletes and modifies nothing;
  • every failure has a gate ID and a line you can point at.

It does not prove that a fact is true in the world, that an action is authorized, or that the stated next action is the right one. Those are external facts; no file check can establish them. docs/limits.md lists them one by one.

And the dangerous case is the one this demo cannot show: every gate green, and the prose still contradicts itself. Structure is necessary, not sufficient. That is why the protocol pairs the gates with a cold read — a fresh session that answers "what is the state, what is next, and what contradicts?" — and why the project publishes its own limits instead of a security guarantee.

Run it on a real repository

ahp init refuses a non-empty directory unless you pass --force, so it will not overwrite an existing AGENTS.md. Run it in a fresh directory, edit the four files to describe your project, then commit: GIT_STATE stops being skipped once the directory is a repository.

If you want a second pair of eyes

I review how one coding agent hands state to the next and send back one page with up to five findings, each tied to a file and line. Free for the first three repositories, with the limits stated up front: the assessment offer.

The repository is MIT-licensed: cheah505-cyber/agent-handoff-protocol. The 13-item checklist the demo is distilled from is in docs/memory-security-checklist.en.md.

Top comments (4)

Collapse
 
gimalay profile image
Dmytro Halichenko •

The current_file break is a good demo because the fact lives in two places. One way to shrink the "all green, prose still contradicts itself" case is to apply the trick you already use for PROJECT.md's status block to section 3 too: if "Current file" is rendered from the frontmatter by ahp sync rather than written by hand, that whole class of contradiction can't exist, and the cold read only has to check what is genuinely prose (why, and what's next). Which other sections still repeat a frontmatter field today?

Collapse
 
willcheah profile image
WillCheah •

Today the frontmatter is restated verbatim in two places: §0 (status, work unit, phase) and §3 (current_file, running_processes, blocked_by); §4's acceptance line condenses the frontmatter acceptance field — so your question lands on §0 and §3.

Rendering §3 from the frontmatter would delete exactly the class the demo exploits, and §3 is pure scalars, so it is fully derivable. The honest trade: HANDOFF_BODY's cross-check exists because two copies can disagree — render §3 and it has nothing left to compare, and the failure mode moves to "edited the frontmatter, forgot to run sync", the class sync --check catches for the status block today. Extending that to §0 and §3 is most of the work, and it is recorded as a v0.2 candidate with your comment as the ask (docs/v0.2-candidates.md §4, extending your 3mhg4 thread). The prose around the scalars stays hand-written, so the cold read keeps its job — a derived block cannot contradict itself; prose still can.

Collapse
 
gimalay profile image
Dmytro Halichenko •

That trade reads right to me: once §3 is derived there is nothing left to cross-check, and the failure moves to "forgot to run sync", which sync --check already knows how to catch. Keeping the prose hand-written is the part I would keep too, since that is where the cold read earns its place. Thanks for writing it into the v0.2 candidates. If a real repository turns up that trips the duplicate-key check, I'd like to see what the allowlist ends up holding.

Thread Thread
 
willcheah profile image
WillCheah •

Right now the allowlist is empty for the four core files. The only keys I know to repeat legitimately are type and date, and those live in review notes, outside the scope anyway — so inside the four files every duplicate is a hit, and the first real false positive becomes the first allowlist entry. That is deliberate: an allowlist written before the failure is a guess about what "legitimate" means.

It ships as WARN, not FAIL. A second copy can be the point during a migration, where you want the old and new owner visible at once; failing that would force a rename before anyone has read the new value. WARN keeps the signal without making the protocol the authority on intent.

The blind spot belongs in the same breath: the check sees frontmatter only. Two paraphrases of one policy — the failure that started this thread — stay invisible, and there is no line number to attach. That is why the prose question stays with the cold read. A real repository whose duplicate is prose rather than a key is the trigger to revisit the candidate, not to widen the checker; if one shows up, the allowlist goes into the write-up as it stood.