A small bot that receives messages and stores them as a raw event log went from skeleton to background daemon in one day. The bug worth keeping from that day is three characters long.

Path("") is the current directory

The data directory could be overridden by an environment variable, with a default next to the code. The environment file contained the variable with nothing after the equals sign. The lookup used the variable's value if the variable existed, so it existed and was the empty string, and Path("") resolves to the current working directory. Under a terminal that is wherever the shell happens to be. Under a service manager it is whatever the service's working directory is. The event log would have been written somewhere different depending on how the process was started.

The fix was to treat an empty value as absent: os.getenv(key) or default. A unit test covering the empty-path fallback was added alongside the tests for owner-only access and for the raw record format.

Running it unattended

Moving the bot under launchd exposed two more small things. The HTTP client and bot libraries logged the bot token at their default level, so those loggers were raised to WARNING, and a scan of the logs after restart showed zero token occurrences. And Python's default logging handler writes to stderr, so the real activity log appeared in the file configured for errors. That was recorded as a known trap rather than changed.

Auto-restart was tested by killing the process and watching the PID change. A photo sent from a real phone arrived and was saved under a dated attachments folder with its original extension. What was not tested was a full reboot: whether the daemon came back on its own after the machine restarted was still on the list.