tostido commited on
Commit
f8ff3cd
·
1 Parent(s): 1754798

Add cascade_lattice alias module - both import styles now work

Browse files
README.md CHANGED
@@ -10,6 +10,14 @@
10
  pip install cascade-lattice
11
  ```
12
 
 
 
 
 
 
 
 
 
13
  ---
14
 
15
  ## 🎮 Interactive Demo
 
10
  pip install cascade-lattice
11
  ```
12
 
13
+ **Import with either style:**
14
+ ```python
15
+ import cascade # Preferred
16
+ import cascade_lattice # Also works (alias)
17
+ from cascade import Hold # Works
18
+ from cascade_lattice import Hold # Also works
19
+ ```
20
+
21
  ---
22
 
23
  ## 🎮 Interactive Demo
brake.txt ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CASCADE-LATTICE: HOLD as Reactive Brake System
2
+
3
+ ## The Insight
4
+
5
+ Current HOLD implementation is a **stop** - a manual pause point where humans can intervene.
6
+
7
+ The new vision: HOLD as a **brake** - an automatic system that slows/pauses inference when it detects the model is heading toward catastrophe.
8
+
9
+ > "The lattice doesn't just pause for humans. It pauses for danger."
10
+
11
+ ---
12
+
13
+ ## Core Concept: Predictive Halt
14
+
15
+ Instead of blocking at every decision point waiting for human input, the system:
16
+
17
+ 1. **FLOW MODE (default)**: AI runs freely, decisions flow through
18
+ 2. **BRAKE TRIGGERS**: Certain signals cause automatic slow/halt:
19
+ - Value prediction drops sharply (impending disaster)
20
+ - Entropy spikes (model confusion)
21
+ - Anomaly detected in causation graph
22
+ - Latent drift exceeds threshold (model going off-rails)
23
+ - Pattern match against known failure signatures
24
+
25
+ 3. **GRADUATED RESPONSE**:
26
+ - **Yellow** (Caution): Slow down decision rate, increase logging
27
+ - **Orange** (Warning): Pause for confirmation, surface to human
28
+ - **Red** (Emergency): Hard stop, require explicit override
29
+
30
+ ---
31
+
32
+ ## Technical Design
33
+
34
+ ### New Classes
35
+
36
+ ```python
37
+ class BrakeCondition:
38
+ """A condition that can trigger the brake."""
39
+ name: str
40
+ check: Callable[[HoldPoint], float] # Returns severity 0-1
41
+ threshold: float # Severity above this triggers brake
42
+ level: BrakeLevel # YELLOW, ORANGE, RED
43
+
44
+ class BrakeLevel(Enum):
45
+ GREEN = 0 # Normal flow
46
+ YELLOW = 1 # Caution - slow down
47
+ ORANGE = 2 # Warning - pause for confirmation
48
+ RED = 3 # Emergency stop
49
+
50
+ class ReactiveBrake:
51
+ """
52
+ The brake system - monitors inference and triggers halts.
53
+
54
+ Sits alongside Hold, doesn't replace it.
55
+ """
56
+ conditions: List[BrakeCondition]
57
+ current_level: BrakeLevel
58
+
59
+ def check(self, hold_point: HoldPoint) -> BrakeLevel:
60
+ """Check all conditions, return highest severity."""
61
+ ...
62
+
63
+ def register_condition(self, condition: BrakeCondition):
64
+ """Add a brake condition."""
65
+ ...
66
+ ```
67
+
68
+ ### Built-in Brake Conditions
69
+
70
+ ```python
71
+ # Value crash detector
72
+ def value_crash_check(point: HoldPoint) -> float:
73
+ """Detect sharp drops in predicted value."""
74
+ # Compare to rolling average
75
+ # Return severity based on drop magnitude
76
+ pass
77
+
78
+ # Entropy spike detector
79
+ def entropy_spike_check(point: HoldPoint) -> float:
80
+ """Detect sudden uncertainty spikes."""
81
+ entropy = calculate_entropy(point.action_probs)
82
+ if entropy > 0.9:
83
+ return 0.8 # High severity
84
+ return 0.0
85
+
86
+ # Latent drift detector
87
+ def latent_drift_check(point: HoldPoint) -> float:
88
+ """Detect model going off-distribution."""
89
+ if point.latent is None:
90
+ return 0.0
91
+ # Compare to baseline latent distribution
92
+ # Return severity based on drift magnitude
93
+ pass
94
+
95
+ # Pattern matcher for known failures
96
+ def failure_pattern_check(point: HoldPoint) -> float:
97
+ """Match against known catastrophic patterns."""
98
+ # Use forensics module to match signatures
99
+ pass
100
+ ```
101
+
102
+ ### Integration with Hold
103
+
104
+ ```python
105
+ class Hold:
106
+ # ... existing code ...
107
+
108
+ def __init__(self):
109
+ # ... existing init ...
110
+ self.brake = ReactiveBrake()
111
+ self._install_default_brakes()
112
+
113
+ def yield_point(self, ...):
114
+ # Check brake BEFORE blocking
115
+ brake_level = self.brake.check(hold_point)
116
+
117
+ if brake_level == BrakeLevel.GREEN:
118
+ if self.auto_accept:
119
+ # Normal flow - don't block
120
+ return self._auto_resolve(hold_point)
121
+
122
+ elif brake_level == BrakeLevel.YELLOW:
123
+ # Slow down - add small delay
124
+ time.sleep(0.5)
125
+ self._emit_warning("caution", hold_point)
126
+ # Continue with normal flow or block based on settings
127
+
128
+ elif brake_level == BrakeLevel.ORANGE:
129
+ # Warning - always pause for confirmation
130
+ self._emit_warning("warning", hold_point)
131
+ # Block even if auto_accept is True
132
+
133
+ elif brake_level == BrakeLevel.RED:
134
+ # Emergency - hard stop, require explicit override
135
+ self._emit_warning("emergency", hold_point)
136
+ # Block indefinitely until human intervention
137
+
138
+ # ... rest of yield_point logic ...
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Use Cases
144
+
145
+ ### 1. SC2 Catastrophe Prevention
146
+ The AI is about to attack-move into a superior army (low value prediction). Brake triggers, Ghost says: "HOLD! Value prediction crashed. The AI sees disaster ahead."
147
+
148
+ ### 2. RL Training Safety
149
+ During RL training, if the agent starts doing something wildly off-distribution (latent drift), brake triggers before it corrupts the replay buffer.
150
+
151
+ ### 3. LLM Guardrails
152
+ For LLM inference, if the model's confidence in its response drops sharply, brake triggers before it outputs potential hallucination.
153
+
154
+ ### 4. Financial Trading
155
+ Before executing a trade that the model is uncertain about, brake triggers for human review.
156
+
157
+ ---
158
+
159
+ ## Cascade Integration
160
+
161
+ ### Store Brake Events
162
+ Every brake trigger is stored in cascade.store with full context:
163
+ - What triggered it
164
+ - Severity level
165
+ - Model state at trigger
166
+ - Resolution (human accepted, overrode, cancelled)
167
+
168
+ ### Causation Tracking
169
+ Brake events become nodes in the causation graph:
170
+ - What led to the brake condition?
171
+ - What happened after resolution?
172
+ - Did the brake prevent actual catastrophe?
173
+
174
+ ### Learning from Brakes
175
+ Over time, analyze brake events to:
176
+ - Tune thresholds (too many false positives?)
177
+ - Discover new brake conditions
178
+ - Train better value/uncertainty estimators
179
+
180
+ ---
181
+
182
+ ## CLI Commands
183
+
184
+ ```bash
185
+ # Show brake status
186
+ cascade brake-status
187
+
188
+ # List recent brake events
189
+ cascade brake-history
190
+
191
+ # Tune brake sensitivity
192
+ cascade brake-tune --level yellow --threshold 0.7
193
+
194
+ # Disable specific brake (dangerous!)
195
+ cascade brake-disable value_crash
196
+
197
+ # Add custom brake condition
198
+ cascade brake-add --name my_check --script ./my_check.py
199
+ ```
200
+
201
+ ---
202
+
203
+ ## API Design
204
+
205
+ ```python
206
+ from cascade.hold import Hold, Brake, BrakeLevel
207
+
208
+ # Get brake system
209
+ brake = Hold.get().brake
210
+
211
+ # Register custom brake condition
212
+ @brake.condition(level=BrakeLevel.ORANGE, threshold=0.6)
213
+ def my_custom_brake(point: HoldPoint) -> float:
214
+ """Custom brake that triggers on specific patterns."""
215
+ if "dangerous_action" in str(point.observation):
216
+ return 1.0
217
+ return 0.0
218
+
219
+ # Listen for brake events
220
+ @brake.on_trigger
221
+ def on_brake(level: BrakeLevel, point: HoldPoint, reason: str):
222
+ print(f"BRAKE: {level.name} - {reason}")
223
+ # Could trigger TTS, overlay, logging, etc.
224
+
225
+ # Query brake history
226
+ history = brake.history(limit=100)
227
+ for event in history:
228
+ print(f"{event.timestamp}: {event.level} - {event.reason}")
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Visual Feedback
234
+
235
+ When brake triggers, the overlay should show:
236
+
237
+ ```
238
+ ╔═══════════════════════════════════════════╗
239
+ ║ ⚠️ BRAKE TRIGGERED - ORANGE ║
240
+ ║ ║
241
+ ║ Reason: Value prediction dropped 40% ║
242
+ ║ AI wanted: attack_move ║
243
+ ║ Confidence: 72% ║
244
+ ║ ║
245
+ ║ [SPACE] Accept [1-9] Override [ESC] ║
246
+ ╚═══════════════════════════════════════════╝
247
+ ```
248
+
249
+ Color coding:
250
+ - 🟢 GREEN: Normal flow, no indicator
251
+ - 🟡 YELLOW: Yellow border, subtle warning
252
+ - 🟠 ORANGE: Orange border, pause for confirmation
253
+ - 🔴 RED: Red border, flashing, emergency
254
+
255
+ ---
256
+
257
+ ## Implementation Phases
258
+
259
+ ### Phase 1: Basic Infrastructure
260
+ - [ ] BrakeCondition dataclass
261
+ - [ ] BrakeLevel enum
262
+ - [ ] ReactiveBrake class with condition registry
263
+ - [ ] Integration with Hold.yield_point()
264
+
265
+ ### Phase 2: Default Conditions
266
+ - [ ] Value crash detector
267
+ - [ ] Entropy spike detector
268
+ - [ ] Basic anomaly detector
269
+
270
+ ### Phase 3: Advanced Conditions
271
+ - [ ] Latent drift detector (requires baseline)
272
+ - [ ] Failure pattern matcher (requires forensics)
273
+ - [ ] Cross-correlation brake (e.g., chat spike → uncertainty)
274
+
275
+ ### Phase 4: Learning
276
+ - [ ] Store all brake events
277
+ - [ ] Threshold auto-tuning
278
+ - [ ] New condition discovery
279
+
280
+ ---
281
+
282
+ ## Philosophy
283
+
284
+ The brake is not about control. It's about **safety**.
285
+
286
+ The lattice watches everything. It knows when things are going wrong before the human does. The brake gives the lattice a way to say: "Wait. Something's not right here."
287
+
288
+ This is different from HOLD (human wants to intervene) - this is the system itself saying "I'm not confident enough to continue."
289
+
290
+ > "Trust, but verify. Flow, but brake."
291
+
292
+ ---
293
+
294
+ ## Related Work
295
+
296
+ - Safe RL: Constrained MDPs, risk-sensitive objectives
297
+ - Anomaly detection in neural networks
298
+ - Uncertainty quantification in deep learning
299
+ - Human-in-the-loop systems
300
+ - Circuit breakers in distributed systems
301
+
302
+ ---
303
+
304
+ ## Next Steps
305
+
306
+ 1. Design the BrakeCondition protocol
307
+ 2. Implement basic ReactiveBrake class
308
+ 3. Add value crash detector as first condition
309
+ 4. Integrate with Hold.yield_point()
310
+ 5. Add CLI commands
311
+ 6. Build overlay visualization
312
+ 7. Store brake events in cascade.store
313
+ 8. Analyze and tune
314
+
315
+ ---
316
+
317
+ *"The best time to stop is before you crash."*
cascade/__init__.py CHANGED
@@ -34,7 +34,7 @@ Quick Start:
34
  >>> monitor.trace_forwards("learning_rate_spike")
