Blog / Architecture

Inside Nightwatch: one Go binary, three guardrails, no retries

2026-11-29·5 min read

Remote sites are tough on software: patchy internet, strict privacy rules, and zero tolerance for an AI improvising system commands at 3 AM. Here is how Nightwatch is structured to stay small and fast, and to hand anything uncertain to a person.

One model call per incident, and no retries

Many AI agents work in a loop: ask the model, and if the answer looks wrong, ask again until something sounds plausible. That works for a chatbot. On an unattended machine at 3 AM, it means the agent can keep trying until it finds an answer that looks plausible.

Nightwatch asks the AI once per problem. Then plain, predictable code checks the answer. If anything fails, it does not retry. It hands the problem to a person.

01 · WatchSpot the troubleFollows the log and grabs the 5 to 15 lines around a burst of warnings or errors.
02 · ThinkAsk the local AIOne question to the model on this machine. Randomness off, no internet allowed.
03 · CheckRun the safety checksOne known action, real names only, no hidden commands.
04 · DecideApply your rulesRe-read for every problem: fix it, ask first, or hands off.
05 · ScrubRemove private detailsEmails, addresses, vehicle IDs, tokens, usernames and phone numbers.
06 · RecordSeal it in the recordSaved in a tamper-evident log, plus a text or call if needed.

Why it is one small program

The first prototype was written in Python, which is great for experiments. But asking every remote machine to set up a Python environment is a support headache. So we rewrote it in Go. That gave us:

Three guardrails between the model and the machine

Every suggestion has to pass three checks, written as plain code, before anything happens:

1. Only six known actions

Restart an app, clear a folder, retry an upload, lock away a suspicious file, alert a person, or ignore harmless noise. Anything else is rejected, and so is any answer containing characters that could sneak in a system command.

2. No made-up names

If the AI says "clear /var/spool/offload", that exact folder must appear in the log it was shown. Invented names are rejected automatically.

3. The policy always wins

Protected things like remote login, the operating system and system drives are off-limits, even if they are listed by mistake as safe to fix. Anything your rules don't mention is treated as off-limits too.

In this release every fix is simulated. Nightwatch decides, checks, records and alerts as it would for real, but never runs destructive commands on the machine.

Redaction in linear time

Before anything is saved or sent, Nightwatch strips out private details. The scrubber uses a pattern-matching engine (Go's RE2) that always runs in a predictable amount of time, so a strange or deliberately nasty log can't make it hang. The raw log itself is never stored. Only a fingerprint of it is kept, so you can still prove what the AI saw.

Reading the records while it runs

The built-in database only allows one program to write at a time. So when you run a query from the command line while Nightwatch is running, the command quietly asks the running program over a local-only connection instead of fighting it for access. Every query is read-only, checked by ClickHouse's own parser, and blocked from reaching files or the internet.

For engineers: the details
PreviousHow a 610 MB model beat an AI 20× its size