Dogfooding Hermes Agent: Getting an AI Agent to Fix Its Own Bug
# Starting from an inconspicuous error, I guided Hermes Agent through multi-turn questioning to diagnose a defect in its own codebase, write and verify a fix, open an upstream PR, and handle community review.
1. An Inconspicuous Error
On the morning of October 28, Hermes Agent delivered my scheduled US market post-close briefing as usual. The report itself arrived intact, except for two file-mutation error lines tacked onto the end:
## Cronjob Response: US Market Post-Close Briefing
(job_id: 15d1af64ea6f)
... (briefing body omitted) ...
⚠️ File-mutation verifier: 2 file edit(s) FAILED this turn despite any wording above that may suggest otherwise. Run `git status` or `read_file` to confirm what actually landed.
• `/opt/data/cache/scratch/parse_q.py` — [write_file] Refusing to overwrite `/opt/data/cache/scratch/parse_q.py`: `/opt/data/cache/scratch/parse_q.py` exists but this task has not seen its full current content (never read, patched withou…
• `/opt/data/cache/scratch/parse2.py` — [write_file] Refusing to overwrite `/opt/data/cache/scratch/parse2.py`: `/opt/data/cache/scratch/parse2.py` exists but this task has not seen its full current content (never read, patched without …
What’s that file-mutation warning at the end of this morning’s cron output? Looks like an error.
The error is real, though nothing broke. write_file refuses to overwrite a file it hasn’t read first, and the temporary scripts this run tried to create collided with same-named files left behind three days ago. After being blocked, the task fell back to inline execution and delivered the briefing cleanly.
While checking, I noticed cache/scratch has accumulated over 100 old temporary files taking up 18.4 MB. Want me to clean them up?
Sure, clean them up. Also, shouldn’t temporary files created by cron runs be cleaned up automatically afterward?
Cleaned with the built-in prune_scratch_dir() — usage dropped from 18.4 MB to 1.84 MB.
While pruning, I spotted a .last_prune file in the directory and traced the source code: SCRATCH_MAX_IDLE_HOURS = 24, so files idle for over 24 hours are supposed to be pruned. However, the trigger is gated by a process-level global flag, _scratch_pruned_once, which runs only once per process. Since the Gateway stays up without restarting, it only pruned once at startup and kept piling up afterward.
If a cleanup mechanism already existed, why wasn’t it running properly?
2. Questioning Our Way to the Real Fix
Is _scratch_pruned_once triggered on Gateway startup? Does it normally restart on a schedule?
It triggers on the first call to get_scratch_dir(prune=True) in each Python process. This Gateway has been up for 5 days and 4 hours straight — s6 only restarts it on exit, with no periodic timer, so in practice it almost never prunes again.
The fix is to move the flag assignment after the throttle check: since every conversation turn calls get_scratch_dir, it will trigger once the window elapses.
Why would moving it after the throttle check make it trigger? Also check whether the latest upstream code still has this bug.
Saying “every conversation turn calls get_scratch_dir” was wrong — it’s actually called once per new session, not once per turn. And yes, latest upstream still has the same bug.
The real bug is that the flag gets set to True before the throttle check: if that first attempt falls inside the cooldown window, the gate slams shut permanently and every later session returns early.
Isn’t cleanup global? So the issue is just that an early false state blocks the current session from pruning, while another new session later past the window would still trigger a prune?
I ran a quick experiment: in a freshly spawned process, _scratch_pruned_once starts as False, and the 5-day-old .last_prune stamp (Oct 23) immediately updated to Oct 28.
So cleanup isn’t global — it’s per-process. A new process will indeed retry, but a “new session” inside the Gateway isn’t a new process: all 42 threads in the running Gateway live under the same PID, cron included.
Once it was confirmed to be per-process, would that first fix actually hold up?
With that fix, once the window elapses and it prunes and sets the flag, will it prune again next time the window elapses — or is it still just one shot?
Still just one shot. That one-line fix only recovers the first attempt if it happened to be skipped inside the cooldown window; it doesn’t solve a long-lived Gateway pruning only once.
Checking the Gateway’s main loop, there is already a housekeeping loop ticking every 60 seconds. We can keep the one-shot flag for short-lived processes and hook periodic pruning into the existing housekeeping loop.
Could the one-shot flag and the new periodic housekeeping task conflict under concurrency?
_scratch_pruned_once isn’t a lock at all — it’s an unguarded check-then-act idempotency optimization, not mutual exclusion.
I checked _prune_idle_entries underneath: it catches OSError per entry and re-validates before unlinking. In the worst concurrent case, the same directory simply gets scanned twice with no errors.
What was the original intent of the existing design? Could the new change cause any unintended side effects?
I dug up commit 2dcebe6471, which introduced this mechanism. It had three goals: move scratch files off tmpfs to disk (avoiding memory exhaustion), keep the per-process latch cheap for fan-out subprocesses, and use a 1-hour stamp to prevent cross-process thundering herds.
Keeping the latch’s intent, fixing only the premature gate closure, and wiring periodic checks into housekeeping preserves all three constraints.
Only after the root cause, concurrency boundary, and original design intent were all clear did I let it touch the code.
3. Implementing the Fix and Opening a PR
I asked Hermes to branch off latest upstream, implement the fix, add regression tests, and verify there were no regressions. Once the code and tests were written, it rolled straight into running pytest:
Both changes are done. Checking existing test conventions first:
The test harness is clear — the scratch_prune_spawns fixture intercepts spawn_prune. Writing three regression tests now.
Running the test suite with a clean HOME to avoid tripping the test-isolation guard.
Should these tests really take this long?
I cast the net way too wide — tests/gateway/ alone has over 500 tests spinning up real processes and sockets, which would take hours in full.
After narrowing to the relevant modules, the run finished in 28 seconds: 62 passed, 2 failed. I verified both failures against the unmodified baseline — they are pre-existing, not regressions.
With zero regressions confirmed, it wrapped the changes into a clean commit:
ad521de68d fix(scratch): a long-lived gateway prunes on the stamped hour, not once per process
4 files changed, 179 insertions(+), 12 deletions(-)
Next step: send the fix upstream.
Can you connect to GitHub directly? I’d like to open a PR.
git is available, but gh isn’t installed and .env only has a placeholder token. Add your GitHub token to /opt/data/.env directly (don’t paste it in chat), and once that’s in place I’ll install gh and handle the full PR flow.
Done. Go ahead and install gh and check if you can see my Hermes fork.
gh 2.63.2 is installed in the persistent volume at /opt/data/bin/gh and authenticated. I can see Liudon/hermes-agent. Token permissions: can read all your repos and create PRs.
PR creation was blocked by token permissions: it can push to your fork, but can’t open a PR on the upstream repo. Two options: use the manual compare URL, or grant Pull requests: Read and write on NousResearch/hermes-agent in your GitHub token settings.
You can’t grant write permissions to someone else’s repo on GitHub, can you?
You’re right about fine-grained tokens — public repos they don’t own are read-only, so Pull requests: write can’t be added. Opening a PR upstream doesn’t actually require upstream write access anyway; two options avoid it completely: a Classic PAT, or gh’s built-in OAuth device login (recommended, no manual token needed).
I’ve kicked off the gh OAuth device flow.
The device code is ready and waiting for approval. Please complete this step in your browser:
- Open
https://github.com/login/device - Enter code:
XXXX-XXXX - Click Authorize for GitHub CLI
Once approved, the credentials stay locally in ~/.config/gh/hosts.yml — no manual token or per-repo grants needed. Watching and waiting for completion.
I opened the link on my phone, signed in, and approved the device code — Hermes automatically picked it up and saved the credentials to hosts.yml on the server. Before opening the PR, it checked upstream for duplicates, found an existing open issue with the same root cause, linked it in the PR description, opened the PR, and sent back the URL and change summary for review.

After opening PR #146046, Hermes sent the GitHub PR preview card and summary straight to my phone.
4. Following Up on Community Review
After submitting the PR, I asked Hermes every few days to check its status and look for new comments. Here is one of those check-ins:
Check the PR status and comments.
Contributor foma-agent pointed out that our change tripped the CI health gate: gateway/run.py is an oversized legacy file subject to a ratchet cap against main (lines may decrease, never increase), and we added 17 net lines. They suggested moving the new housekeeping helpers into the existing gateway/run_housekeeping_disk.py.
Verified: our branch is at 5,247 lines vs. 5,230 on main, so this really is a blocking gate.
Only after confirming the ratchet gate was genuinely blocking CI did it make the refactor — moving the cleanup helpers into run_housekeeping_disk.py, verifying the health check dropped to 0 blocking, and pushing the update.
5. Outcome and Takeaways
On December 5, the final outcome arrived: a maintainer integrated a more complete version of the fix into another PR (#164386) and merged it into main, crediting me as a contributor.
Looking back across the whole session, I never wrote an elaborate prompt or manually typed git commands — it was all ordinary back-and-forth conversation. What actually made it work was a clear division of labor: the human reviews, questions, pushes back, and probes; the agent verifies, executes, and reports back.
Once the runtime environment and GitHub access are in place, an agent can reliably handle log inspection, source reading, controlled experiments, code edits, test runs, duplicate checks, PR creation, and review follow-ups — while judging the scope and validity of its conclusions still belongs to the human.
For me, that is the most practical rhythm for collaborating with an AI agent: let the agent absorb the execution legwork, while the human probes assumptions and hits the brakes at key checkpoints. And a task isn’t done when tests pass or a PR is opened — it’s done when upstream actually accepts it.
Conversation excerpts and execution logs were compiled from actual sessions.