Inspiration

I keep a markdown memory vault that my coding agent loads every session. Over months it accumulated instructions pointing at tools I had retired, boilerplate pinning old model ids, three notes saying the same thing, and one note claiming a tool was "used daily" next to a log showing one use in 17 days. Every note tool helps you add. None helps you delete. I had a manual checklist for this; it never ran, because I had to run it.

What it does

On every push to a vault repo, vault-patrol clones the commit, runs deterministic checks (broken index links, orphans, dangling wikilinks), then asks Gemini 3.5 once per context batch — with a JSON schema — for five kinds of semantic rot: stale active references, pinned old versions, overlap clusters, hard conflicts, falsified claims. Code verifies every citation before a human sees it, then opens one PR that deletes dead index lines and lists the rest with a proposed subtraction. It never creates notes or tasks.

How we built it

Python 3.12, FastAPI on Cloud Run (webhook returns 202, patrol runs in background with CPU always allocated). Gemini 3.5 Flash through the Google GenAI SDK on Vertex AI, with response_schema set to a pydantic model whose first field is reasoning. The prompt is a versioned file, not a string in code. GitHub REST for the branch and PR.

Challenges: keeping the model honest

An audit that cites text which is not in the file is worse than no audit. The fixes were structural, not prompt-based, and each one was measured on my real 175-note vault:

  1. Every finding must carry a quote that appears verbatim in the accused file, or code drops it and reports the count.
  2. That was not enough: the model produced a true quote with an invented rationale. Now every cross-note finding must also quote the sentence in the other note that proves it — the retirement line, the contradicting rule, the usage number — and code verifies that quote too.
  3. Still not enough: a quote lifted from a one-line-per-project index file can be real but belong to a different project's line. Counter-quotes from the index must now sit on the accused note's own line.
  4. Dated research logs describing dead projects in the present tense are records, not rot. A deterministic rule (filename date, frontmatter, folder name) exempts them; the model never decides this.

False positives went from 4-of-10 to zero across these gates, measured run by run.

What we learned

The agent got more useful the less it was allowed to do. Restricting actions to a subtraction-only enum removed the whole class of "agent invents work for me" failures, and moving every verification from the prompt into code turned a plausible demo into something I will keep running on my own notes.

What's next

Run it locally through the same entry point (python -m patrol run

) on the real vault after every big merge, and let the retired-tool findings drive the next cleanup.

Built With

  • docker
  • fastapi
  • github-api
  • google-cloud-run
  • google-gemini
  • python
  • vertex-ai
Share this project:

Updates

Submission history