decision-cascade

Local engine for typed, calibrated decisions for AI agents.

View the Project on GitHub slavabars/decision-cascade

Troubleshooting

English · Русский

Typical service errors: what a code means, where it comes from and what to do. For operations (systemd, upgrade/rollback) see deploy.md.

1. Quick triad

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”.

2. API error codes

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)

3. 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

Options:

The startup log points more precisely:

WARNING no checkpoint <sig>.pt for questions signature <sig>; serving untrained heads

4. 422 from pydantic

Common causes:

The FastAPI response body contains detail[].loc — the path to the field.

5. 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.

6. 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

7. FEEDBACK_UNSUPPORTED

/v1/feedback is not a universal label intake, but transport for the cascade. One of these modes is required:

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.

8. The cascade does not start: no q, risk model or URL

These 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

9. /ready answers 503

The 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.

10. A pack was not picked up: dim or choice_head

In 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 ...

10a. The pack failed signature verification

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.

11. The first request is slow

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.

12. Port is busy

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.

13. Several domains: the wrong pack

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"])'

Metrics and request id — observability.md.