Skip to content

[CRITICAL] NAV: Implement canonical transition logic - regime detection, phase shift, vf adjustment #2861

@fermga

Description

@fermga

Problem

NAV (Transition) operator currently lacks its own operational logic. It only applies grammar U1-U4 via Operator.__call__ but performs no structural transformations (θ, νf, ΔNFR adjustments).

Canonical Requirements (TNFR.pdf §2.3.11)

NAV must implement:

  1. Regime Detection: Identify if node is in latent/active/resonant state
  2. Phase Transition: θ → θ' controlled shift
  3. Frequency Adjustment: νf modulation per regime
  4. ΔNFR Damping: Reduce reorganization pressure during transition
  5. Latency Handling: Manage SHA → NAV transitions

Current Behavior

  • NAV applies grammar only, no structural changes
  • Cannot detect regime origin
  • Does not handle latency reactivation (SHA → NAV → AL)
  • No phase/frequency/ΔNFR transformation

Proposed Implementation

class Transition(Operator):
    def __call__(self, G: TNFRGraph, node: Any, **kw: Any) -> None:
        """Apply NAV with regime detection and controlled transition."""
        
        # 1. Detectar régimen actual
        current_regime = self._detect_regime(G, node)
        
        # 2. Gestionar reactivación desde latencia (si aplica)
        if G.nodes[node].get("latent", False):
            self._handle_latency_transition(G, node)
        
        # 3. Aplicar gramática base
        super().__call__(G, node, **kw)
        
        # 4. Ejecutar transición estructural
        self._apply_structural_transition(G, node, current_regime, **kw)
    
    def _detect_regime(self, G: TNFRGraph, node: Any) -> str:
        """Detecta régimen estructural actual: latente/activo/resonante."""
        epi = float(get_attr(G.nodes[node], ALIAS_EPI, 0.0))
        vf = float(get_attr(G.nodes[node], ALIAS_VF, 0.0))
        latent = G.nodes[node].get("latent", False)
        
        if latent or vf < 0.05:
            return "latent"
        elif epi > 0.5 and vf > 0.8:
            return "resonant"
        else:
            return "active"
    
    def _handle_latency_transition(self, G: TNFRGraph, node: Any) -> None:
        """Gestiona transición desde estado latente (similar a AL)."""
        import warnings
        from datetime import datetime, timezone
        
        # Verificar duración de latencia
        if "latency_start_time" in G.nodes[node]:
            start = datetime.fromisoformat(G.nodes[node]["latency_start_time"])
            duration = (datetime.now(timezone.utc) - start).total_seconds()
            G.nodes[node]["silence_duration"] = duration
            
            max_silence = G.graph.get("MAX_SILENCE_DURATION", float("inf"))
            if duration > max_silence:
                warnings.warn(
                    f"Node {node} transitioning after extended silence "
                    f"(duration: {duration:.2f}s, max: {max_silence:.2f}s)",
                    stacklevel=3
                )
        
        # Limpiar estado latente
        del G.nodes[node]["latent"]
        if "latency_start_time" in G.nodes[node]:
            del G.nodes[node]["latency_start_time"]
        if "preserved_epi" in G.nodes[node]:
            del G.nodes[node]["preserved_epi"]
    
    def _apply_structural_transition(
        self, G: TNFRGraph, node: Any, regime: str, **kw: Any
    ) -> None:
        """Aplica transformación estructural según régimen origen."""
        from ..alias import get_attr, set_attr
        from ..constants.aliases import ALIAS_THETA, ALIAS_VF, ALIAS_DNFR
        import math
        
        # Obtener estado actual
        theta = float(get_attr(G.nodes[node], ALIAS_THETA, 0.0))
        vf = float(get_attr(G.nodes[node], ALIAS_VF, 1.0))
        dnfr = float(get_attr(G.nodes[node], ALIAS_DNFR, 0.0))
        
        # Ajustar según régimen
        if regime == "latent":
            # Reactivación gradual
            vf_new = vf * 1.2  # Incremento 20%
            theta_shift = kw.get("phase_shift", 0.1)  # Pequeño ajuste
            theta_new = (theta + theta_shift) % (2 * math.pi)
            dnfr_new = dnfr * 0.7  # Reducción para transición suave
        elif regime == "active":
            # Transición estándar
            vf_new = vf * kw.get("vf_factor", 1.0)
            theta_shift = kw.get("phase_shift", 0.2)
            theta_new = (theta + theta_shift) % (2 * math.pi)
            dnfr_new = dnfr * 0.8
        else:  # resonant
            # Transición cuidadosa (alta energía)
            vf_new = vf * 0.95  # Ligera reducción para estabilidad
            theta_shift = kw.get("phase_shift", 0.15)
            theta_new = (theta + theta_shift) % (2 * math.pi)
            dnfr_new = dnfr * 0.9
        
        # Aplicar cambios
        set_attr(G.nodes[node], ALIAS_VF, vf_new)
        set_attr(G.nodes[node], ALIAS_THETA, theta_new)
        set_attr(G.nodes[node], ALIAS_DNFR, dnfr_new)
        
        # Telemetría
        if "_nav_transitions" not in G.graph:
            G.graph["_nav_transitions"] = []
        G.graph["_nav_transitions"].append({
            "node": node,
            "regime_origin": regime,
            "vf_before": vf,
            "vf_after": vf_new,
            "theta_before": theta,
            "theta_after": theta_new,
            "dnfr_before": dnfr,
            "dnfr_after": dnfr_new,
            "phase_shift": theta_new - theta,
        })

Acceptance Criteria

  • Transition.__call__ implements _detect_regime
  • _handle_latency_transition manages SHA → NAV flow
  • _apply_structural_transition modifies θ, νf, ΔNFR per regime
  • Telemetry tracked in G.graph["_nav_transitions"]
  • Tests cover latent → active, active → resonant, resonant → latent
  • Metrics verify EPI preservation (< 5% drift)

References

  • TNFR.pdf §2.3.11 (NAV glyph canonical definition)
  • definitions.py:Emission.__call__ (latency handling reference)
  • definitions.py:Coherence.__call__ (phase transformation reference)

Priority

CRITICAL - Blocks canonical NAV behavior per TNFR theory

Affected Invariants (AGENTS.md)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions