OpenClaw has a guard that arms after a context overflow forces a compaction retry. If the agent then makes the same tool call, with the same arguments, and gets the same result, several times in a short window, the guard decides compaction did not break the loop. It aborts the run with this error.
So the agent was stuck before the error. The abort is the guard stopping it from burning tokens forever.
How to fix it
Find the line in the gateway log that says post-compaction guard armed for N attempts. The calls right after it show what repeated.
Read the repeated call. It is the same call, the same arguments and the same result each time, and often the same error. Fix the cause: a wrong path, a missing permission, a command that always fails, or a task the agent cannot finish.
Rerun with a narrower task or a clearer instruction that tells the agent what to do when that call fails. The guard fires after a context overflow, so also look for command output that floods the context.
For smaller models, turn on the rolling loop detectors. OpenClaw recommends this. They warn the agent first, then block the call if the pattern continues.
Read the log again after the next run. Loop events show a warning before any block, so you can see whether the agent changed course.
Do not set enabled to false to make the error go away. OpenClaw says that turns off the post-compaction guard as well, so a real loop can then run until it has used a large amount of tokens.
When it is not this
If the run simply took too long, that is a run timeout, which aborts on expiry. It is a separate setting from loop detection.
If the message is session.stuck, the session stopped making progress. OpenClaw recovers from that on its own and backs off repeated reports.
Cursor and other tools have their own loop messages. This page covers OpenClaw only.
Questions
What does compaction_loop_persisted mean?
After a compaction retry, the agent kept repeating the same tool call with the same arguments and result. OpenClaw's post-compaction guard concluded compaction did not break the loop and aborted the run.
Should I disable loop detection to stop the error?
No. Setting tools.loopDetection.enabled to false also disables the post-compaction guard. Fix the repeated call instead.
The free health check asks ten questions about your app and shows the three fixes to do first. It runs in your browser.
If you would rather have someone read the code, the fixed-price audit is $497 one-time. It covers security and scaling, with a written report ranked by severity.