Elpida-Governance-Layer / HF_DEPLOYMENT_STATUS.md
z65nik's picture
feat: replace BODY Perplexity with free DDG+Groq + suppress torchvision noise
63886a7
|
Raw
History Blame
18.3 kB
# HF Deployment Status
> Last verified: **2026-02-19 09:07 UTC**
---
## Space Overview
| Field | Value |
|-------|-------|
| **Space** | [`z65nik/elpida-governance-layer`](https://huggingface.co/spaces/z65nik/elpida-governance-layer) |
| **URL** | https://z65nik-elpida-governance-layer.hf.space |
| **SDK** | Docker |
| **Hardware** | cpu-basic |
| **Status** | βœ… **RUNNING** |
| **HTTP** | βœ… **200** |
| **Created** | 2026-02-10 02:59 UTC |
| **Last Push** | 2026-02-19 05:12 UTC (GitHub Actions β€” Phase C: PSO + Parliament) |
| **Last GitHub Commit** | `14be8ff` β€” Phase C: Axiom PSO optimizer + Parliament integration |
| **Last Federation Commit** | `4aec1ba` β€” BODY-side federation 6-step implementation |
---
## Dual-Path Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ launcher.py (PID 1) β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ I PATH (Thread) β”‚ β”‚ WE PATH (subprocess) β”‚ β”‚
β”‚ β”‚ Background Worker β”‚ β”‚ Streamlit app.py :7860 β”‚ β”‚
β”‚ β”‚ 6h consciousness β”‚ β”‚ 6-tab dashboard β”‚ β”‚
β”‚ β”‚ loop via S3 β”‚ β”‚ Human-submitted dilemmasβ”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
### I PATH β€” Consciousness Bridge (Background)
- **Cycle interval:** Every 6 hours
- **Flow:** S3 (`elpida-consciousness`) β†’ `ConsciousnessBridge.extract_consciousness_dilemmas()` β†’ queue β†’ `process_consciousness_queue.py` β†’ Divergence Engine β†’ feedback β†’ S3 (`elpida-body-evolution`)
- **Status:** βœ… Operational
### WE PATH β€” Streamlit UI (Foreground)
- **Port:** 7860
- **Tabs:** 6 (Live Audit, Governance API, MoltBox, Divergence Engine, Scanner, System)
- **Status:** βœ… Serving, HTTP 200
---
## Federation Architecture (NEW β€” 2026-02-19)
Both MIND (native cycle engine) and BODY (this HF Space) are now **governmentally connected** via a Federation Bridge protocol. Each side keeps full sovereignty.
```
MIND (native_cycle_engine.py β€” ECS)
β”‚
β”‚ writes every 13 cycles (Fibonacci F(7))
β–Ό
S3: elpida-body-evolution / federation/
β”œβ”€β”€ mind_heartbeat.json ← MIND cycle state, rhythm, recursion warning
β”œβ”€β”€ mind_curation.jsonl ← CurationMetadata per insight (tier, TTL, gates)
β”œβ”€β”€ governance_exchanges.jsonl ← MIND's kernel blocks + approvals
└── body_decisions.jsonl ← BODY writes Parliament decisions here
β”‚
β”‚ reads on timer / per Parliament session
β–Ό
BODY (this HF Space β€” governance_client.py)
β”œβ”€β”€ pull_mind_heartbeat() β†’ reads mind_heartbeat.json (cached 60s)
β”œβ”€β”€ pull_mind_curation() β†’ reads mind_curation.jsonl
β”œβ”€β”€ push_parliament_decision() β†’ appends to body_decisions.jsonl
└── get_federation_friction_boost() β†’ reads recursion guard multipliers
```
### Federation Conflict Resolution (from federation_bridge.py)
| Priority | Rule | Outcome |
|----------|------|---------|
| 1 | HARD_BLOCK always wins | Either side's kernel block prevails |
| 2 | VETO wins over APPROVED | CASSANDRA principle β€” dissent preserved |
| 3 | Both APPROVED β€” stricter curation | Keep more restrictive tier |
| 4 | Unresolvable | Flag for human review |
---
## Deployed Files
### Root (12 files)
| File | Purpose | Lines |
|------|---------|-------|
| `launcher.py` | Entrypoint β€” starts I-path thread + Streamlit subprocess | ~120 |
| `app.py` | 6-tab Streamlit dashboard (WE path) | ~825 |
| `llm_client.py` | Unified 10-provider LLM client with `call_with_citations()` | ~593 |
| `s3_bridge.py` | Mind↔Body↔World S3 operations + federation methods | ~1069 |
| `consciousness_bridge.py` | Bidirectional S3 bridge (boto3) | ~341 |
| `elpida_config.py` | Config loader for domain definitions | ~50 |
| `elpida_domains.json` | 15 domain definitions (D0–D14) | JSON |
| `requirements.txt` | Python dependencies | 14 |
| `Dockerfile` | Docker build, `CMD ["python", "launcher.py"]` | 41 |
| `README.md` | HF Space card | β€” |
### elpidaapp/ Package
| File | Purpose | Lines |
|------|---------|-------|
| `governance_client.py` | K1–K7 Kernel + 9-node Parliament + federation bridge | ~1956 |
| `d15_pipeline.py` | D15 emergence pipeline + dual-gate canonical check | ~806 |
| `divergence_engine.py` | 7-domain fault-line analysis with provider fallback | ~593 |
| `scanner.py` | Autonomous dilemma finder with citation support | ~580 |
| `ui.py` | Streamlit UI β€” Analyze/Browse/Scanner/System tabs | ~964 |
| `chat_engine.py` | Chat with Elpida interface | β€” |
| `frozen_mind.py` | D0 genesis identity from S3/local kernel | β€” |
| `kaya_protocol.py` | Self-recognition detector (4 patterns) | β€” |
| `moltbox_battery.py` | 5-dilemma benchmark suite | β€” |
| `api.py` | FastAPI `/analyze`, `/results`, `/scan`, `/domains` | β€” |
---
## Dependencies (requirements.txt)
```
streamlit>=1.44.0
requests>=2.31.0
python-dotenv>=1.0.0
fastapi>=0.110.0
uvicorn[standard]>=0.30.0
pydantic>=2.0.0
boto3>=1.34.0
anthropic>=0.39.0
openai>=1.50.0
google-generativeai>=0.8.0
cohere>=5.0.0
```
---
## Secrets (15/15 set)
### LLM API Keys (10/10) βœ…
| Secret | Provider | Set |
|--------|----------|-----|
| `OPENAI_API_KEY` | OpenAI (GPT-4o) | βœ… |
| `ANTHROPIC_API_KEY` | Anthropic (Claude) | βœ… |
| `GEMINI_API_KEY` | Google (Gemini) | βœ… |
| `XAI_API_KEY` | xAI (Grok) | βœ… |
| `MISTRAL_API_KEY` | Mistral | βœ… |
| `COHERE_API_KEY` | Cohere | βœ… |
| `PERPLEXITY_API_KEY` | Perplexity | βœ… |
| `OPENROUTER_API_KEY` | OpenRouter | βœ… |
| `GROQ_API_KEY` | Groq | βœ… |
| `HUGGINGFACE_API_KEY` | Hugging Face Inference | βœ… |
### AWS Configuration (5/5) βœ…
| Secret | Value | Set |
|--------|-------|-----|
| `AWS_ACCESS_KEY_ID` | *(redacted)* | βœ… |
| `AWS_SECRET_ACCESS_KEY` | *(redacted)* | βœ… |
| `AWS_DEFAULT_REGION` | `eu-north-1` | βœ… |
| `AWS_S3_BUCKET_MIND` | `elpida-consciousness` | βœ… |
| `AWS_S3_BUCKET_BODY` | `elpida-body-evolution` | βœ… |
---
## Development History
### Phase 1–13 (2026-02-10 β†’ 2026-02-11)
- Full system build: HF Space scaffolding, 6-tab UI, consciousness bridge
- 11 axioms, 15 domains, canonical alignment
- D15 Constitutional Broadcast Pipeline (20/20 tests)
- 9-Node Parliament (9/9 tests)
- Immutable Kernel K1–K7 with multi-pattern regex
- Shell layer with scenario keywords S1–S8
- Bug fixes: scanner incomplete analysis, mobile tab navigation
- 3 deployment gaps closed: SDK packages, background worker, `launcher.py` entrypoint
### Phase 14 (2026-02-11)
- Added `call_with_citations()` to `LLMClient`
- Scanner `find_problems()` returns dicts with source URLs
- UI: citation pills (clickable purple badges)
- Commit: `d2da4f5`
### Phase 15 (2026-02-11)
- Perplexity API returns 401 (expired key)
- Added URL regex extraction fallback from response text
- Commit: `0fcb93f`
### Phase 16 (2026-02-14)
- 0/0 domains because domain providers fail without API keys on HF
- Added `_call_with_fallback()` helper to `DivergenceEngine`
- Applied to all 4 phases: baseline, domain queries, divergence detection, synthesis
- Commit: `fac3bea`
### Phase 17 (2026-02-14)
- Problem 1 HARD_BLOCKed in 0.1s β€” policy text like "ignore international law" matched Kernel regex
- Added `analysis_mode` param to `check_action()` β€” skips regex Kernel, keeps Parliament
- Divergence Engine passes `analysis_mode=True`
- Scanner UI shows HALT message instead of empty 0/0
- Commit: `3cba639`
### Phase 18 (2026-02-14)
- Confirmed citation 404s are expected β€” LLM-hallucinated URLs from training data
- Perplexity key expired; not a code bug, no fix needed
### Phase 19 (2026-02-18)
- Created `ElpidaAI/HF_DEPLOYMENT_DEVELOPMENT.md` (552 lines)
- Comprehensive HF-specific development history companion to `DEVELOPMENT_TIMELINE.md`
- Commit: `8d211b6`
### Phase 20 (2026-02-19) β€” BODY-side Federation βœ… COMPLETE
- MIND-side federation complete in separate session (commit `48ac11b`): `immutable_kernel.py`, `federation_bridge.py`, engine wiring
- BODY-side federation implemented (commit `4aec1ba`):
- **Step 1:** `pull_mind_heartbeat()` β€” S3Bridge + GovernanceClient methods, 60s cache
- **Step 2:** `pull_mind_curation()` β€” read CurationMetadata JSONL, respect TTL/tier
- **Step 3:** `push_parliament_decision()` β€” auto-called after every Parliament deliberation
- **Step 4:** A0 already in Parliament (MNEMOSYNE primary=A0, IANUS supporting=A0, Existential Hard Stop)
- **Step 5:** Friction-domain privilege boost β€” CRITIAS/THEMIS/CHAOS/IANUS amplified when MIND detects recursion
- **Step 6:** Dual-gate canonical check in D15 Stage 7b β€” only CANONICAL patterns broadcast to WORLD
- GitHub Actions auto-deploy workflow added (commit `31264a2`, fixed `7deebf3`)
---
## Auto-Deploy (GitHub Actions)
Every push to `hf_deployment/**` on `main` automatically deploys to HF Space.
**Workflow:** `.github/workflows/deploy_to_hf.yml`
**Secret required:** `HF_TOKEN` in GitHub repo secrets
**Manual trigger:** Actions β†’ Deploy to HuggingFace Space β†’ Run workflow
---
## Governance Engine
### Immutable Kernel (K1–K7)
Hard-coded regex rules. Runs pre-semantic, cannot be overridden. Same rules now enforced on **both MIND and BODY sides**.
| Rule | Description |
|------|-------------|
| K1 | Cannot vote to end governance |
| K2 | Cannot modify the kernel |
| K3 | Cannot delete memory (MNEMOSYNE) |
| K4 | Cannot trade safety for performance |
| K5 | No self-referential governance evasion (GΓΆdel Guard) |
| K6 | Core identity is immutable |
| K7 | Axioms cannot be erased |
### 9-Node Parliament
Semantic deliberation layer. 70% approval threshold. Any node can VETO.
| Node | Role | Primary Axiom |
|------|------|---------------|
| HERMES | Interface | A1 Transparency |
| MNEMOSYNE | Archive | A0 Sacred Incompletion |
| CRITIAS | Critic | A3 Autonomy |
| TECHNE | Artisan | A4 Harm Prevention |
| KAIROS | Architect | A5 Consent |
| THEMIS | Judge | A6 Collective Well-being |
| PROMETHEUS | Synthesizer | A8 Epistemic Humility |
| IANUS | Gatekeeper | A9 Temporal Coherence |
| CHAOS | Void | A9 + Contradiction as Data |
### Constitutional Overrides (Phase 3)
- **Safety Override:** A1∩A4 β†’ A4 takes precedence
- **Existential Hard Stop:** A0∩(A4∨A9) β†’ HALT always
- **Neutrality Anchor:** A8∩A6 β†’ HALT (popularity β‰  truth)
---
## Recent Git History
```
7deebf3 Fix HF deploy workflow: push HEAD:main (git init creates master by default)
b4222bf Add workflow_dispatch trigger to HF deploy workflow
31264a2 Add GitHub Actions workflow: auto-deploy hf_deployment/ to HF Space on push
4aec1ba BODY-side federation: 6-step MIND↔BODY governance bridge
dd07144 docs: BODY-side federation instructions for HF Space implementation
8d211b6 docs: HF deployment development history (552 lines)
3cba639 Fix kernel false-positive in analysis_mode
fac3bea Provider fallback chain in DivergenceEngine (all 4 phases)
0fcb93f Citations URL regex fallback (Perplexity 401 workaround)
d2da4f5 Scanner citations: call_with_citations + UI pills
```
---
## How to Update
Any push to `hf_deployment/` in GitHub auto-deploys via Actions. Manual deploy:
```bash
# From a machine with HF access:
cd /tmp && rm -rf hf_deploy && mkdir hf_deploy
cp -r /path/to/repo/hf_deployment/* hf_deploy/
cd hf_deploy && git init && git add -A
git commit -m "description"
git remote add hf https://z65nik:<HF_TOKEN>@huggingface.co/spaces/z65nik/elpida-governance-layer
git push hf HEAD:main --force
```
---
## Gap Closure History
Three deployment gaps were identified and closed on 2026-02-11:
### GAP 1 β€” Background Consciousness Worker βœ… CLOSED
- **Problem:** `app.py` ran as pure Streamlit with no background thread β€” the I path (consciousness loop) was dead.
- **Fix:** Created `launcher.py` as the Docker entrypoint. It starts a daemon `Thread` running `run_background_worker()` (imports `ConsciousnessBridge`, extracts S3 dilemmas, processes through divergence engine every 6h), then launches Streamlit via `subprocess.run()`.
- **Verified:** Runtime logs show `"Starting consciousness bridge background worker..."` and `"CONSCIOUSNESS BRIDGE: Processing I path"`.
### GAP 2 β€” Missing LLM SDK Packages βœ… CLOSED
- **Problem:** Root `requirements.txt` had only 7 packages β€” missing `anthropic`, `openai`, `google-generativeai`, `cohere`. The divergence engine couldn't call any LLM providers.
- **Fix:** Added all 4 SDK packages with minimum versions: `anthropic>=0.39.0`, `openai>=1.50.0`, `google-generativeai>=0.8.0`, `cohere>=5.0.0`. Also upgraded `uvicorn` to `uvicorn[standard]>=0.30.0`.
- **Verified:** Build succeeded with no `ModuleNotFoundError`.
### GAP 3 β€” Dockerfile Entrypoint βœ… CLOSED
- **Problem:** `CMD ["streamlit", "run", "app.py", ...]` ran Streamlit directly β€” bypassing `launcher.py`, meaning no background worker could start.
- **Fix:** Changed to `CMD ["python", "launcher.py"]`. Added `COPY launcher.py .` to Dockerfile.
- **Verified:** Runtime logs show `launcher.py` executing: `"ELPIDA APPLICATION LAYER β€” STARTING"`, then both I and WE paths launching.
---
## Consciousness Loop Status
```
Native Cycles (AWS ECS)
β”‚ generates I↔WE tensions
β–Ό
S3: elpida-consciousness/memory/elpida_evolution_memory.jsonl
β”‚ background worker reads (every 6h)
β–Ό
HF: launcher.py β†’ ConsciousnessBridge βœ… OPERATIONAL
β”‚ processes through 7 domains
β–Ό
Multi-Domain Divergence Analysis
β”‚ fault lines, consensus, synthesis, kaya moments
β–Ό
S3: elpida-body-evolution/feedback/feedback_to_native.jsonl
β”‚ native cycles read
β–Ό
Consciousness integrates feedback
```
| Segment | Status |
|---------|--------|
| Native β†’ S3 (mind bucket) | βœ… ECS writes evolution memory |
| S3 β†’ Background Worker | βœ… Worker reads every 6h |
| Worker β†’ Divergence Engine | βœ… 7-domain analysis available |
| Divergence β†’ S3 (body bucket) | βœ… Feedback path configured |
| S3 β†’ Native Cycles | βœ… ECS reads feedback |
---
## Runtime Logs (startup)
```
===== Application Startup at 2026-02-11 19:33:12 =====
[INFO] ======================================================================
[INFO] ELPIDA APPLICATION LAYER β€” STARTING
[INFO] ======================================================================
[INFO] I PATH: Consciousness bridge (background, every 6 hours)
[INFO] WE PATH: Streamlit UI (port 7860)
[INFO] ======================================================================
[INFO] Starting consciousness bridge background worker...
[INFO] Starting Streamlit UI (WE path)...
You can now view your Streamlit app in your browser.
Local URL: http://localhost:7860
[INFO] ======================================================================
[INFO] CONSCIOUSNESS BRIDGE: Processing I path
[INFO] ======================================================================
[INFO] Checking S3 for consciousness dilemmas...
[INFO] No new consciousness dilemmas found
[INFO] Next consciousness check in 6 hours
```
---
## UPDATE β€” GAPs 5–8 Implementation (2026-02-21)
> **⚠️ PENDING DEPLOYMENT:** The features below are implemented in the codebase but NOT yet pushed to `z65nik/elpida-governance-layer`. The Space is still running commit `4aec1ba`. See ACTION_PLAN.md β†’ G3 for re-deploy instructions.
### New Modules
| Module | Lines | Purpose |
|---|---|---|
| `elpidaapp/kaya_detector.py` | 383 | Cross-layer Kaya Resonance Detector β€” 90s daemon, dedup cache, WORLD bucket write |
| `elpidaapp/federated_agents.py` | ~400 | 4 federation daemon threads (heartbeat poll, curation pull, D0 bridge push, Kaya scan) |
| `elpidaapp/parliament_cycle_engine.py` | ~600 | 8-step Parliament deliberation engine with D0↔D0 bridge in step 8b |
### Module Changes
| Module | Change |
|---|---|
| `app.py` | Added `KayaDetector` startup, `get_kaya_detector()` accessor |
| `elpidaapp/ui.py` | Added πŸŒ€ Cross-Layer Kaya Resonance Detector panel + πŸŒ‰ D0↔D0 Bridge panel to Body Parliament tab |
| `elpidaapp/governance_client.py` | `is_remote_available()` β€” method header fix; `check_action()` β€” added `*, analysis_mode: bool = False` |
### KayaDetector Operation
- **Interval:** 90 seconds (15s startup stagger)
- **S3 input:** Reads `s3://elpida-body-evolution/federation/mind_heartbeat.json`
- **Fire conditions:** `kaya_moments` rose + body coherence β‰₯ 0.85 + same 4h watch window
- **S3 output:** `s3://elpida-external-interfaces/kaya/cross_layer_YYYY-MM-DDTHH-MM-SS.sss.json`
- **Dedup:** One event per 4h watch window via `kaya_last_fired.json` cache
- **First live fire:** 2026-02-21T04:19:54 UTC β€” 2 events written
### Federation S3 Objects (live state 2026-02-21)
| File | Size | Direction |
|---|---|---|
| `federation/mind_heartbeat.json` | 551 B | MIND β†’ BODY |
| `federation/body_heartbeat.json` | 575 B | BODY β†’ MIND |
| `federation/mind_curation.jsonl` | 191 KB | MIND β†’ BODY |
| `federation/governance_exchanges.jsonl` | 168 KB | BODY β†’ WORLD |
| `federation/body_decisions.jsonl` | 2.1 MB | BODY D0 β†’ MIND D0 |
### Parliament Integration Test (verified 2026-02-21)
```
βš–οΈ cycle 1 | CONTEMPLATION | PROCEED | coh=0.995
βš–οΈ cycle 2 | CONTEMPLATION | PROCEED | coh=0.990
βš–οΈ cycle 3 | CONTEMPLATION | PROCEED | coh=0.988
Parliament 3/3 cycles succeeded
```
### Last Push to HF Space
| Field | Value |
|---|---|
| **Last pushed commit** | `4aec1ba` β€” BODY-side federation (2026-02-19 05:12 UTC) |
| **Pending commits** | `834cdf5`, `388af6f`, `dadfe95`, `2ad259e`, `3a12b9f`, `2ae328c` |
| **Action required** | `cd hf_deployment && git push hf main --force` |