Local engine for typed, calibrated decisions for AI agents.
English · Русский
Typical service errors: what a code means, where it comes from and what to do. For operations (systemd, upgrade/rollback) see deploy.md.
curl -fsS http://127.0.0.1:8080/health # is the process alive?
curl -sS http://127.0.0.1:8080/ready # is it ready to serve? (503 + reasons)
curl -fsS http://127.0.0.1:8080/info # backend, modalities, engine
journalctl -u decision-api@api -n 100 --no-pager
/health always answers while the process is alive. If it is silent, check systemctl status decision-api@api.service and the port (ss -ltnp | grep 8080). /ready is the only correct source for a load balancer: 503 means “do not send traffic”.
All errors are JSON {"error": {"code": ..., "message": ...}}.
| Code | HTTP | When |
|---|---|---|
UNTRAINED_HEADS |
409 | there is no trained pack for the question set, and DECISION_UNTRAINED=refuse/auto with an explicit DECISION_CHECKPOINT_DIR |
MODALITY_NOT_SUPPORTED |
422 | images/videos arrived at /v1/systemone, but the backend cannot handle them |
DECISION_LOG_DISABLED |
409 | DELETE /v1/decisions/{id} without DECISION_DECISION_LOG |
DECISION_NOT_FOUND |
404 | unknown or already deleted decision_id |
POLICY_UNSUPPORTED |
409 | policy.mode=risk without a risk model, conformal without a conformal cascade, or max_cost_usd without DECISION_PRICE_TABLE pricing the external model |
POLICY_LIMIT_EXCEEDED |
422 | risk_budget/max_cost_units/max_cost_usd/latency_ms above the server limit |
UNAUTHORIZED |
401 | GET /v1/stats or MCP HTTP without Authorization: Bearer when the matching token is set |
DECISION_EXPIRED |
410 | feedback by decision_id older than DECISION_DECISION_LOG_TTL_HOURS |
IDEMPOTENCY_CONFLICT |
409 | idempotency_key was already used with a different request body |
QUESTION_REQUIRED |
422 | the decision has several questions and items[].question is omitted |
DECISION_LOG_INVALID |
422 | the audit entry has no parsable decision |
MEDIA_INVALID |
422 | media failed validation: path outside DECISION_MEDIA_ROOT, symlink/FIFO, oversized file/image, invalid image data |
REQUEST_INVALID |
422 | request body failed pydantic validation (including media_kwargs) or exceeded field limits |
REQUEST_TOO_LARGE |
413 | body exceeds DECISION_MAX_BODY_BYTES, DECISION_MCP_MAX_BYTES or the proxy limit |
HOST_NOT_ALLOWED |
403 | MCP HTTP received a Host outside the loopback allowlist (DNS rebinding) |
ORIGIN_NOT_ALLOWED |
403 | MCP HTTP received an Origin outside the loopback allowlist |
INVALID_CONTENT_LENGTH |
400 | MCP HTTP received a non-numeric Content-Length |
FEEDBACK_LIMIT_EXCEEDED |
422 | /v1/feedback exceeded the unique-question limit (256) |
JOB_NOT_FOUND |
404 | GET /decisions/batch/jobs/{id}: unknown or TTL-expired job |
JOB_QUEUE_FULL |
429 | active async job queue is full; retry later |
BACKEND_UNAVAILABLE |
502 | the external SystemOne did not answer within the DECISION_BACKEND_TIMEOUT budget (all retries exhausted) |
FEEDBACK_UNSUPPORTED |
409 | /v1/feedback was called without a cascade, without DECISION_CASCADE_RISK_BUDGET, with DECISION_RISK_FEW_SHOT_N < 2, or with a conformal cascade whose certificate is fixed |
FEEDBACK_STORE_BUSY |
503 | the SQLite journal is held by another process longer than busy_timeout; retry the request |
INVALID_QUESTION |
422 | a question from /v1/systemone could not be converted into a spec |
422 (FastAPI) |
422 | the request body failed pydantic validation (see §4) |
UNTRAINED_HEADS{"error": {"code": "UNTRAINED_HEADS", "signature": "d4dcbc937478268a",
"checkpoint_dir": "checkpoints"}}
The heads exist, but there is no trained pack for the questions signature. The signature is computed from names, types, instructions, options and criteria — changing any of them yields a different signature.
What to check:
ls checkpoints/packs/*/metadata.json
.venv/bin/python - <<'EOF'
import json, glob
for path in glob.glob("checkpoints/packs/*/metadata.json"):
m = json.load(open(path))
print(path, m.get("specs"), m.get("questions_signature"))
EOF
DECISION_CHECKPOINT_DIR point to the directory with packs?instructions/options/criteria as training?checkpoints/packs/<name>/ rather than in checkpoints/?Options:
python -m training.recipe.train_heads ...);DECISION_UNTRAINED=allow (the response carries trained: false, the numbers are random).The startup log points more precisely:
WARNING no checkpoint <sig>.pt for questions signature <sig>; serving untrained heads
422 from pydanticCommon causes:
options/levels with duplicates — options must be unique;criteria of a score does not match levels in length;states in /decisions/batch contains an empty string;confidence/probabilities in /v1/feedback outside [0, 1] or not summing to 1 (examples with an invalid decision are not accepted, so we do not train on them).The FastAPI response body contains detail[].loc — the path to the field.
MODALITY_NOT_SUPPORTED{"error": {"code": "MODALITY_NOT_SUPPORTED", "supported": ["text"],
"requested": ["image"]}}
A local backend without a vision encoder accepts text only. To enable CLIP:
DECISION_VISION_MODEL_ID=openai/clip-vit-base-patch32 \
.venv/bin/uvicorn api.server.main:app --port 8000
/info → modalities shows the actual set, and media.ffmpeg shows the decoder version. Video requires ffmpeg/ffprobe 4.4+ and DECISION_VIDEO not set to off: ffmpeg decodes frames and the vision encoder embeds them. Without ffmpeg the service starts with images only; DECISION_VIDEO=on turns a missing ffmpeg into a startup error.
BACKEND_UNAVAILABLE{"error": {"code": "BACKEND_UNAVAILABLE", "backend": "systemone", "status_code": null}}
The external service (DECISION_BACKEND=http or the cascade fallback) did not answer within the call budget. The request body (state, images) never appears in the response or the log.
# is the external service alive and is the URL correct
curl -fsS "$DECISION_BACKEND_URL/health"
# budget and retries
echo "$DECISION_BACKEND_TIMEOUT $DECISION_BACKEND_RETRIES"
journalctl -u decision-api@api -n 50 --no-pager | grep -i unavailable
status_code: 4xx — the external service rejected the request; there will be no retries, fix the contract/authorization.status_code: 5xx or null — network/timeout/overload; increase DECISION_BACKEND_TIMEOUT, check the network./ready shows degraded: true — this is not an error, but escalations do not work.FEEDBACK_UNSUPPORTED/v1/feedback is not a universal label intake, but transport for the cascade. One of these modes is required:
DECISION_BACKEND=cascade + DECISION_CASCADE_RISK_BUDGET + DECISION_RISK_FEW_SHOT_N >= 2 — few-shot retraining of the risk model;DECISION_BACKEND=cascade + DECISION_CASCADE_POLICY=benefit — refining the external model accuracy q.The conformal cascade (DECISION_CASCADE_POLICY=conformal) does not accept feedback: the certificate is a property of the calibration sample, and retraining the threshold without recomputing the bound would break the guarantee. Check /info → accepts_feedback. A plain confidence threshold does not accept feedback either.
If feedback was accepted but disappeared after a restart, check DECISION_FEEDBACK_PATH: without it examples and counters live only in process memory. /info → engine.feedback_path shows the journal path, feedback_restored — how many events were restored at startup.
q, risk model or URLThese are configuration errors at startup (the process does not come up), not HTTP codes:
| Message | What to do |
|---|---|
DECISION_BACKEND=http requires DECISION_BACKEND_URL |
set the external SystemOne URL |
DECISION_BACKEND=cascade requires DECISION_CASCADE_FALLBACK_URL |
set the fallback URL |
DECISION_CASCADE_POLICY=benefit requires DECISION_CASCADE_REMOTE_ACCURACY |
fit q: python -m eval.competitors.fit_remote_accuracy ..., put the JSON/number into the variable |
DECISION_CASCADE_POLICY must be one of ... |
a typo in the policy: "", threshold, confidence, benefit, benefit-aware or conformal |
DECISION_CASCADE_REMOTE_ACCURACY_BOUND must be 'point' or 'lower' |
a typo in the q bound; only point and lower are accepted |
DECISION_CASCADE_RISK_BUDGET requires a fitted risk model at ... |
train risk.json (python -m eval.risk.run) or point DECISION_RISK_MODEL_PATH at it |
DECISION_CASCADE_POLICY=conformal requires a certificate at ... |
fit the certificate (python -m eval.conformal.run) or set DECISION_CONFORMAL_PATH |
DECISION_CASCADE_POLICY=conformal requires a fitted risk model at ... |
train risk.json (python -m eval.risk.run) or point DECISION_RISK_MODEL_PATH at it |
DECISION_FEEDBACK_PATH=... is not writable |
point the journal at a writable path or unset the variable (feedback then lives in memory only) |
DECISION_UNTRAINED must be one of (...) |
allow, refuse, fallback or auto |
/ready answers 503The body contains reasons:
| Reason | Meaning | What to do |
|---|---|---|
encoder is not loaded |
the encoder did not load | check the startup log, DECISION_MODEL_ID, memory/disk |
vision encoder is not loaded |
CLIP did not load | check DECISION_VISION_MODEL_ID and the HF cache |
no trained checkpoints for untrained_policy=refuse |
the policy requires a pack, there are none | add a pack or set DECISION_UNTRAINED=allow |
checkpoints are not readable by this service |
packs exist, but none matched | see §10 (dim/choice_head/signature) |
heads_loaded and checkpoints in the response show how many packs the service sees and how many are actually loaded.
dim or choice_headIn the warmup log:
WARNING skip checkpoint heads.pt: choice_head=option_scoring, service choice_head=linear
WARNING checkpoint dim=768 does not match features dim=64; ignoring ...
DECISION_FEATURE_DIM must match feature_dim from the pack’s metadata.json (gpt2 — 768, hash encoder — 64).DECISION_CHOICE_HEAD (linear or option_scoring) and must match how the pack was trained. Retrain for another mode: python -m training.recipe.train_heads --choice-head ....questions_signature) must match: compare questions in metadata.json with the request.pack signature: ... in the startup log means manifest.json is signed, but the signature does not match or the key is unknown. Check DECISION_PACK_PUBKEY/DECISION_PACK_PUBKEY_FILE; for revisions signed by an old key, keep that key in the file — rotation must not make them unreadable. DECISION_PACK_REQUIRE_SIGNATURE=1 turns a missing signature into an error: disable it only for old unsigned packs. sha256 without a signature does not protect against a coordinated replacement of files and manifest.
By default packs are warmed up at startup (DECISION_WARMUP=1). If warmup is off (DECISION_WARMUP=0), the first request pays for reading checkpoints and loading the encoder — that is expected, but in this mode /ready does not guarantee that the heads are already in memory.
ERROR: [Errno 98] Address already in use
ss -ltnp | grep 8080
systemctl status decision-api@api.service
One instance per port; for several — decision-api@<instance>.service with different ports in the unit.
DECISION_CHECKPOINT_DIR may point to a directory with packs (checkpoints/packs/), where each domain lives separately:
checkpoints/packs/
support-gpt2/ heads.pt + metadata.json
routerbench-gpt2/ heads.pt + metadata.json
A pack is selected by questions_signature from metadata.json, not by directory name. To check which pack actually serves a request:
curl -fsS http://127.0.0.1:8080/info | \
.venv/bin/python -c 'import json,sys; print(json.load(sys.stdin)["engine"]["heads"])'
trained: false or source: null — there is no pack for the questions signature;skip checkpoint ... already served by ... — remove the duplicate;metadata.json is not considered a pack (we do not guess from heads.pt).Metrics and request id — observability.md.