Skip to content

Commit 099ba1e

Browse files
cdeustclaude
andcommitted
fix(verif): wire CORTEX_ABLATE_<MECH> env-var reads into production hot-paths (23 mechanisms)
Adds is_mechanism_disabled() helper in core.ablation that reads CORTEX_ABLATE_<NAME>=1 on every call (no memoization -- production env never set, test env varies per run). Wires guards at the primary entry point of 23 of the 26 Mechanism enum values so the E1 verification campaign produces real per-mechanism causal deltas instead of identical numbers from inert hooks. Wired (23): OSCILLATORY_CLOCK -> modulate_encoding/retrieval/plasticity CASCADE -> compute_advancement_readiness PREDICTIVE_CODING -> gate_decision + hierarchical_gate_decision PATTERN_SEPARATION -> orthogonalize_embedding SCHEMA_ENGINE -> find_best_matching_schema TRIPARTITE_SYNAPSE -> compute_ltp_modulation INTERFERENCE -> orthogonalize_pair + compute_retrieval_suppression HOMEOSTATIC_PLASTICITY -> compute_scaling_factor SYNAPTIC_PLASTICITY -> apply_hebbian_update SYNAPTIC_TAGGING -> apply_synaptic_tags EMOTIONAL_TAGGING -> compute_importance_boost EMOTIONAL_DECAY -> compute_decay_resistance MICROGLIAL_PRUNING -> identify_prunable_edges SPREADING_ACTIVATION -> spread_activation ENGRAM_ALLOCATION -> find_best_slot RECONSOLIDATION -> decide_action DENDRITIC_CLUSTERS -> find_best_branch TWO_STAGE_MODEL -> should_release_hippocampal_trace HOPFIELD -> retrieve HDC -> compute_hdc_scores ADAPTIVE_DECAY -> compute_decay (constant lambda when ablated) NEUROMODULATION -> update_state (frozen state when ablated) SURPRISE_MOMENTUM -> TitansMemory.update CO_ACTIVATION -> _apply_co_activation (handler) Not wired (no production code paths exist; flagged for follow-up): EMOTIONAL_RETRIEVAL -- emotion-conditioned recall scoring not implemented MOOD_CONGRUENT_RERANK -- mood-congruent rerank not implemented at recall Smoke run (longmemeval-s --quick) confirms non-baseline deltas: PATTERN_SEPARATION MRR delta -0.009 (0.691 -> 0.682) HOPFIELD MRR delta -0.044 (0.672 -> 0.628) HDC R@10 delta -0.050, MRR delta -0.013 26 unit tests in tests_py/core/test_ablation_hooks.py verify each guard short-circuits when CORTEX_ABLATE_<NAME>=1 and runs the active path otherwise. All 1663 existing core tests pass (no regression). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent df14e16 commit 099ba1e

25 files changed

Lines changed: 670 additions & 1 deletion

mcp_server/core/ablation.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,41 @@
1010
- Other mechanisms continue operating normally
1111
- System-level metrics are tracked for comparison
1212
13-
Pure business logic -- no I/O.
13+
Pure business logic -- no I/O (the env-var read is a single os.environ
14+
lookup, performed only when an E1 verification campaign sets it; in
15+
production the var is never set so the lookup is a constant-time miss).
1416
"""
1517

1618
from __future__ import annotations
1719

20+
import os
1821
from dataclasses import dataclass, field
1922
from enum import Enum
2023

2124

25+
def is_mechanism_disabled(mechanism: "Mechanism | str") -> bool:
26+
"""True iff CORTEX_ABLATE_<NAME>=1 is set for this mechanism.
27+
28+
Production hot-paths call this at the entry point and short-circuit to
29+
a no-op when True. Used by the E1 verification campaign
30+
(benchmarks/lib/ablation_runner.py) to produce per-mechanism causal
31+
deltas; in production the env var is never set so every check is a
32+
single dict lookup.
33+
34+
Reads os.environ on every call -- callers are not in a tight loop;
35+
test env varies per-run; production env never changes mid-process.
36+
DO NOT memoize.
37+
38+
Accepts either a Mechanism enum (uses .name -> e.g. "OSCILLATORY_CLOCK")
39+
or a string (upper-cased, hyphens normalized).
40+
"""
41+
if hasattr(mechanism, "name"):
42+
name = mechanism.name
43+
else:
44+
name = str(mechanism).upper().replace("-", "_")
45+
return os.environ.get(f"CORTEX_ABLATE_{name}") == "1"
46+
47+
2248
class Mechanism(Enum):
2349
"""Enumeration of all ablatable Cortex mechanisms."""
2450

mcp_server/core/cascade_advancement.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def compute_advancement_readiness(
160160
161161
Returns (is_ready, next_stage_name, readiness_score_0_to_1).
162162
"""
163+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
164+
165+
if is_mechanism_disabled(Mechanism.CASCADE):
166+
# No-op: never advance the consolidation stage; memories remain LABILE.
167+
return False, current_stage, 0.0
168+
163169
try:
164170
stage = ConsolidationStage(current_stage)
165171
except ValueError:

