diff --git a/.env.example b/.env.example
index 60cf8a0..3414073 100644
--- a/.env.example
+++ b/.env.example
@@ -3,7 +3,8 @@
TRYOPS_POSTGRES_USER=tryops
TRYOPS_POSTGRES_DB=tryops
-TRYOPS_POSTGRES_PASSWORD=change-me-postgres-password
+# TRYOPS_POSTGRES_PASSWORD=change-me-postgres-password
+TRYOPS_POSTGRES_PASSWORD=tryops-local-postgres
TRYOPS_MINIO_ROOT_USER=tryops
TRYOPS_MINIO_ROOT_PASSWORD=change-me-minio-root-password
diff --git a/MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md b/MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md
index d7e1497..676256f 100644
--- a/MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md
+++ b/MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md
@@ -1233,12 +1233,12 @@ Current readiness: backend/data/native edge are real; the browser Console still
- [~] **P3 — Frontend.** PARTIAL: React/Vite/TypeScript Console shell, typed API client, LLM Playground with direct/canary/A-B/bandit routing, VTON Studio contract form with persisted side-by-side comparison outputs, Dashboard, Request History, Pipeline Runs, Model Registry, Evaluation evidence plus optimization/Pareto/sustainability panel, Experiments board, Governance, Incident posture plus live bad-candidate and rollback drills, native incident workflow/postmortem evidence loading, API-key session field, RBAC role-aware navigation, degraded banner, and responsive styling are implemented under `web/`; browser upload/download controls, full audit-log UI, live alert workflow controls, screenshots, and accessibility/export hardening remain.
- [x] **P4 — Services & edge wiring.** Rust gateway reverse-proxies `/api/*` to FastAPI `/v1/*`, adds request IDs, propagates trace context, enforces native rate/payload/signed-artifact/quota controls plus artifact-path preflight, calls the Go guardrail sidecar before LLM generation, and `docker-compose` ties gateway+api+Postgres+Prometheus+Grafana+guardrail+MinIO+MLflow with healthchecks/restart policies. `make app-smoke` now validates the stack through a disposable Compose project so stale local volumes do not taint readiness.
- [~] **P5 — Monitoring & dashboard.** API metrics, native Rust gateway metrics, native Go runtime telemetry, OpenTelemetry Collector wiring, native trace/log correlation evidence, and Alertmanager page/ticket routing are in place; remaining work: in-app timeseries, audit-log UI, external pager/chat credentials, and live OTLP exporters for full gateway->API->model trace stitching.
-- [~] **P6 — Enterprise hardening.** PARTIAL: Rust edge API-key/JWT auth preflight, viewer/operator/admin RBAC session and nav enforcement, native edge limits, quota admission, optional file quota persistence, opt-in Postgres-backed distributed quota admission with fail-closed behavior, Postgres quota usage upsert mirroring, native Postgres migration/pooling evidence, native Postgres/MinIO backup-restore drill evidence, Valkey-compatible quota counter mirroring, `.env.example` plus Compose secret loading, native Go secret-rotation/workload-identity contract evidence, live Vault KV v2 secret retrieval/rotation evidence, Kubernetes Vault `SecretStore`/`ExternalSecret` manifests, native dependency-lock contract evidence across Python/Node/Rust/Go, native rustls TLS termination, payload limits, Rust->Go guardrail enforcement, native Go full-stack load/SLO evidence, native Go incident workflow/postmortem evidence, GitHub Actions plus native Go CI/supply-chain contract evidence, and local live Syft/Trivy/Cosign execution are in place. Remaining work: production Kubernetes External Secrets sync, external k6/locust confirmation, and external error-tracker DSN exercise.
+- [~] **P6 — Enterprise hardening.** PARTIAL: Rust edge API-key/JWT auth preflight, viewer/operator/admin RBAC session and nav enforcement, native edge limits, quota admission, optional file quota persistence, opt-in Postgres-backed distributed quota admission with fail-closed behavior, Postgres quota usage upsert mirroring, native Postgres migration/pooling evidence, native Postgres/MinIO backup-restore drill evidence, Valkey-compatible quota counter mirroring, `.env.example` plus Compose secret loading, native Go secret-rotation/workload-identity contract evidence, live Vault KV v2 secret retrieval/rotation evidence, Kubernetes Vault `SecretStore`/`ExternalSecret` manifests, native dependency-lock contract evidence across Python/Node/Rust/Go, native rustls TLS termination, payload limits, Rust->Go guardrail enforcement, native C++ content-safety gating, native Go full-stack load/SLO evidence, native Go incident workflow/postmortem evidence, GitHub Actions plus native Go CI/supply-chain contract evidence, and local live Syft/Trivy/Cosign execution are in place. Remaining work: production Kubernetes External Secrets sync, external k6/locust confirmation, and external error-tracker DSN exercise.
- [~] **P7 — Demo & docs.** PARTIAL: `docs/presentation_outline.md` contains the professor demo path and `make professor-demo-acceptance` now verifies the live bad-candidate gate plus seeded Pareto, energy, full-stack, VTON, lineage, promotion, rollback, and governance artifacts. Remaining work: seed data loader, product runbook, screenshots/walkthrough, and full end-user/admin guide.
-- [~] **P8 — Native-first product expansion.** PARTIAL: local P8 rows PA072-PA086 are closed by verified native evidence. Rust gateway now serves `web/dist` with SPA fallback, performs API-key/JWT auth preflight, terminates optional rustls HTTPS, makes native semantic-cache admission decisions and optional C++ vector-cache lookups before FastAPI for LLM generation, mirrors accepted quota usage into Postgres plus Valkey-compatible counters with hashed-tenant usage snapshots, can use Postgres row locks as the shared quota admission ledger when `TRYOPS_GATEWAY_QUOTA_POSTGRES_ADMISSION=true`, falls back to the local quota ledger when a non-admission durable mirror is unavailable, emits the shared native trace/log envelope as JSONL, and has a validated split-image contract with Rust builder/runtime ABI checks for gateway/controller/guardrail/benchmark/C++ tools/API/web assets; native Go modules now cover VTON/LLM job execution, signed audit/webhook event dispatch, full-stack gateway/BFF load generation with SLO reporting, native CI/supply-chain contract validation plus live Syft/Trivy/Cosign evidence, native dependency-lock contract validation, native secret-rotation/workload-identity contract validation plus live Vault KV rotation, native incident workflow/postmortem evidence, distributed quota admission validation, config-contract drift checks, TLS termination contract validation, native Postgres migration/pool execution, native Postgres/MinIO backup-restore drills, container-contract validation, quota read-model/showback generation for the BFF dashboard, trace-envelope validation/reporting, observability Collector/correlation validation, Alertmanager routing validation, runtime telemetry export, SLO regression gating over native benchmark output, and a CI-grade Rust/Go/C++ performance-budget report; native C++ VTON preprocessing, image-quality metrics, production A/B/bandit routing, semantic-cache lookup, and trace-envelope validation now flow through edge/API/evidence paths. Production Kubernetes External Secrets sync, external k6/locust confirmation, external error-tracker DSN exercise, and live OTLP exporters remain.
+- [~] **P8 — Native-first product expansion.** PARTIAL: local P8 rows PA072-PA086 are closed by verified native evidence. Rust gateway now serves `web/dist` with SPA fallback, performs API-key/JWT auth preflight, terminates optional rustls HTTPS, makes native semantic-cache admission decisions and optional C++ vector-cache lookups before FastAPI for LLM generation, mirrors accepted quota usage into Postgres plus Valkey-compatible counters with hashed-tenant usage snapshots, can use Postgres row locks as the shared quota admission ledger when `TRYOPS_GATEWAY_QUOTA_POSTGRES_ADMISSION=true`, falls back to the local quota ledger when a non-admission durable mirror is unavailable, emits the shared native trace/log envelope as JSONL, and has a validated split-image contract with Rust builder/runtime ABI checks for gateway/controller/guardrail/benchmark/C++ tools/API/web assets; native Go modules now cover VTON/LLM job execution, signed audit/webhook event dispatch, full-stack gateway/BFF load generation with SLO reporting, native CI/supply-chain contract validation plus live Syft/Trivy/Cosign evidence, native dependency-lock contract validation, native secret-rotation/workload-identity contract validation plus live Vault KV rotation, native incident workflow/postmortem evidence, distributed quota admission validation, config-contract drift checks, TLS termination contract validation, native Postgres migration/pool execution, native Postgres/MinIO backup-restore drills, container-contract validation, quota read-model/showback generation for the BFF dashboard, trace-envelope validation/reporting, observability Collector/correlation validation, Alertmanager routing validation, runtime telemetry export, SLO regression gating over native benchmark output, and a CI-grade Rust/Go/C++ performance-budget report; Wave 3 native fabric now adds C++ admission control, retry budgets, PII/secret redaction, content-safety gating, tamper-evident audit logs, Bloom idempotency dedup, HyperLogLog cardinality, LRU/TTL response cache, cost attribution, reservoir/priority trace sampling, plus Go consistent-hash routing; native C++ VTON preprocessing, image-quality metrics, production A/B/bandit routing, semantic-cache lookup, and trace-envelope validation also flow through edge/API/evidence paths. Production Kubernetes External Secrets sync, external k6/locust confirmation, external error-tracker DSN exercise, and live OTLP exporters remain.
### Execution order
P3 Console shell -> thin LLM slice -> VTON product slice -> operator control room -> native enterprise boundary -> production profile. Ship the thin vertical slice first: UI -> Rust gateway -> API -> real/fallback LLM -> DB -> feedback -> dashboard -> Grafana.
### Acceptance (Gate: Product Ready)
-A user opens the Console in a browser and can, with no terminal, run LLM and VTON requests, see metrics/quota/trace/lineage, submit feedback, review history/dashboard/registry/audit, and as an admin promote or block a model through policy-gated controls. The full stack starts with `make app-up` and is smoke-tested with `make app-smoke`; native edge/job/SLO/config/container/CI/load/trace/observability/alerts/postgres/backup/TLS/performance/quota-read-model/distributed-quota/runtime-telemetry/live-secret evidence comes from `make native-rust-smoke`, `make native-edge-cache-smoke`, `make native-edge-guardrail-smoke`, `make native-quota-ledger-smoke`, `make native-distributed-quota-smoke`, `make native-secret-rotation-live`, `make native-quota-read-model-sample`, `make native-runtime-telemetry-sample`, `make native-observability-contract-sample`, `make native-alertmanager-contract-sample`, `make native-db-migrator-sample`, `make native-backup-restore-sample`, `make native-tls-contract-sample`, `make native-tls-smoke`, `make native-static-smoke`, `make native-job-runner-sample`, `make vton-native-api-sample`, `make gateway-benchmark-native`, `make native-fullstack-load-sample`, `make native-ci-contract-live`, `make native-slo-gate-sample`, `make native-config-contract-sample`, `make native-container-contract-sample`, `make native-trace-envelope-sample`, and `make native-performance-budget-sample`; backend contracts remain covered by the Python test suite. The professor-demo evidence bundle is gated by `make professor-demo-acceptance`.
+A user opens the Console in a browser and can, with no terminal, run LLM and VTON requests, see metrics/quota/trace/lineage, submit feedback, review history/dashboard/registry/audit, and as an admin promote or block a model through policy-gated controls. The full stack starts with `make app-up` and is smoke-tested with `make app-smoke`; native edge/job/SLO/config/container/CI/load/trace/observability/alerts/postgres/backup/TLS/performance/quota-read-model/distributed-quota/runtime-telemetry/live-secret evidence comes from `make native-rust-smoke`, `make native-edge-cache-smoke`, `make native-edge-guardrail-smoke`, `make native-admission-sample`, `make native-redaction-sample`, `make native-safety-sample`, `make native-audit-log-sample`, `make native-dedup-sample`, `make native-hll-sample`, `make native-consistent-hash-sample`, `make native-cache-sample`, `make native-cost-sample`, `make native-sampler-sample`, `make native-retry-sample`, `make native-quota-ledger-smoke`, `make native-distributed-quota-smoke`, `make native-secret-rotation-live`, `make native-quota-read-model-sample`, `make native-runtime-telemetry-sample`, `make native-observability-contract-sample`, `make native-alertmanager-contract-sample`, `make native-db-migrator-sample`, `make native-backup-restore-sample`, `make native-tls-contract-sample`, `make native-tls-smoke`, `make native-static-smoke`, `make native-job-runner-sample`, `make vton-native-api-sample`, `make gateway-benchmark-native`, `make native-fullstack-load-sample`, `make native-ci-contract-live`, `make native-slo-gate-sample`, `make native-config-contract-sample`, `make native-container-contract-sample`, `make native-trace-envelope-sample`, and `make native-performance-budget-sample`; backend contracts remain covered by the Python test suite. The professor-demo evidence bundle is gated by `make professor-demo-acceptance`.
diff --git a/Makefile b/Makefile
index c855f89..525ffd4 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ TRYOPS_COSIGN_IMAGE ?= ghcr.io/sigstore/cosign/cosign:v2.4.1
.PHONY: native-container-contract-build native-container-contract-test native-container-contract-sample
.PHONY: native-distributed-quota-build native-distributed-quota-test native-distributed-quota-smoke
.PHONY: native-quota-read-model-build native-quota-read-model-test native-quota-read-model-sample
+.PHONY: native-safety-build native-safety-test native-safety-sample
.PHONY: native-runtime-telemetry-build native-runtime-telemetry-test native-runtime-telemetry-sample
.PHONY: native-observability-contract-build native-observability-contract-test native-observability-contract-sample
.PHONY: native-alertmanager-contract-build native-alertmanager-contract-test native-alertmanager-contract-sample
@@ -46,9 +47,9 @@ native-go-toolchain:
prepare-container-artifacts:
@set -eu; \
uid=$$(id -u); gid=$$(id -g); \
- mkdir -p artifacts/app artifacts/cache artifacts/logs artifacts/traces artifacts/runtime artifacts/runtime/vton artifacts/eval/full_stack artifacts/eval/jobs; \
- if ! chown -R "$$uid:$$gid" artifacts/app artifacts/cache artifacts/logs artifacts/traces artifacts/runtime artifacts/eval/full_stack artifacts/eval/jobs 2>/dev/null; then \
- docker run --rm -v "$(CURDIR)/artifacts:/work" alpine:3.20 sh -lc "chown -R $$uid:$$gid /work/app /work/cache /work/logs /work/traces /work/runtime /work/eval/full_stack /work/eval/jobs"; \
+ mkdir -p artifacts/app artifacts/cache artifacts/logs artifacts/otel artifacts/traces artifacts/runtime artifacts/runtime/vton artifacts/eval/full_stack artifacts/eval/jobs; \
+ if ! chown -R "$$uid:$$gid" artifacts/app artifacts/cache artifacts/logs artifacts/otel artifacts/traces artifacts/runtime artifacts/eval/full_stack artifacts/eval/jobs 2>/dev/null; then \
+ docker run --rm -v "$(CURDIR)/artifacts:/work" alpine:3.20 sh -lc "chown -R $$uid:$$gid /work/app /work/cache /work/logs /work/otel /work/traces /work/runtime /work/eval/full_stack /work/eval/jobs"; \
fi
web-typecheck:
@@ -57,7 +58,7 @@ web-typecheck:
web-build:
cd web && npm ci && npm run build
-ci: test web-typecheck native-go-test native-rust-test native-cpp-test supply-chain-sample vulnerability-scan-sample native-container-contract-sample native-dependency-lock-contract-sample native-secret-rotation-contract-sample native-incident-workflow-sample native-ci-contract-live evaluation-index-sample
+ci: test web-typecheck native-go-test native-rust-test native-cpp-test native-admission-sample native-redaction-sample native-safety-sample native-audit-log-sample native-dedup-sample native-hll-sample native-consistent-hash-sample native-cache-sample native-cost-sample native-sampler-sample native-retry-sample supply-chain-sample vulnerability-scan-sample native-container-contract-sample native-dependency-lock-contract-sample native-secret-rotation-contract-sample native-incident-workflow-sample native-ci-contract-live evaluation-index-sample
docker compose config --quiet
docker compose --profile tls config --quiet
@@ -265,6 +266,146 @@ native-cpp-cli-build:
mkdir -p artifacts/native
$(CXX) $(CXXFLAGS) -Inative/cpp/tryops_policy/include native/cpp/tryops_policy/src/tryops_policy.cpp native/cpp/tryops_policy/src/tryops_policy_cli.cpp -o artifacts/native/tryops_policy_cli
+native-admission-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_admission/include native/cpp/tryops_admission/src/tryops_admission.cpp native/cpp/tryops_admission/src/tryops_admission_cli.cpp -o artifacts/native/tryops_admission_cli
+
+native-admission-sample: native-admission-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_admission.py --wire samples/admission/mixed_traffic.wire --output artifacts/admission/admission_report.json --max-shed-rate 0.7
+
+native-admission-test:
+ @set -eu; \
+ tmp_adm=$$(mktemp /tmp/tryops_admission_test.XXXXXX); \
+ trap 'rm -f "$$tmp_adm"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_admission/include native/cpp/tryops_admission/src/tryops_admission.cpp native/cpp/tryops_admission/tests/test_admission.cpp -o $$tmp_adm; \
+ $$tmp_adm
+
+native-redaction-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_redaction/include native/cpp/tryops_redaction/src/tryops_redaction.cpp native/cpp/tryops_redaction/src/tryops_redaction_cli.cpp -o artifacts/native/tryops_redaction_cli
+
+native-redaction-sample: native-redaction-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_redaction.py --input samples/redaction/sensitive_log.txt --output artifacts/redaction/redaction_report.json
+
+native-redaction-test:
+ @set -eu; \
+ tmp_red=$$(mktemp /tmp/tryops_redaction_test.XXXXXX); \
+ trap 'rm -f "$$tmp_red"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_redaction/include native/cpp/tryops_redaction/src/tryops_redaction.cpp native/cpp/tryops_redaction/tests/test_redaction.cpp -o $$tmp_red; \
+ $$tmp_red
+
+native-safety-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_safety/include native/cpp/tryops_safety/src/tryops_safety.cpp native/cpp/tryops_safety/src/tryops_safety_cli.cpp -o artifacts/native/tryops_safety_cli
+
+native-safety-sample: native-safety-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_safety.py --input samples/safety/prompts.jsonl --output artifacts/safety/safety_report.json --flag 0.4 --block 0.8
+
+native-safety-test:
+ @set -eu; \
+ tmp_saf=$$(mktemp /tmp/tryops_safety_test.XXXXXX); \
+ trap 'rm -f "$$tmp_saf"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_safety/include native/cpp/tryops_safety/src/tryops_safety.cpp native/cpp/tryops_safety/tests/test_safety.cpp -o $$tmp_saf; \
+ $$tmp_saf
+
+native-audit-log-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_audit_log/include native/cpp/tryops_audit_log/src/tryops_audit_log.cpp native/cpp/tryops_audit_log/src/tryops_audit_log_cli.cpp -o artifacts/native/tryops_audit_log_cli
+
+native-audit-log-sample: native-audit-log-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_audit_log.py --input samples/audit/events.txt --output artifacts/audit/audit_log_report.json --prove 0
+
+native-audit-log-test:
+ @set -eu; \
+ tmp_aud=$$(mktemp /tmp/tryops_audit_log_test.XXXXXX); \
+ trap 'rm -f "$$tmp_aud"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_audit_log/include native/cpp/tryops_audit_log/src/tryops_audit_log.cpp native/cpp/tryops_audit_log/tests/test_audit_log.cpp -o $$tmp_aud; \
+ $$tmp_aud
+
+native-dedup-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_dedup/include native/cpp/tryops_dedup/src/tryops_dedup.cpp native/cpp/tryops_dedup/src/tryops_dedup_cli.cpp -o artifacts/native/tryops_dedup_cli
+
+native-dedup-sample: native-dedup-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_dedup.py --input samples/dedup/idempotency_keys.txt --output artifacts/dedup/dedup_report.json --expected-items 5000 --target-fp-rate 0.01 --max-fp-rate 0.05
+
+native-dedup-test:
+ @set -eu; \
+ tmp_ded=$$(mktemp /tmp/tryops_dedup_test.XXXXXX); \
+ trap 'rm -f "$$tmp_ded"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_dedup/include native/cpp/tryops_dedup/src/tryops_dedup.cpp native/cpp/tryops_dedup/tests/test_dedup.cpp -o $$tmp_ded; \
+ $$tmp_ded
+
+native-hll-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_hll/include native/cpp/tryops_hll/src/tryops_hll.cpp native/cpp/tryops_hll/src/tryops_hll_cli.cpp -o artifacts/native/tryops_hll_cli
+
+native-hll-sample: native-hll-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_hll.py --input samples/hll/event_keys.txt --output artifacts/hll/hll_report.json --precision 14 --max-rel-error 0.05
+
+native-hll-test:
+ @set -eu; \
+ tmp_hll=$$(mktemp /tmp/tryops_hll_test.XXXXXX); \
+ trap 'rm -f "$$tmp_hll"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_hll/include native/cpp/tryops_hll/src/tryops_hll.cpp native/cpp/tryops_hll/tests/test_hll.cpp -o $$tmp_hll; \
+ $$tmp_hll
+
+native-cache-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cache/include native/cpp/tryops_cache/src/tryops_cache.cpp native/cpp/tryops_cache/src/tryops_cache_cli.cpp -o artifacts/native/tryops_cache_cli
+
+native-cache-sample: native-cache-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_cache.py --wire samples/cache/requests.wire --output artifacts/cache/cache_report.json --min-hit-rate 0.5
+
+native-cache-test:
+ @set -eu; \
+ tmp_ch=$$(mktemp /tmp/tryops_cache_test.XXXXXX); \
+ trap 'rm -f "$$tmp_ch"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cache/include native/cpp/tryops_cache/src/tryops_cache.cpp native/cpp/tryops_cache/tests/test_cache.cpp -o $$tmp_ch; \
+ $$tmp_ch
+
+native-cost-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cost/include native/cpp/tryops_cost/src/tryops_cost.cpp native/cpp/tryops_cost/src/tryops_cost_cli.cpp -o artifacts/native/tryops_cost_cli
+
+native-cost-sample: native-cost-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_cost.py --input samples/cost/usage.json --output artifacts/cost/cost_report.json
+
+native-cost-test:
+ @set -eu; \
+ tmp_co=$$(mktemp /tmp/tryops_cost_test.XXXXXX); \
+ trap 'rm -f "$$tmp_co"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cost/include native/cpp/tryops_cost/src/tryops_cost.cpp native/cpp/tryops_cost/tests/test_cost.cpp -o $$tmp_co; \
+ $$tmp_co
+
+native-sampler-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_sampler/include native/cpp/tryops_sampler/src/tryops_sampler.cpp native/cpp/tryops_sampler/src/tryops_sampler_cli.cpp -o artifacts/native/tryops_sampler_cli
+
+native-sampler-sample: native-sampler-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_sampler.py --wire samples/sampler/trace_stream.wire --output artifacts/sampler/sampler_report.json
+
+native-sampler-test:
+ @set -eu; \
+ tmp_sa=$$(mktemp /tmp/tryops_sampler_test.XXXXXX); \
+ trap 'rm -f "$$tmp_sa"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_sampler/include native/cpp/tryops_sampler/src/tryops_sampler.cpp native/cpp/tryops_sampler/tests/test_sampler.cpp -o $$tmp_sa; \
+ $$tmp_sa
+
+native-retry-build:
+ mkdir -p artifacts/native
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_retry/include native/cpp/tryops_retry/src/tryops_retry.cpp native/cpp/tryops_retry/src/tryops_retry_cli.cpp -o artifacts/native/tryops_retry_cli
+
+native-retry-sample: native-retry-build
+ PYTHONPATH=$(PYTHONPATH) python scripts/evaluate_native_retry.py --wire samples/retry/requests.wire --output artifacts/retry/retry_report.json --min-success-rate 0.85
+
+native-retry-test:
+ @set -eu; \
+ tmp_re=$$(mktemp /tmp/tryops_retry_test.XXXXXX); \
+ trap 'rm -f "$$tmp_re"' EXIT; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_retry/include native/cpp/tryops_retry/src/tryops_retry.cpp native/cpp/tryops_retry/tests/test_retry.cpp -o $$tmp_re; \
+ $$tmp_re
+
native-image-metrics-build:
mkdir -p artifacts/native
$(CXX) $(CXXFLAGS) native/cpp/tryops_image_metrics/src/tryops_image_metrics_cli.cpp -o artifacts/native/tryops_image_metrics_cli
@@ -373,9 +514,39 @@ native-cpp-test:
tmp_cache=$$(mktemp /tmp/tryops_semantic_cache_test.XXXXXX); \
tmp_gguf=$$(mktemp /tmp/tryops_gguf_preflight_test.XXXXXX); \
tmp_trace=$$(mktemp /tmp/tryops_trace_envelope_test.XXXXXX); \
- trap 'rm -f "$$tmp_policy" "$$tmp_cache" "$$tmp_gguf" "$$tmp_trace" /tmp/tryops_gguf_preflight_fixture.gguf' EXIT; \
+ tmp_adm=$$(mktemp /tmp/tryops_admission_test.XXXXXX); \
+ tmp_red=$$(mktemp /tmp/tryops_redaction_test.XXXXXX); \
+ tmp_saf=$$(mktemp /tmp/tryops_safety_test.XXXXXX); \
+ tmp_aud=$$(mktemp /tmp/tryops_audit_log_test.XXXXXX); \
+ tmp_ded=$$(mktemp /tmp/tryops_dedup_test.XXXXXX); \
+ tmp_hll=$$(mktemp /tmp/tryops_hll_test.XXXXXX); \
+ tmp_ch=$$(mktemp /tmp/tryops_cache_test.XXXXXX); \
+ tmp_co=$$(mktemp /tmp/tryops_cost_test.XXXXXX); \
+ tmp_sa=$$(mktemp /tmp/tryops_sampler_test.XXXXXX); \
+ tmp_re=$$(mktemp /tmp/tryops_retry_test.XXXXXX); \
+ trap 'rm -f "$$tmp_policy" "$$tmp_cache" "$$tmp_gguf" "$$tmp_trace" "$$tmp_adm" "$$tmp_red" "$$tmp_saf" "$$tmp_aud" "$$tmp_ded" "$$tmp_hll" "$$tmp_ch" "$$tmp_co" "$$tmp_sa" "$$tmp_re" /tmp/tryops_gguf_preflight_fixture.gguf' EXIT; \
$(CXX) $(CXXFLAGS) -Inative/cpp/tryops_policy/include native/cpp/tryops_policy/src/tryops_policy.cpp native/cpp/tryops_policy/tests/test_policy.cpp -o $$tmp_policy; \
$$tmp_policy; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_admission/include native/cpp/tryops_admission/src/tryops_admission.cpp native/cpp/tryops_admission/tests/test_admission.cpp -o $$tmp_adm; \
+ $$tmp_adm; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_redaction/include native/cpp/tryops_redaction/src/tryops_redaction.cpp native/cpp/tryops_redaction/tests/test_redaction.cpp -o $$tmp_red; \
+ $$tmp_red; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_safety/include native/cpp/tryops_safety/src/tryops_safety.cpp native/cpp/tryops_safety/tests/test_safety.cpp -o $$tmp_saf; \
+ $$tmp_saf; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_audit_log/include native/cpp/tryops_audit_log/src/tryops_audit_log.cpp native/cpp/tryops_audit_log/tests/test_audit_log.cpp -o $$tmp_aud; \
+ $$tmp_aud; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_dedup/include native/cpp/tryops_dedup/src/tryops_dedup.cpp native/cpp/tryops_dedup/tests/test_dedup.cpp -o $$tmp_ded; \
+ $$tmp_ded; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_hll/include native/cpp/tryops_hll/src/tryops_hll.cpp native/cpp/tryops_hll/tests/test_hll.cpp -o $$tmp_hll; \
+ $$tmp_hll; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cache/include native/cpp/tryops_cache/src/tryops_cache.cpp native/cpp/tryops_cache/tests/test_cache.cpp -o $$tmp_ch; \
+ $$tmp_ch; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_cost/include native/cpp/tryops_cost/src/tryops_cost.cpp native/cpp/tryops_cost/tests/test_cost.cpp -o $$tmp_co; \
+ $$tmp_co; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_sampler/include native/cpp/tryops_sampler/src/tryops_sampler.cpp native/cpp/tryops_sampler/tests/test_sampler.cpp -o $$tmp_sa; \
+ $$tmp_sa; \
+ $(CXX) $(CXXFLAGS) -Inative/cpp/tryops_retry/include native/cpp/tryops_retry/src/tryops_retry.cpp native/cpp/tryops_retry/tests/test_retry.cpp -o $$tmp_re; \
+ $$tmp_re; \
$(CXX) $(CXXFLAGS) -Inative/cpp/tryops_semantic_cache/include native/cpp/tryops_semantic_cache/src/tryops_semantic_cache.cpp native/cpp/tryops_semantic_cache/tests/test_semantic_cache.cpp -o $$tmp_cache; \
$$tmp_cache; \
$(CXX) $(CXXFLAGS) -Inative/cpp/tryops_gguf_preflight/include native/cpp/tryops_gguf_preflight/src/tryops_gguf_preflight.cpp native/cpp/tryops_gguf_preflight/tests/test_gguf_preflight.cpp -o $$tmp_gguf; \
@@ -424,7 +595,7 @@ native-guardrail-smoke: native-guardrail-build
native-go-build:
cd native/go/tryops-controller && GOFLAGS=-mod=mod $(GO) build -buildvcs=false -o ../../../artifacts/native/tryops-controller .
-native-go-test: native-go-toolchain
+native-go-test: native-go-toolchain native-consistent-hash-test
@if command -v "$(GO)" >/dev/null 2>&1; then \
mkdir -p artifacts/.gocache; \
cd native/go/tryops-controller && GOCACHE=$(CURDIR)/artifacts/.gocache GOFLAGS=-mod=mod $(GO) test ./...; \
@@ -569,6 +740,23 @@ native-slo-gate-test:
native-slo-gate-sample: native-slo-gate-build
artifacts/native/tryops_slo_gate --input artifacts/eval/gateway_benchmark/native_gateway_benchmark.json --output artifacts/eval/slo/native_slo_gate_report.json
+native-consistent-hash-build:
+ mkdir -p artifacts/native
+ cd native/go/tryops-consistent-hash && GOFLAGS=-mod=mod $(GO) build -buildvcs=false -o ../../../artifacts/native/tryops_consistent_hash .
+
+native-consistent-hash-test:
+ @if command -v "$(GO)" >/dev/null 2>&1; then \
+ mkdir -p artifacts/.gocache; \
+ cd native/go/tryops-consistent-hash && GOCACHE=$(CURDIR)/artifacts/.gocache GOFLAGS=-mod=mod $(GO) test ./...; \
+ else \
+ echo "go not installed; skipping consistent-hash ring tests"; \
+ fi
+
+native-consistent-hash-sample: native-consistent-hash-build
+ mkdir -p artifacts/consistent_hash
+ artifacts/native/tryops_consistent_hash < samples/consistent_hash/ring_request.wire > artifacts/consistent_hash/ring_report.json
+ @python -c "import json;r=json.load(open('artifacts/consistent_hash/ring_report.json'));print('[ring] nodes=%d keys=%d imbalance=%.3f removed=%s moved_fraction=%.3f ideal=%.3f minimal_disruption=%s'%(r['nodes'],r['total_keys'],r['imbalance_ratio'],r['removed_node'],r['moved_fraction'],r['ideal_fraction'],r['minimal_disruption']))"
+
native-event-dispatcher-build:
mkdir -p artifacts/native
cd native/go/tryops-event-dispatcher && GOFLAGS=-mod=mod $(GO) build -buildvcs=false -o ../../../artifacts/native/tryops_event_dispatcher .
@@ -1134,22 +1322,22 @@ app-up: evaluation-index-sample
uid=$$(id -u); gid=$$(id -g); \
TRYOPS_CONTAINER_UID=$$uid \
TRYOPS_CONTAINER_GID=$$gid \
- TRYOPS_POSTGRES_PORT=15432 \
+ TRYOPS_POSTGRES_PORT=$${TRYOPS_POSTGRES_PORT:-15432} \
TRYOPS_POSTGRES_USER=$${TRYOPS_POSTGRES_USER:-tryops} \
TRYOPS_POSTGRES_DB=$${TRYOPS_POSTGRES_DB:-tryops} \
TRYOPS_POSTGRES_PASSWORD=$${TRYOPS_POSTGRES_PASSWORD:-tryops-local-postgres} \
- TRYOPS_VALKEY_PORT=16379 \
+ TRYOPS_VALKEY_PORT=$${TRYOPS_VALKEY_PORT:-16379} \
TRYOPS_MINIO_ROOT_USER=$${TRYOPS_MINIO_ROOT_USER:-tryops} \
TRYOPS_MINIO_ROOT_PASSWORD=$${TRYOPS_MINIO_ROOT_PASSWORD:-tryops-local-minio} \
- TRYOPS_MINIO_PORT=19000 \
- TRYOPS_MINIO_CONSOLE_PORT=19001 \
- TRYOPS_MLFLOW_PORT=15000 \
- TRYOPS_PROMETHEUS_PORT=19090 \
- TRYOPS_ALERTMANAGER_PORT=19093 \
- TRYOPS_GRAFANA_PORT=13000 \
- TRYOPS_GUARDRAIL_PORT=18093 \
- TRYOPS_API_PORT=18080 \
- TRYOPS_GATEWAY_PORT=18081 \
+ TRYOPS_MINIO_PORT=$${TRYOPS_MINIO_PORT:-19000} \
+ TRYOPS_MINIO_CONSOLE_PORT=$${TRYOPS_MINIO_CONSOLE_PORT:-19001} \
+ TRYOPS_MLFLOW_PORT=$${TRYOPS_MLFLOW_PORT:-15000} \
+ TRYOPS_PROMETHEUS_PORT=$${TRYOPS_PROMETHEUS_PORT:-19090} \
+ TRYOPS_ALERTMANAGER_PORT=$${TRYOPS_ALERTMANAGER_PORT:-19093} \
+ TRYOPS_GRAFANA_PORT=$${TRYOPS_GRAFANA_PORT:-13000} \
+ TRYOPS_GUARDRAIL_PORT=$${TRYOPS_GUARDRAIL_PORT:-18093} \
+ TRYOPS_API_PORT=$${TRYOPS_API_PORT:-18080} \
+ TRYOPS_GATEWAY_PORT=$${TRYOPS_GATEWAY_PORT:-18081} \
TRYOPS_GATEWAY_QUOTA_POSTGRES_DSN="$${TRYOPS_GATEWAY_QUOTA_POSTGRES_DSN:-host=postgres port=5432 user=tryops password=tryops-local-postgres dbname=tryops}" \
docker compose up --build -d gateway prometheus grafana minio mlflow guardrail
@@ -1163,32 +1351,32 @@ app-smoke: native-stack-smoke-build native-job-runner-build evaluation-index-sam
COMPOSE_PROJECT_NAME=$$project \
TRYOPS_CONTAINER_UID=$$uid \
TRYOPS_CONTAINER_GID=$$gid \
- TRYOPS_POSTGRES_PORT=15432 \
+ TRYOPS_POSTGRES_PORT=$${TRYOPS_POSTGRES_PORT:-15432} \
TRYOPS_POSTGRES_USER=$${TRYOPS_POSTGRES_USER:-tryops} \
TRYOPS_POSTGRES_DB=$${TRYOPS_POSTGRES_DB:-tryops} \
TRYOPS_POSTGRES_PASSWORD=$${TRYOPS_POSTGRES_PASSWORD:-tryops-local-postgres} \
- TRYOPS_VALKEY_PORT=16379 \
+ TRYOPS_VALKEY_PORT=$${TRYOPS_VALKEY_PORT:-16379} \
TRYOPS_MINIO_ROOT_USER=$${TRYOPS_MINIO_ROOT_USER:-tryops} \
TRYOPS_MINIO_ROOT_PASSWORD=$${TRYOPS_MINIO_ROOT_PASSWORD:-tryops-local-minio} \
- TRYOPS_MINIO_PORT=19000 \
- TRYOPS_MINIO_CONSOLE_PORT=19001 \
- TRYOPS_MLFLOW_PORT=15000 \
- TRYOPS_PROMETHEUS_PORT=19090 \
- TRYOPS_ALERTMANAGER_PORT=19093 \
- TRYOPS_GRAFANA_PORT=13000 \
- TRYOPS_GUARDRAIL_PORT=18093 \
- TRYOPS_API_PORT=18080 \
- TRYOPS_GATEWAY_PORT=18081 \
+ TRYOPS_MINIO_PORT=$${TRYOPS_MINIO_PORT:-19000} \
+ TRYOPS_MINIO_CONSOLE_PORT=$${TRYOPS_MINIO_CONSOLE_PORT:-19001} \
+ TRYOPS_MLFLOW_PORT=$${TRYOPS_MLFLOW_PORT:-15000} \
+ TRYOPS_PROMETHEUS_PORT=$${TRYOPS_PROMETHEUS_PORT:-19090} \
+ TRYOPS_ALERTMANAGER_PORT=$${TRYOPS_ALERTMANAGER_PORT:-19093} \
+ TRYOPS_GRAFANA_PORT=$${TRYOPS_GRAFANA_PORT:-13000} \
+ TRYOPS_GUARDRAIL_PORT=$${TRYOPS_GUARDRAIL_PORT:-18093} \
+ TRYOPS_API_PORT=$${TRYOPS_API_PORT:-18080} \
+ TRYOPS_GATEWAY_PORT=$${TRYOPS_GATEWAY_PORT:-18081} \
TRYOPS_GATEWAY_QUOTA_POSTGRES_DSN="$${TRYOPS_GATEWAY_QUOTA_POSTGRES_DSN:-host=postgres port=5432 user=tryops password=tryops-local-postgres dbname=tryops}" \
docker compose up --build -d gateway prometheus grafana minio mlflow guardrail; \
- TRYOPS_STACK_GATEWAY_URL=http://127.0.0.1:18081 \
- TRYOPS_STACK_GUARDRAIL_URL=http://127.0.0.1:18093 \
- TRYOPS_STACK_PROMETHEUS_URL=http://127.0.0.1:19090 \
- TRYOPS_STACK_GRAFANA_URL=http://127.0.0.1:13000 \
- TRYOPS_STACK_MINIO_URL=http://127.0.0.1:19000 \
- TRYOPS_STACK_MLFLOW_URL=http://127.0.0.1:15000 \
+ TRYOPS_STACK_GATEWAY_URL=http://127.0.0.1:$${TRYOPS_GATEWAY_PORT:-18081} \
+ TRYOPS_STACK_GUARDRAIL_URL=http://127.0.0.1:$${TRYOPS_GUARDRAIL_PORT:-18093} \
+ TRYOPS_STACK_PROMETHEUS_URL=http://127.0.0.1:$${TRYOPS_PROMETHEUS_PORT:-19090} \
+ TRYOPS_STACK_GRAFANA_URL=http://127.0.0.1:$${TRYOPS_GRAFANA_PORT:-13000} \
+ TRYOPS_STACK_MINIO_URL=http://127.0.0.1:$${TRYOPS_MINIO_PORT:-19000} \
+ TRYOPS_STACK_MLFLOW_URL=http://127.0.0.1:$${TRYOPS_MLFLOW_PORT:-15000} \
artifacts/native/tryops_stack_smoke --output artifacts/eval/full_stack/full_stack_smoke.json; \
- TRYOPS_JOB_RUNNER_BASE_URL=http://127.0.0.1:18081 \
+ TRYOPS_JOB_RUNNER_BASE_URL=http://127.0.0.1:$${TRYOPS_GATEWAY_PORT:-18081} \
artifacts/native/tryops_job_runner --output artifacts/eval/jobs/native_job_runner_report.json; \
artifacts/native/tryops_evaluation_index --root . --output artifacts/eval/evaluation_index/evaluation_index.json
@@ -1198,7 +1386,7 @@ app-down:
roadmap-status:
PYTHONPATH=$(PYTHONPATH) python scripts/roadmap_status.py MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md
-smoke: native-policy-sample native-vton-preprocess-sample native-image-metrics-sample native-perf-stats-sample native-burn-rate-build energy-demo-sample quota-sample native-quota-read-model-sample native-runtime-telemetry-sample native-observability-contract-sample native-alertmanager-contract-sample native-dependency-lock-contract-sample native-secret-rotation-contract-sample native-db-migrator-sample native-backup-restore-sample native-tls-contract-sample native-quota-ledger-smoke native-distributed-quota-smoke native-rust-test native-rust-smoke native-edge-cache-smoke native-edge-guardrail-smoke auth-sample supply-chain-sample model-supply-chain-sample finops-sample orchestration-sample vton-preprocess-sample vton-job-sample vton-native-api-sample vton-garment-similarity-sample native-trace-envelope-sample native-container-contract-sample test validate-sample deploy-package-sample signed-pr-promotion-sample registry-webhook-sample chaos-sample vton-compare-sample vton-advanced-eval-sample llm-benchmark-sample guardrail-sample native-guardrail-test native-go-test native-config-contract-test native-db-migrator-test native-backup-restore-test native-tls-contract-test native-dependency-lock-contract-test native-performance-budget-test native-benchmark-test native-vllm-probe-test native-quantized-preflight-test native-job-runner-test native-slo-gate-test native-event-dispatcher-test native-demo-acceptance-test alert-sample dashboard-sample drift-sample trace-sample endpoint-smoke-sample slo-burn-rate-sample llm-sensitivity-sample llm-continuous-batching-sample native-eval-stats-build eval-leaderboard-sample experiment-routing-sample experiment-analysis-sample llm-fallback-sample llm-load-sample governance-sample native-cpp-test native-gguf-preflight-test professor-demo-acceptance
+smoke: native-policy-sample native-admission-sample native-redaction-sample native-safety-sample native-audit-log-sample native-dedup-sample native-hll-sample native-consistent-hash-sample native-cache-sample native-cost-sample native-sampler-sample native-retry-sample native-vton-preprocess-sample native-image-metrics-sample native-perf-stats-sample native-burn-rate-build energy-demo-sample quota-sample native-quota-read-model-sample native-runtime-telemetry-sample native-observability-contract-sample native-alertmanager-contract-sample native-dependency-lock-contract-sample native-secret-rotation-contract-sample native-db-migrator-sample native-backup-restore-sample native-tls-contract-sample native-quota-ledger-smoke native-distributed-quota-smoke native-rust-test native-rust-smoke native-edge-cache-smoke native-edge-guardrail-smoke auth-sample supply-chain-sample model-supply-chain-sample finops-sample orchestration-sample vton-preprocess-sample vton-job-sample vton-native-api-sample vton-garment-similarity-sample native-trace-envelope-sample native-container-contract-sample test validate-sample deploy-package-sample signed-pr-promotion-sample registry-webhook-sample chaos-sample vton-compare-sample vton-advanced-eval-sample llm-benchmark-sample guardrail-sample native-guardrail-test native-go-test native-config-contract-test native-db-migrator-test native-backup-restore-test native-tls-contract-test native-dependency-lock-contract-test native-performance-budget-test native-benchmark-test native-vllm-probe-test native-quantized-preflight-test native-job-runner-test native-slo-gate-test native-event-dispatcher-test native-demo-acceptance-test alert-sample dashboard-sample drift-sample trace-sample endpoint-smoke-sample slo-burn-rate-sample llm-sensitivity-sample llm-continuous-batching-sample native-eval-stats-build eval-leaderboard-sample experiment-routing-sample experiment-analysis-sample llm-fallback-sample llm-load-sample governance-sample native-cpp-test native-gguf-preflight-test professor-demo-acceptance
vton-real-sample: native-vton-preprocess-build native-image-metrics-build
PYTHONPATH=$(PYTHONPATH) python scripts/create_synthetic_vton_demo.py --output-dir artifacts/demo/vton
diff --git a/README-backup-2.md b/README-backup-2.md
new file mode 100644
index 0000000..299ffb5
--- /dev/null
+++ b/README-backup-2.md
@@ -0,0 +1,508 @@
+# TryOps
+
+Enterprise open-source MLOps product for Virtual Try-On, optimized LLM serving, quota enforcement, native guardrails, governance evidence, and production operations.
+
+The repo is intentionally native-first at the production boundary:
+
+- Rust: Axum gateway, static UI serving, auth preflight, quota/rate/payload gates, trace propagation, semantic-cache admission.
+- Go: controllers, guardrail sidecar, job runner, load driver, CI/supply-chain contracts, runtime evidence tools.
+- C++: deterministic hot-path CLIs for policy, image metrics, experiment routing/stats, cache, SLO/perf, VTON preprocessing/eval, lineage and manifest checks.
+- Python: FastAPI product BFF, model adapters, deterministic fallbacks, orchestration glue, contract tests.
+- React/Vite/TypeScript: browser Console under `web/`.
+
+## Newbie Quick Start
+
+You have two good ways to run this repo. Pick **Option A** if you just want to see the product working. Pick **Option B** if you are editing the frontend with `npm run dev`.
+
+### Option A: Easiest Full App
+
+This starts the real local product stack: Rust gateway, React Console, FastAPI backend, Postgres, Valkey, MinIO, MLflow, Prometheus, Grafana, and Go guardrail.
+
+Terminal 1:
+
+```bash
+cd /home/tcuong1000/flow
+make app-up
+```
+
+Wait until the command finishes. Then open:
+
+```text
+http://127.0.0.1:18081
+```
+
+In Option A, `http://127.0.0.1:15173` is not used. That port only works in Option B after you start Vite with `npm --prefix web run dev`.
+
+Use this API key in the Console:
+
+```text
+tryops-viewer-demo-key
+```
+
+Check that backend is alive:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/health
+```
+
+Stop everything:
+
+```bash
+make app-down
+```
+
+Use this option when you want the closest local version of the enterprise product. You do **not** need `npm run dev` for Option A because the Rust gateway serves the built frontend.
+
+### Option B: Frontend Dev + Simple Backend
+
+Use this when you already ran `npm run dev` and want a backend/database for it.
+
+Terminal 1, start the backend with the simple SQLite database:
+
+```bash
+cd /home/tcuong1000/flow
+python -m pip install -e ".[dev]"
+make db-init
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 18180
+```
+
+Leave Terminal 1 running.
+
+Terminal 2, start the frontend and point it at the backend:
+
+```bash
+cd /home/tcuong1000/flow
+npm --prefix web ci
+VITE_TRYOPS_API_BASE=http://127.0.0.1:18180 npm --prefix web run dev
+```
+
+Open:
+
+```text
+http://127.0.0.1:15173
+```
+
+Use this API key in the Console:
+
+```text
+tryops-viewer-demo-key
+```
+
+If your frontend is already running from plain `npm run dev`, stop it with `Ctrl-C` and restart it with the `VITE_TRYOPS_API_BASE=... npm --prefix web run dev` command above. Otherwise the UI may open but API calls will fail.
+
+In Option B, the database is this local SQLite file:
+
+```text
+artifacts/app/tryops.db
+```
+
+Quick backend checks:
+
+```bash
+curl -fsS http://127.0.0.1:18180/api/health
+curl -fsS "http://127.0.0.1:18180/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:18180/api/dashboard?api_key=tryops-viewer-demo-key"
+```
+
+### Which Option Should I Use?
+
+Use this first:
+
+```text
+Option A: make app-up
+```
+
+Use this while changing React code:
+
+```text
+Option B: FastAPI on 18180 + Vite on 15173
+```
+
+Use this to prove the stack works automatically:
+
+```bash
+make app-smoke
+```
+
+## What Runs Where
+
+`make app-up` uses Docker Compose port forwarding. It does not use nginx by default. The browser connects to a host port, Docker forwards that port into the container, and the Rust gateway serves the Console plus `/api/*`.
+
+| Service | Default URL or port | Override variable | Notes |
+| --- | --- | --- | --- |
+| TryOps Console + Rust gateway | `http://127.0.0.1:18081` | `TRYOPS_GATEWAY_PORT` | Main app URL. Use this first. |
+| FastAPI backend direct | `http://127.0.0.1:18080` | `TRYOPS_API_PORT` | Direct API/docs access. Gateway normally proxies this. |
+| Postgres | `127.0.0.1:15432` | `TRYOPS_POSTGRES_PORT` | Database for the full Compose stack. |
+| Valkey | `127.0.0.1:16379` | `TRYOPS_VALKEY_PORT` | Hot quota/rate counter store. |
+| MinIO API | `http://127.0.0.1:19000` | `TRYOPS_MINIO_PORT` | Object/artifact storage API. |
+| MinIO Console | `http://127.0.0.1:19001` | `TRYOPS_MINIO_CONSOLE_PORT` | Browser UI for MinIO. |
+| MLflow | `http://127.0.0.1:15000` | `TRYOPS_MLFLOW_PORT` | Experiment/model tracking. |
+| Prometheus | `http://127.0.0.1:19090` | `TRYOPS_PROMETHEUS_PORT` | Metrics database. |
+| Alertmanager | `http://127.0.0.1:19093` | `TRYOPS_ALERTMANAGER_PORT` | Alert routing. |
+| Grafana | `http://127.0.0.1:13000` | `TRYOPS_GRAFANA_PORT` | Dashboards. Default login is `admin` / `admin` on a fresh local volume. |
+| Go guardrail sidecar | `127.0.0.1:18093` | `TRYOPS_GUARDRAIL_PORT` | LLM guardrail service. Usually called by gateway/API. |
+| Manual FastAPI dev | `http://127.0.0.1:18180` | `--port` in the `uvicorn` command | Only for Option B. |
+| Vite frontend dev | `http://127.0.0.1:15173` | `npm --prefix web run dev` uses this port; Vite auto-picks another port if busy. | Only for Option B. `make app-up` does not start this server. |
+
+If a default port conflicts, override only the ports you need:
+
+```bash
+TRYOPS_GATEWAY_PORT=28081 \
+TRYOPS_API_PORT=28080 \
+TRYOPS_GRAFANA_PORT=23000 \
+make app-up
+```
+
+Then open the changed gateway URL:
+
+```text
+http://127.0.0.1:28081
+```
+
+You can use the same override style for `make app-smoke`:
+
+```bash
+TRYOPS_GATEWAY_PORT=28081 TRYOPS_API_PORT=28080 make app-smoke
+```
+
+## Common Problems
+
+If the frontend opens but data does not load, restart frontend like this:
+
+```bash
+VITE_TRYOPS_API_BASE=http://127.0.0.1:18180 npm --prefix web run dev
+```
+
+If `curl http://127.0.0.1:15173/` fails after `make app-up`, that is expected. Use `http://127.0.0.1:18081` for Option A, or start Vite separately for Option B.
+
+If port `15173` is busy, Vite will print another URL. Open the URL Vite prints.
+
+If port `18180` is busy, run FastAPI on another port and match the frontend env var:
+
+```bash
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 18182
+VITE_TRYOPS_API_BASE=http://127.0.0.1:18182 npm --prefix web run dev
+```
+
+If Docker services are confusing or stale, reset the full stack:
+
+```bash
+make app-down
+docker compose down --volumes --remove-orphans
+make app-up
+```
+
+## Requirements
+
+Install these first:
+
+- Docker Engine with Docker Compose v2
+- Python 3.11 or 3.12
+- Node.js 20+ and npm
+- Go 1.22+; `make native-go-toolchain` downloads the pinned `go1.25.5` wrapper used by this repo
+- Rust/Cargo through rustup
+- `g++` with C++17 support
+- `make`, `curl`, and `git`
+
+Optional for real model paths:
+
+- CUDA GPU plus the Python `.[ml]` extras for real diffusion VTON and real LLM runs
+- `syft`, `trivy`, and `cosign`, or Docker access so the live supply-chain targets can run their pinned container images
+- `vllm`, KServe, Vault, k6, Locust, and external observability services for production-profile extensions
+
+## First Setup
+
+From the repo root:
+
+```bash
+python -m pip install -e ".[dev]"
+npm --prefix web ci
+make native-go-toolchain
+make native-tooling
+```
+
+Optional local secrets:
+
+```bash
+cp .env.example .env
+```
+
+`make app-up` already supplies safe local defaults, so `.env` is only needed when you want to override credentials, ports, TLS material, or provider keys.
+
+## Run The Product Stack
+
+Start the local product stack through Docker Compose:
+
+```bash
+make app-up
+```
+
+Open these URLs:
+
+- Console through the Rust gateway: `http://127.0.0.1:18081`
+- FastAPI docs direct: `http://127.0.0.1:18080/api/docs`
+- Grafana: `http://127.0.0.1:13000` with default login `admin` / `admin`
+- Prometheus: `http://127.0.0.1:19090`
+- MLflow: `http://127.0.0.1:15000`
+- MinIO API: `http://127.0.0.1:19000`
+- MinIO Console: `http://127.0.0.1:19001`
+
+Demo API keys for the Console session field:
+
+```text
+tryops-viewer-demo-key
+tryops-operator-demo-key
+tryops-admin-demo-key
+tryops-risk-demo-key
+```
+
+Stop the stack:
+
+```bash
+make app-down
+```
+
+Remove local Compose volumes too:
+
+```bash
+docker compose down --volumes --remove-orphans
+```
+
+## Smoke Test The Stack
+
+Run a disposable full-stack smoke test. It builds the stack, verifies gateway/API/product evidence paths, runs native job execution, writes evidence under `artifacts/eval`, and tears down its temporary Compose project.
+
+```bash
+make app-smoke
+```
+
+Manual checks against a running `make app-up` stack:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/health
+curl -fsS "http://127.0.0.1:18081/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:18081/api/evaluations/summary?api_key=tryops-viewer-demo-key"
+curl -fsS http://127.0.0.1:18081/metrics | head
+```
+
+Run one LLM request through the product API:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/llm/generate \
+ -H "Content-Type: application/json" \
+ -d '{
+ "api_key": "tryops-viewer-demo-key",
+ "request_id": "readme-llm-001",
+ "prompt": "Explain why TryOps uses a native gateway.",
+ "model_alias": "champion",
+ "max_tokens": 128,
+ "structured": true,
+ "routing_mode": "direct",
+ "user_id": "demo-user",
+ "quota_plan": "free"
+ }'
+```
+
+## Run Lightweight Dev Mode
+
+Use this when you already started the frontend with `npm run dev` and want the backend/database next.
+
+Terminal 1, initialize the zero-config local SQLite database and start FastAPI:
+
+```bash
+make db-init
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 18180
+```
+
+The SQLite file is created at `artifacts/app/tryops.db`.
+
+Terminal 2, start the React Console with the backend URL:
+
+```bash
+VITE_TRYOPS_API_BASE=http://127.0.0.1:18180 npm --prefix web run dev
+```
+
+Open `http://127.0.0.1:15173`.
+
+If you already ran `npm --prefix web run dev` without `VITE_TRYOPS_API_BASE`, stop it with `Ctrl-C` and restart it with the command above. The Console needs that env var when FastAPI is running separately on port `18180`.
+
+Quick backend checks:
+
+```bash
+curl -fsS http://127.0.0.1:18180/api/health
+curl -fsS "http://127.0.0.1:18180/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:18180/api/dashboard?api_key=tryops-viewer-demo-key"
+```
+
+Use the full Postgres-backed local stack instead of SQLite:
+
+```bash
+make app-up
+```
+
+Then open `http://127.0.0.1:18081`. In this mode the built Console is served by the Rust gateway and the backing services are managed by Docker Compose, so you do not need `npm run dev` unless you are actively editing frontend code.
+
+Build the production UI bundle:
+
+```bash
+make web-typecheck web-build
+```
+
+Serve the built UI through the native Rust gateway smoke profile:
+
+```bash
+make native-static-smoke
+```
+
+## Tests And Verification
+
+Core contract tests:
+
+```bash
+make test
+make native-go-test
+make native-rust-test
+make native-cpp-test
+npm --prefix web run typecheck
+```
+
+CI-grade local evidence:
+
+```bash
+make native-ci-contract-live
+make native-container-contract-sample
+make native-dependency-lock-contract-sample
+make evaluation-index-sample
+```
+
+Full local CI mirror:
+
+```bash
+make ci
+```
+
+`make ci` is intentionally heavy. It runs Python, Node, Go, Rust, C++, Compose validation, supply-chain evidence, native contracts, and evaluation-index generation.
+
+## Useful Product Samples
+
+LLM:
+
+```bash
+make llm-benchmark-sample
+make llm-continuous-batching-sample
+make llm-fallback-sample
+make llm-load-sample
+```
+
+VTON:
+
+```bash
+make vton-baseline-sample
+make vton-preprocess-sample
+make vton-job-sample
+make vton-advanced-eval-sample
+```
+
+Quota, FinOps, and guardrails:
+
+```bash
+make quota-sample
+make finops-sample
+make guardrail-sample
+make native-edge-guardrail-smoke
+```
+
+Experiments:
+
+```bash
+make experiment-routing-sample
+make experiment-analysis-sample
+```
+
+Promotion, lineage, deployment, and recovery:
+
+```bash
+make validate-sample
+make pipeline-sample
+make deploy-package-sample
+make signed-pr-promotion-sample
+make registry-webhook-sample
+make chaos-sample
+```
+
+Observability and governance:
+
+```bash
+make dashboard-sample
+make alert-sample
+make slo-burn-rate-sample
+make trace-sample
+make governance-sample
+```
+
+## Real Model Runs
+
+Most commands work offline through deterministic fallbacks. Use these only when the machine has model dependencies and GPU access:
+
+```bash
+python -m pip install -e ".[dev,ml]"
+make vton-real-sample
+make llm-real-sample
+make llm-pareto-sample
+make energy-sample
+```
+
+Probe an external OpenAI-compatible vLLM server:
+
+```bash
+VLLM_BASE_URL=http://127.0.0.1:8000/v1 \
+VLLM_MODEL=HuggingFaceTB/SmolLM2-135M-Instruct \
+make llm-vllm-probe-sample
+```
+
+## Repository Map
+
+```text
+web/ React/Vite/TypeScript Console
+src/tryops/ FastAPI BFF, adapters, contracts, fallbacks
+native/rust/tryops-gateway Rust Axum gateway and static-serving profile
+native/go/ Go controllers, sidecars, contracts, load tools
+native/cpp/ C++ policy/eval/cache/VTON/LLM CLIs
+infra/ Prometheus, Grafana, OTel, Alertmanager, Kubernetes
+configs/ API keys, image contracts, secret and service config
+contracts/ JSON schemas
+samples/ Candidate, eval, and demo payloads
+scripts/ Local automation and evidence generation
+tests/ Python contract tests
+artifacts/ Generated local evidence; ignored by Git
+reports/generated/ Generated promotion/model/data cards; ignored by Git
+```
+
+## Generated Files
+
+The repo intentionally ignores generated outputs such as:
+
+```text
+artifacts/
+reports/generated/
+web/dist/
+web/node_modules/
+native/rust/tryops-gateway/target/
+.pytest_cache/
+.ruff_cache/
+__pycache__/
+```
+
+If `git status --ignored` shows those paths, that is expected. They are local build/test/evidence outputs and should not be committed.
+
+## Main Docs
+
+- Roadmap: `MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md`
+- Production app plan: `docs/production_app_plan.md`
+- API contract: `docs/api_contract.md`
+- Enterprise quota: `docs/enterprise_quota.md`
+- Serving controls: `docs/serving_controls.md`
+- Release engineering: `docs/release_engineering.md`
+- Supply chain: `docs/supply_chain.md`
+- Observability: `docs/observability_contract.md`
+- Demo outline: `docs/presentation_outline.md`
diff --git a/README-backup.md b/README-backup.md
new file mode 100644
index 0000000..c5cf9e1
--- /dev/null
+++ b/README-backup.md
@@ -0,0 +1,476 @@
+# TryOps
+
+Enterprise open-source MLOps product for Virtual Try-On, optimized LLM serving, quota enforcement, native guardrails, governance evidence, and production operations.
+
+The repo is intentionally native-first at the production boundary:
+
+- Rust: Axum gateway, static UI serving, auth preflight, quota/rate/payload gates, trace propagation, semantic-cache admission.
+- Go: controllers, guardrail sidecar, job runner, load driver, CI/supply-chain contracts, runtime evidence tools.
+- C++: deterministic hot-path CLIs for policy, image metrics, experiment routing/stats, cache, SLO/perf, VTON preprocessing/eval, lineage and manifest checks.
+- Python: FastAPI product BFF, model adapters, deterministic fallbacks, orchestration glue, contract tests.
+- React/Vite/TypeScript: browser Console under `web/`.
+
+## Newbie Quick Start
+
+You have two good ways to run this repo. Pick **Option A** if you just want to see the product working. Pick **Option B** if you are editing the frontend with `npm run dev`.
+
+### Option A: Easiest Full App
+
+This starts the real local product stack: Rust gateway, React Console, FastAPI backend, Postgres, Valkey, MinIO, MLflow, Prometheus, Grafana, and Go guardrail.
+
+Terminal 1:
+
+```bash
+cd /home/tcuong1000/flow
+make app-up
+```
+
+Wait until the command finishes. Then open:
+
+```text
+http://127.0.0.1:18081
+```
+
+Use this API key in the Console:
+
+```text
+tryops-viewer-demo-key
+```
+
+Check that backend is alive:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/health
+```
+
+Stop everything:
+
+```bash
+make app-down
+```
+
+Use this option when you want the closest local version of the enterprise product. You do **not** need `npm run dev` for Option A because the Rust gateway serves the built frontend.
+
+### Option B: Frontend Dev + Simple Backend
+
+Use this when you already ran `npm run dev` and want a backend/database for it.
+
+Terminal 1, start the backend with the simple SQLite database:
+
+```bash
+cd /home/tcuong1000/flow
+python -m pip install -e ".[dev]"
+make db-init
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 8080
+```
+
+Leave Terminal 1 running.
+
+Terminal 2, start the frontend and point it at the backend:
+
+```bash
+cd /home/tcuong1000/flow
+npm --prefix web ci
+VITE_TRYOPS_API_BASE=http://127.0.0.1:8080 npm --prefix web run dev
+```
+
+Open:
+
+```text
+http://127.0.0.1:5173
+```
+
+Use this API key in the Console:
+
+```text
+tryops-viewer-demo-key
+```
+
+If your frontend is already running from plain `npm run dev`, stop it with `Ctrl-C` and restart it with the `VITE_TRYOPS_API_BASE=... npm --prefix web run dev` command above. Otherwise the UI may open but API calls will fail.
+
+In Option B, the database is this local SQLite file:
+
+```text
+artifacts/app/tryops.db
+```
+
+Quick backend checks:
+
+```bash
+curl -fsS http://127.0.0.1:8080/api/health
+curl -fsS "http://127.0.0.1:8080/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:8080/api/dashboard?api_key=tryops-viewer-demo-key"
+```
+
+### Which Option Should I Use?
+
+Use this first:
+
+```text
+Option A: make app-up
+```
+
+Use this while changing React code:
+
+```text
+Option B: FastAPI on 8080 + Vite on 5173
+```
+
+Use this to prove the stack works automatically:
+
+```bash
+make app-smoke
+```
+
+## What Runs Where
+
+```text
+http://127.0.0.1:18081 Full app through Rust gateway, from make app-up
+http://127.0.0.1:18080 FastAPI direct, from make app-up
+http://127.0.0.1:8080 FastAPI direct, from manual uvicorn dev command
+http://127.0.0.1:5173 Vite frontend dev server
+http://127.0.0.1:13000 Grafana, from make app-up
+http://127.0.0.1:19090 Prometheus, from make app-up
+http://127.0.0.1:15000 MLflow, from make app-up
+http://127.0.0.1:19001 MinIO Console, from make app-up
+```
+
+## Common Problems
+
+If the frontend opens but data does not load, restart frontend like this:
+
+```bash
+VITE_TRYOPS_API_BASE=http://127.0.0.1:8080 npm --prefix web run dev
+```
+
+If port `5173` is busy, Vite will print another URL. Open the URL Vite prints.
+
+If port `8080` is busy, run FastAPI on another port and match the frontend env var:
+
+```bash
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 8082
+VITE_TRYOPS_API_BASE=http://127.0.0.1:8082 npm --prefix web run dev
+```
+
+If Docker services are confusing or stale, reset the full stack:
+
+```bash
+make app-down
+docker compose down --volumes --remove-orphans
+make app-up
+```
+
+## Requirements
+
+Install these first:
+
+- Docker Engine with Docker Compose v2
+- Python 3.11 or 3.12
+- Node.js 20+ and npm
+- Go 1.22+; `make native-go-toolchain` downloads the pinned `go1.25.5` wrapper used by this repo
+- Rust/Cargo through rustup
+- `g++` with C++17 support
+- `make`, `curl`, and `git`
+
+Optional for real model paths:
+
+- CUDA GPU plus the Python `.[ml]` extras for real diffusion VTON and real LLM runs
+- `syft`, `trivy`, and `cosign`, or Docker access so the live supply-chain targets can run their pinned container images
+- `vllm`, KServe, Vault, k6, Locust, and external observability services for production-profile extensions
+
+## First Setup
+
+From the repo root:
+
+```bash
+python -m pip install -e ".[dev]"
+npm --prefix web ci
+make native-go-toolchain
+make native-tooling
+```
+
+Optional local secrets:
+
+```bash
+cp .env.example .env
+```
+
+`make app-up` already supplies safe local defaults, so `.env` is only needed when you want to override credentials, ports, TLS material, or provider keys.
+
+## Run The Product Stack
+
+Start the local product stack through Docker Compose:
+
+```bash
+make app-up
+```
+
+Open these URLs:
+
+- Console through the Rust gateway: `http://127.0.0.1:18081`
+- FastAPI docs direct: `http://127.0.0.1:18080/api/docs`
+- Grafana: `http://127.0.0.1:13000`
+- Prometheus: `http://127.0.0.1:19090`
+- MLflow: `http://127.0.0.1:15000`
+- MinIO API: `http://127.0.0.1:19000`
+- MinIO Console: `http://127.0.0.1:19001`
+
+Demo API keys for the Console session field:
+
+```text
+tryops-viewer-demo-key
+tryops-operator-demo-key
+tryops-admin-demo-key
+tryops-risk-demo-key
+```
+
+Stop the stack:
+
+```bash
+make app-down
+```
+
+Remove local Compose volumes too:
+
+```bash
+docker compose down --volumes --remove-orphans
+```
+
+## Smoke Test The Stack
+
+Run a disposable full-stack smoke test. It builds the stack, verifies gateway/API/product evidence paths, runs native job execution, writes evidence under `artifacts/eval`, and tears down its temporary Compose project.
+
+```bash
+make app-smoke
+```
+
+Manual checks against a running `make app-up` stack:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/health
+curl -fsS "http://127.0.0.1:18081/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:18081/api/evaluations/summary?api_key=tryops-viewer-demo-key"
+curl -fsS http://127.0.0.1:18081/metrics | head
+```
+
+Run one LLM request through the product API:
+
+```bash
+curl -fsS http://127.0.0.1:18081/api/llm/generate \
+ -H "Content-Type: application/json" \
+ -d '{
+ "api_key": "tryops-viewer-demo-key",
+ "request_id": "readme-llm-001",
+ "prompt": "Explain why TryOps uses a native gateway.",
+ "model_alias": "champion",
+ "max_tokens": 128,
+ "structured": true,
+ "routing_mode": "direct",
+ "user_id": "demo-user",
+ "quota_plan": "free"
+ }'
+```
+
+## Run Lightweight Dev Mode
+
+Use this when you already started the frontend with `npm run dev` and want the backend/database next.
+
+Terminal 1, initialize the zero-config local SQLite database and start FastAPI:
+
+```bash
+make db-init
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 8080
+```
+
+The SQLite file is created at `artifacts/app/tryops.db`.
+
+Terminal 2, start the React Console with the backend URL:
+
+```bash
+VITE_TRYOPS_API_BASE=http://127.0.0.1:8080 npm --prefix web run dev
+```
+
+Open `http://127.0.0.1:5173`.
+
+If you already ran `npm --prefix web run dev` without `VITE_TRYOPS_API_BASE`, stop it with `Ctrl-C` and restart it with the command above. The Console needs that env var when FastAPI is running separately on port `8080`.
+
+Quick backend checks:
+
+```bash
+curl -fsS http://127.0.0.1:8080/api/health
+curl -fsS "http://127.0.0.1:8080/api/auth/session?api_key=tryops-viewer-demo-key"
+curl -fsS "http://127.0.0.1:8080/api/dashboard?api_key=tryops-viewer-demo-key"
+```
+
+Use the full Postgres-backed local stack instead of SQLite:
+
+```bash
+make app-up
+```
+
+Then open `http://127.0.0.1:18081`. In this mode the built Console is served by the Rust gateway and the backing services are managed by Docker Compose, so you do not need `npm run dev` unless you are actively editing frontend code.
+
+Build the production UI bundle:
+
+```bash
+make web-typecheck web-build
+```
+
+Serve the built UI through the native Rust gateway smoke profile:
+
+```bash
+make native-static-smoke
+```
+
+## Tests And Verification
+
+Core contract tests:
+
+```bash
+make test
+make native-go-test
+make native-rust-test
+make native-cpp-test
+npm --prefix web run typecheck
+```
+
+CI-grade local evidence:
+
+```bash
+make native-ci-contract-live
+make native-container-contract-sample
+make native-dependency-lock-contract-sample
+make evaluation-index-sample
+```
+
+Full local CI mirror:
+
+```bash
+make ci
+```
+
+`make ci` is intentionally heavy. It runs Python, Node, Go, Rust, C++, Compose validation, supply-chain evidence, native contracts, and evaluation-index generation.
+
+## Useful Product Samples
+
+LLM:
+
+```bash
+make llm-benchmark-sample
+make llm-continuous-batching-sample
+make llm-fallback-sample
+make llm-load-sample
+```
+
+VTON:
+
+```bash
+make vton-baseline-sample
+make vton-preprocess-sample
+make vton-job-sample
+make vton-advanced-eval-sample
+```
+
+Quota, FinOps, and guardrails:
+
+```bash
+make quota-sample
+make finops-sample
+make guardrail-sample
+make native-edge-guardrail-smoke
+```
+
+Experiments:
+
+```bash
+make experiment-routing-sample
+make experiment-analysis-sample
+```
+
+Promotion, lineage, deployment, and recovery:
+
+```bash
+make validate-sample
+make pipeline-sample
+make deploy-package-sample
+make signed-pr-promotion-sample
+make registry-webhook-sample
+make chaos-sample
+```
+
+Observability and governance:
+
+```bash
+make dashboard-sample
+make alert-sample
+make slo-burn-rate-sample
+make trace-sample
+make governance-sample
+```
+
+## Real Model Runs
+
+Most commands work offline through deterministic fallbacks. Use these only when the machine has model dependencies and GPU access:
+
+```bash
+python -m pip install -e ".[dev,ml]"
+make vton-real-sample
+make llm-real-sample
+make llm-pareto-sample
+make energy-sample
+```
+
+Probe an external OpenAI-compatible vLLM server:
+
+```bash
+VLLM_BASE_URL=http://127.0.0.1:8000/v1 \
+VLLM_MODEL=HuggingFaceTB/SmolLM2-135M-Instruct \
+make llm-vllm-probe-sample
+```
+
+## Repository Map
+
+```text
+web/ React/Vite/TypeScript Console
+src/tryops/ FastAPI BFF, adapters, contracts, fallbacks
+native/rust/tryops-gateway Rust Axum gateway and static-serving profile
+native/go/ Go controllers, sidecars, contracts, load tools
+native/cpp/ C++ policy/eval/cache/VTON/LLM CLIs
+infra/ Prometheus, Grafana, OTel, Alertmanager, Kubernetes
+configs/ API keys, image contracts, secret and service config
+contracts/ JSON schemas
+samples/ Candidate, eval, and demo payloads
+scripts/ Local automation and evidence generation
+tests/ Python contract tests
+artifacts/ Generated local evidence; ignored by Git
+reports/generated/ Generated promotion/model/data cards; ignored by Git
+```
+
+## Generated Files
+
+The repo intentionally ignores generated outputs such as:
+
+```text
+artifacts/
+reports/generated/
+web/dist/
+web/node_modules/
+native/rust/tryops-gateway/target/
+.pytest_cache/
+.ruff_cache/
+__pycache__/
+```
+
+If `git status --ignored` shows those paths, that is expected. They are local build/test/evidence outputs and should not be committed.
+
+## Main Docs
+
+- Roadmap: `MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md`
+- Production app plan: `docs/production_app_plan.md`
+- API contract: `docs/api_contract.md`
+- Enterprise quota: `docs/enterprise_quota.md`
+- Serving controls: `docs/serving_controls.md`
+- Release engineering: `docs/release_engineering.md`
+- Supply chain: `docs/supply_chain.md`
+- Observability: `docs/observability_contract.md`
+- Demo outline: `docs/presentation_outline.md`
diff --git a/README.md b/README.md
index 797a921..01c4152 100644
--- a/README.md
+++ b/README.md
@@ -1,419 +1,222 @@
# TryOps
-Enterprise open-source MLOps platform for Virtual Try-On and optimized LLM serving.
-
-The project thesis is simple: MLOps is the product. VTON and LLM optimization are the proof workloads used to show reproducibility, governance, model promotion, monitoring, rollback, and continuous improvement.
-
-## What Exists Now
-
-This is the day-one execution scaffold:
-
-- Open-source enterprise architecture and roadmap: `MLOPS_VTON_LLM_ENTERPRISE_ROADMAP.md`
-- Runnable Python package under `src/tryops`
-- Promotion policy gate with sample passing and failing candidates
-- Dataset manifest validator
-- VTON and LLM metric summary helpers
-- Deterministic local LLM baseline with structured output, safety flags, quality scoring, latency, memory, and cost metrics
-- LLM prefill/decode phase timing in benchmark records, structured logs, and Prometheus metrics
-- Real diffusion Virtual Try-On: SD1.5 inpainting on CUDA refines a garment composited onto the person (real pixels), behind the unchanged `tryops.vton_baseline.v1` contract with a deterministic fallback (`make vton-real-sample`)
-- Real GPU LLM path (R1): `SmolLM2-135M-Instruct` via Transformers on CUDA behind the same `tryops.llm_generation.v1` contract, with a per-record deterministic fallback
-- Real LLM quantization Pareto evidence and generated optimization report for fp16-style, bitsandbytes 8-bit, and bitsandbytes 4-bit variants
-- Native C++ benchmark statistics + SLO engine (`tryops_perf_stats`): p50/p95/p99 latency, throughput, and pass/fail SLO gating in compiled code rather than Python
-- Native C++ multi-window burn-rate engine (`tryops_burn_rate`): LLM/VTON/control-plane error budgets, page/ticket alerts, and Prometheus burn-rate rules
-- Native-backed chaos drill and auto rollback: C++ fault evaluator for GPU OOM, slow decode, corrupted weights, and poisoned candidates, feeding the C++ burn-rate engine and rollback records
-- Green-MLOps energy/carbon (Theme M): real NVML GPU power sampling + native C++ `tryops_energy_stats` (Wh, CO2e, Software Carbon Intensity, energy-delay product) + a carbon-aware promotion gate, with a deterministic fallback for offline runs
-- `/v1` API contract with readiness, structured errors, request IDs, safe aliases, canary routing, and metrics
-- Endpoint smoke report for `/v1/ready`, `/v1/llm/generate`, `/v1/vton/infer`, and `/v1/metrics`
-- Usage-based quota checks for LLM and VTON requests with hashed user telemetry
-- FinOps unit economics, tenant budget showback, budget alerts, semantic-cache hit/savings evidence, and cost/capacity dashboard panels with energy/CO2e plus cost-vs-energy views
-- Runtime LLM guardrails: Rust gateway edge enforcement, PII redaction, native Go sidecar/CLI prompt-output classifier, structured-output gate, OWASP LLM 2025 report, and promotion-gate input
-- Optimized LLM fallback routing from unavailable optimized aliases to the baseline route
-- Timeout handling and async VTON job mode with queue-depth metrics
-- Least-privilege API-key simulation for promotion and lineage admin actions
-- Structured JSONL API logs and latency/quality alert threshold reports
-- Provisioned Grafana service, model-quality, and cost/capacity dashboards
-- Local drift reports for VTON image metadata and LLM prompt/topic distributions
-- OpenTelemetry-compatible trace/span IDs, `traceparent` propagation, sanitized span JSONL, and trace metrics
-- NIST AI RMF, OWASP LLM 2025, and responsible-AI residual-risk mapping evidence
-- Dependency lockfile, local SPDX SBOM fallback, and model/dataset license inventories
-- Native C++ model artifact scanner enforcing SafeTensors-only promotion and rejecting pickle-family `.bin` weights
-- Kubeflow-target orchestration skeleton plus Argo CD / Argo Rollouts GitOps manifests for deployment packaging
-- Model lineage record builder plus OpenLineage-standard RunEvent emission
-- FastAPI product backend for VTON, LLM, promotion, history, feedback, dashboard, and model-registry endpoints
-- Local promotion pipeline that writes model card, data card, internal lineage, OpenLineage, validation, and decision artifacts
-- Native production boundary under `native/`: modular Rust gateway artifact/proxy front door with Go-sidecar LLM guardrails at the edge, verified Go controller/guardrail services, and seventeen compiled C++ engines
-- Native Go guardrail sidecar integrated into both the Rust gateway edge path and `/v1/llm/generate`, with CLI and Python fallbacks for offline runs
-- Native Go signed-PR promotion trigger that verifies GitHub-style HMAC webhook delivery before accepting merged promotion PR evidence
-- C++ policy CLI integrated into the Python promotion path as native decision evidence
-- C++ model artifact scanner integrated into Python, C++, and Rego promotion gates
-- C++ model provenance verifier integrated into local DSSE/SLSA model signing evidence and promotion gates
-- C++ OpenLineage validator integrated into promotion and deployment release evidence
-- C++ GitOps manifest validator integrated into Argo CD / Argo Rollouts deployment packages
-- Native Go registry-webhook deployment trigger that verifies signed MLflow-style alias events before issuing GitOps sync and canary rollout actions
-- C++ online experiment router integrated with the routing layer for guarded A/B allocation, holdback, and UCB-style bandit traffic shifts
-- C++ online experiment statistics engine for holdback uplift confidence intervals and sequential early-stop decisions
-- C++ continuous-batching scheduler benchmark comparing static request-level batching with iteration-level admission
-- C++ chaos scenario evaluator integrated into SLO burn-rate and rollback drills
-- C++ semantic-cache lookup CLI integrated into `/v1/llm/generate` and `make finops-sample`
-- C++ image metrics CLI integrated into VTON comparison artifacts
-- C++ VTON preprocessing CLI integrated into optional mask and pose artifacts
-- C++ VTON advanced evaluation CLI integrated into identity, masked-fidelity, pose, fairness, and Bradley-Terry evidence
-- Modular Rust gateway artifact vs Python FastAPI benchmark (`make gateway-benchmark`), `/api/*` reverse-proxy smoke, and native Prometheus gateway metrics for non-Python serving-boundary evidence
-- Garment-preservation similarity proxy with OpenCLIP-ready reporting
-- Docker Compose product stack for Rust gateway, FastAPI, MLflow, MinIO, PostgreSQL, Prometheus, Grafana, and Go guardrail
-- OPA/Rego policy sketch for model promotion
-- Tests that run with the Python standard library
-
-## Chosen Open-Source Stack
-
-- Pipelines: Kubeflow Pipelines
-- Registry and tracking: MLflow
-- Data and artifact versioning: DVC plus MinIO
-- Serving: FastAPI locally, KServe for the enterprise deployment profile
-- Production boundary: Rust gateway and Go platform controller
-- LLM serving: vLLM
-- Semantic cache: native C++ hot path locally, FAISS/Qdrant-ready vector lookup for production
-- Monitoring: Prometheus, Grafana, OpenTelemetry, Evidently
-- Governance: OPA/Rego, model cards, data cards, risk register
-- Supply chain: SafeTensors, native C++ model scanning/provenance verification, Trivy, Syft, Cosign, Sigstore model signing
-
-## Quickstart
-
-Run the standard-library test suite:
+TryOps is an MLOps product stack for virtual try-on, optimized LLM serving, quota enforcement, guardrails, governance evidence, and production operations.
-```bash
-make test
-```
-
-Run the native online experimentation sample:
-
-```bash
-make experiment-routing-sample
-make experiment-analysis-sample
-```
-
-Validate a passing sample candidate:
-
-```bash
-make validate-sample
-```
-
-Validate a failing sample candidate:
-
-```bash
-python scripts/validate_candidate.py samples/candidates/vton_candidate_bad.json --stage champion
-```
+The repo is native-first at the product boundary: a Rust gateway protects the edge, a Python FastAPI backend coordinates product workflows, Go services handle platform/control-plane concerns, and C++ CLIs cover deterministic hot paths.
-Run the first local promotion pipeline and generate evidence artifacts:
+## Quick Start
-```bash
-make pipeline-sample
-```
-
-Run the synthetic VTON baseline:
+Start the local product stack:
```bash
-make vton-baseline-sample
-```
-
-Run optional VTON mask and pose preprocessing:
-
-```bash
-make vton-preprocess-sample
-```
-
-Submit and poll a local async VTON job:
-
-```bash
-make vton-job-sample
-```
-
-Run garment-preservation similarity:
-
-```bash
-make vton-garment-similarity-sample
-```
-
-Run advanced VTON evaluation and fairness evidence:
-
-```bash
-make vton-advanced-eval-sample
-```
-
-Run the local LLM baseline benchmark:
-
-```bash
-make llm-benchmark-sample
-```
-
-Run the native continuous-batching scheduler benchmark:
-
-```bash
-make llm-continuous-batching-sample
-```
-
-Run the real GPU LLM benchmark (R1; needs `pip install .[ml]`, a CUDA GPU, and HuggingFace access; falls back to the deterministic baseline per record otherwise):
-
-```bash
-make llm-real-sample
-```
-
-Compute benchmark percentiles and an SLO verdict with the native C++ engine:
-
-```bash
-make native-perf-stats-sample
-```
-
-Evaluate SLO error-budget burn rates with the native C++ engine:
-
-```bash
-make slo-burn-rate-sample
+make app-up
```
-Measure GPU energy/carbon and run the carbon-aware gate (smoke-safe; real NVML when a GPU is present, deterministic fallback otherwise):
+Open the Console:
-```bash
-make energy-demo-sample
+```text
+http://127.0.0.1:18081
```
-Run the real per-variant GPU energy sweep (Theme M; Wh-per-1k-tokens + Software Carbon Intensity per fp16/8-bit/4-bit variant; needs a CUDA GPU + bitsandbytes):
+Use a demo API key:
-```bash
-make energy-sample
+```text
+tryops-viewer-demo-key
```
-Run the real GPU quantization Pareto sweep (R2; fp16 vs 8-bit vs 4-bit, each SLO-gated by the native C++ engine; needs `pip install .[ml]` + bitsandbytes + a CUDA GPU, falls back to the deterministic baseline otherwise):
+Check the stack:
```bash
-make llm-pareto-sample
+curl -fsS http://127.0.0.1:18081/api/health
+make app-smoke
```
-Generate the LLM quality-latency-memory optimization report from an existing Pareto artifact:
+Stop it:
```bash
-make llm-optimization-report-sample
+make app-down
```
-Exercise the signed registry-webhook deployment trigger:
+For frontend development:
```bash
-make registry-webhook-sample
+python -m pip install -e ".[dev]"
+make db-init
+PYTHONPATH=src python -m uvicorn tryops.api:create_app --factory --host 0.0.0.0 --port 18180
```
-Exercise the signed promotion-PR controller trigger:
+In another terminal:
```bash
-make signed-pr-promotion-sample
+npm --prefix web ci
+VITE_TRYOPS_API_BASE=http://127.0.0.1:18180 npm --prefix web run dev
```
-Run LLM prompt/output length sensitivity:
+Open `http://127.0.0.1:15173`.
-```bash
-make llm-sensitivity-sample
-```
+## Architecture
-Simulate usage-based quota accounting through the native Rust gateway:
+```mermaid
+flowchart LR
+ user["Browser Console
React + Vite"] --> gateway["Rust Gateway
Axum edge"]
+ gateway --> api["FastAPI BFF
Python product API"]
+ gateway --> guardrail["Go Guardrail
LLM safety"]
+ gateway --> quota[(Postgres
quota ledger)]
+ gateway --> valkey[(Valkey
hot counters)]
-```bash
-make quota-sample
-```
+ api --> workflows["Product workflows
LLM, VTON, eval, governance"]
+ api --> mlflow["MLflow
tracking"]
+ api --> minio[(MinIO
artifacts)]
+ api --> dvc["DVC
data versions"]
+ api --> native["Native tools
Go, C++, Rust"]
-Generate FinOps unit economics, budget showback, and native semantic-cache evidence:
-
-```bash
-make finops-sample
+ gateway --> otel["OpenTelemetry
logs + traces"]
+ gateway --> prometheus["Prometheus
metrics"]
+ prometheus --> alertmanager["Alertmanager"]
+ prometheus --> grafana["Grafana"]
```
-Evaluate least-privilege admin API keys:
-
-```bash
-make auth-sample
-```
-
-Simulate optimized LLM fallback to baseline:
-
-```bash
-make llm-fallback-sample
-```
+Main responsibilities:
-Regenerate the local VTON and LLM benchmark artifacts:
+- `web/`: React Console for operators, admins, risk, and demo users.
+- `native/rust/tryops-gateway`: edge gateway, static UI serving, auth preflight, quota, rate limits, payload limits, proxying, metrics, tracing, and semantic-cache admission.
+- `src/tryops/`: FastAPI BFF, product API, model adapters, deterministic fallbacks, governance, evaluation, orchestration, and evidence helpers.
+- `native/go/`: guardrail service, controllers, job runners, load tools, quota read models, CI/config/supply-chain contracts.
+- `native/cpp/`: deterministic policy, metrics, image, VTON, LLM, cache, SLO, and evaluation CLIs.
+- `infra/`: local observability, Postgres migrations, Kubernetes examples, backup and alerting assets.
-```bash
-make benchmark-sample
-```
+## Tech Stack
-Create deployment release artifacts:
+- Frontend: React, Vite, TypeScript, lucide-react.
+- API/BFF: Python 3.11+, FastAPI, Pydantic, Uvicorn.
+- ML/MLOps: MLflow, DVC, Evidently, optional PyTorch/Transformers/Diffusers/vLLM.
+- Edge/runtime: Rust, Axum, Tokio.
+- Platform tools: Go.
+- Native hot paths: C++17.
+- Data/services: Postgres, Valkey, MinIO.
+- Observability: OpenTelemetry, Prometheus, Alertmanager, Grafana.
+- Local runtime: Docker Compose, Makefile targets, JSON contracts.
-```bash
-make deploy-package-sample
-```
+## Data Flow
-Run the SRE chaos drill and auto rollback evidence:
+```mermaid
+sequenceDiagram
+ participant User
+ participant Console as React Console
+ participant Gateway as Rust Gateway
+ participant Guardrail as Go Guardrail
+ participant API as FastAPI BFF
+ participant Tools as Models + Native Tools
+ participant Evidence as Artifacts + Reports
+ participant Obs as Observability
-```bash
-make chaos-sample
+ User->>Console: Open app
+ Console->>Gateway: /api/* with API key
+ Gateway->>Gateway: Auth, limits, quota, tracing
+ Gateway->>Guardrail: Safety check when needed
+ Guardrail-->>Gateway: Allow or block
+ Gateway->>API: Proxy accepted request as /v1/*
+ API->>Tools: Run LLM, VTON, eval, governance workflow
+ Tools-->>API: Result or deterministic fallback
+ API->>Evidence: Write local evidence
+ Gateway->>Obs: Emit logs, traces, metrics
+ API-->>Gateway: Product response
+ Gateway-->>Console: Response
+ Console-->>User: Dashboard or workflow result
```
-Compile and run the native C++ policy bridge:
+Summary:
-```bash
-make native-policy-sample
-```
+1. Console sends `/api/*` requests through the gateway.
+2. Gateway enforces auth, limits, quota, tracing, and guardrails.
+3. FastAPI runs product workflows and calls model/native paths.
+4. Evidence lands in `artifacts/` and `reports/generated/`.
+5. Observability flows to OpenTelemetry, Prometheus, and Grafana.
-Compile and run the native C++ image metrics bridge:
+## Project Flow
-```bash
-make native-image-metrics-sample
-```
+Typical development loop:
-Compile and run the native C++ VTON preprocessing bridge:
+```mermaid
+flowchart TD
+ edit["Edit code/config
web, src/tryops, native, configs, contracts"]
+ tests["Run focused tests
Python, web, Rust, Go, C++"]
+ samples["Run product samples
LLM, VTON, quota, guardrails"]
+ evidence["Generate evidence
artifacts and reports"]
+ smoke["Smoke full stack
make app-smoke"]
-```bash
-make native-vton-preprocess-sample
+ edit --> tests --> samples --> evidence --> smoke
```
-Run a local LLM concurrency load test:
+Useful commands:
```bash
-make llm-load-sample
+make test
+make web-typecheck
+make native-rust-test
+make native-go-test
+make native-cpp-test
+make app-smoke
```
-Evaluate runtime LLM guardrails and write the OWASP LLM 2025 guardrail report:
+Common sample flows:
```bash
+make vton-baseline-sample
+make llm-benchmark-sample
make guardrail-sample
-```
-
-Run the native Go guardrail sidecar smoke test:
-
-```bash
-make native-guardrail-smoke
-```
-
-Evaluate local latency and quality alert thresholds:
-
-```bash
-make alert-sample
-```
-
-Validate provisioned Grafana dashboards:
-
-```bash
-make dashboard-sample
-```
-
-Generate local image and prompt drift reports:
-
-```bash
-make drift-sample
-```
-
-Smoke test the local API endpoint contract:
-
-```bash
-make endpoint-smoke-sample
-```
-
-Generate governance and responsible-AI risk mapping evidence:
-
-```bash
-make governance-sample
-```
-
-Generate dependency lock, SBOM, and source/license evidence:
-
-```bash
-make supply-chain-sample
-```
-
-Run the native C++ SafeTensors-only model artifact gate:
-
-```bash
-make model-supply-chain-sample
-```
-
-Generate promotion evidence with OpenLineage-standard lineage and native validation:
-
-```bash
+make quota-sample
make pipeline-sample
+make deploy-package-sample
```
-Generate the Kubeflow-target orchestration skeleton:
-
-```bash
-make orchestration-sample
-```
-
-Compile and run the native C++ policy engine:
-
-```bash
-make native-cpp-test
-```
-
-Compile the native C++ OpenLineage validator:
-
-```bash
-make native-openlineage-build
-```
-
-Check native toolchain availability:
-
-```bash
-make native-tooling
-```
-
-Start the open-source service stack after installing dependencies and Docker:
+Real model runs are optional and need ML extras plus suitable hardware:
```bash
-make app-up
+python -m pip install -e ".[dev,ml]"
+make vton-real-sample
+make llm-real-sample
```
-API contract and observability notes:
-
-- `docs/api_contract.md`
-- `docs/observability_contract.md`
-- `docs/dashboard_design.md`
-- `docs/chaos_reliability.md`
-- `docs/drift_monitoring.md`
-- `docs/enterprise_quota.md`
-- `docs/finops_semantic_cache.md`
-- `docs/admin_auth.md`
-- `docs/serving_controls.md`
-- `docs/release_engineering.md`
-- `docs/reproducibility_checklist.md`
-- `docs/native_image_metrics.md`
-- `docs/vton_preprocessing.md`
-- `docs/garment_similarity.md`
-- `docs/llm_sensitivity.md`
-- `docs/llm_phase_timing.md`
-- `docs/opentelemetry_tracing.md`
-- `docs/responsible_ai_risk_mapping.md`
-- `docs/supply_chain.md`
-- `docs/orchestration.md`
-
-## Project Shape
+## Repository Map
```text
-configs/ Project and promotion settings
-contracts/ JSON request schemas
-docs/ Architecture, governance, execution notes
-infra/ Prometheus, Grafana, and deployment config
-policies/ OPA/Rego policy
-samples/ Sample candidate payloads
-scripts/ Local automation
-src/tryops/ Python package
-tests/ Standard-library tests
-```
+web/ React/Vite Console
+src/tryops/ FastAPI app, pipelines, adapters, product logic
+native/rust/ Rust gateway
+native/go/ Go services and operational tools
+native/cpp/ C++ deterministic CLIs
+infra/ Observability, migrations, deployment assets
+configs/ Runtime and policy config
+contracts/ JSON schemas
+samples/ Demo inputs and candidate payloads
+scripts/ Automation and evidence generation
+tests/ Python contract tests
+docs/ Detailed architecture and operations notes
+artifacts/ Generated local outputs, ignored by Git
+reports/generated/ Generated cards/reports, ignored by Git
+```
+
+## Main Ports
+
+When using `make app-up`:
-## First Execution Milestone
-
-The first milestone is not "train a model." It is:
-
-1. Validate data.
-2. Run a benchmark.
-3. Produce an evaluation report.
-4. Register a candidate.
-5. Block or allow promotion through policy.
-6. Emit lineage that links model, data, code, run, and artifacts.
-
-That is the foundation for the VTON and LLM work.
+```text
+Console + gateway: http://127.0.0.1:18081
+FastAPI direct: http://127.0.0.1:18080
+Grafana: http://127.0.0.1:13000
+Prometheus: http://127.0.0.1:19090
+MLflow: http://127.0.0.1:15000
+MinIO API: http://127.0.0.1:19000
+MinIO Console: http://127.0.0.1:19001
+```
+
+## Deeper Docs
+
+- Architecture: `docs/architecture.md`
+- API contract: `docs/api_contract.md`
+- Production app plan: `docs/production_app_plan.md`
+- Orchestration: `docs/orchestration.md`
+- Observability: `docs/observability_contract.md`
+- Supply chain: `docs/supply_chain.md`
+- Native modules: `native/README.md`
diff --git a/docker-compose.yml b/docker-compose.yml
index f299060..dfd3546 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -119,6 +119,7 @@ services:
otel-collector:
image: otel/opentelemetry-collector-contrib:latest
+ user: "${TRYOPS_CONTAINER_UID:-1000}:${TRYOPS_CONTAINER_GID:-1000}"
restart: unless-stopped
command: ["--config=/etc/otelcol-contrib/config.yml"]
ports:
diff --git a/docs/production_app_plan.md b/docs/production_app_plan.md
index 57e5e89..d145da0 100644
--- a/docs/production_app_plan.md
+++ b/docs/production_app_plan.md
@@ -63,6 +63,7 @@ Current readiness: backend/data/native edge are real; the browser Console is fun
- Supply-chain gates should use open-source scanner/signing tools when installed: Syft for SBOMs, Trivy for vulnerability/misconfig/secret scans, Cosign for keyless image signing, GitHub OIDC for signing identity, uploaded artifacts for durable evidence, and Docker Buildx metadata/SBOM/provenance capture in CI: https://github.com/anchore/syft, https://trivy.dev/docs/latest/target/filesystem/, https://docs.sigstore.dev/cosign/signing/signing_with_containers/, https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect, https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts, and https://docs.docker.com/build/ci/github-actions/
- Dependency-lock evidence should be generated from first-party ecosystem lockfiles: `uv.lock` for Python project resolution, `package-lock.json` plus `npm ci` for the Console, `Cargo.lock` for the Rust gateway binary, and Go `go.mod`/`go.sum` checksums for native modules: https://docs.astral.sh/uv/concepts/projects/sync/, https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json/, https://docs.npmjs.com/cli/v8/commands/npm-ci, https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html, and https://go.dev/ref/mod
- Incident evidence should be native-first and based on open standards: OpenTelemetry log/exception fields for fingerprinted error events, Alertmanager webhook payloads as the incident trigger, SRE blameless postmortem practice for the template, and an optional open-source GlitchTip/Sentry-compatible DSN for external error tracking: https://opentelemetry.io/docs/specs/otel/logs/data-model/, https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-spans/, https://prometheus.io/docs/alerting/latest/configuration/#webhook_config, https://sre.google/sre-book/postmortem-culture/, and https://glitchtip.com/documentation/
+- Native content-safety should combine deterministic input/output filtering with stronger model-based classifiers when available; OWASP LLM01 frames prompt injection mitigations around input validation, output filtering, and structured validation, while NIST AI RMF requires continuous risk measurement and management: https://genai.owasp.org/llmrisk/llm01-prompt-injection/ and https://www.nist.gov/itl/ai-risk-management-framework
### Product rule
@@ -90,9 +91,9 @@ Python stays as BFF/control-plane glue and model adapter code where the current
- [~] **P3 — Frontend.** PARTIAL: React/Vite/TypeScript Console shell, left nav, typed API client, LLM Playground with direct/canary/A-B/bandit routing modes, VTON Studio contract form plus persisted side-by-side comparison outputs, Dashboard with native quota/showback read model, Request History, Pipeline Runs, Model Registry, Evaluation evidence plus optimization/Pareto/sustainability panel, Experiments board, Governance, Incident posture plus live bad-candidate and rollback drills, native incident workflow/postmortem evidence loading, Professor Demo mode, API-key session field, RBAC role-aware navigation, degraded banner, and responsive styling are implemented under `web/`; browser upload/download controls, full audit-log UI, live alert workflow controls, screenshots, and accessibility/export hardening remain.
- [x] **P4 — Services & edge wiring.** DONE: modular Rust gateway reverse-proxies `/api/*` to FastAPI `/v1/*`, adds request IDs, propagates trace context, enforces edge limits/preflight plus artifact-path preflight, calls the modular Go guardrail sidecar before LLM generation, and `docker-compose` ties gateway+api+db+prometheus+grafana+guardrail+minio+mlflow with healthchecks plus `make app-up`, `make app-smoke`, and `make app-down`.
- [~] **P5 — Monitoring & dashboard.** PARTIAL: API metrics, native Rust gateway metrics, native Go runtime telemetry for LLM tokens/sec plus live NVIDIA GPU memory/utilization/power, OpenTelemetry Collector wiring, native trace/log correlation, and Alertmanager page/ticket routing evidence now emit Prometheus/JSONL evidence; in-app dashboard timeseries, audit-log UI, external pager/chat credentials, and live OTLP exporters for full gateway->API->model trace stitching remain.
-- [~] **P6 — Enterprise hardening.** PARTIAL: Rust edge API-key/JWT auth preflight, viewer/operator/admin RBAC session and nav enforcement, edge rate limits, native quota admission, optional file quota persistence, opt-in Postgres-backed distributed quota admission with fail-closed startup behavior, Postgres durable quota upsert mirroring, native Postgres migration/pooling evidence, native Postgres/MinIO backup-restore drill evidence, Valkey-compatible quota counter mirroring, `.env.example` plus Compose secret loading, native Go secret-rotation/workload-identity contract evidence, live Vault KV v2 secret retrieval/rotation evidence, Kubernetes Vault `SecretStore`/`ExternalSecret` manifests, native dependency-lock contract evidence across Python/Node/Rust/Go, native Rust TLS termination, payload limits, Rust->Go LLM guardrail enforcement, native Go full-stack load/SLO evidence, native Go incident workflow/postmortem evidence, GitHub Actions plus native Go CI/supply-chain contract, and local live Syft/Trivy/Cosign execution are in place; production Kubernetes External Secrets sync, external k6/locust confirmation, and external error-tracker DSN exercise remain.
+- [~] **P6 — Enterprise hardening.** PARTIAL: Rust edge API-key/JWT auth preflight, viewer/operator/admin RBAC session and nav enforcement, edge rate limits, native quota admission, optional file quota persistence, opt-in Postgres-backed distributed quota admission with fail-closed startup behavior, Postgres durable quota upsert mirroring, native Postgres migration/pooling evidence, native Postgres/MinIO backup-restore drill evidence, Valkey-compatible quota counter mirroring, `.env.example` plus Compose secret loading, native Go secret-rotation/workload-identity contract evidence, live Vault KV v2 secret retrieval/rotation evidence, Kubernetes Vault `SecretStore`/`ExternalSecret` manifests, native dependency-lock contract evidence across Python/Node/Rust/Go, native Rust TLS termination, payload limits, Rust->Go LLM guardrail enforcement, native C++ content-safety evidence, native Go full-stack load/SLO evidence, native Go incident workflow/postmortem evidence, GitHub Actions plus native Go CI/supply-chain contract, and local live Syft/Trivy/Cosign execution are in place; production Kubernetes External Secrets sync, external k6/locust confirmation, and external error-tracker DSN exercise remain.
- [~] **P7 — Demo & docs.** PARTIAL: `docs/presentation_outline.md` defines the professor demo path, the Console has a seeded Professor Demo view, `make professor-demo-acceptance` verifies the platform evidence bundle, and `make professor-demo-video` records a deterministic offline MP4 backup. Seed loader, product runbook, and full user/admin guides remain.
-- [~] **P8 — Native-first product expansion.** PARTIAL: local P8 rows PA072-PA086 are now closed by verified native evidence. Rust gateway serves `web/dist` with SPA fallback, performs API-key/JWT auth preflight, terminates optional rustls HTTPS, makes native semantic-cache admission decisions plus optional C++ vector-cache lookups before FastAPI for LLM generation, mirrors accepted quota usage into Postgres plus Valkey-compatible counters with tenant usage snapshots, can use Postgres row locks as the shared quota admission ledger when `TRYOPS_GATEWAY_QUOTA_POSTGRES_ADMISSION=true`, degrades to the local quota ledger when a non-admission durable mirror is unavailable, emits a shared native trace/log envelope as JSONL, and has split container image definitions with Rust builder/runtime ABI compatibility checks for gateway/controller/guardrail/benchmark/C++ tools/API/web assets; native Go modules now cover VTON/LLM job execution, signed audit/webhook event dispatch, registry-webhook C++ policy enforcement, full-stack gateway/BFF load generation with SLO reporting, native CI/supply-chain contract validation plus live Syft/Trivy/Cosign evidence, native secret-rotation/workload-identity contract validation plus live Vault KV rotation, native incident workflow/postmortem evidence, distributed quota admission validation, SLO regression gating over native benchmark output, config-contract drift checks, TLS termination contract validation, Postgres migration/pool execution, Postgres/MinIO backup-restore drills, container-contract validation, trace-envelope validation/reporting, observability Collector/correlation validation, runtime telemetry export for LLM throughput/GPU memory, quota read-model/showback generation for the BFF dashboard, a CI-grade Rust/Go/C++ performance-budget report, GPTQ/AWQ model/runtime preflight, and vLLM OpenAI-compatible endpoint probing; native C++ now also validates real GGUF artifacts for CPU-first LLM deployment preflight, validates trace envelopes, powers production A/B and guarded bandit routing through FastAPI/React, and feeds semantic-cache lookup plus VTON preprocessing/image-quality metrics through edge/API/job paths. External k6/locust confirmation, external error-tracker DSN exercise, live GPTQ/AWQ loading, live llama.cpp generation, live vLLM serving, production Kubernetes External Secrets sync, and live OTLP exporters remain.
+- [~] **P8 — Native-first product expansion.** PARTIAL: local P8 rows PA072-PA086 are now closed by verified native evidence. Rust gateway serves `web/dist` with SPA fallback, performs API-key/JWT auth preflight, terminates optional rustls HTTPS, makes native semantic-cache admission decisions plus optional C++ vector-cache lookups before FastAPI for LLM generation, mirrors accepted quota usage into Postgres plus Valkey-compatible counters with tenant usage snapshots, can use Postgres row locks as the shared quota admission ledger when `TRYOPS_GATEWAY_QUOTA_POSTGRES_ADMISSION=true`, degrades to the local quota ledger when a non-admission durable mirror is unavailable, emits a shared native trace/log envelope as JSONL, and has split container image definitions with Rust builder/runtime ABI compatibility checks for gateway/controller/guardrail/benchmark/C++ tools/API/web assets; native Go modules now cover VTON/LLM job execution, signed audit/webhook event dispatch, registry-webhook C++ policy enforcement, full-stack gateway/BFF load generation with SLO reporting, native CI/supply-chain contract validation plus live Syft/Trivy/Cosign evidence, native secret-rotation/workload-identity contract validation plus live Vault KV rotation, native incident workflow/postmortem evidence, distributed quota admission validation, SLO regression gating over native benchmark output, config-contract drift checks, TLS termination contract validation, Postgres migration/pool execution, Postgres/MinIO backup-restore drills, container-contract validation, trace-envelope validation/reporting, observability Collector/correlation validation, runtime telemetry export for LLM throughput/GPU memory, quota read-model/showback generation for the BFF dashboard, a CI-grade Rust/Go/C++ performance-budget report, GPTQ/AWQ model/runtime preflight, and vLLM OpenAI-compatible endpoint probing; Wave 3 native fabric now adds C++ admission control, retry budgets, PII/secret redaction, content-safety gating, tamper-evident audit logs, Bloom idempotency dedup, HyperLogLog cardinality, LRU/TTL response cache, cost attribution, reservoir/priority trace sampling, plus Go consistent-hash routing; native C++ also validates real GGUF artifacts for CPU-first LLM deployment preflight, validates trace envelopes, powers production A/B and guarded bandit routing through FastAPI/React, and feeds semantic-cache lookup plus VTON preprocessing/image-quality metrics through edge/API/job paths. External k6/locust confirmation, external error-tracker DSN exercise, live GPTQ/AWQ loading, live llama.cpp generation, live vLLM serving, production Kubernetes External Secrets sync, and live OTLP exporters remain.
### Acceptance (Gate: Product Ready)
@@ -102,7 +103,7 @@ A user opens the Console in a browser and can, with no terminal:
- Upload person+garment assets, run VTON, compare inputs/output, download through a persisted local/MinIO object URL, and inspect lineage.
- Review request history, request detail, feedback, dashboard rollups, model registry, governance/lineage, and audit log.
- As an admin/operator, promote or block a model through signed/policy-gated controls and see the action in metrics, audit, and incident views.
-- Start the full local stack with `make app-up`; prove startup with `make app-smoke`; prove the native edge/job/SLO/config/container/CI/dependencies/performance/load/trace/observability/alerts/secrets/live-secrets/postgres/backup/TLS/quota-read-model/distributed-quota/runtime-telemetry/incident layer with `make native-rust-smoke`, `make native-edge-cache-smoke`, `make native-edge-guardrail-smoke`, `make native-quota-ledger-smoke`, `make native-distributed-quota-smoke`, `make native-quota-read-model-sample`, `make native-runtime-telemetry-sample`, `make native-observability-contract-sample`, `make native-alertmanager-contract-sample`, `make native-dependency-lock-contract-sample`, `make native-secret-rotation-contract-sample`, `make native-secret-rotation-live`, `make native-incident-workflow-sample`, `make native-db-migrator-sample`, `make native-backup-restore-sample`, `make native-tls-contract-sample`, `make native-tls-smoke`, `make native-static-smoke`, `make native-job-runner-sample`, `make vton-native-api-sample`, `make gateway-benchmark-native`, `make native-fullstack-load-sample`, `make native-ci-contract-live`, `make native-slo-gate-sample`, `make native-config-contract-sample`, `make native-container-contract-sample`, `make native-trace-envelope-sample`, and `make native-performance-budget-sample`; prove the native CPU-first LLM artifact path with `make llm-gguf-preflight-sample`; prove GPTQ/AWQ candidate/runtime readiness with `make llm-quantized-preflight-sample`; prove vLLM serving readiness or explicit skip status with `make llm-vllm-probe-sample`; prove the professor demo evidence with `make professor-demo-acceptance`; prove backend contracts with `PYTHONPATH=src python -m unittest discover -s tests`.
+- Start the full local stack with `make app-up`; prove startup with `make app-smoke`; prove the native edge/job/SLO/config/container/CI/dependencies/performance/load/trace/observability/alerts/secrets/live-secrets/postgres/backup/TLS/quota-read-model/distributed-quota/runtime-telemetry/incident layer with `make native-rust-smoke`, `make native-edge-cache-smoke`, `make native-edge-guardrail-smoke`, `make native-admission-sample`, `make native-redaction-sample`, `make native-safety-sample`, `make native-audit-log-sample`, `make native-dedup-sample`, `make native-hll-sample`, `make native-consistent-hash-sample`, `make native-cache-sample`, `make native-cost-sample`, `make native-sampler-sample`, `make native-retry-sample`, `make native-quota-ledger-smoke`, `make native-distributed-quota-smoke`, `make native-quota-read-model-sample`, `make native-runtime-telemetry-sample`, `make native-observability-contract-sample`, `make native-alertmanager-contract-sample`, `make native-dependency-lock-contract-sample`, `make native-secret-rotation-contract-sample`, `make native-secret-rotation-live`, `make native-incident-workflow-sample`, `make native-db-migrator-sample`, `make native-backup-restore-sample`, `make native-tls-contract-sample`, `make native-tls-smoke`, `make native-static-smoke`, `make native-job-runner-sample`, `make vton-native-api-sample`, `make gateway-benchmark-native`, `make native-fullstack-load-sample`, `make native-ci-contract-live`, `make native-slo-gate-sample`, `make native-config-contract-sample`, `make native-container-contract-sample`, `make native-trace-envelope-sample`, and `make native-performance-budget-sample`; prove the native CPU-first LLM artifact path with `make llm-gguf-preflight-sample`; prove GPTQ/AWQ candidate/runtime readiness with `make llm-quantized-preflight-sample`; prove vLLM serving readiness or explicit skip status with `make llm-vllm-probe-sample`; prove the professor demo evidence with `make professor-demo-acceptance`; prove backend contracts with `PYTHONPATH=src python -m unittest discover -s tests`.
- Open the Console Professor Demo view and walk the seeded no-network/no-GPU path across quota, optimization, VTON quality, lineage, rollback, and governance without relying on live model service availability.
---
@@ -319,5 +320,81 @@ Advanced enterprise dimensions beyond the MVP product. Not blocking the first ve
- [ ] PA142 Data-warehouse export (Parquet/BigQuery)
- [ ] PA143 Embedded BI dashboard for admins
+## Wave 3 — Resilience, Trust & Edge Fabric (native-first)
+
+> Design principle: every item below pushes a control-plane or data-plane concern
+> down to a **low-level engine** (C++/Go/Rust) at the production boundary, with a
+> thin Python bridge and graceful offline fallback. Python orchestrates; native
+> decides on the hot path. Each item must ship a real binary + test + measured
+> sample, not a checkbox.
+
+### Resilience & admission control (PA144–PA153)
+- [x] PA144 Native adaptive admission controller — token bucket + circuit breaker + load shedding (C++) — `native/cpp/tryops_admission`, `make native-admission-{build,sample,test}`, wired into `ci`+`smoke`; sample sheds 50% of a 414-event mixed-traffic stream, native binary agrees bit-for-bit with the Python reference
+- [x] PA145 Native circuit breaker with half-open probing — closed→open on windowed error-rate ≥ threshold, open→half-open after cooldown, half-open→closed on healthy probe (sample: 2 trips, 1 recovery, ends closed)
+- [x] PA146 Native concurrency limiter / bulkhead isolation — in-flight slot accounting with duration-based release (`max_concurrency` gate, `peak_inflight` reported)
+- [x] PA147 Native retry budget + exponential backoff with jitter — `native/cpp/tryops_retry`, `make native-retry-{build,sample,test}`, wired into `ci`+`smoke`; full/equal/none jitter, cumulative retry budget (gRPC-style storm prevention), shared xorshift64 so native == reference incl. jittered backoff sum; sample: 71.2%→89.3% success, 206 retries denied by budget
+- [ ] PA148 Native request hedging (tail-latency cut)
+- [ ] PA149 Deadline propagation + timeout enforcement at boundary
+- [ ] PA150 Graceful shutdown / connection draining in Rust gateway
+- [ ] PA151 Backpressure signalling end-to-end (gateway→controller)
+- [ ] PA152 Priority queueing / weighted fair share across tenants
+- [ ] PA153 Brownout mode (shed non-critical features under load)
+
+### Trust & tamper-evidence (PA154–PA162)
+- [x] PA154 Native Merkle tamper-evident audit log (C++) — `native/cpp/tryops_audit_log`, `make native-audit-log-{build,sample,test}`, wired into `ci`+`smoke`; hand-rolled SHA-256 verified bit-for-bit against Python `hashlib` (incl. FIPS-180-4 KAT vectors); sample tamper-detection confirmed
+- [x] PA155 Append-only hash-chained event ledger + verification — each entry chains `sha256(prev_chain + leaf)`; `verify_chain()` recomputes and detects any in-place mutation
+- [~] PA156 Signed audit checkpoints + inclusion proofs — O(log n) Merkle inclusion proofs implemented + verified (`prove`/`verify_inclusion`); HMAC checkpoint signing still TODO
+- [x] PA157 Native PII/secret redaction engine (C++ scrubber) — `native/cpp/tryops_redaction`, `make native-redaction-{build,sample,test}`, wired into `ci`+`smoke`; 10 detectors (email, CC w/ Luhn gate, API/AWS/GitHub keys, bearer, JWT, IPv4, SSN, phone) + FNV-1a audit fingerprints; native C++ and Python reference agree bit-for-bit incl. fingerprints
+- [x] PA158 Content-safety gate (prompt-injection + toxicity) at boundary — `native/cpp/tryops_safety`, `make native-safety-{build,sample,test}`, wired into `ci`+`smoke` and FastAPI ingress guardrails; sample labels pass at 100% accuracy with zero native/reference disagreement, and `/v1/llm/generate` verdicts include `native_engine.content_safety`
+- [x] PA159 Native idempotency-key dedup (bloom filter, C++) — `native/cpp/tryops_dedup`, `make native-dedup-{build,sample,test}`, wired into `ci`+`smoke`; optimal m/k sizing from (n, p), Kirsch-Mitzenmacher double hashing, zero false negatives; sample: 600 reqs → 400 unique admitted / 200 replays rejected, native == reference bit-for-bit
+- [ ] PA160 Request/response signing (HMAC) at the boundary
+- [ ] PA161 SLSA build-provenance attestation verification
+- [ ] PA162 Data-access audit + least-privilege enforcement
+
+### Edge & performance fabric (PA163–PA172)
+- [x] PA163 Native consistent-hash ring for sharding/routing (Go) — `native/go/tryops-consistent-hash`, `make native-consistent-hash-{build,test,sample}`, wired into `native-go-test`+`ci`+`smoke`; 200 virtual nodes + fmix64-finalised FNV hashing → imbalance 1.14; node removal remaps only 18.4% of keys (≈ ideal 1/N) and only that node's keys
+- [x] PA164 Native HyperLogLog cardinality estimator for metrics (C++) — `native/cpp/tryops_hll`, `make native-hll-{build,sample,test}`, wired into `ci`+`smoke`; FNV-1a+fmix64 hash, HLL++ linear-counting small-range correction; sample: 8000 distinct from 24k observations estimated at 8020 (0.26% error, 16KB state), native == reference
+- [x] PA165 Native reservoir/priority trace sampler (C++) — `native/cpp/tryops_sampler`, `make native-sampler-{build,sample,test}`, wired into `ci`+`smoke`; Algorithm-R reservoir + priority (force-keep error/slow spans) modes, shared deterministic xorshift64 so native == reference bit-for-bit incl. randomized picks; uniformity test passes
+- [x] PA166 Native response cache with TTL + LRU eviction (C++) — `native/cpp/tryops_cache`, `make native-cache-{build,sample,test}`, wired into `ci`+`smoke`; LRU + sliding-TTL, O(1) hash+list; Zipfian sample: 77.6% hit rate (256-cap over 800 keys), 866 evictions, native == reference bit-for-bit
+- [ ] PA167 Native streaming token relay (SSE) at gateway
+- [ ] PA168 Native zstd/gzip response compression at edge
+- [ ] PA169 Connection-pool + keep-alive tuning (measured)
+- [ ] PA170 Edge request coalescing (single-flight) for hot keys
+- [ ] PA171 Structured JSON access log + adaptive sampling
+- [ ] PA172 Latency-aware load balancing (EWMA power-of-two-choices) in Go
+
+### Multi-tenancy & quota (PA173–PA180)
+- [ ] PA173 Tenant isolation namespaces + per-tenant config
+- [ ] PA174 Hierarchical quota (org→team→user) read model
+- [ ] PA175 Per-tenant rate limits + burst credits
+- [ ] PA176 Tenant-scoped envelope encryption keys
+- [ ] PA177 Noisy-neighbour detection + auto-throttle
+- [ ] PA178 Tenant offboarding + GDPR data-erasure
+- [ ] PA179 Usage metering → billing export (per tenant)
+- [ ] PA180 Tenant-level SLA tracking + breach alerts
+
+### Privacy, governance & FinOps (PA181–PA189)
+- [ ] PA181 Native data-residency policy enforcement
+- [ ] PA182 Differential-privacy noise for aggregate analytics
+- [ ] PA183 Consent + data-retention lifecycle engine
+- [x] PA184 Native cost-attribution engine (token/GPU-sec → $) — `native/cpp/tryops_cost`, `make native-cost-{build,sample,test}`, wired into `ci`+`smoke`; per-tenant/per-model showback of token+GPU+energy cost and carbon (grid-intensity priced, consistent with green-MLOps); sample: 2000 reqs → $79.37 / 392g CO₂ across 4 tenants, native == reference
+- [ ] PA185 Budget guardrails + spend-anomaly detection
+- [ ] PA186 Rightsizing recommender (GPU utilisation → instance)
+- [ ] PA187 Carbon-aware scheduler hook into admission
+- [ ] PA188 Spot/preemptible fallback with checkpoint-resume
+- [ ] PA189 FinOps showback/chargeback report
+
+### DevEx, release & verification (PA190–PA198)
+- [ ] PA190 Native fuzz harness for boundary parsers (libFuzzer)
+- [ ] PA191 Property-based tests for native engines
+- [ ] PA192 Deterministic record/replay harness for events
+- [ ] PA193 Native closed-loop load generator (concurrency control)
+- [ ] PA194 Golden-output contract tests across all native CLIs
+- [ ] PA195 ASan/UBSan/TSan sanitizer CI lane
+- [ ] PA196 Reproducible-build (bit-for-bit) verification
+- [ ] PA197 Performance-regression gate wired to CI (budget diff)
+- [ ] PA198 One-command production smoke (`make prod-smoke`)
+
### Backlog totals
-Core (PA001–PA071): 71 items. Long-term (PA072–PA143): 72 items. **143 total**, 5 done (P1).
+Core (PA001–PA071): 71 items. Long-term (PA072–PA143): 72 items.
+Wave 3 (PA144–PA198): 55 items. **198 total.**
diff --git a/native/README.md b/native/README.md
index 800766b..4632fd0 100644
--- a/native/README.md
+++ b/native/README.md
@@ -6,7 +6,8 @@ This folder makes the project stronger than a Python-only ML demo.
- Rust is the target production gateway language.
- Go is the target Kubernetes/platform controller language.
-- C++ is used for hot metric, policy, preprocessing, energy, burn-rate, online experimentation and experiment statistics, chaos, model-artifact scan, and semantic-cache lookup paths.
+- C++ is used for hot metric, policy, preprocessing, energy, burn-rate, online experimentation and experiment statistics, chaos, model-artifact scan, semantic-cache lookup, admission control (rate limit + circuit breaker + bulkhead), PII/secret redaction, prompt/content-safety gating, tamper-evident audit-log, idempotency dedup (Bloom filter), cardinality estimation (HyperLogLog), LRU+TTL response cache, FinOps cost-attribution, and reservoir/priority trace sampling paths.
+- Go additionally provides the consistent-hash routing ring for sharding requests across backend replicas.
- Go is used for platform/control-plane services and the deterministic LLM guardrail CLI.
- Python remains the ML research, training, evaluation, and pipeline glue layer.
@@ -1279,3 +1280,183 @@ Current verified binary:
```text
artifacts/native/tryops_vton_preprocess_cli
```
+
+## C++ Admission Controller
+
+Path: `native/cpp/tryops_admission`
+
+Purpose: make the request-admission decision on the production boundary in a
+low-level language — a token bucket (rate limiting), a circuit breaker (fault
+isolation with half-open probing), and a concurrency bulkhead (load shedding) in
+one deterministic, replayable engine.
+
+Source layout:
+
+- `include/tryops_admission.hpp` / `src/tryops_admission.cpp`: the controller and
+ the `key=value` event-stream wire runner.
+- `src/tryops_admission_cli.cpp`: stdin wire → JSON report, with a `--max-shed-rate`
+ gate (exit 2 when the breaker is open or shedding too hard).
+
+Integration:
+
+- `src/tryops/native_admission.py` invokes the binary and carries a Python
+ reference reimplementation that agrees with the C++ engine bit-for-bit.
+- `scripts/evaluate_native_admission.py` cross-checks native vs reference counts.
+- `make native-admission-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_admission_cli
+```
+
+## C++ PII / Secret Redaction Engine
+
+Path: `native/cpp/tryops_redaction`
+
+Purpose: scrub secrets and PII (email, Luhn-validated credit cards, API/AWS/GitHub
+keys, bearer/JWT tokens, IPv4, SSN, phone) out of free text *before* it is logged,
+cached, or persisted — on the hot path, in C++. Emits per-category counts plus
+FNV-1a input/output fingerprints for audit.
+
+- `src/tryops/native_redaction.py` mirrors the detectors; native and reference
+ agree on counts, redacted body, and fingerprints.
+- `make native-redaction-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_redaction_cli
+```
+
+## C++ Content-Safety Gate
+
+Path: `native/cpp/tryops_safety`
+
+Purpose: block or flag prompt-injection, system-prompt exfiltration, and abusive
+content before the request reaches LLM generation. The gate is deterministic,
+dependency-free, and cheap enough for the request boundary; it complements the Go
+LLM guardrail sidecar and can be replaced or augmented by Llama Guard-style model
+classifiers later.
+
+- `src/tryops/native_safety.py` mirrors the C++ rule set and scoring.
+- `scripts/evaluate_native_safety.py` runs labeled prompt fixtures and fails the
+ evidence gate if native/reference parity or label accuracy regresses.
+- `src/tryops/guardrails.py` includes the native safety verdict in
+ `native_engine.content_safety` and turns flag/block results into ingress
+ guardrail findings.
+- `make native-safety-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_safety_cli
+```
+
+## C++ Tamper-Evident Audit Log
+
+Path: `native/cpp/tryops_audit_log`
+
+Purpose: an append-only, hash-chained ledger with a SHA-256 Merkle tree over all
+entries. Tampering with any past record changes the Merkle root and breaks the
+chain; O(log n) inclusion proofs let a verifier confirm membership against a
+published root. SHA-256 is implemented from scratch (no deps) and verified
+bit-for-bit against Python `hashlib`, including FIPS-180-4 KAT vectors.
+
+- `src/tryops/native_audit_log.py` provides the `hashlib`-based reference.
+- `scripts/evaluate_native_audit_log.py` emits root + inclusion proof and
+ demonstrates tamper detection.
+- `make native-audit-log-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_audit_log_cli
+```
+
+## C++ Idempotency Dedup (Bloom Filter)
+
+Path: `native/cpp/tryops_dedup`
+
+Purpose: reject replayed idempotency keys at the boundary without a database
+round-trip. A Bloom filter sized from (expected items, target false-positive
+rate) using Kirsch-Mitzenmacher double hashing — zero false negatives, fixed tiny
+memory. Sample: 600 requests → 400 unique admitted / 200 replays rejected.
+
+- `src/tryops/native_dedup.py` reproduces the FNV-1a double-hashing + optimal
+ sizing exactly; native and reference agree bit-for-bit on admit/reject.
+- `make native-dedup-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_dedup_cli
+```
+
+## C++ HyperLogLog Cardinality
+
+Path: `native/cpp/tryops_hll`
+
+Purpose: estimate distinct counts (unique users/prompts/error fingerprints) over
+a high-volume stream in O(2^p) bytes instead of storing every key. Standard HLL
+estimator with FNV-1a+fmix64 hashing and HLL++ linear-counting small-range
+correction. Sample: 8000 distinct from 24k observations estimated at 8020
+(0.26% error) in 16 KB of state.
+
+- `src/tryops/native_hll.py` replicates the hash + estimator; an estimate match
+ proves identical register state (hence identical hashing) across C++/Python.
+- `make native-hll-{build,sample,test}`; wired into `ci` and `smoke`.
+
+```text
+artifacts/native/tryops_hll_cli
+```
+
+## C++ LRU+TTL Response Cache
+
+Path: `native/cpp/tryops_cache`
+
+Purpose: short-circuit repeated identical requests at the edge with a fixed-
+capacity LRU cache plus per-entry sliding TTL (O(1) hash map + intrusive list).
+Zipfian sample: 77.6% hit rate at 256 entries over an 800-key space, 866
+evictions. `src/tryops/native_cache.py` reproduces the eviction/expiry semantics
+exactly (native == reference). `make native-cache-{build,sample,test}`.
+
+```text
+artifacts/native/tryops_cache_cli
+```
+
+## C++ Cost-Attribution (FinOps Showback)
+
+Path: `native/cpp/tryops_cost`
+
+Purpose: turn a per-request usage stream (tokens, GPU-seconds, energy) into
+auditable per-tenant / per-model cost + carbon breakdowns. Pricing is consistent
+with the green-MLOps methodology (GPU $/hr, $/kWh, grid gCO2e/kWh). Sample: 2000
+requests → $79.37 total / 392 g CO2e across 4 tenants. `src/tryops/native_cost.py`
+mirrors the arithmetic (native == reference). `make native-cost-{build,sample,test}`.
+
+```text
+artifacts/native/tryops_cost_cli
+```
+
+## C++ Trace Sampler (Reservoir + Priority)
+
+Path: `native/cpp/tryops_sampler`
+
+Purpose: keep a bounded, representative sample of a high-volume trace stream so
+observability stays affordable. Reservoir mode (Algorithm R) gives every span an
+equal k/n keep-probability in one pass with O(k) memory; priority mode force-keeps
+flagged spans (errors/slow requests) and fills the rest uniformly. A shared
+deterministic xorshift64* RNG makes selection reproducible, so the C++ engine and
+`src/tryops/native_sampler.py` agree bit-for-bit (including randomized picks).
+`make native-sampler-{build,sample,test}`.
+
+```text
+artifacts/native/tryops_sampler_cli
+```
+
+## C++ Retry Policy (Backoff + Jitter + Budget)
+
+Path: `native/cpp/tryops_retry`
+
+Purpose: model the boundary's retry behaviour — exponential backoff with jitter
+(full/equal/none, the AWS/SRE pattern) bounded by a cumulative retry budget
+(gRPC-style throttle) so a wave of failures can't trigger a retry storm that
+amplifies load on a struggling backend. Shared xorshift64 RNG makes jittered
+delays reproducible, so `src/tryops/native_retry.py` agrees with the binary on
+outcomes *and* the accumulated backoff. Sample: 71.2%→89.3% success with 206
+retries denied by budget. `make native-retry-{build,sample,test}`.
+
+```text
+artifacts/native/tryops_retry_cli
+```
diff --git a/native/cpp/tryops_admission/include/tryops_admission.hpp b/native/cpp/tryops_admission/include/tryops_admission.hpp
new file mode 100644
index 0000000..06a9a51
--- /dev/null
+++ b/native/cpp/tryops_admission/include/tryops_admission.hpp
@@ -0,0 +1,115 @@
+// TryOps native admission controller.
+//
+// Pushes the request-admission hot path down to a low-level engine: a token
+// bucket (rate limiting), a circuit breaker (fault isolation with half-open
+// probing), and concurrency-based load shedding (bulkhead). Python orchestrates;
+// this code decides admit/reject per request on the production boundary.
+//
+// The controller is deterministic given an ordered event stream, which makes it
+// replayable and unit-testable offline.
+#ifndef TRYOPS_ADMISSION_HPP
+#define TRYOPS_ADMISSION_HPP
+
+#include
+#include
+#include
+#include
+
+namespace tryops {
+
+// One request arriving at the boundary.
+struct RequestEvent {
+ std::int64_t ts_ms = 0; // monotonic arrival time in milliseconds
+ double cost = 1.0; // tokens consumed if admitted (e.g. estimated tokens)
+ int duration_ms = 0; // how long the work occupies a concurrency slot
+ std::string outcome = "ok"; // "ok" or "error" — feeds the circuit breaker
+};
+
+struct AdmissionConfig {
+ double bucket_capacity = 100.0; // max burst (tokens)
+ double refill_per_sec = 50.0; // sustained admit rate (tokens/sec)
+ int max_concurrency = 32; // bulkhead limit (in-flight slots)
+ int breaker_window = 20; // sliding window of recent admitted outcomes
+ double breaker_error_threshold = 0.5; // open when error-rate >= this
+ std::int64_t breaker_cooldown_ms = 1000; // open -> half-open delay
+ int breaker_min_samples = 5; // don't trip before this many samples
+};
+
+enum class RejectReason {
+ kNone,
+ kRateLimited,
+ kBreakerOpen,
+ kConcurrencyFull,
+};
+
+enum class BreakerState {
+ kClosed,
+ kOpen,
+ kHalfOpen,
+};
+
+struct AdmissionReport {
+ std::int64_t total = 0;
+ std::int64_t admitted = 0;
+ std::int64_t rejected_rate_limited = 0;
+ std::int64_t rejected_breaker_open = 0;
+ std::int64_t rejected_concurrency_full = 0;
+ std::int64_t breaker_trips = 0; // closed/half-open -> open transitions
+ std::int64_t breaker_recoveries = 0; // half-open -> closed transitions
+ int peak_inflight = 0;
+ double min_tokens = 0.0;
+ double admit_rate = 0.0; // admitted / total
+ double shed_rate = 0.0; // 1 - admit_rate
+ double observed_error_rate = 0.0; // errors / admitted
+ BreakerState final_state = BreakerState::kClosed;
+};
+
+// Stateful controller. Feed events in non-decreasing ts_ms order.
+class AdmissionController {
+ public:
+ explicit AdmissionController(const AdmissionConfig& config);
+
+ // Returns the reason a request was rejected, or kNone if admitted.
+ RejectReason admit(const RequestEvent& event);
+
+ // Snapshot of accumulated decisions.
+ AdmissionReport report() const;
+
+ BreakerState breaker_state() const { return breaker_state_; }
+ double tokens() const { return tokens_; }
+
+ private:
+ void refill(std::int64_t now_ms);
+ void release_finished(std::int64_t now_ms);
+ void record_outcome(const std::string& outcome);
+ double window_error_rate() const;
+
+ AdmissionConfig config_;
+ double tokens_;
+ std::int64_t last_refill_ms_ = 0;
+ bool started_ = false;
+
+ // Concurrency bulkhead: heap of finish times for in-flight requests.
+ std::deque inflight_finish_ms_;
+
+ // Circuit breaker state.
+ BreakerState breaker_state_ = BreakerState::kClosed;
+ std::int64_t breaker_opened_ms_ = 0;
+ std::deque outcome_window_; // 1 = error, 0 = ok
+ int outcome_errors_ = 0;
+
+ AdmissionReport report_;
+};
+
+// Parse a `key=value` config/event wire stream from `text` and run the
+// controller over it. Lines:
+// bucket_capacity=... refill_per_sec=... max_concurrency=... etc.
+// event=ts_ms=;cost=;duration_ms=;outcome=
+AdmissionReport run_admission_wire(const std::string& text);
+
+const char* breaker_state_name(BreakerState state);
+const char* reject_reason_name(RejectReason reason);
+
+} // namespace tryops
+
+#endif // TRYOPS_ADMISSION_HPP
diff --git a/native/cpp/tryops_admission/src/tryops_admission.cpp b/native/cpp/tryops_admission/src/tryops_admission.cpp
new file mode 100644
index 0000000..550ccba
--- /dev/null
+++ b/native/cpp/tryops_admission/src/tryops_admission.cpp
@@ -0,0 +1,254 @@
+#include "tryops_admission.hpp"
+
+#include
+#include
+#include
+
+namespace tryops {
+namespace {
+
+double parse_double(const std::string& value, double fallback) {
+ if (value.empty()) {
+ return fallback;
+ }
+ return std::atof(value.c_str());
+}
+
+std::int64_t parse_i64(const std::string& value, std::int64_t fallback) {
+ if (value.empty()) {
+ return fallback;
+ }
+ return static_cast(std::atoll(value.c_str()));
+}
+
+int parse_int(const std::string& value, int fallback) {
+ if (value.empty()) {
+ return fallback;
+ }
+ return std::atoi(value.c_str());
+}
+
+} // namespace
+
+AdmissionController::AdmissionController(const AdmissionConfig& config)
+ : config_(config), tokens_(config.bucket_capacity) {
+ report_.min_tokens = config.bucket_capacity;
+}
+
+void AdmissionController::refill(std::int64_t now_ms) {
+ if (!started_) {
+ last_refill_ms_ = now_ms;
+ started_ = true;
+ return;
+ }
+ if (now_ms <= last_refill_ms_) {
+ return;
+ }
+ const double elapsed_sec = static_cast(now_ms - last_refill_ms_) / 1000.0;
+ tokens_ = std::min(config_.bucket_capacity,
+ tokens_ + elapsed_sec * config_.refill_per_sec);
+ last_refill_ms_ = now_ms;
+}
+
+void AdmissionController::release_finished(std::int64_t now_ms) {
+ while (!inflight_finish_ms_.empty() && inflight_finish_ms_.front() <= now_ms) {
+ inflight_finish_ms_.pop_front();
+ }
+}
+
+double AdmissionController::window_error_rate() const {
+ if (outcome_window_.empty()) {
+ return 0.0;
+ }
+ return static_cast(outcome_errors_) /
+ static_cast(outcome_window_.size());
+}
+
+void AdmissionController::record_outcome(const std::string& outcome) {
+ const int is_error = (outcome == "error") ? 1 : 0;
+ outcome_window_.push_back(is_error);
+ outcome_errors_ += is_error;
+ while (static_cast(outcome_window_.size()) > config_.breaker_window) {
+ outcome_errors_ -= outcome_window_.front();
+ outcome_window_.pop_front();
+ }
+}
+
+RejectReason AdmissionController::admit(const RequestEvent& event) {
+ report_.total += 1;
+ refill(event.ts_ms);
+ release_finished(event.ts_ms);
+
+ // 1. Circuit breaker gate (fail fast when downstream is unhealthy).
+ if (breaker_state_ == BreakerState::kOpen) {
+ if (event.ts_ms - breaker_opened_ms_ >= config_.breaker_cooldown_ms) {
+ breaker_state_ = BreakerState::kHalfOpen; // allow a single probe through
+ } else {
+ report_.rejected_breaker_open += 1;
+ return RejectReason::kBreakerOpen;
+ }
+ }
+
+ // 2. Concurrency bulkhead.
+ if (static_cast(inflight_finish_ms_.size()) >= config_.max_concurrency) {
+ report_.rejected_concurrency_full += 1;
+ return RejectReason::kConcurrencyFull;
+ }
+
+ // 3. Token bucket rate limit.
+ if (tokens_ < event.cost) {
+ report_.rejected_rate_limited += 1;
+ report_.min_tokens = std::min(report_.min_tokens, tokens_);
+ return RejectReason::kRateLimited;
+ }
+
+ // Admit: consume tokens, occupy a slot, account the outcome.
+ tokens_ -= event.cost;
+ report_.min_tokens = std::min(report_.min_tokens, tokens_);
+ const std::int64_t finish = event.ts_ms + std::max(0, event.duration_ms);
+ inflight_finish_ms_.push_back(finish);
+ report_.peak_inflight =
+ std::max(report_.peak_inflight, static_cast(inflight_finish_ms_.size()));
+ report_.admitted += 1;
+
+ record_outcome(event.outcome);
+
+ // Breaker state machine on observed outcome.
+ const bool was_half_open = (breaker_state_ == BreakerState::kHalfOpen);
+ if (was_half_open) {
+ if (event.outcome == "error") {
+ breaker_state_ = BreakerState::kOpen; // probe failed, re-open
+ breaker_opened_ms_ = event.ts_ms;
+ report_.breaker_trips += 1;
+ } else {
+ breaker_state_ = BreakerState::kClosed; // probe succeeded, recover
+ report_.breaker_recoveries += 1;
+ outcome_window_.clear();
+ outcome_errors_ = 0;
+ }
+ } else if (breaker_state_ == BreakerState::kClosed) {
+ const int samples = static_cast(outcome_window_.size());
+ if (samples >= config_.breaker_min_samples &&
+ window_error_rate() >= config_.breaker_error_threshold) {
+ breaker_state_ = BreakerState::kOpen;
+ breaker_opened_ms_ = event.ts_ms;
+ report_.breaker_trips += 1;
+ }
+ }
+
+ return RejectReason::kNone;
+}
+
+AdmissionReport AdmissionController::report() const {
+ AdmissionReport out = report_;
+ out.final_state = breaker_state_;
+ out.admit_rate =
+ out.total > 0 ? static_cast(out.admitted) / out.total : 0.0;
+ out.shed_rate = 1.0 - out.admit_rate;
+ // observed_error_rate is computed by the wire runner which tracks all admitted
+ // outcomes; here we report the window-bounded view if used standalone.
+ return out;
+}
+
+AdmissionReport run_admission_wire(const std::string& text) {
+ AdmissionConfig config;
+ std::vector events;
+ std::int64_t admitted_errors = 0;
+
+ std::istringstream stream(text);
+ std::string line;
+ while (std::getline(stream, line)) {
+ if (line.empty()) {
+ continue;
+ }
+ const auto sep = line.find('=');
+ if (sep == std::string::npos) {
+ continue;
+ }
+ const std::string key = line.substr(0, sep);
+ const std::string value = line.substr(sep + 1);
+
+ if (key == "bucket_capacity") {
+ config.bucket_capacity = parse_double(value, config.bucket_capacity);
+ } else if (key == "refill_per_sec") {
+ config.refill_per_sec = parse_double(value, config.refill_per_sec);
+ } else if (key == "max_concurrency") {
+ config.max_concurrency = parse_int(value, config.max_concurrency);
+ } else if (key == "breaker_window") {
+ config.breaker_window = parse_int(value, config.breaker_window);
+ } else if (key == "breaker_error_threshold") {
+ config.breaker_error_threshold =
+ parse_double(value, config.breaker_error_threshold);
+ } else if (key == "breaker_cooldown_ms") {
+ config.breaker_cooldown_ms = parse_i64(value, config.breaker_cooldown_ms);
+ } else if (key == "breaker_min_samples") {
+ config.breaker_min_samples = parse_int(value, config.breaker_min_samples);
+ } else if (key == "event") {
+ // value form: ts_ms=;cost=;duration_ms=;outcome=
+ RequestEvent ev;
+ std::istringstream fields(value);
+ std::string field;
+ while (std::getline(fields, field, ';')) {
+ const auto fsep = field.find('=');
+ if (fsep == std::string::npos) {
+ continue;
+ }
+ const std::string fk = field.substr(0, fsep);
+ const std::string fv = field.substr(fsep + 1);
+ if (fk == "ts_ms") {
+ ev.ts_ms = parse_i64(fv, ev.ts_ms);
+ } else if (fk == "cost") {
+ ev.cost = parse_double(fv, ev.cost);
+ } else if (fk == "duration_ms") {
+ ev.duration_ms = parse_int(fv, ev.duration_ms);
+ } else if (fk == "outcome") {
+ ev.outcome = fv;
+ }
+ }
+ events.push_back(ev);
+ }
+ }
+
+ AdmissionController controller(config);
+ for (const auto& ev : events) {
+ const RejectReason reason = controller.admit(ev);
+ if (reason == RejectReason::kNone && ev.outcome == "error") {
+ admitted_errors += 1;
+ }
+ }
+
+ AdmissionReport report = controller.report();
+ report.observed_error_rate =
+ report.admitted > 0
+ ? static_cast(admitted_errors) / report.admitted
+ : 0.0;
+ return report;
+}
+
+const char* breaker_state_name(BreakerState state) {
+ switch (state) {
+ case BreakerState::kClosed:
+ return "closed";
+ case BreakerState::kOpen:
+ return "open";
+ case BreakerState::kHalfOpen:
+ return "half_open";
+ }
+ return "closed";
+}
+
+const char* reject_reason_name(RejectReason reason) {
+ switch (reason) {
+ case RejectReason::kNone:
+ return "admitted";
+ case RejectReason::kRateLimited:
+ return "rate_limited";
+ case RejectReason::kBreakerOpen:
+ return "breaker_open";
+ case RejectReason::kConcurrencyFull:
+ return "concurrency_full";
+ }
+ return "admitted";
+}
+
+} // namespace tryops
diff --git a/native/cpp/tryops_admission/src/tryops_admission_cli.cpp b/native/cpp/tryops_admission/src/tryops_admission_cli.cpp
new file mode 100644
index 0000000..30546e9
--- /dev/null
+++ b/native/cpp/tryops_admission/src/tryops_admission_cli.cpp
@@ -0,0 +1,61 @@
+// Reads an admission wire stream on stdin, runs the controller, prints a JSON
+// report on stdout. Exit code: 0 if final breaker state is closed and the shed
+// rate is within the optional --max-shed-rate gate, 2 otherwise.
+#include "tryops_admission.hpp"
+
+#include
+#include
+#include
+
+namespace {
+
+std::string json_double(double value) {
+ std::ostringstream out;
+ out.setf(std::ios::fixed);
+ out.precision(6);
+ out << value;
+ return out.str();
+}
+
+} // namespace
+
+int main(int argc, char** argv) {
+ double max_shed_rate = 1.0;
+ for (int i = 1; i < argc; ++i) {
+ const std::string arg = argv[i];
+ if (arg == "--max-shed-rate" && i + 1 < argc) {
+ max_shed_rate = std::atof(argv[++i]);
+ }
+ }
+
+ std::ostringstream buffer;
+ buffer << std::cin.rdbuf();
+ const tryops::AdmissionReport report = tryops::run_admission_wire(buffer.str());
+
+ const bool gate_ok =
+ report.final_state == tryops::BreakerState::kClosed &&
+ report.shed_rate <= max_shed_rate;
+
+ std::cout << "{";
+ std::cout << "\"total\":" << report.total << ",";
+ std::cout << "\"admitted\":" << report.admitted << ",";
+ std::cout << "\"rejected_rate_limited\":" << report.rejected_rate_limited << ",";
+ std::cout << "\"rejected_breaker_open\":" << report.rejected_breaker_open << ",";
+ std::cout << "\"rejected_concurrency_full\":" << report.rejected_concurrency_full
+ << ",";
+ std::cout << "\"breaker_trips\":" << report.breaker_trips << ",";
+ std::cout << "\"breaker_recoveries\":" << report.breaker_recoveries << ",";
+ std::cout << "\"peak_inflight\":" << report.peak_inflight << ",";
+ std::cout << "\"min_tokens\":" << json_double(report.min_tokens) << ",";
+ std::cout << "\"admit_rate\":" << json_double(report.admit_rate) << ",";
+ std::cout << "\"shed_rate\":" << json_double(report.shed_rate) << ",";
+ std::cout << "\"observed_error_rate\":" << json_double(report.observed_error_rate)
+ << ",";
+ std::cout << "\"final_breaker_state\":\""
+ << tryops::breaker_state_name(report.final_state) << "\",";
+ std::cout << "\"max_shed_rate\":" << json_double(max_shed_rate) << ",";
+ std::cout << "\"gate_ok\":" << (gate_ok ? "true" : "false");
+ std::cout << "}\n";
+
+ return gate_ok ? 0 : 2;
+}
diff --git a/native/cpp/tryops_admission/tests/test_admission.cpp b/native/cpp/tryops_admission/tests/test_admission.cpp
new file mode 100644
index 0000000..0e50f22
--- /dev/null
+++ b/native/cpp/tryops_admission/tests/test_admission.cpp
@@ -0,0 +1,119 @@
+// Minimal assertion-based tests for the admission controller. Built and run by
+// `make native-admission-test`.
+#include "tryops_admission.hpp"
+
+#include
+#include
+#include
+#include
+
+namespace {
+
+int failures = 0;
+
+void check(bool cond, const char* what) {
+ if (!cond) {
+ std::printf("FAIL: %s\n", what);
+ failures += 1;
+ }
+}
+
+bool approx(double a, double b) { return std::fabs(a - b) < 1e-6; }
+
+// Rate limiting: a tight bucket with no refill admits exactly capacity/cost
+// requests issued at the same instant, sheds the rest.
+void test_rate_limit() {
+ std::string wire =
+ "bucket_capacity=3\nrefill_per_sec=0\nmax_concurrency=100\n";
+ for (int i = 0; i < 10; ++i) {
+ wire += "event=ts_ms=0;cost=1;duration_ms=0;outcome=ok\n";
+ }
+ const auto r = tryops::run_admission_wire(wire);
+ check(r.total == 10, "rate_limit total");
+ check(r.admitted == 3, "rate_limit admitted == capacity");
+ check(r.rejected_rate_limited == 7, "rate_limit rejected");
+ check(approx(r.admit_rate, 0.3), "rate_limit admit_rate");
+}
+
+// Refill restores burst capacity over time.
+void test_refill() {
+ // capacity 1, refill 1000/sec => 1 token per ms. Two events 1ms apart both
+ // admit because the second ms refills the spent token.
+ std::string wire =
+ "bucket_capacity=1\nrefill_per_sec=1000\nmax_concurrency=100\n"
+ "event=ts_ms=0;cost=1;duration_ms=0;outcome=ok\n"
+ "event=ts_ms=1;cost=1;duration_ms=0;outcome=ok\n";
+ const auto r = tryops::run_admission_wire(wire);
+ check(r.admitted == 2, "refill admits after replenish");
+}
+
+// Concurrency bulkhead: long-running requests occupy slots and block new ones
+// until they finish.
+void test_concurrency() {
+ std::string wire =
+ "bucket_capacity=1000\nrefill_per_sec=1000\nmax_concurrency=2\n";
+ // three simultaneous 100ms requests -> only 2 slots, third is shed
+ wire += "event=ts_ms=0;cost=1;duration_ms=100;outcome=ok\n";
+ wire += "event=ts_ms=0;cost=1;duration_ms=100;outcome=ok\n";
+ wire += "event=ts_ms=0;cost=1;duration_ms=100;outcome=ok\n";
+ // one after they finish -> admitted
+ wire += "event=ts_ms=200;cost=1;duration_ms=10;outcome=ok\n";
+ const auto r = tryops::run_admission_wire(wire);
+ check(r.rejected_concurrency_full == 1, "concurrency shed one");
+ check(r.peak_inflight == 2, "concurrency peak == limit");
+ check(r.admitted == 3, "concurrency admits after release");
+}
+
+// Circuit breaker: a burst of errors trips it open; later requests are shed
+// until the cooldown elapses, then a healthy probe closes it.
+void test_breaker() {
+ std::string wire =
+ "bucket_capacity=1000\nrefill_per_sec=1000\nmax_concurrency=1000\n"
+ "breaker_window=10\nbreaker_error_threshold=0.5\n"
+ "breaker_cooldown_ms=1000\nbreaker_min_samples=5\n";
+ // 6 errors in a row -> error rate 1.0 >= 0.5 with >=5 samples -> trips
+ for (int i = 0; i < 6; ++i) {
+ wire += "event=ts_ms=" + std::to_string(i) +
+ ";cost=1;duration_ms=0;outcome=error\n";
+ }
+ // immediately after, still within cooldown -> breaker_open rejects
+ wire += "event=ts_ms=10;cost=1;duration_ms=0;outcome=ok\n";
+ // after cooldown -> half-open probe, ok -> recover/close
+ wire += "event=ts_ms=2000;cost=1;duration_ms=0;outcome=ok\n";
+ const auto r = tryops::run_admission_wire(wire);
+ check(r.breaker_trips >= 1, "breaker tripped");
+ check(r.rejected_breaker_open >= 1, "breaker shed while open");
+ check(r.breaker_recoveries == 1, "breaker recovered");
+ check(r.final_state == tryops::BreakerState::kClosed, "breaker closed at end");
+}
+
+// All-healthy traffic under ample capacity admits everything, breaker stays
+// closed.
+void test_happy_path() {
+ std::string wire =
+ "bucket_capacity=1000\nrefill_per_sec=1000\nmax_concurrency=1000\n";
+ for (int i = 0; i < 50; ++i) {
+ wire += "event=ts_ms=" + std::to_string(i * 10) +
+ ";cost=1;duration_ms=1;outcome=ok\n";
+ }
+ const auto r = tryops::run_admission_wire(wire);
+ check(r.admitted == 50, "happy admits all");
+ check(approx(r.shed_rate, 0.0), "happy shed_rate zero");
+ check(r.final_state == tryops::BreakerState::kClosed, "happy stays closed");
+}
+
+} // namespace
+
+int main() {
+ test_rate_limit();
+ test_refill();
+ test_concurrency();
+ test_breaker();
+ test_happy_path();
+ if (failures == 0) {
+ std::printf("ok: all admission tests passed\n");
+ return 0;
+ }
+ std::printf("FAILED: %d admission checks\n", failures);
+ return 1;
+}
diff --git a/native/cpp/tryops_audit_log/include/tryops_audit_log.hpp b/native/cpp/tryops_audit_log/include/tryops_audit_log.hpp
new file mode 100644
index 0000000..74e9008
--- /dev/null
+++ b/native/cpp/tryops_audit_log/include/tryops_audit_log.hpp
@@ -0,0 +1,66 @@
+// TryOps native tamper-evident audit log.
+//
+// Maintains an append-only, hash-chained ledger of audit entries and a Merkle
+// tree over them. Any modification to a past entry changes the Merkle root and
+// breaks the hash chain, so tampering is detectable with a single root compare
+// plus O(log n) inclusion proofs. SHA-256 is implemented from scratch (no
+// external deps) so the engine is self-contained on the production boundary; it
+// is verified bit-for-bit against Python's hashlib in the test suite.
+#ifndef TRYOPS_AUDIT_LOG_HPP
+#define TRYOPS_AUDIT_LOG_HPP
+
+#include
+#include
+#include
+#include
+
+namespace tryops {
+
+// 32-byte SHA-256 digest rendered as lowercase hex.
+std::string sha256_hex(const std::string& data);
+
+struct AuditEntry {
+ std::string payload; // opaque audit record (e.g. a decision JSON)
+ std::string leaf_hash; // sha256(payload)
+ std::string chain_hash; // sha256(prev_chain_hash + leaf_hash)
+};
+
+struct InclusionProof {
+ std::size_t index = 0;
+ std::size_t tree_size = 0;
+ std::string leaf_hash;
+ // ordered sibling hashes from leaf to root, each tagged left/right
+ std::vector> siblings; // bool: sibling_is_right
+ std::string root;
+};
+
+class AuditLog {
+ public:
+ // Append a record; returns its index.
+ std::size_t append(const std::string& payload);
+
+ std::size_t size() const { return entries_.size(); }
+ const AuditEntry& entry(std::size_t i) const { return entries_.at(i); }
+ const std::string& chain_head() const { return chain_head_; }
+
+ // Merkle root over all leaf hashes (empty-tree root is sha256("")).
+ std::string merkle_root() const;
+
+ // Proof that entry `index` is included under the current root.
+ InclusionProof prove(std::size_t index) const;
+
+ // Recompute the chain from scratch and confirm it matches stored chain hashes
+ // — detects any in-place mutation of a past entry.
+ bool verify_chain() const;
+
+ private:
+ std::vector entries_;
+ std::string chain_head_; // sha256 of the whole chain so far
+};
+
+// Verify an inclusion proof against an expected root. Pure function.
+bool verify_inclusion(const InclusionProof& proof, const std::string& expected_root);
+
+} // namespace tryops
+
+#endif // TRYOPS_AUDIT_LOG_HPP
diff --git a/native/cpp/tryops_audit_log/src/tryops_audit_log.cpp b/native/cpp/tryops_audit_log/src/tryops_audit_log.cpp
new file mode 100644
index 0000000..734c140
--- /dev/null
+++ b/native/cpp/tryops_audit_log/src/tryops_audit_log.cpp
@@ -0,0 +1,191 @@
+#include "tryops_audit_log.hpp"
+
+#include
+
+namespace tryops {
+namespace {
+
+// ---- SHA-256 (FIPS 180-4), self-contained ----
+
+inline std::uint32_t rotr(std::uint32_t x, std::uint32_t n) {
+ return (x >> n) | (x << (32 - n));
+}
+
+const std::uint32_t kK[64] = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
+
+std::array sha256(const std::string& msg) {
+ std::uint32_t h[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
+
+ std::vector data(msg.begin(), msg.end());
+ const std::uint64_t bit_len = static_cast(data.size()) * 8;
+ data.push_back(0x80);
+ while (data.size() % 64 != 56) {
+ data.push_back(0x00);
+ }
+ for (int i = 7; i >= 0; --i) {
+ data.push_back(static_cast((bit_len >> (i * 8)) & 0xff));
+ }
+
+ for (std::size_t chunk = 0; chunk < data.size(); chunk += 64) {
+ std::uint32_t w[64];
+ for (int i = 0; i < 16; ++i) {
+ w[i] = (static_cast(data[chunk + i * 4]) << 24) |
+ (static_cast(data[chunk + i * 4 + 1]) << 16) |
+ (static_cast(data[chunk + i * 4 + 2]) << 8) |
+ (static_cast(data[chunk + i * 4 + 3]));
+ }
+ for (int i = 16; i < 64; ++i) {
+ const std::uint32_t s0 =
+ rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >> 3);
+ const std::uint32_t s1 =
+ rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >> 10);
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1;
+ }
+
+ std::uint32_t a = h[0], b = h[1], c = h[2], d = h[3];
+ std::uint32_t e = h[4], f = h[5], g = h[6], hh = h[7];
+ for (int i = 0; i < 64; ++i) {
+ const std::uint32_t S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
+ const std::uint32_t ch = (e & f) ^ (~e & g);
+ const std::uint32_t t1 = hh + S1 + ch + kK[i] + w[i];
+ const std::uint32_t S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
+ const std::uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
+ const std::uint32_t t2 = S0 + maj;
+ hh = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2;
+ }
+ h[0] += a; h[1] += b; h[2] += c; h[3] += d;
+ h[4] += e; h[5] += f; h[6] += g; h[7] += hh;
+ }
+
+ std::array out{};
+ for (int i = 0; i < 8; ++i) {
+ out[i * 4 + 0] = static_cast((h[i] >> 24) & 0xff);
+ out[i * 4 + 1] = static_cast((h[i] >> 16) & 0xff);
+ out[i * 4 + 2] = static_cast((h[i] >> 8) & 0xff);
+ out[i * 4 + 3] = static_cast(h[i] & 0xff);
+ }
+ return out;
+}
+
+std::string to_hex(const std::array& bytes) {
+ static const char* digits = "0123456789abcdef";
+ std::string out;
+ out.reserve(64);
+ for (std::uint8_t b : bytes) {
+ out.push_back(digits[b >> 4]);
+ out.push_back(digits[b & 0x0f]);
+ }
+ return out;
+}
+
+} // namespace
+
+std::string sha256_hex(const std::string& data) { return to_hex(sha256(data)); }
+
+std::size_t AuditLog::append(const std::string& payload) {
+ AuditEntry e;
+ e.payload = payload;
+ e.leaf_hash = sha256_hex(payload);
+ e.chain_hash = sha256_hex(chain_head_ + e.leaf_hash);
+ chain_head_ = e.chain_hash;
+ entries_.push_back(e);
+ return entries_.size() - 1;
+}
+
+std::string AuditLog::merkle_root() const {
+ if (entries_.empty()) {
+ return sha256_hex("");
+ }
+ std::vector level;
+ level.reserve(entries_.size());
+ for (const auto& e : entries_) {
+ level.push_back(e.leaf_hash);
+ }
+ while (level.size() > 1) {
+ std::vector next;
+ next.reserve((level.size() + 1) / 2);
+ for (std::size_t i = 0; i < level.size(); i += 2) {
+ if (i + 1 < level.size()) {
+ next.push_back(sha256_hex(level[i] + level[i + 1]));
+ } else {
+ // odd node is promoted (hashed with itself) — RFC 6962 style duplication
+ next.push_back(sha256_hex(level[i] + level[i]));
+ }
+ }
+ level = std::move(next);
+ }
+ return level.front();
+}
+
+InclusionProof AuditLog::prove(std::size_t index) const {
+ InclusionProof proof;
+ proof.index = index;
+ proof.tree_size = entries_.size();
+ proof.root = merkle_root();
+ if (index >= entries_.size()) {
+ return proof;
+ }
+ proof.leaf_hash = entries_[index].leaf_hash;
+
+ std::vector level;
+ for (const auto& e : entries_) {
+ level.push_back(e.leaf_hash);
+ }
+ std::size_t idx = index;
+ while (level.size() > 1) {
+ std::vector next;
+ for (std::size_t i = 0; i < level.size(); i += 2) {
+ const std::string& left = level[i];
+ const std::string& right = (i + 1 < level.size()) ? level[i + 1] : level[i];
+ if (i == idx || i + 1 == idx) {
+ const bool sibling_is_right = (idx % 2 == 0);
+ const std::string& sibling = sibling_is_right ? right : left;
+ proof.siblings.emplace_back(sibling, sibling_is_right);
+ }
+ next.push_back(sha256_hex(left + right));
+ }
+ idx /= 2;
+ level = std::move(next);
+ }
+ return proof;
+}
+
+bool AuditLog::verify_chain() const {
+ std::string head;
+ for (const auto& e : entries_) {
+ if (sha256_hex(e.payload) != e.leaf_hash) {
+ return false;
+ }
+ head = sha256_hex(head + e.leaf_hash);
+ if (head != e.chain_hash) {
+ return false;
+ }
+ }
+ return head == chain_head_;
+}
+
+bool verify_inclusion(const InclusionProof& proof, const std::string& expected_root) {
+ std::string computed = proof.leaf_hash;
+ for (const auto& sib : proof.siblings) {
+ if (sib.second) { // sibling on the right -> computed is left
+ computed = sha256_hex(computed + sib.first);
+ } else {
+ computed = sha256_hex(sib.first + computed);
+ }
+ }
+ return computed == expected_root && expected_root == proof.root;
+}
+
+} // namespace tryops
diff --git a/native/cpp/tryops_audit_log/src/tryops_audit_log_cli.cpp b/native/cpp/tryops_audit_log/src/tryops_audit_log_cli.cpp
new file mode 100644
index 0000000..cf8242f
--- /dev/null
+++ b/native/cpp/tryops_audit_log/src/tryops_audit_log_cli.cpp
@@ -0,0 +1,58 @@
+// Reads audit payloads (one per stdin line), builds the tamper-evident log, and
+// emits a JSON summary: size, Merkle root, chain head, chain-valid flag. With
+// --prove it also emits an inclusion proof and its verification result.
+// Exit code: 0 if the chain verifies (and any requested proof verifies), 2 else.
+#include "tryops_audit_log.hpp"
+
+#include
+#include
+#include
+
+int main(int argc, char** argv) {
+ long prove_index = -1;
+ for (int i = 1; i < argc; ++i) {
+ const std::string arg = argv[i];
+ if (arg == "--prove" && i + 1 < argc) {
+ prove_index = std::atol(argv[++i]);
+ }
+ }
+
+ tryops::AuditLog log;
+ std::string line;
+ while (std::getline(std::cin, line)) {
+ if (line.empty()) {
+ continue;
+ }
+ // allow an optional "entry=" prefix for symmetry with other engines
+ if (line.rfind("entry=", 0) == 0) {
+ line = line.substr(6);
+ }
+ log.append(line);
+ }
+
+ const std::string root = log.merkle_root();
+ const bool chain_ok = log.verify_chain();
+ bool proof_ok = true;
+
+ std::cout << "{";
+ std::cout << "\"size\":" << log.size() << ",";
+ std::cout << "\"merkle_root\":\"" << root << "\",";
+ std::cout << "\"chain_head\":\"" << log.chain_head() << "\",";
+ std::cout << "\"chain_valid\":" << (chain_ok ? "true" : "false");
+
+ if (prove_index >= 0 && static_cast(prove_index) < log.size()) {
+ const tryops::InclusionProof proof =
+ log.prove(static_cast(prove_index));
+ proof_ok = tryops::verify_inclusion(proof, root);
+ std::cout << ",\"proof\":{";
+ std::cout << "\"index\":" << proof.index << ",";
+ std::cout << "\"tree_size\":" << proof.tree_size << ",";
+ std::cout << "\"leaf_hash\":\"" << proof.leaf_hash << "\",";
+ std::cout << "\"path_len\":" << proof.siblings.size() << ",";
+ std::cout << "\"verified\":" << (proof_ok ? "true" : "false");
+ std::cout << "}";
+ }
+
+ std::cout << "}\n";
+ return (chain_ok && proof_ok) ? 0 : 2;
+}
diff --git a/native/cpp/tryops_audit_log/tests/test_audit_log.cpp b/native/cpp/tryops_audit_log/tests/test_audit_log.cpp
new file mode 100644
index 0000000..26edb04
--- /dev/null
+++ b/native/cpp/tryops_audit_log/tests/test_audit_log.cpp
@@ -0,0 +1,95 @@
+#include "tryops_audit_log.hpp"
+
+#include
+#include
+
+namespace {
+
+int failures = 0;
+
+void check(bool cond, const char* what) {
+ if (!cond) {
+ std::printf("FAIL: %s\n", what);
+ failures += 1;
+ }
+}
+
+// Known-answer tests against the SHA-256 spec / standard vectors.
+void test_sha256_kat() {
+ check(tryops::sha256_hex("") ==
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+ "sha256 empty");
+ check(tryops::sha256_hex("abc") ==
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
+ "sha256 abc");
+ check(tryops::sha256_hex(
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") ==
+ "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
+ "sha256 56-byte vector");
+}
+
+void test_root_and_proofs() {
+ tryops::AuditLog log;
+ for (int i = 0; i < 5; ++i) {
+ log.append("decision-" + std::to_string(i));
+ }
+ check(log.size() == 5, "size");
+ const std::string root = log.merkle_root();
+ check(root.size() == 64, "root is 32-byte hex");
+ check(log.verify_chain(), "chain valid after append");
+
+ // every leaf has a verifiable inclusion proof
+ for (std::size_t i = 0; i < log.size(); ++i) {
+ auto proof = log.prove(i);
+ check(tryops::verify_inclusion(proof, root), "inclusion proof verifies");
+ }
+ // a proof must NOT verify against a different root
+ auto p = log.prove(2);
+ check(!tryops::verify_inclusion(p, tryops::sha256_hex("not-the-root")),
+ "proof rejects wrong root");
+}
+
+void test_tamper_detection() {
+ tryops::AuditLog clean;
+ clean.append("a");
+ clean.append("b");
+ clean.append("c");
+ const std::string clean_root = clean.merkle_root();
+
+ // a log with a tampered middle entry yields a different root
+ tryops::AuditLog tampered;
+ tampered.append("a");
+ tampered.append("b-MUTATED");
+ tampered.append("c");
+ check(tampered.merkle_root() != clean_root, "tamper changes merkle root");
+ // the tampered log's own chain is internally consistent (attacker recomputed),
+ // but it cannot match the independently published clean root — that's the
+ // point of anchoring the root externally.
+ check(tampered.verify_chain(), "recomputed chain self-consistent");
+}
+
+void test_determinism() {
+ tryops::AuditLog a;
+ tryops::AuditLog b;
+ for (int i = 0; i < 8; ++i) {
+ a.append("e" + std::to_string(i));
+ b.append("e" + std::to_string(i));
+ }
+ check(a.merkle_root() == b.merkle_root(), "deterministic root");
+ check(a.chain_head() == b.chain_head(), "deterministic chain head");
+}
+
+} // namespace
+
+int main() {
+ test_sha256_kat();
+ test_root_and_proofs();
+ test_tamper_detection();
+ test_determinism();
+ if (failures == 0) {
+ std::printf("ok: all audit_log tests passed\n");
+ return 0;
+ }
+ std::printf("FAILED: %d audit_log checks\n", failures);
+ return 1;
+}
diff --git a/native/cpp/tryops_cache/include/tryops_cache.hpp b/native/cpp/tryops_cache/include/tryops_cache.hpp
new file mode 100644
index 0000000..4bca703
--- /dev/null
+++ b/native/cpp/tryops_cache/include/tryops_cache.hpp
@@ -0,0 +1,67 @@
+// TryOps native response cache: fixed-capacity LRU with per-entry TTL.
+//
+// Sits at the edge to short-circuit repeated identical requests (e.g. a
+// normalized prompt or a rendered VTON key). LRU eviction bounds memory; TTL
+// bounds staleness. Deterministic given an ordered event stream, so cache
+// behaviour (hit rate, evictions, expirations) is replayable and testable.
+#ifndef TRYOPS_CACHE_HPP
+#define TRYOPS_CACHE_HPP
+
+#include
+#include
+#include
+#include
+
+namespace tryops {
+
+struct CacheConfig {
+ std::size_t capacity = 1024;
+ std::int64_t ttl_ms = 60000; // default entry lifetime
+};
+
+struct CacheReport {
+ std::int64_t total = 0;
+ std::int64_t hits = 0;
+ std::int64_t misses = 0;
+ std::int64_t evictions = 0; // LRU evictions
+ std::int64_t expirations = 0; // TTL expirations observed on access
+ std::size_t final_size = 0;
+ double hit_rate = 0.0;
+};
+
+// LRU cache keyed by string. value payloads are irrelevant to the simulation, so
+// only presence + expiry are tracked.
+class LruTtlCache {
+ public:
+ explicit LruTtlCache(const CacheConfig& config);
+
+ // Look up a key at time `now_ms`. Returns true on a fresh hit. On a miss (or
+ // an expired entry) the key is inserted, possibly evicting the LRU entry.
+ bool access(const std::string& key, std::int64_t now_ms);
+
+ std::size_t size() const { return map_.size(); }
+ const CacheReport& report() const { return report_; }
+
+ private:
+ struct Node {
+ std::string key;
+ std::int64_t expire_at;
+ };
+
+ void touch(std::list::iterator it, std::int64_t now_ms);
+ void insert(const std::string& key, std::int64_t now_ms);
+
+ CacheConfig config_;
+ std::list lru_; // front = most-recently-used
+ std::unordered_map::iterator> map_;
+ CacheReport report_;
+};
+
+// Parse and run a wire stream:
+// capacity=... ttl_ms=...
+// event=ts_ms=;key=
+CacheReport run_cache_wire(const std::string& text);
+
+} // namespace tryops
+
+#endif // TRYOPS_CACHE_HPP
diff --git a/native/cpp/tryops_cache/src/tryops_cache.cpp b/native/cpp/tryops_cache/src/tryops_cache.cpp
new file mode 100644
index 0000000..da21dcf
--- /dev/null
+++ b/native/cpp/tryops_cache/src/tryops_cache.cpp
@@ -0,0 +1,113 @@
+#include "tryops_cache.hpp"
+
+#include
+#include
+#include
+#include
+
+namespace tryops {
+
+LruTtlCache::LruTtlCache(const CacheConfig& config) : config_(config) {
+ if (config_.capacity == 0) {
+ config_.capacity = 1;
+ }
+}
+
+void LruTtlCache::touch(std::list::iterator it, std::int64_t now_ms) {
+ it->expire_at = now_ms + config_.ttl_ms; // sliding TTL on access
+ lru_.splice(lru_.begin(), lru_, it); // move to front (MRU)
+}
+
+void LruTtlCache::insert(const std::string& key, std::int64_t now_ms) {
+ if (map_.size() >= config_.capacity) {
+ // evict least-recently-used (tail)
+ const Node& victim = lru_.back();
+ map_.erase(victim.key);
+ lru_.pop_back();
+ report_.evictions += 1;
+ }
+ lru_.push_front(Node{key, now_ms + config_.ttl_ms});
+ map_[key] = lru_.begin();
+}
+
+bool LruTtlCache::access(const std::string& key, std::int64_t now_ms) {
+ report_.total += 1;
+ auto found = map_.find(key);
+ if (found != map_.end()) {
+ auto it = found->second;
+ if (it->expire_at > now_ms) {
+ report_.hits += 1;
+ touch(it, now_ms);
+ report_.final_size = map_.size();
+ report_.hit_rate =
+ static_cast(report_.hits) / report_.total;
+ return true;
+ }
+ // expired: remove and fall through to miss/insert
+ report_.expirations += 1;
+ lru_.erase(it);
+ map_.erase(found);
+ }
+ report_.misses += 1;
+ insert(key, now_ms);
+ report_.final_size = map_.size();
+ report_.hit_rate = static_cast(report_.hits) / report_.total;
+ return false;
+}
+
+CacheReport run_cache_wire(const std::string& text) {
+ CacheConfig config;
+ LruTtlCache* cache = nullptr;
+ CacheReport last{};
+
+ std::istringstream stream(text);
+ std::string line;
+ // first pass: read config lines until the first event, then construct.
+ std::vector> events;
+ while (std::getline(stream, line)) {
+ if (line.empty()) {
+ continue;
+ }
+ const auto sep = line.find('=');
+ if (sep == std::string::npos) {
+ continue;
+ }
+ const std::string key = line.substr(0, sep);
+ const std::string value = line.substr(sep + 1);
+ if (key == "capacity") {
+ config.capacity = static_cast(std::atoll(value.c_str()));
+ } else if (key == "ttl_ms") {
+ config.ttl_ms = static_cast(std::atoll(value.c_str()));
+ } else if (key == "event") {
+ std::int64_t ts = 0;
+ std::string ekey;
+ std::istringstream fields(value);
+ std::string field;
+ while (std::getline(fields, field, ';')) {
+ const auto fsep = field.find('=');
+ if (fsep == std::string::npos) {
+ continue;
+ }
+ const std::string fk = field.substr(0, fsep);
+ const std::string fv = field.substr(fsep + 1);
+ if (fk == "ts_ms") {
+ ts = static_cast(std::atoll(fv.c_str()));
+ } else if (fk == "key") {
+ ekey = fv;
+ }
+ }
+ events.emplace_back(ts, ekey);
+ }
+ }
+
+ cache = new LruTtlCache(config);
+ for (const auto& ev : events) {
+ cache->access(ev.second, ev.first);
+ }
+ last = cache->report();
+ last.final_size = cache->size();
+ delete cache;
+ return last;
+}
+
+} // namespace tryops
diff --git a/native/cpp/tryops_cache/src/tryops_cache_cli.cpp b/native/cpp/tryops_cache/src/tryops_cache_cli.cpp
new file mode 100644
index 0000000..8d747f8
--- /dev/null
+++ b/native/cpp/tryops_cache/src/tryops_cache_cli.cpp
@@ -0,0 +1,40 @@
+// Reads a cache event wire stream on stdin, simulates the LRU+TTL cache, prints
+// a JSON report. Exit 0 if the hit rate meets --min-hit-rate, else 2.
+#include "tryops_cache.hpp"
+
+#include
+#include
+#include
+
+int main(int argc, char** argv) {
+ double min_hit_rate = 0.0;
+ for (int i = 1; i < argc; ++i) {
+ if (std::string(argv[i]) == "--min-hit-rate" && i + 1 < argc) {
+ min_hit_rate = std::atof(argv[++i]);
+ }
+ }
+
+ std::ostringstream buffer;
+ buffer << std::cin.rdbuf();
+ const tryops::CacheReport r = tryops::run_cache_wire(buffer.str());
+
+ std::ostringstream hr;
+ hr.setf(std::ios::fixed);
+ hr.precision(6);
+ hr << r.hit_rate;
+
+ const bool gate_ok = r.hit_rate >= min_hit_rate;
+
+ std::cout << "{";
+ std::cout << "\"total\":" << r.total << ",";
+ std::cout << "\"hits\":" << r.hits << ",";
+ std::cout << "\"misses\":" << r.misses << ",";
+ std::cout << "\"evictions\":" << r.evictions << ",";
+ std::cout << "\"expirations\":" << r.expirations << ",";
+ std::cout << "\"final_size\":" << r.final_size << ",";
+ std::cout << "\"hit_rate\":" << hr.str() << ",";
+ std::cout << "\"min_hit_rate\":" << min_hit_rate << ",";
+ std::cout << "\"gate_ok\":" << (gate_ok ? "true" : "false");
+ std::cout << "}\n";
+ return gate_ok ? 0 : 2;
+}
diff --git a/native/cpp/tryops_cache/tests/test_cache.cpp b/native/cpp/tryops_cache/tests/test_cache.cpp
new file mode 100644
index 0000000..ece0a8c
--- /dev/null
+++ b/native/cpp/tryops_cache/tests/test_cache.cpp
@@ -0,0 +1,80 @@
+#include "tryops_cache.hpp"
+
+#include
+#include
+
+namespace {
+
+int failures = 0;
+void check(bool cond, const char* what) {
+ if (!cond) { std::printf("FAIL: %s\n", what); failures += 1; }
+}
+
+// Repeated access to the same key hits after the first miss.
+void test_basic_hits() {
+ tryops::CacheConfig cfg; cfg.capacity = 10; cfg.ttl_ms = 1000;
+ tryops::LruTtlCache c(cfg);
+ check(!c.access("a", 0), "first access miss");
+ check(c.access("a", 1), "second access hit");
+ check(c.access("a", 2), "third access hit");
+ const auto& r = c.report();
+ check(r.hits == 2 && r.misses == 1, "hit/miss counts");
+}
+
+// LRU eviction: capacity 2, three distinct keys -> first is evicted.
+void test_lru_eviction() {
+ tryops::CacheConfig cfg; cfg.capacity = 2; cfg.ttl_ms = 100000;
+ tryops::LruTtlCache c(cfg);
+ c.access("a", 0);
+ c.access("b", 1);
+ c.access("c", 2); // evicts "a" (LRU)
+ check(!c.access("a", 3), "evicted key misses"); // miss -> reinsert, evicts "b"
+ check(c.report().evictions >= 2, "evictions counted");
+}
+
+// TTL expiry: an entry past its TTL is a miss.
+void test_ttl_expiry() {
+ tryops::CacheConfig cfg; cfg.capacity = 10; cfg.ttl_ms = 100;
+ tryops::LruTtlCache c(cfg);
+ c.access("k", 0);
+ check(c.access("k", 50), "within ttl hit");
+ check(!c.access("k", 1000), "past ttl miss"); // sliding ttl from t=50 -> expires by 1000
+ check(c.report().expirations >= 1, "expiration counted");
+}
+
+// Hot-key workload yields a high hit rate via the wire runner.
+void test_hot_key_hit_rate() {
+ std::string wire = "capacity=100\nttl_ms=1000000\n";
+ // 1000 accesses, 90% to a small hot set of 5 keys
+ for (int i = 0; i < 1000; ++i) {
+ const int k = (i % 10 < 9) ? (i % 5) : (100 + i);
+ wire += "event=ts_ms=" + std::to_string(i) + ";key=hk-" + std::to_string(k) + "\n";
+ }
+ auto r = tryops::run_cache_wire(wire);
+ check(r.total == 1000, "total");
+ check(r.hit_rate > 0.6, "hot-key hit rate high");
+}
+
+// LRU keeps recently-used keys: re-touching a key prevents its eviction.
+void test_recency_protects() {
+ tryops::CacheConfig cfg; cfg.capacity = 2; cfg.ttl_ms = 100000;
+ tryops::LruTtlCache c(cfg);
+ c.access("a", 0);
+ c.access("b", 1);
+ c.access("a", 2); // a is now MRU
+ c.access("c", 3); // evicts b (LRU), not a
+ check(c.access("a", 4), "recently-used key survived");
+}
+
+} // namespace
+
+int main() {
+ test_basic_hits();
+ test_lru_eviction();
+ test_ttl_expiry();
+ test_hot_key_hit_rate();
+ test_recency_protects();
+ if (failures == 0) { std::printf("ok: all cache tests passed\n"); return 0; }
+ std::printf("FAILED: %d cache checks\n", failures);
+ return 1;
+}
diff --git a/native/cpp/tryops_cost/include/tryops_cost.hpp b/native/cpp/tryops_cost/include/tryops_cost.hpp
new file mode 100644
index 0000000..2394f5e
--- /dev/null
+++ b/native/cpp/tryops_cost/include/tryops_cost.hpp
@@ -0,0 +1,64 @@
+// TryOps native cost-attribution (FinOps showback/chargeback) engine.
+//
+// Turns a per-request usage stream (tokens, GPU-seconds, energy) into auditable
+// per-tenant and per-model cost + carbon breakdowns. The arithmetic lives in a
+// compiled engine so chargeback numbers are exact and reproducible at the
+// boundary, consistent with the green-MLOps energy methodology
+// (GPU $/hr dominates; electricity and carbon priced from grid intensity).
+#ifndef TRYOPS_COST_HPP
+#define TRYOPS_COST_HPP
+
+#include
+#include