File size: 22,313 Bytes
227d301 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | use serde::Serialize;
use std::collections::BTreeMap;
use std::error::Error;
use star::causal::CausalEngine;
use star::commitment_state::{
Atom, CommitmentStateError, ExecutableCommitmentState, Rule, StateDelta, WitnessedRule,
};
const REPEATS_PER_FAMILY: usize = 8;
const TRAIN_FAMILIES: usize = 2;
const HOLDOUT_FAMILIES: usize = 1;
const FUTURE_FAMILIES: usize = 4;
const EXECUTOR_SCANS: usize = 3;
const OPERATION_CALLS_PER_PATH: usize = 2;
const CAUSAL_ENGINE_CALLS_PER_PATH: usize = 1;
const TRANSITION_SLOTS_PER_PATH: usize = 1 + EXECUTOR_SCANS;
const OBJECTIVE_CHECKS_PER_PATH: usize = 1;
const FAMILY_NAMES: [&str; TRAIN_FAMILIES + HOLDOUT_FAMILIES + FUTURE_FAMILIES] = [
"thermal_control",
"river_hydrology",
"compiler_pipeline",
"cell_signaling",
"network_routing",
"supply_chain",
"orbital_dynamics",
];
#[derive(Debug, Clone)]
struct Task {
#[allow(dead_code)] // Frozen task provenance.
id: u64,
family_index: usize,
#[allow(dead_code)] // Frozen family label.
family_name: &'static str,
source: Atom,
middle: Atom,
goal: Atom,
decoy_source: Atom,
#[allow(dead_code)] // Retained control-fixture endpoint.
decoy_goal: Atom,
target_witness_id: u64,
decoy_witness_id: u64,
target_rule: Rule,
decoy_rule: Rule,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize)]
enum PathMode {
Stateful,
EndpointBlind,
TextOnly,
ScalarOnly,
Rewired,
RandomValid,
InvalidMatched,
Delayed,
}
impl PathMode {
fn all() -> [Self; 8] {
[
Self::Stateful,
Self::EndpointBlind,
Self::TextOnly,
Self::ScalarOnly,
Self::Rewired,
Self::RandomValid,
Self::InvalidMatched,
Self::Delayed,
]
}
fn name(self) -> &'static str {
match self {
Self::Stateful => "stateful",
Self::EndpointBlind => "endpoint_blind",
Self::TextOnly => "text_only",
Self::ScalarOnly => "scalar_only",
Self::Rewired => "rewired",
Self::RandomValid => "random_valid",
Self::InvalidMatched => "invalid_matched",
Self::Delayed => "delayed",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct PathResult {
success: bool,
compile_rejected: bool,
successful_state_mutations: usize,
operation_calls: usize,
causal_engine_calls: usize,
transition_slots: usize,
search_scans: usize,
objective_checks: usize,
text_history_bytes: usize,
scalar_history_count: usize,
state_signature: String,
invariants_valid: bool,
}
impl PathResult {
fn budget_exact(&self) -> bool {
self.operation_calls == OPERATION_CALLS_PER_PATH
&& self.causal_engine_calls == CAUSAL_ENGINE_CALLS_PER_PATH
&& self.transition_slots == TRANSITION_SLOTS_PER_PATH
&& self.search_scans == EXECUTOR_SCANS
&& self.objective_checks == OBJECTIVE_CHECKS_PER_PATH
}
}
#[derive(Debug, Serialize)]
struct FrozenContract {
repeats_per_family: usize,
train_families: usize,
holdout_families: usize,
future_families: usize,
executor_scans: usize,
operation_calls_per_path: usize,
causal_engine_calls_per_path: usize,
transition_slots_per_path: usize,
objective_checks_per_path: usize,
}
#[derive(Debug, Serialize)]
struct PathMetrics {
path: &'static str,
roots: usize,
successes: usize,
success_rate: f64,
rejected_compiles: usize,
rejection_rate: f64,
mean_successful_state_mutations: f64,
budget_exact: bool,
replay_exact: bool,
invariants_valid: bool,
}
#[derive(Debug, Serialize)]
struct SplitReport {
name: &'static str,
roots: usize,
paths: Vec<PathMetrics>,
}
#[derive(Debug, Serialize)]
struct FutureFamilyReport {
family: &'static str,
roots: usize,
stateful_success_rate: f64,
maximum_control_success_rate: f64,
pass: bool,
}
#[derive(Debug, Serialize)]
struct GateReport {
train_support_exact: bool,
holdout_support_exact: bool,
future_support_exact: bool,
future_family_count_exact: bool,
stateful_training_perfect: bool,
stateful_holdout_perfect: bool,
stateful_future_perfect: bool,
endpoint_future_zero: bool,
text_future_zero: bool,
scalar_future_zero: bool,
rewired_future_zero: bool,
random_valid_future_zero: bool,
delayed_future_zero: bool,
invalid_rejection_perfect: bool,
rewired_rejection_perfect: bool,
all_future_families_pass: bool,
budgets_exact: bool,
replay_exact: bool,
invariants_valid: bool,
}
impl GateReport {
fn all_pass(&self) -> bool {
self.train_support_exact
&& self.holdout_support_exact
&& self.future_support_exact
&& self.future_family_count_exact
&& self.stateful_training_perfect
&& self.stateful_holdout_perfect
&& self.stateful_future_perfect
&& self.endpoint_future_zero
&& self.text_future_zero
&& self.scalar_future_zero
&& self.rewired_future_zero
&& self.random_valid_future_zero
&& self.delayed_future_zero
&& self.invalid_rejection_perfect
&& self.rewired_rejection_perfect
&& self.all_future_families_pass
&& self.budgets_exact
&& self.replay_exact
&& self.invariants_valid
}
}
#[derive(Debug, Serialize)]
struct Report {
experiment: &'static str,
primitive: &'static str,
operation_a: &'static str,
operation_b: &'static str,
objective_witness: &'static str,
claim_boundary: &'static str,
frozen_contract: FrozenContract,
total_roots: usize,
training: SplitReport,
holdout: SplitReport,
future: SplitReport,
future_families: Vec<FutureFamilyReport>,
gates: GateReport,
terminal_classification: &'static str,
}
fn main() -> Result<(), Box<dyn Error>> {
let tasks = build_tasks()?;
let train_end = TRAIN_FAMILIES * REPEATS_PER_FAMILY;
let holdout_end = train_end + HOLDOUT_FAMILIES * REPEATS_PER_FAMILY;
let train = &tasks[..train_end];
let holdout = &tasks[train_end..holdout_end];
let future = &tasks[holdout_end..];
if train.len() != 16 || holdout.len() != 8 || future.len() != 32 || tasks.len() != 56 {
return Err(format!(
"H9 frozen cohort mismatch: total={} train={} holdout={} future={}",
tasks.len(),
train.len(),
holdout.len(),
future.len()
)
.into());
}
let train_eval = evaluate_split("training", train)?;
let holdout_eval = evaluate_split("holdout", holdout)?;
let future_eval = evaluate_split("future", future)?;
let training = split_report("training", train, &train_eval);
let holdout_report = split_report("holdout", holdout, &holdout_eval);
let future_report = split_report("future", future, &future_eval);
let mut future_family_reports = Vec::new();
for family_index in (TRAIN_FAMILIES + HOLDOUT_FAMILIES)..FAMILY_NAMES.len() {
let family_tasks: Vec<_> = future
.iter()
.filter(|task| task.family_index == family_index)
.cloned()
.collect();
let evaluation = evaluate_split("future_family", &family_tasks)?;
let stateful = metrics_for(PathMode::Stateful, &family_tasks, &evaluation);
let maximum_control_success_rate = PathMode::all()
.into_iter()
.filter(|mode| *mode != PathMode::Stateful)
.map(|mode| metrics_for(mode, &family_tasks, &evaluation).success_rate)
.fold(0.0_f64, f64::max);
future_family_reports.push(FutureFamilyReport {
family: FAMILY_NAMES[family_index],
roots: family_tasks.len(),
stateful_success_rate: stateful.success_rate,
maximum_control_success_rate,
pass: exact_one(stateful.success_rate) && exact_zero(maximum_control_success_rate),
});
}
let train_stateful = path_from_report(&training, PathMode::Stateful);
let holdout_stateful = path_from_report(&holdout_report, PathMode::Stateful);
let future_stateful = path_from_report(&future_report, PathMode::Stateful);
let future_endpoint = path_from_report(&future_report, PathMode::EndpointBlind);
let future_text = path_from_report(&future_report, PathMode::TextOnly);
let future_scalar = path_from_report(&future_report, PathMode::ScalarOnly);
let future_rewired = path_from_report(&future_report, PathMode::Rewired);
let future_random = path_from_report(&future_report, PathMode::RandomValid);
let _future_invalid = path_from_report(&future_report, PathMode::InvalidMatched);
let future_delayed = path_from_report(&future_report, PathMode::Delayed);
let all_reports = [&training, &holdout_report, &future_report];
let gates = GateReport {
train_support_exact: training.roots == 16,
holdout_support_exact: holdout_report.roots == 8,
future_support_exact: future_report.roots == 32,
future_family_count_exact: future_family_reports.len() == FUTURE_FAMILIES,
stateful_training_perfect: exact_one(train_stateful.success_rate),
stateful_holdout_perfect: exact_one(holdout_stateful.success_rate),
stateful_future_perfect: exact_one(future_stateful.success_rate),
endpoint_future_zero: exact_zero(future_endpoint.success_rate),
text_future_zero: exact_zero(future_text.success_rate),
scalar_future_zero: exact_zero(future_scalar.success_rate),
rewired_future_zero: exact_zero(future_rewired.success_rate),
random_valid_future_zero: exact_zero(future_random.success_rate),
delayed_future_zero: exact_zero(future_delayed.success_rate),
invalid_rejection_perfect: all_reports.iter().all(|report| {
exact_one(path_from_report(report, PathMode::InvalidMatched).rejection_rate)
}),
rewired_rejection_perfect: all_reports
.iter()
.all(|report| exact_one(path_from_report(report, PathMode::Rewired).rejection_rate)),
all_future_families_pass: future_family_reports.iter().all(|report| report.pass),
budgets_exact: all_reports
.iter()
.flat_map(|report| report.paths.iter())
.all(|metrics| metrics.budget_exact),
replay_exact: all_reports
.iter()
.flat_map(|report| report.paths.iter())
.all(|metrics| metrics.replay_exact),
invariants_valid: all_reports
.iter()
.flat_map(|report| report.paths.iter())
.all(|metrics| metrics.invariants_valid),
};
let terminal_classification = if !gates.invariants_valid {
"INFRASTRUCTURE_FAILURE"
} else if !gates.budgets_exact {
"BUDGET_FAILURE"
} else if !gates.replay_exact {
"REPLAY_FAILURE"
} else if gates.stateful_future_perfect
&& (!gates.endpoint_future_zero
|| !gates.text_future_zero
|| !gates.scalar_future_zero
|| !gates.rewired_future_zero
|| !gates.random_valid_future_zero
|| !gates.delayed_future_zero
|| !gates.invalid_rejection_perfect
|| !gates.rewired_rejection_perfect)
{
"CONTROL_FAILURE"
} else if gates.all_pass() {
"PASS"
} else {
"REJECTED"
};
let report = Report {
experiment: "H9 proof-carrying executable commitment state",
primitive: "validated typed commitments with witness or derivation provenance; only committed facts and rules participate in future execution",
operation_a: "existing CausalEngine-backed compilation of one raw witnessed relation into a typed CompileWitnessedRule delta",
operation_b: "three fixed canonical executable-closure scans that can read commitments but cannot read raw observations, transcript text, scalar history, family labels, or verifier target",
objective_witness: "external exact target-atom membership check over final executable facts",
claim_boundary: "demonstrates state-dependent composition in the H9 shadow substrate only; does not establish learned operator invention, automatic ontology induction, live routing readiness, AGI, consciousness, or human-level reasoning",
frozen_contract: FrozenContract {
repeats_per_family: REPEATS_PER_FAMILY,
train_families: TRAIN_FAMILIES,
holdout_families: HOLDOUT_FAMILIES,
future_families: FUTURE_FAMILIES,
executor_scans: EXECUTOR_SCANS,
operation_calls_per_path: OPERATION_CALLS_PER_PATH,
causal_engine_calls_per_path: CAUSAL_ENGINE_CALLS_PER_PATH,
transition_slots_per_path: TRANSITION_SLOTS_PER_PATH,
objective_checks_per_path: OBJECTIVE_CHECKS_PER_PATH,
},
total_roots: tasks.len(),
training,
holdout: holdout_report,
future: future_report,
future_families: future_family_reports,
gates,
terminal_classification,
};
println!("{}", serde_json::to_string_pretty(&report)?);
if terminal_classification != "PASS" {
std::process::exit(1);
}
Ok(())
}
fn build_tasks() -> Result<Vec<Task>, Box<dyn Error>> {
let mut tasks = Vec::with_capacity(FAMILY_NAMES.len() * REPEATS_PER_FAMILY);
for (family_index, family_name) in FAMILY_NAMES.iter().copied().enumerate() {
for repeat in 0..REPEATS_PER_FAMILY {
let id = (family_index * REPEATS_PER_FAMILY + repeat + 1) as u64;
let prefix = format!("{family_name}_{repeat}");
let source = Atom::new(format!("{prefix}_source"))?;
let middle = Atom::new(format!("{prefix}_middle"))?;
let goal = Atom::new(format!("{prefix}_goal"))?;
let decoy_source = Atom::new(format!("{prefix}_decoy_source"))?;
let decoy_goal = Atom::new(format!("{prefix}_decoy_goal"))?;
let target_rule = Rule::new(middle.clone(), goal.clone())?;
let decoy_rule = Rule::new(decoy_source.clone(), decoy_goal.clone())?;
tasks.push(Task {
id,
family_index,
family_name,
source,
middle,
goal,
decoy_source,
decoy_goal,
target_witness_id: id * 2,
decoy_witness_id: id * 2 + 1,
target_rule,
decoy_rule,
});
}
}
Ok(tasks)
}
fn initial_state(task: &Task) -> Result<ExecutableCommitmentState, CommitmentStateError> {
let mut state = ExecutableCommitmentState::new();
state.seed_fact(task.source.clone())?;
state.seed_fact(task.decoy_source.clone())?;
state.seed_rule(Rule::new(task.source.clone(), task.middle.clone())?)?;
state.add_observation(WitnessedRule {
witness_id: task.target_witness_id,
rule: task.target_rule.clone(),
})?;
state.add_observation(WitnessedRule {
witness_id: task.decoy_witness_id,
rule: task.decoy_rule.clone(),
})?;
Ok(state)
}
fn compile_with_causal_engine(
state: &ExecutableCommitmentState,
witness_id: u64,
) -> Result<StateDelta, Box<dyn Error>> {
let witness = state
.observation(witness_id)
.ok_or_else(|| format!("missing witness {witness_id}"))?;
let mut engine = CausalEngine::new();
engine.add_edge(
witness.rule.antecedent.as_str(),
witness.rule.consequent.as_str(),
1.0,
None,
);
let edge = engine
.get_effects_of(witness.rule.antecedent.as_str())
.into_iter()
.find(|edge| edge.effect == witness.rule.consequent.as_str())
.ok_or("CausalEngine failed to reproduce witnessed relation")?;
Ok(StateDelta::CompileWitnessedRule {
witness_id,
rule: Rule::new(Atom::new(edge.cause.clone())?, Atom::new(edge.effect.clone())?)?,
})
}
fn execute_split_path(
task: &Task,
mode: PathMode,
rewired_rule: Option<&Rule>,
) -> Result<PathResult, Box<dyn Error>> {
let mut state = initial_state(task)?;
let compiler_delta = match mode {
PathMode::RandomValid => compile_with_causal_engine(&state, task.decoy_witness_id)?,
_ => compile_with_causal_engine(&state, task.target_witness_id)?,
};
let mut compile_rejected = false;
let mut successful_state_mutations = 0usize;
let mut text_history_bytes = 0usize;
let mut scalar_history_count = 0usize;
if mode != PathMode::Delayed {
match mode {
PathMode::Stateful | PathMode::RandomValid => {
state.apply_delta(compiler_delta.clone())?;
successful_state_mutations += 1;
}
PathMode::EndpointBlind => {}
PathMode::TextOnly => {
text_history_bytes = serde_json::to_string(&compiler_delta)?.len();
}
PathMode::ScalarOnly => {
scalar_history_count = 1;
}
PathMode::Rewired => {
let delta = StateDelta::CompileWitnessedRule {
witness_id: task.target_witness_id,
rule: rewired_rule.ok_or("rewired path missing donor rule")?.clone(),
};
match state.apply_delta(delta) {
Ok(_) => successful_state_mutations += 1,
Err(CommitmentStateError::WitnessMismatch(_)) => compile_rejected = true,
Err(error) => return Err(error.into()),
}
}
PathMode::InvalidMatched => {
let delta = StateDelta::CompileWitnessedRule {
witness_id: task.target_witness_id,
rule: task.decoy_rule.clone(),
};
match state.apply_delta(delta) {
Ok(_) => successful_state_mutations += 1,
Err(CommitmentStateError::WitnessMismatch(_)) => compile_rejected = true,
Err(error) => return Err(error.into()),
}
}
PathMode::Delayed => unreachable!(),
}
}
for _ in 0..EXECUTOR_SCANS {
if let Some(delta) = state.enabled_derivations().into_iter().next() {
state.apply_delta(delta)?;
successful_state_mutations += 1;
}
}
if mode == PathMode::Delayed {
state.apply_delta(compiler_delta)?;
successful_state_mutations += 1;
}
let invariants_valid = state.verify_invariants().is_ok();
let success = independent_objective_check(&state, &task.goal);
Ok(PathResult {
success,
compile_rejected,
successful_state_mutations,
operation_calls: OPERATION_CALLS_PER_PATH,
causal_engine_calls: CAUSAL_ENGINE_CALLS_PER_PATH,
transition_slots: TRANSITION_SLOTS_PER_PATH,
search_scans: EXECUTOR_SCANS,
objective_checks: OBJECTIVE_CHECKS_PER_PATH,
text_history_bytes,
scalar_history_count,
state_signature: state.canonical_signature(),
invariants_valid,
})
}
fn independent_objective_check(state: &ExecutableCommitmentState, target: &Atom) -> bool {
state.contains_fact(target)
}
fn evaluate_split(
_name: &'static str,
tasks: &[Task],
) -> Result<BTreeMap<PathMode, Vec<(PathResult, bool)>>, Box<dyn Error>> {
let mut result = BTreeMap::<PathMode, Vec<(PathResult, bool)>>::new();
for mode in PathMode::all() {
let mut rows = Vec::with_capacity(tasks.len());
for (index, task) in tasks.iter().enumerate() {
let donor_rule = if tasks.is_empty() {
None
} else {
Some(&tasks[(index + 1) % tasks.len()].target_rule)
};
let first = execute_split_path(task, mode, donor_rule)?;
let second = execute_split_path(task, mode, donor_rule)?;
let replay_exact = first == second;
rows.push((first, replay_exact));
}
result.insert(mode, rows);
}
Ok(result)
}
fn split_report(
name: &'static str,
tasks: &[Task],
evaluation: &BTreeMap<PathMode, Vec<(PathResult, bool)>>,
) -> SplitReport {
SplitReport {
name,
roots: tasks.len(),
paths: PathMode::all()
.into_iter()
.map(|mode| metrics_for(mode, tasks, evaluation))
.collect(),
}
}
fn metrics_for(
mode: PathMode,
tasks: &[Task],
evaluation: &BTreeMap<PathMode, Vec<(PathResult, bool)>>,
) -> PathMetrics {
let rows = evaluation.get(&mode).map(Vec::as_slice).unwrap_or(&[]);
let roots = tasks.len();
let successes = rows.iter().filter(|(row, _)| row.success).count();
let rejected_compiles = rows
.iter()
.filter(|(row, _)| row.compile_rejected)
.count();
let mutation_total: usize = rows
.iter()
.map(|(row, _)| row.successful_state_mutations)
.sum();
PathMetrics {
path: mode.name(),
roots,
successes,
success_rate: rate(successes, roots),
rejected_compiles,
rejection_rate: rate(rejected_compiles, roots),
mean_successful_state_mutations: mutation_total as f64 / roots.max(1) as f64,
budget_exact: rows.iter().all(|(row, _)| row.budget_exact()),
replay_exact: rows.iter().all(|(_, replay)| *replay),
invariants_valid: rows.iter().all(|(row, _)| row.invariants_valid),
}
}
fn path_from_report(report: &SplitReport, mode: PathMode) -> &PathMetrics {
report
.paths
.iter()
.find(|metrics| metrics.path == mode.name())
.expect("every frozen path must be present")
}
fn rate(numerator: usize, denominator: usize) -> f64 {
numerator as f64 / denominator.max(1) as f64
}
fn exact_one(value: f64) -> bool {
value.to_bits() == 1.0_f64.to_bits()
}
fn exact_zero(value: f64) -> bool {
value.to_bits() == 0.0_f64.to_bits()
}
|