Repository navigation
The bug that made every step of my local coding agent take 30 seconds (and it wasn't the hardware) #3
nightguard-labs
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I run a local coding agent on a 32 GB M1 Pro: Qwen models on MLX, native Swift. Each step of the agent was taking 25-35 seconds, while actually writing the answer took about 1 second. I assumed the Mac was just slow. It wasn't.
What was going on
Every step, the model re-read the whole conversation from scratch. That should not happen: the server keeps a prompt cache, so if the start of the prompt is the same as last time, it skips re-reading that part.
The cache only matches from the top of the prompt down, and stops at the first token that's different.
My server put recalled memories (lessons the agent learned on earlier tasks) at the top of the system prompt, sorted by relevance. Relevance changes every step, so the order changed every step, so the cache never matched past the first few hundred tokens. Everything after that got re-read.
Worse: it got slower as the agent learned more, because more memories meant more text above the part that could be cached. That's why an earlier "fix" seemed to not stick.
The fix
Keep the top of the prompt fixed. The stable stuff (rules, tools, the task) goes first, and anything that changes from step to step goes at the end.
If you do RAG or memory injection, check this
This one change mattered more for speed than any model or hardware tweak I tried.
Project: https://github.com/nightguard-labs/code-smash-teti
I design and decide; Claude Code writes the code.
All reactions