Local engine for typed, calibrated decisions for AI agents.
English · Русский
The service is installed into /opt/decision-model (overridable with DECISION_INSTALL_DIR), and the decision-api@.service unit is rendered for that directory and the service user. Ubuntu and the CentOS/RHEL family follow one path: only package installation differs (apt vs dnf), everything else is the shared deploy/lib/common.sh.
# Ubuntu 22.04+ / Debian
sudo bash deploy/ubuntu/install.sh
# CentOS Stream 9 / Rocky 9 / AlmaLinux 9
sudo bash deploy/centos/install.sh
What the installer does:
python3/venv, CentOS — python3.11), pip, curl and git;/opt/decision-model (git clone from the checkout the script runs in; a dirty tree is an error, so unverified code never reaches the server);.venv from uv.lock already inside the installation directory;decision system user without a login and gives it read access to the tree (owner is root, so upgrade.sh can git pull);decision-api@.service unit for the actual directory and user with hardening and starts the api instance on 127.0.0.1:8080.| Variable | Default | Purpose |
|---|---|---|
DECISION_INSTALL_DIR |
/opt/decision-model |
installation directory |
DECISION_SERVICE_USER |
decision |
service user (created if missing) |
If you install straight from a working tree (DECISION_INSTALL_DIR equals the checkout directory), the service runs as the user who invoked sudo and source permissions are not changed — handy for a one-off VM, not for production. The service never runs as root: SUDO_USER=root is replaced with decision.
# check the installation without touching /opt
sudo DECISION_INSTALL_DIR=/srv/decision-model bash deploy/ubuntu/install.sh
The unit enables NoNewPrivileges, PrivateTmp, ProtectSystem=strict, kernel/control-group protection, an empty CapabilityBoundingSet, RestrictAddressFamilies and MemoryMax=4G. Writes are allowed only to data/ and .cache/ (ReadWritePaths); checkpoints/ is read-only for the service; the unit points model and pack caches to .cache/ (HF_HOME, DECISION_PACK_CACHE), and feedback or audit journals elsewhere need a drop-in. ProtectHome=yes is used for /opt, while a checkout under /home//root renders ProtectHome=no so systemd does not hide WorkingDirectory. checkpoints/ belongs to root and is read-only for the service; data/ and .cache/ belong to the service. The installer and restore.sh refuse to follow symlinks in these directories, and restore runs with the service stopped, so the service user cannot point a root operation at /etc.
The installer does not create state (.env, packs, risk model): on a new server it comes from a backup (deploy/restore.sh) or from the release packs. Without .env the service starts on defaults — the file is optional, so “forgot to copy it” does not turn into a broken service.
Post-install checks:
curl -fsS http://127.0.0.1:8080/health # liveness: the process is alive
curl -fsS http://127.0.0.1:8080/ready # readiness: encoder and heads are ready
curl -fsS http://127.0.0.1:8080/metrics # Prometheus (see observability.md)
journalctl -u decision-api@api -n 50 --no-pager
/ready answers 503 while the service is not ready; the body contains reasons. For diagnosing the causes see troubleshooting.md; metrics and logs are in observability.md.
Each worker keeps its own LRU of loaded heads: PyTorch tensors are not shared between processes. A shared DECISION_HEADS_INDEX_DIR removes duplicated lookups: the first worker walks the packs and parses metadata.json, while the others read the resolved choice from an atomically updated index. An entry is validated by the checkpoint and metadata mtime_ns/size; sha256 is computed on insert. A corrupted or stale index is ignored and rebuilt. DECISION_HEADS_INDEX_VERIFY_SHA=1 also compares the hash on every hit — it protects against content swaps that preserve mtime, but reads the whole heads.pt. Updates take a flock with a roughly one-second timeout: the lock is waited for at most that long and only on a heads-cache miss, then the index write is skipped.
The index directory is created with 0700, the file and lock with 0600; an existing wider directory is not tightened but is logged as a warning. An indexed path must stay inside DECISION_CHECKPOINT_DIR, and the index must not be the checkpoint directory itself: writing would change its mtime on every update; a nested directory is allowed but causes a one-time root mtime change.
# .env
DECISION_HEADS_INDEX_DIR=/opt/decision-model/.cache/heads-index
The index is optional: without the variable nothing changes. It does not cache the heads themselves and does not save RAM — only directory walks and metadata parsing on the first request for a signature. hits/misses/stale counters are exposed in GET /info → heads_index; a write from another worker is noticed on the next lookup, no restart needed. A metadata.json that appears inside an already existing pack directory changes only the subdirectory mtime, so that pack is picked up on another invalidation (a new directory in the root, an edit to the selected pack) or after deleting the index file; a restart alone does not invalidate the index.
A backup includes only what cannot be restored from a release or a recipe:
| Path | Why |
|---|---|
.env |
DECISION_*: backend, device, cascade threshold, paths. Read by the unit (EnvironmentFile=-<project>/.env), sample in .env.example |
checkpoints/packs/ |
trained head packs (heads.pt, metadata.json, temperature.json) |
checkpoints/risk.json |
trained risk model (if the risk-aware cascade is enabled) |
data/ |
feedback journal, decision audit and other state files |
data/ is copied while the service runs: JSONL is safe, but for a SQLite journal (-wal/-shm) stop the service or use sqlite3 <db> ".backup ..."; copying a live file may produce an inconsistent snapshot.
Not included: .venv (rebuilt), .cache/ (model and pack caches, downloaded again), encoder weights (downloaded from HF or a release), checkpoints/finetune/ (reproduced by the recipe and weighs gigabytes).
Archives are stored in /var/backups/decision-cascade (overridable with DECISION_BACKUP_ROOT). The name is decision-cascade-<UTC timestamp>.tar.gz, and inside there is .installed-version with the version at backup time. The archive is 600, and .env inside it is also 600; restore_state returns .env with 600 and rejects archives with symlinks/hardlinks/special files.
sudo bash deploy/backup.sh /opt/decision-model
# backup: /var/backups/decision-cascade/decision-cascade-20261029T091500Z.tar.gz
cd /opt/decision-model
sudo bash deploy/upgrade.sh /opt/decision-model
The order of steps (all in one script, identical on Ubuntu and CentOS):
.env + packs + risk model + data/;git fetch --tags --prune and git pull --ff-only;.venv from uv.lock;decision-api@api.service;200 from /ready (60 s by default).If /ready does not come up, the script rolls back by itself: data from the backup, code to the previous commit (git checkout --detach <old>), rebuilds the venv, restarts the service and exits with code 1. After an automatic rollback the repository stays in detached HEAD on the old commit — to return to the branch:
sudo git -C /opt/decision-model checkout main
Script environment parameters:
| Variable | Default | Purpose |
|---|---|---|
DECISION_INSTANCE |
api |
instance of the decision-api@<instance> unit |
DECISION_READY_URL |
http://127.0.0.1:8080/ready |
where the readiness check goes |
DECISION_READY_TIMEOUT |
60 |
how many seconds to wait for /ready |
DECISION_BACKUP_ROOT |
/var/backups/decision-cascade |
backup directory |
If the upgrade succeeded but quality/behaviour is not acceptable:
# 1. data (.env, packs, risk model) — from the backup
sudo bash deploy/restore.sh /var/backups/decision-cascade/decision-cascade-<stamp>.tar.gz /opt/decision-model
# 2. code — to the previous tag
sudo git -C /opt/decision-model checkout v0.13.0
# 3. venv and restart
sudo bash -c 'source deploy/lib/common.sh; ensure_venv /opt/decision-model; restart_service api'
# 4. check
curl -fsS http://127.0.0.1:8080/ready
restore.sh restarts the service itself and waits for /ready; if the service does not come up, it prints the command for systemctl status and exits with an error. The script takes the user and group from the installed unit, creates data/, checkpoints/packs and .cache/, and aligns the owner of restored directories with the destination, so the decision service can write to the journal again.
| Step | Ubuntu | CentOS/RHEL |
|---|---|---|
| Packages | apt-get install python3 python3-venv python3-pip curl git ffmpeg |
dnf install python3.11 python3.11-pip curl git; ffmpeg from RPM Fusion |
| venv | python3 -m venv .venv |
python3.11 -m venv .venv |
| Install directory | /opt/decision-model (DECISION_INSTALL_DIR) |
the same |
| Service user | system decision (DECISION_SERVICE_USER) |
the same |
| Python | 3.11+ (Ubuntu 24.04+; on 22.04 — python3.11) |
3.11+ (python3.11 from AppStream) |
| systemd | systemctl enable --now decision-api@api |
the same |
| upgrade/rollback | deploy/upgrade.sh, deploy/restore.sh |
the same |
Video requires ffmpeg/ffprobe 4.4+. The Ubuntu installer installs the ffmpeg package; Rocky/CentOS Stream has no ffmpeg in the base repository, so the installer checks the binaries and prints RPM Fusion instructions. Without ffmpeg the service starts with images only (DECISION_VIDEO=auto); DECISION_VIDEO=on turns a missing ffmpeg into a startup error, off disables video explicitly.
What is checked automatically (tests/test_deploy.py):
distro_from_release recognises ubuntu/debian and centos/rocky/almalinux/rhel, and rejects an unknown distribution;.env, packs and the risk model in a temporary directory;shellcheck -x for every deploy/**/*.sh;render_unit substitutes the actual directory and user into the unit and rejects unexpanded placeholders;ensure_project_dir deploys only the committed state, does not copy .venv/checkpoints and does not overwrite a non-empty directory;KillSignal=SIGTERM, TimeoutStopSec=30, --timeout-graceful-shutdown 30, hardening directives and path-aware ProtectHome (tests/test_systemd_unit.py);ensure_venv install exact versions from uv.lock (uv export --locked); GitHub Actions are pinned by SHA.A live VM run is not automated: the scripts require root and systemd. Before rolling out to a new distribution, run install.sh → upgrade.sh → restore.sh on a disposable VM and check /ready.
The interpreter is chosen once and identically for install and upgrade: DECISION_PYTHON, otherwise the first available python3.13/python3.12/python3.11/python3 with version ≥ 3.11. If none fits, the script fails with a hint (dnf install python3.11) instead of building a venv on 3.9. On Ubuntu 22.04 python3 is 3.10, so you need python3.11 (deadsnakes) or 24.04.
Verified live on both distributions: install.sh → /health, /ready, /metrics, X-Request-ID, POST /decisions → upgrade.sh → backup.sh → corrupt .env → restore.sh → teardown — PASS. The unit is rendered for /opt/decision-model, the service runs as the decision user, and after teardown neither the unit, nor the directory, nor the user remain.
| Date | Distribution | Version | What was checked |
|---|---|---|---|
| 2026-10-29 | Ubuntu 24.04.5, systemd 255 | 0.15.0 |
full cycle |
| 2026-11-10 | CentOS Stream 9 (cloud VM) | 1.0.0 (11fe196) |
full cycle, python3.11 from AppStream |
The CentOS run closed a real defect: python3 there is 3.9, and the installation built the venv on it. Now python_bin requires ≥ 3.11 and hints at dnf install python3.11; on Stream 9 it installs python3.11 (3.11.13).
systemctl restart/stop sends SIGTERM. uvicorn stops accepting new connections but finishes requests already accepted; TimeoutStopSec=30 is the upper bound. The contract is pinned by tests/test_graceful_shutdown.py: a request started before SIGTERM gets 200, not a connection reset.