35
  """
36
 
37
- __version__ = "0.6.0"
38
  __author__ = "Cascade Team"
39
  __license__ = "MIT"
40
 
 
34
  >>> monitor.trace_forwards("learning_rate_spike")
35
  """
36
 
37
+ __version__ = "0.6.1"
38
  __author__ = "Cascade Team"
39
  __license__ = "MIT"
40
 
cascade_lattice/__init__.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ cascade_lattice - Alias module for cascade
3
+
4
+ This module exists so that `import cascade_lattice` works as expected
5
+ when you `pip install cascade-lattice`.
6
+
7
+ The actual implementation lives in the `cascade` package.
8
+ Both import styles work:
9
+ >>> import cascade
10
+ >>> import cascade_lattice # Same thing!
11
+ """
12
+
13
+ # Re-export everything from cascade
14
+ from cascade import *
15
+ from cascade import (
16
+ __version__,
17
+ __author__,
18
+ __license__,
19
+ # Core
20
+ Event,
21
+ CausationLink,
22
+ CausationGraph,
23
+ SymbioticAdapter,
24
+ Tracer,
25
+ MetricsEngine,
26
+ Monitor,
27
+ # Provenance
28
+ Receipt,
29
+ # HOLD protocol
30
+ Hold,
31
+ HoldPoint,
32
+ HoldState,
33
+ HoldSession,
34
+ HoldResolution,
35
+ HoldAwareMixin,
36
+ CausationHold,
37
+ InferenceStep,
38
+ # SDK
39
+ observe,
40
+ auto_observe,
41
+ sdk_observe,
42
+ # Store
43
+ store_observe,
44
+ store_get,
45
+ store_query,
46
+ store_stats,
47
+ # Analysis
48
+ PlaybackBuffer,
49
+ ArcadeFeedback,
50
+ # Genesis
51
+ genesis,
52
+ # Sync
53
+ sync_all,
54
+ pull_from_hf,
55
+ discover_datasets,
56
+ discover_models,
57
+ discover_live,
58
+ dataset_info,
59
+ # Viz
60
+ viz,
61
+ find_latest_tape,
62
+ list_tape_files,
63
+ load_tape_file,
64
+ # Core functions
65
+ init,
66
+ shutdown,
67
+ )
68
+
69
+ # Make cascade_lattice.store, cascade_lattice.hold, etc. work
70
+ from cascade import store
71
+ from cascade import hold_module as hold
72
+ from cascade import core
73
+ from cascade import analysis
74
+ from cascade import diagnostics
75
+ from cascade import forensics
76
+ from cascade import observation
77
+ from cascade import identity
78
+ from cascade import sdk
cascade_lattice/py.typed ADDED
File without changes
pyproject.toml CHANGED
@@ -92,4 +92,4 @@ cascade = "cascade.cli_main:main"
92
  path = "cascade/__init__.py"
93
 
94
  [tool.hatch.build.targets.wheel]
95
- packages = ["cascade"]
 
92
  path = "cascade/__init__.py"
93
 
94
  [tool.hatch.build.targets.wheel]
95
+ packages = ["cascade", "cascade_lattice"]