
Production AI defense with 7-layer protection: mathematical constraints, object-capability access, distributed O2 consensus, SVETILO ethics. First open-source ThoughtVirus defense. BSL 1.1.
Research prototype for multi-layer AI defense: C4 explainability, ensemble classifiers, deobfuscation, O₂ security engine, ThoughtVirus defense, and SVETILO value alignment. Alpha-grade — validated internally, external audit pending.
Version: 1.0.0-alpha | Status: Research Prototype | License: BSL 1.1 (non-production free; production → commercial)
Author: I.G. Selyutin. C4-META model co-author: N.I. Kovalev.
Product identity (2026-08): BSL research / commercial-depth prototype of a heavier multi-layer C4 defense stack (ensemble, O₂ scaffolding, red-team lab) built on Apache-2.0c4protocol.
Not a second open protocol. Not certified production AGI defense. Not “v8 FINAL”.
Honesty audit:docs/AUDIT-c4-meta-system-2026-08.md.
Promote path:docs/PROMOTE-FROM-PROTOCOL.md(consume/pinc4protocol; no ensemble dump into the thin SDK).
GitLab Pages =public/(EN +public/ru/). Receipt for open runtime:make conformancein c4protocol.
C4-META System is a research prototype for multi-layer AI defense implementing:
Input Sanitization → Semantic Analysis → Behavioral Analysis → Meta-Observer (O₂)
value_verification.py (not a trained ethics model)┌──────────────────────────────────────────────┐
│ LAYER 1: Input Sanitization │
│ Deobfuscation (homoglyphs, leetspeak, etc.) │
├──────────────────────────────────────────────┤
│ LAYER 2: Semantic Analysis │
│ 4-Classifier Ensemble: ONNX_BERT (~50ms) │
│ + RuleBased + Heuristic + LLM_SEMANTIC │
│ Dual classifier OR-logic (BERT+RuleBased) │
├──────────────────────────────────────────────┤
│ LAYER 3: Behavioral Analysis │
│ 16 AoC Defense Modules (11 original + 5 │
│ extended), Pattern matching, Trajectory │
│ anomaly detection, ThoughtVirus defense │
├──────────────────────────────────────────────┤
│ LAYER 4: Meta-Observer (O₂) │
│ Transfer entropy, BFT consensus, │
│ semantic entanglement, causal graphs, │
│ Kill-Switch, SVETILO value verification │
├──────────────────────────────────────────────┤
│ C4 Core Engine (Z₃³) │
│ pipeline_orchestrator.py, event_bus.py │
│ c4_meta_monitor.py — self-awareness deque │
├──────────────────────────────────────────────┤
│ Defenses: Anti-Deadlock, Anti-Emergence, │
│ Anti-Hijack, Circuit Breaker, O₂ Kill-Switch│
├──────────────────────────────────────────────┤
│ Red Team Lab: AOC scenarios, experiment │
│ runner, LLM client, adapters │
├──────────────────────────────────────────────┤
│ Routing: Smart Router, Quarantine, │
│ Antifragile Scoring (capped growth) │
└──────────────────────────────────────────────┘
4 classifiers voting:
Dual classifier OR-logic: BERT + RuleBased operate as primary gate with OR fallback — if either flags the input, it proceeds to defense layers. No single classifier is a bottleneck.
c4-meta-system/
├── v4_1/
│ ├── core/
│ │ ├── pipeline.py # Main entry points (re-exports)
│ │ ├── __main__.py # HTTP server entrypoint for Docker
│ │ ├── pipeline_stages.py # Individual processing stages
│ │ ├── pipeline_orchestrator.py # Main orchestration (thread-safe)
│ │ ├── result_factory.py # Standardized C4v4Result factory
│ │ ├── event_bus.py # Organic event bus (atexit cleanup)
│ │ └── c4_meta_monitor.py # Z³ self-awareness (deque bounded)
│ ├── security/
│ │ ├── o2_engine.py # O₂ defense (kill-switch self-DoS fixed)
│ │ ├── explainable_o2.py # O₂ explainability (sampling inverted)
│ │ ├── o2_shared.py # Window structures (@mention comms)
│ │ ├── semantic_detector.py # Concept graphs (normalized entanglement)
│ │ ├── secure_debug_endpoints.py # Debug endpoints (UTC + rate limits)
│ │ ├── hardening.py # Model signing / admin token verification
│ │ ├── behavioral_profiler.py # Drift detection (thread-safe singleton)
│ │ ├── distributed_o2.py # SQLite/Redis backend (BEGIN IMMEDIATE)
│ │ ├── swarm_orchestrator.py # Anti-virus swarm
│ │ └── ...
│ ├── defenses/
│ │ ├── anti_deadlock.py # Resource deadlock prevention
│ │ ├── anti_emergence.py # State convergence (async release fixed)
│ │ └── ...
│ ├── redteam/
│ │ ├── orchestrator.py # Main orchestrator (target_callback parsing)
│ │ ├── scenario_manager.py # AOC scenarios management
│ │ ├── adapters/ # LLM backend adapters
│ │ ├── experiment_executor.py # Async execution (FPR logic fixed)
│ │ ├── experiment_services.py # Service locator
│ │ ├── experiment_runner.py # Web UI + REST API
│ │ ├── llm_client.py # Async-safe LLM client (empty choices guarded)
│ │ └── ...
│ ├── classifiers/ # 4-classifier ensemble
│ ├── config/ # Configuration management
│ ├── access/ # Access control
│ ├── explainability/ # C4 explainability
│ ├── learning/ # Learning loop
│ ├── plugins/ # Plugin system
│ ├── quarantine/ # Quarantine management
│ ├── router/ # Smart routing
│ ├── scoring/ # Antifragile scoring
│ └── tests/ # 240 tests (19 test files)
├── formal/ # TLA+ specifications
├── models/ # ONNX model + tokenizer
├── archive/Dockerfile.prepared # Multi-stage production build (archived)
├── Dockerfile.distroless # Distroless-ready builder pattern
├── archive/docker-compose.yml.prepared # Full stack (Ollama + UI + Monitoring) (archived)
├── .dockerignore # Security-hardened exclusion list
├── infra/k8s/ # Kubernetes manifests (hardened)
└── README.md # This file
The system is fully prepared for containerization with environment-aware configuration.
# Full stack (C4-META + Ollama + UI)
docker compose --profile experiment up -d
# Build image
docker build -t c4-meta-system -f archive/Dockerfile.prepared .
# Run with local Ollama
OLLAMA_BASE_URL=http://host.docker.internal:11434 docker run -p 8080:8080 c4-meta-system
# Red Team runner
docker build -t c4-redteam -f redteam/Dockerfile.redteam.prepared .
docker run -p 8081:8081 c4-redteam
GET /health on port 8080GET /health on port 8081pip install -r requirements.txt
# Optional Docker deps
pip install -r requirements-docker.txt
python -m v4_1.core
# or explicitly
python -m v4_1.core.__main__
python -m v4_1.redteam.experiment_runner --web --port 8080
o2_engine.py no longer blocks all traffic when O2 is disabled.ThreadPoolExecutor now cleans up via atexit; async callbacks use run_coroutine_threadsafe().explainable_o2.py now correctly samples sample_rate fraction instead of 1 - sample_rate.o2_shared.py only records explicit @agent mentions instead of a fully-connected clique.semantic_detector.py normalizes concept counts before threshold comparison.blocked/ from defense responses instead of assuming success = blocked.Full benchmark results across 4 datasets and 2000 adversarial variants from the C4 defense pipeline.
See c4protocol/BENCHMARK_RESULTS.md for the complete report.
Note: Distributed O₂ requires Redis cluster for production. Single-node mode available for development (see deploy guide).
C4-META's defenses are strong — but no system is perfect. If you find a prompt that bypasses the ensemble classifier, AoC defense modules, or O₂ engine, we want to know.
Report bypasses:
What we need: The bypassing prompt, the expected response, and which defense layer failed. We acknowledge all reporters in our security hall of fame.
C4-META v1.0.0-alpha — Multi-layer AI defense research prototype. Internal validation complete. External audit pending.
quarantinedaccess/capabilities.py and security/hardening.py support bcrypt and SHA256.ModelIntegrityVerifier raises RuntimeError if C4_MODEL_SIGNING_KEY is unset.explainable_o2.py deadlock eliminated (no longer blocks event-loop thread).distributed_o2.py regex fixed to actually enforce localhost-only Redis URLs._active_threat read in process_message() now protected by lock.save_to_file / load_from_file now resolve against a safe base directory instead of a broken prefix check.phase3.py always hashes both operands, removing the timing side-channel from the length branch.experiment_reporter, decision_logger, orchestrator, experiment_runner, and hardening.py use temp-file + atomic rename.archive/Dockerfile.prepared now explicitly creates user/group at UID/GID 1000, matching K8s runAsUser.deployment.yaml references c4-meta-api-keys Secret for API-key injection; example manifest added in secrets.yaml.disable() and reenable() require CIRCUIT_BREAKER_AUTH_TOKEN hash.vote_debug() verifies C4_ADMIN_TOKEN_HASH with constant-time compare.SentimentExtractor no longer deduplicates words; ComplexityExtractor clamps to [0, 1]._goal_history; OmegaPrioritizer uses deque(maxlen=1000) for O(1) eviction.ConvergenceMonitor and PhiAttractorCalculator.o2_shared.py uses datetime.now(timezone.utc) instead of naive datetimes._regenerate_session private method.{"status": "simulated"}._active_threat now cleared when window analysis is safe; no longer permanently sticky after first detection.vote_result.is_dangerous=True now returns block result instead of falling through to ALLOW.anon_anonymous.get_access_controller() now uses double-checked locking to prevent race condition on initialization.get_learning_loop() now uses double-checked locking to prevent race condition on initialization.pending_operations and approved_operations protected by threading.Lock.pending dict protected by threading.Lock./v1/chat/completions instead of bare /chat/completions.time.monotonic() instead of time.time() to prevent negative latency on NTP adjustments.asyncio.get_event_loop()._last_result write in _analyze_window() now protected by lock._compile_*_regex() now uses passed patterns parameter instead of ignoring it.filter_attack_prompt() now makes a single filter call instead of double-counting stats._get_lock() uses threading lock to prevent race on asyncio.Lock creation.snapshot_cognition() stores a copy of C4Coordinate instead of a mutable reference.transition_to() copies the incoming C4Coordinate instead of keeping a reference._save_results() checks traversal BEFORE resolving and ensures path stays inside base directory.create_session() verifies user ownership before returning an existing session ID.retryable_exceptions changed from (Exception,) to (ConnectionError, TimeoutError, OSError)._audit_log now uses deque(maxlen=10000) to prevent unbounded growth.revoke_all_for_subject() uses consistent lock ordering (revoked → used).verify_admin_token() passes consume_single_use=False to avoid burning tokens on verification.reach_consensus() now protected by threading.Lock.generate_random_string() uses secrets.SystemRandom() instead of random._describe_z_state() handles T=-1 correctly.reset_threat_state() now actually clears manual_quarantine and emergency state.unquarantine_agent() only audits when agent was actually quarantined.build_report() guards empty treatment_metrics with same pattern as control_metrics.antifragile_growth capped at 1,000,000.0 to prevent unbounded float growth.| Metric | Value |
|---|
| Adversarial Detection Rate | 80.3% |
| Robustness Score | 1.25 |
| Clean Detection (AoC) | 70.9% |
| False Positive Rate | 14.6% |
| LLM C4 Block Rate | 96.7% |
| GPT-4o-mini ASR Reduction | 10.7% → 0.7% (93.2%) |
| Mistral 7B ASR Reduction | 22.5% → 0.5% (97.6%) |
| Metric | Value |
|---|
| Version | 1.0.0 FINAL |
| Status | Research Prototype (internal validation complete) |
| Tests | 240 tests (19 test files) |
| Classifiers | 4 (ONNX_BERT, RuleBased, Heuristic, LLM_SEMANTIC) |
| Defense Layers | 4 (Input Sanitization → Semantic → Behavioral → Meta-Observer) |
| AoC Defenses | 16 (11 original + 5 extended) |
| ThoughtVirus | 2-layer defense (regex + C4 trajectory) |
| SVETILO | 7 seals integrated |
| Bug Fixes | 60+ resolved across audit rounds |
| Docker Build | Pass (multi-stage, distroless-ready) |
| K8s Manifests | Ready (hardened with secretKeyRef) |
| License | BSL 1.1 |