key-data / models /tests /deep_dive_hold.py
tostido's picture
Upload folder using huggingface_hub
a80c9f6 verified
"""Deep dive into HOLD system and real-time inference interception."""
import sys
sys.path.insert(0, 'F:/End-Game/glassboxgames/children')
import cascade
from cascade import Hold, HoldPoint, HoldState
import numpy as np
import threading
import time
print("=" * 70)
print("⏸️ CASCADE HOLD SYSTEM - Real-time Inference Interception")
print("=" * 70)
# Get the Hold singleton
hold = Hold.get()
print(f"\nHold singleton: {hold}")
print(f"Current hold: {hold.current_hold}")
print(f"Stats: {hold.stats}")
# Register a listener to see hold points
hold_points_received = []
def my_listener(hold_point: HoldPoint):
print(f"\n🛑 HOLD POINT RECEIVED!")
print(f" Brain: {hold_point.brain_id}")
print(f" AI choice: {hold_point.ai_choice}")
print(f" Confidence: {hold_point.ai_confidence:.2%}")
print(f" Merkle: {hold_point.merkle_root}")
print(f" State: {hold_point.state}")
hold_points_received.append(hold_point)
# Auto-accept after 0.1s for demo
time.sleep(0.1)
hold.accept()
hold.register_listener(my_listener)
print("\n✅ Listener registered")
# Simulate a brain yielding a hold point
print("\n=== Simulating Hold Point (non-blocking) ===")
def simulate_brain():
# Simulate what happens inside a brain's forward()
action_probs = np.array([0.1, 0.15, 0.5, 0.25]) # 4 actions
value = 0.73
observation = {'game': 'test', 'frame': 42}
print(f"Brain: yielding hold point...")
resolution = hold.yield_point(
action_probs=action_probs,
value=value,
observation=observation,
brain_id="test_brain_001",
action_labels=["UP", "DOWN", "FIRE", "STAY"],
blocking=False # Non-blocking for demo
)
print(f"Brain: got resolution -> action={resolution.action}, override={resolution.was_override}, source={resolution.override_source}")
return resolution
result = simulate_brain()
print(f"\n=== Result ===")
print(f"Action taken: {result.action}")
print(f"Was override: {result.was_override}")
print(f"Override source: {result.override_source}")
print(f"Hold duration: {result.hold_duration:.4f}s")
print(f"Merkle root: {result.merkle_root}")
# Try override scenario
print("\n=== Testing Override Scenario ===")
override_received = None
def override_listener(hp: HoldPoint):
global override_received
override_received = hp
print(f"\n🛑 HOLD for override test")
print(f" AI wants action {hp.ai_choice} ({hp.ai_confidence:.0%} confident)")
# Simulate human override
time.sleep(0.05)
hold.override(action=0, source="human_player")
hold.unregister_listener(my_listener)
hold.register_listener(override_listener)
action_probs = np.array([0.1, 0.8, 0.05, 0.05]) # AI strongly prefers action 1
resolution = hold.yield_point(
action_probs=action_probs,
value=0.9,
observation={'test': 'override'},
brain_id="test_brain_002",
action_labels=["CONSERVATIVE", "AGGRESSIVE", "RETREAT", "WAIT"],
blocking=False
)
print(f"\n Final action: {resolution.action}")
print(f" Was override: {resolution.was_override}")
print(f" Override source: {resolution.override_source}")
print(f" AI wanted: 1 (AGGRESSIVE)")
print(f" Human chose: 0 (CONSERVATIVE)")
print("\n=== Hold Stats After Test ===")
print(hold.stats)