mcp_server/core/coupled_neuromodulation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def update_state(
133133
Takes current state + operation signals, returns new state with all
134134
channels updated and cross-coupled. Original not mutated.
135135
"""
136+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
137+
138+
if is_mechanism_disabled(Mechanism.NEUROMODULATION):
139+
# No-op: state is frozen at the current values; no DA/NE/ACh/5-HT updates.
140+
return current
141+
136142
da, ne, ach, ser, new_baseline, new_adaptation = _compute_raw_channels(
137143
current, signals
138144
)

mcp_server/core/dendritic_clusters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ def find_best_branch(
8080
Returns:
8181
(best_branch, affinity_score). None if no branch qualifies.
8282
"""
83+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
84+
85+
if is_mechanism_disabled(Mechanism.DENDRITIC_CLUSTERS):
86+
# No-op: no branch-based modulation; no cluster match.
87+
return None, 0.0
88+
8389
best: DendriticBranch | None = None
8490
best_score = 0.0
8591

mcp_server/core/emotional_tagging.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def compute_importance_boost(
186186
187187
Returns multiplier in [1.0, 2.0].
188188
"""
189+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
190+
191+
if is_mechanism_disabled(Mechanism.EMOTIONAL_TAGGING):
192+
# No-op: base priority (no Yerkes-Dodson modulation).
193+
return 1.0
194+
189195
# Smooth Yerkes-Dodson: f(a) = c * a * exp(-b * a) + 1.0
190196
# b = 1/0.7 ≈ 1.4286 => peak at arousal = 0.7
191197
# c chosen so peak value ≈ 1.57: c = 1.57 / (0.7 * exp(-1)) ≈ 6.094 * 0.57 ... let me compute
@@ -216,6 +222,11 @@ def compute_decay_resistance(
216222
217223
Returns multiplier in [1.0, 2.0].
218224
"""
225+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
226+
227+
if is_mechanism_disabled(Mechanism.EMOTIONAL_DECAY):
228+
# No-op: no emotion-modulated decay slowdown.
229+
return 1.0
219230
if arousal < 0.1:
220231
return 1.0
221232

mcp_server/core/engram.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def find_best_slot(
7373
Returns:
7474
(best_slot_index, best_excitability).
7575
"""
76+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
77+
78+
if is_mechanism_disabled(Mechanism.ENGRAM_ALLOCATION):
79+
# No-op: baseline allocation -- always slot 0 with neutral excitability.
80+
return 0, 0.5
81+
7682
best_slot = 0
7783
best_exc = -1.0
7884

mcp_server/core/hdc_encoder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def compute_hdc_scores(
224224
List of (memory_id, similarity_score) sorted descending.
225225
Scores are in [-1, 1] but practically [0, 1] for relevant results.
226226
"""
227+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
228+
229+
if is_mechanism_disabled(Mechanism.HDC):
230+
# No-op: no HDC contribution to recall.
231+
return []
227232
if not memory_contents:
228233
return []
229234

mcp_server/core/homeostatic_plasticity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def compute_scaling_factor(
9595
Returns:
9696
Multiplicative scaling factor. Apply to all heats in domain.
9797
"""
98+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
99+
100+
if is_mechanism_disabled(Mechanism.HOMEOSTATIC_PLASTICITY):
101+
# No-op: factor 1.0 -> no scaling applied.
102+
return 1.0
98103
return 1.0 + scaling_rate * (target_heat - current_avg_heat)
99104

100105

mcp_server/core/hopfield.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def retrieve(
9595
Computes: attention = softmax(beta * X * query)
9696
Returns top_k (memory_id, attention_weight) sorted descending.
9797
"""
98+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
99+
100+
if is_mechanism_disabled(Mechanism.HOPFIELD):
101+
# No-op: no Hopfield-attention contribution.
102+
return []
98103
if pattern_matrix.size == 0:
99104
return []
100105

mcp_server/core/interference.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ def orthogonalize_pair(
157157
One step of gradual rotation per call. Multiple sleep cycles
158158
achieve full separation. Returns (new_a, new_b, remaining_sim).
159159
"""
160+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
161+
162+
if is_mechanism_disabled(Mechanism.INTERFERENCE):
163+
# No-op: identity; no orthogonalization.
164+
return (
165+
list(embedding_a),
166+
list(embedding_b),
167+
cosine_similarity(embedding_a, embedding_b)
168+
if len(embedding_a) == len(embedding_b)
169+
else 0.0,
170+
)
160171
if len(embedding_a) != len(embedding_b):
161172
return list(embedding_a), list(embedding_b), 0.0
162173

@@ -213,6 +224,11 @@ def compute_retrieval_suppression(
213224
Returns:
214225
Suppressed retrieval score [0, target_score].
215226
"""
227+
from mcp_server.core.ablation import Mechanism, is_mechanism_disabled
228+
229+
if is_mechanism_disabled(Mechanism.INTERFERENCE):
230+
# No-op: no lateral suppression at retrieval.
231+
return target_score
216232
if not competitor_scores:
217233
return target_score
218234

0 commit comments

Comments
 (0)