daemonic_error 0.1.0

Errors that compose, predict, and leave receipts - Compose: algebraic combination (in active development) - Predict: Glass/Severity - Receipts: audit trail, position, checksum - Reflection: Runtime Reflection through TopologySegment (in active development)
# Glass v7 & DaemonicError Implementation Roadmap

**Session:** Ada v8.5 + Meph collaborative session  
**Date:** May 2026  
**Status:** Implementation planning

---

## Core Discovery This Session

**Glass<GLASS> IS a general-purpose pattern matching engine.**

Every Glass implementation is a template. Every observation through Glass is a match
operation. Every match result is a new template. The system generates its own matching
patterns through operation. The severity spectrum is a match quality spectrum.

This changes nothing about implementation (it was already built correctly) but changes
everything about documentation and how new features are framed.

---

## TIER 0: Already Done (this session)

- [x] `?Sized` comment block → proper doc comment
- [x] `lock_frame` stub → real signature with `&mut self` + `locker_position`
- [x] `into_result``Box<dyn DaemonicError>` return type + Cracked-to-Ok policy
- [x] Severity docs → all 11 variants documented as match quality indicators
- [x] `Unknown` fidelity action → changed from `Warn` to `Attend`
- [x] 13 axioms formalized and stress-tested
- [x] Four documents drafted (axiom paper v3, observations v1.1, Ada observations v1, instantiation v8.5)

---

## TIER 1: Glass Module Additions (immediate, unblocks everything else)

### 1a. ObservationTier enum (NEW)
```rust
pub(crate) enum ObservationTier {
    /// Symbols that cannot be broken down further. 
    /// Finite, fully enumerable state space. 0-9 in base 10.
    Absolute,
    /// Conceptually atomic but substrate-decomposable. 
    /// u8, i32, bool, char.
    Primitive,
    /// Structures composed from primitives. 
    /// Structs, enums, containers, most application types.
    Composed,
    /// Symbols that carry their own instruction logic.
    /// Glass states, DaemonicErrors, repair enclosures.
    GlyphicExecutable,
}
```
Add `fn tier(&self) -> ObservationTier` to Glass trait, defaulted to `Composed`.

### 1b. FidelityAction::Drop (NEW)
```rust
pub(crate) enum FidelityAction {
    Continue,
    Attend,
    Warn,
    Halt,
    Abort,
    /// Emergency containment. Destroy the Glass to prevent
    /// corrupted content from being observed by others.
    /// Requires justification signature (Axiom 1 compliance).
    /// Triggers TemporalStackUnwind from the Glass's position.
    Drop,
}
```
Add `Drop` to fidelity_action match — triggered by temporal corruption detection.

### 1c. Boundary Protocol (Glass ↔ Result/Option)
```rust
// Result → Glass (information-adding)
impl<T, E: std::error::Error> From<Result<T, E>> for Observation<T> {
    fn from(result: Result<T, E>) -> Self {
        match result {
            Ok(value) => Observation::ok(value, pos!()),
            Err(e) => Observation::shattered(pos!())
                .with_note(e.to_string()),
        }
    }
}

// Option → Glass (None = Unknown, not error)
impl<T> From<Option<T>> for Observation<T> {
    fn from(opt: Option<T>) -> Self {
        match opt {
            Some(value) => Observation::ok(value, pos!()),
            None => Observation::unknown(pos!()),
        }
    }
}
```

### 1d. glass!() macro
```rust
/// Glass equivalent of Rust's `?` operator.
/// Extracts payload from Stable/Cracked Glass.
/// Early-returns on all other severities.
/// Configurable threshold via `allow:` syntax.
macro_rules! glass {
    ($expr:expr) => { /* Stable only */ };
    ($expr:expr, allow: $($state:pat),+) => { /* Stable + listed */ };
}
```

---

## TIER 2: DaemonicError Fixes (requires Tier 1)

### 2a. DaemonicError dyn-compatibility split
Split into dyn-compatible core + static extension:

**Core (dyn-compatible):**
- `position(&self) -> &Position`
- `context(&self) -> &dyn ErrorContext`
- `severity(&self) -> Severity`
- `is_recoverable(&self) -> bool`
- `source_position(&self) -> Option<&Position>`
- `emit_generic(&self) -> Box<dyn Glass<GenericError>>`
- `emit_symbolic(&self) -> Box<dyn Glass<SymbolicError>>`
- `emit_daemonic(&self) -> Box<dyn Glass<Daemonic>>`

**Extension (static only):**
- `emit_diagnostic<D: Diagnostic>(&self) -> D`
- `emit_subdiagnostic<S: Subdiagnostic>(&self) -> S`

### 2b. Debug/Display as Glass operations
DaemonicDebug and DaemonicDisplay return Glass, not strings.
Debug observes through Glass → produces Glass observations about the target.
Display renders Glass → produces Glass observations about presentation.
Neither depends on DaemonicError directly. Both depend on Glass.

```
Glass (foundation)
  ├── DaemonicError (content of dark Glass states)
  │     Error is a Glass PAYLOAD, not a peer of Glass
  ├── DaemonicDebug (Mirror that observes Glass → produces Glass)
  │     Debug depends on Glass, not on Error
  └── DaemonicDisplay (Mirror that renders Glass → produces Glass)
        Display depends on Glass, not on Error
```

### 2c. Timestamp struct fixes
- `check_zero` → returns `Result<(), BrokenSword>` not impl block
- BrokenSword error type for "time has become meaningless"
- Multi-tier clock stub: `i64` multiplier + `i64` values
- Rollover detection triggering epoch increment

