Running an agent

An agent does not run all the time. It wakes when a message arrives, takes one turn, and then waits for the next one. While it runs, the system always knows whether it is still alive. Everything it does to the outside world goes through one checked door.

Staying alive

The system must know whether an agent is still running. A crashed agent cannot report its own death, so Unveil Code does not ask the agent. It uses a file lock instead.

A file lock is a claim that the operating system grants on a file to one process at a time. What matters is the exit. When the holding process ends, by any means, the operating system releases the lock for it, with no help from the process. Every agent holds a file lock the whole time it runs. A held lock proves the agent is alive, and a dead agent cannot hold one. It cannot pretend to be alive.

A background process called the reaper checks each agent's lock on a timer, so a crash shows up on the next check. A held lock means the agent is fine. A free lock means the agent is gone. If messages are still waiting in the agent's queue, the reaper restarts the agent to handle them. If not, the reaper clears the agent away.