Detector runtime and isolation
Verity never imports detector models into the orchestrator or API process. Each of the 58 detector ports under detectors/<id>/ owns an isolated Python virtual environment and communicates with DetectorRunner solely through staged input files, stdout/stderr logs, and JSON/PNG outputs.
Keeping every detector in its own uv project solves a severe practical problem in media forensics: published research detectors pin incompatible versions of PyTorch, CUDA wheels, timm, transformers, mediapipe, and facenet-pytorch. Subprocess isolation allows all 58 architectures to coexist without dependency conflicts and ensures that one failing detector cannot poison another or corrupt the admitted evidence.
Component ownership
DetectorRegistry(src/verity/detect/detector_registry.py) — scansdetectors/in sorted directory order, parses eachdetector.yamlinto aDetectorDefinition, and reports whether required local weights exist.DetectorRunner(src/verity/detect/detector_runner.py) — stages read-only inputs into a temporary directory, executes the detector environment, captures stdout/stderr tails, parses outputs into aFinding, and stamps the weight trust tier.verity.runtime.env_manager(src/verity/runtime/env_manager.py) — the single in-processuvruntime manager used directly by the standalone single binary and CLI/API, whilescripts/verity.pydelegates toenv_manager.mainfor container (verity-run) and native script invocations.verity.detect.output_parser(src/verity/detect/output_parser.py) — defaultresult.json->Findingmapper and explainability artifact collector.
The detector package contract
Each detectors/<id>/ directory defines:
| File | Required | Role |
|---|---|---|
detector.yaml | yes | Capabilities, input_mode, preprocessing, cam/region_analysis, weights block, targets, optional caveat |
pyproject.toml | yes | Pinned Python version and exact package requirements for this detector alone |
model.py | yes | Network definition and build_model(weights_path, device) returning normalized [real, fake] logits |
inference.py | yes | Thin entrypoint invoking common.engine.run_detector(build_model, detector.yaml) |
output_parser.py | no | Optional custom parse(raw, output_path, version) override |
weights/ | when applicable | Checkpoint file(s) plus README.md provenance (symlinked to persistent storage in standalone/container mode) |
Registration and live visibility
DetectorRegistry scans detectors/ cleanly on instantiation and exposes get(), list_detectors(), register(), and weights_available(). Because the API constructs a fresh registry per request via build_registry(), dropping a new checkpoint into weights/ or adding a detector directory takes effect immediately without restarting the server.
Execution lifecycle in DetectorRunner
When DetectorRunner.run(media_id, detector_id) executes:
- Resolves the read-only working copy under
workspace/media/and ensuresworkspace/output/<media_id>_<detector_id>/exists. _prepare_input_dirstages a temporary directory containing a copy of the media and the case'sartifacts/<media_id>/tree so the detector cannot mutate the workspace working copy.- By default (when
VERITY_RUNNERis unset),_run_detectorcallsverity.runtime.env_manager.run_detector_processin-process so frozen PyInstaller binaries never rely on an external repository checkout or system Python. IfVERITY_RUNNERis set,_invoke_verityexecutes the configured external script. - Enforces
VERITY_DETECTOR_TIMEOUT(default3600seconds), surfacing timeouts as an explicitRuntimeError. - Saves bounded
stdout.logandstderr.log(last 20,000 characters each) alongsideresult.json. - If
result.jsonwas not created (e.g., non-zero exit), returns a neutral fallback finding (prediction: 0.5,confidence: 0.0) embedding the exit code and stderr tail so examination of the remaining panel continues uninterrupted. - Calls
_parse_output, stampsfinding.tier = definition.weights.tier, and writesfinding.json.
Environment provisioning and air-gap safety (env_manager)
src/verity/runtime/env_manager.py replaces external shell scripts with a portable Python implementation designed for both containers and zero-dependency single-binary workstations:
- Self-bootstrapped
uvand managed Python:ensure_uv()locatesuvin Verity's private<data_dir>/bin/orPATH, and if absent online, downloads the official Astral binary intopaths.bin_dir(). In standalone/air-gap mode,build_subprocess_env()setsUV_PYTHON_INSTALL_DIR=<data_dir>/pythonandUV_PYTHON_PREFERENCE=only-managedso detector environments do not depend on any host system Python installation. - Optional static
ffmpeg/ffprobe:ensure_ffmpeg()can fetch static Linux x86_64 builds intopaths.bin_dir()when missing fromPATH. - Hardware profiles (
auto/cuda/cpu):detect_profile()checks user config (hw_profile) andnvidia-smito choosecudaorcpu. Forcpu,cpu_pyproject()rewritestorch/torchvisionexact pins withoverride-dependencies(+cpu) and adds the PyTorch CPU index so plainuv syncyields ~12x smaller environments. - Baked container environments: If
VERITY_DETECTOR_ENVS_BAKEDis set (full Docker builds),project_dir()checks whether the baked.verity-syncedSHA-256 marker matchesproject_pyproject()and reuses that read-only environment directly. - Deterministic hash-gated sync and offline rebuilds:
sync_one()compares the SHA-256 of the effectivepyproject.tomlagainst.verity-synced. When changed (or--force), online syncs refreshuv.lockand runuv sync --project <dir>, while offline syncs preserve transferreduv.lockfiles and pass--offline --no-python-downloads. - Air-gap runtime sealing: When
paths.is_offline()is true,build_subprocess_env()forcesVERITY_OFFLINE=1,HF_HUB_OFFLINE=1,TRANSFORMERS_OFFLINE=1,DIFFUSERS_OFFLINE=1,UV_OFFLINE=1, andUV_NO_PYTHON_DOWNLOADS=1on every detector subprocess. - Persistent weights symlinking:
ensure_weights_links()maintainsdetectors/<id>/weights -> $VERITY_WEIGHTS_ROOT/<id>in container and standalone modes so refreshing bundled detector code never touches downloaded checkpoints.
Output parsing and evidence discovery
DetectorRunner._parse_output checks first for a detector-local detectors/<id>/output_parser.py defining parse(raw, output_path, version), and falls back to verity.detect.output_parser.parse, which maps prediction > 0.7 to FAKE, < 0.3 to REAL, and [0.3, 0.7] to UNCERTAIN. Even when a custom parser omits explicit paths, discover_evidence_paths() scans timeline.png, full_frames/*_frame.png, attention_maps/*_attention.png, reconstructions/*_recon.png, faces/*.png, and frames/*.png in sorted order so all explainability exhibits reach Finding.reasoning.evidence.
Related pages
- Shared detector engine — what executes inside each isolated environment.
- Weights and checkpoints — checkpoint verification and symlink targets.
- Deployment, configuration and air-gap operations — how
uv, managed Pythons, wheel caches, and lockfiles transfer viaairgap export.