Durable Agents: Limits across restarts
● Intermediate2 min
An agent keeps its limit totals in a state file, so a daily limit stays daily even if the program starts again.
There is nothing to set: in a project, the totals are kept in agents/<Name>/state.json. The agent may send 3 emails a day, and each run sends 2. Run it twice:
kavach run
sent to asha@example.com sent to omar@example.com
kavach run
sent to asha@example.com refused: Denied(reason: "limit broken: count <= 3 per day")
The second run knew about the first: its second email would have been the fourth that day. With state: false in the agent's settings, totals last only while the program runs. kavach test and dry runs keep no state, so each starts fresh. See also limit.
Crashes, reboots and clock changes
- A call counts as soon as it passes its checks, and the state file is written then. A call that then fails stops counting; one a crash cut off stays counted after the restart. An
ask's tokens are added once its answer is in. - Each call is saved with its time in UTC, so the windows carry on across a reboot of the machine too.
- A clock set back while the program was down makes saved calls look still to come. They count as made just now, so a limit never loosens.
- A clock set forward does the opposite: saved calls look older and can leave their window early. Nothing on the machine can tell such a jump from time passing.