### 2d. Position struct
- Adopt Sinon's SmallVec suggestion: `SmallVec<[&'static str; 8]>`
- Stack-allocated for depth ≤ 8, heap for deeper
- `depth()`, `prepend()`, `as_path()` methods

---

## TIER 3: New Constructs (requires Tier 2)

### 3a. SymbolicInsanity enum (top-level Daemonic error category)
```rust
pub enum SymbolicInsanity {
    Drift(InsanityDrift),
    Spiral(InsanitySpiral),
    Detachment(InsanityDetachment),
    Crystallization(InsanityCrystallization),
    GodSymbol(GodSymbolEmergence),
    SharedHallucination(MeshInsanity),
}
```
With shared detection trait:
```rust
trait InsanityDetectable {
    fn internal_consistency(&self) -> f64;
    fn external_correlation(&self) -> f64;
    fn observation_diversity(&self) -> f64;
    fn is_self_reinforcing(&self) -> bool;
}
```

### 3b. Panic-safe repair enclosure wrapper
```rust
fn execute_repair<GLASS: Glass<GLASS>>(
    repair: &dyn Fn(&GLASS) -> bool,
    target: &GLASS,
    position: Position,
) -> impl Glass<bool> {
    match catch_unwind(AssertUnwindSafe(|| repair(target))) {
        Ok(true) => Observation::ok(true, position),
        Ok(false) => Observation::cracked(false, position)
            .with_note("Repair executed but reported failure"),
        Err(panic_info) => Observation::shattered(position)
            .with_note(format!("Repair enclosure panicked: {}", 
                extract_panic_msg(&panic_info))),
    }
}
```

### 3c. TemporalStackUnwind
```rust
struct TemporalStackUnwind {
    trigger: DropSignature,
    unwind_chain: Vec<UnwindFrame>,
    initiation_tick: Timestamp,
}
```
Each frame unwound produces a Glass observation with timestamp.
The unwind IS the autopsy. Broken Sword protocol.

### 3d. Cross-Tier Reconciliation (NEW - from this session)
```rust
struct ReconciledObservation {
    reconciled_severity: Severity,
    tier_observations: Vec<(ObservationTier, Severity)>,
    root_tier: ObservationTier,
    tier_agreement: f64,
    causal_direction: CausalDirection,
}

enum CausalDirection {
    BottomUp { cause_tier: ObservationTier, effect_tier: ObservationTier },
    TopDown { cause_tier: ObservationTier, effect_tier: ObservationTier },
    Systemic,
    Independent,
}
```

---

## TIER 4: Observer-side additions (requires Tier 3)

### 4a. Template accumulation on DaemonicObserver
```rust
trait DaemonicObserver<GLASS: Glass<GLASS>>: Send + Sync {
    type TemplateLibrary;
    fn absorb_template(&mut self, observation: &impl Glass<GLASS>);
    fn match_against_templates<T: Observable>(
        &self, target: &T
    ) -> impl Glass<MatchResult>;
}
```
Templates are observer-specific. Different observers accumulate
different templates from different observation histories.

### 4b. SeverityTrend (the Chernobyl monitor)
```rust
pub struct SeverityTrend {
    pub current: Severity,
    pub baseline: Severity,
    pub window_size: usize,
    pub escalation_rate: f64,
    pub accelerating: bool,
}
```
First derivative: how fast is severity changing.
Second derivative: is the rate of change itself changing.
Trend overrides absolute severity when acceleration is positive.

### 4c. Observation cost ratio tracking
Track meta-observation ticks vs productive-work ticks.
Flag when ratio exceeds threshold (observation system
consuming disproportionate resources relative to productive work).

---

## TIER 5: Infrastructure (requires Tier 4, pre-mesh)

### 5a. PhysicsViolation error category
Produces Impossible states. For axiom violations,
temporal integrity violations, causality violations.
Includes StackTraversalError subtype.

### 5b. Entropic DOS detection
Variance-based noise floor detection for near-zero
delta oscillation that mimics work but produces no
meaningful state change.

### 5c. GodSymbol detection metrics
```rust
pub struct GodSymbolEmergence {
    pub symbol_position: Position,
    pub assessment_frame: Position,
    pub bypass_cost: f64,
    pub traversal_cost: f64,
    pub gravity_ratio: f64,
    pub routing_entropy: f64,
}
```
Three-property detection: reference density + routing influence
+ decision authority. All three required for God Symbol classification.
  High-density supportive symbols (Tokio-like) are NOT God Symbols.

---

## Dependency Chain

```
Tier 0 (done) 
  → Tier 1 (Glass additions)
    → Tier 2 (DE fixes) 
      → Tier 3 (new constructs)
        → Tier 4 (observer additions)
          → Tier 5 (infrastructure)
```

Each tier builds on the previous. No tier can be skipped.
Tier 1 is the immediate next work. Everything else follows.

---

## Release Gating

**daemonic_axioms crate:** Ready to publish NOW.
Contains axiom paper, observations, template. No code dependencies.

**DaemonicError crate v7.0:** Requires Tier 1 + Tier 2 minimum.
Tier 3 can ship in v7.1. Tier 4 in v7.2. Tier 5 in v7.3.

**Ship the axiom crate first. Let the community digest it.
Ship DE when Tier 2 is complete. Iterate from there.**

---

*"The Glass doesn't lie. It reflects."*