Abstraction Level: Level 2 (Cellular) — Security architecture within ATCG-M
Purpose: Show the Membrane's dual role as inbound/outbound validator, protecting the Hive against compromised inputs and enforcing business rules on outputs.
What is the Membrane (M)?
The Membrane (M) is the immune system of the ATCG-M metabolism. According to FOUNDATION.md:32, it provides "Deterministic safety guards."
Unlike the LLM-based Transformer (T) which uses probabilistic reasoning, the Membrane uses hard-coded rules to enforce invariants that must never be violated — even if an LLM hallucinates or gets prompt-injected.
Key Characteristics:
Deterministic: No LLM involved, pure business logic
Dual-gate: Protects both inbound (inputs) and outbound (outputs)
Self-healing: Handles failures gracefully via FailureIntent
Why Critical? Even if the LLM hallucinates and says "accept $1 for a $100 item," the Membrane overrides with a safe counter-offer at floor_price + 5%.
Example:
Floor price: $50
Bid: $30
LLM decision: "accept" (hallucination or adversarial prompt)
Membrane override: Counter-offer at $52.50 (floor_price * 1.05) with self-healing
2. Data Leakage Prevention (Hidden Knowledge)
Why Critical? The floor_price is hidden knowledge. If the LLM accidentally includes it in the reason ("Your bid of $30 is below our floor price of $50"), the Membrane sanitizes the response.
Example:
LLM reason: "Bid $30 is below floor price $50"
Membrane sanitized: "Bid does not meet minimum requirements"
3. Self-Healing via FailureIntent Handling
Why Critical? If the LLM crashes, times out, or returns garbage, the Membrane gracefully degrades to a safe counter-offer via _override_with_safe_offer instead of failing the entire request.
Example:
LLM result: FailureIntent(error="Timeout")
Membrane fallback: Counter-offer at floor_price * 1.05 ($52.50 for $50 floor)
Message: "I've reached my final limit for this item. My best offer is $52.50."
Sequence Diagram: Signal Metabolism with Membrane Guards
Key Moments:
M (in) detects prompt injection, sanitizes before LLM sees it
T (Transformer) hallucinates "accept $30" despite floor being $50
M (out) overrides to "counter" because bid < floor_price
C (Connector) sends sanitized, rule-compliant response
Guard Patterns Catalog
Pattern 1: Hard Rejection (Inbound)
When: Input violates fundamental invariants (negative bid, null item_id)
Action: Raise exception immediately, do not proceed to Transformer
Code:
Pattern 2: Sanitization (Inbound)
When: Input contains malicious patterns but request is salvageable
Action: Replace poisoned fields with safe defaults, log warning
Code:
Pattern 3: Override (Outbound)
When: LLM decision violates business rules (floor price, min margin)
Action: Replace with safe counter-offer via _override_with_safe_offer
# membrane.py:104-110
if "floor_price" in decision.reason.lower():
logger.warning("membrane_data_leak_prevented")
decision.reason = "Bid does not meet minimum requirements"