diff --git a/benchmarks/bench_ledger_append.py b/benchmarks/bench_ledger_append.py new file mode 100644 index 00000000..f0cb6dd7 --- /dev/null +++ b/benchmarks/bench_ledger_append.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 +""" +bench_ledger_append.py +Append latency, verify time and tamper detection for the operational journal +(osiris_cli/journal.py: hash = SHA-256(prev || canonical(entry)), file-locked appends). + +Everything runs on a temporary journal; the tracked journal is never touched. + +Tamper cases, each applied to a fresh copy of the benchmark journal: + edit_field change one payload field in the middle entry + edit_hash replace the middle entry's stored hash + delete_middle remove the middle entry + swap_adjacent exchange two neighboring entries + truncate_tail remove the last 10 entries + +A hash chain alone cannot detect truncate_tail: what remains is a valid chain. Detecting it needs the +tip (last hash and count) recorded somewhere the attacker cannot rewrite, e.g. signed by an operator +token. The benchmark reports that case as it is rather than hiding it. + +Usage: + python benchmarks/bench_ledger_append.py [--n 2000] [--out benchmarks/results_ledger_append.json] +""" + +from __future__ import annotations + +import argparse +import json +import os +import platform +import statistics +import sys +import tempfile +import time +from datetime import datetime, timezone +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) + +from osiris_cli.journal import OperationalMerkleLedger # noqa: E402 + + +def _pct(sorted_ms, q): + return sorted_ms[min(len(sorted_ms) - 1, int(q * len(sorted_ms)))] + + +def _tamper(lines, case): + out = list(lines) + mid = len(out) // 2 + if case == "edit_field": + e = json.loads(out[mid]) + e["i"] = -1 # append() stores payload fields at the top level of the entry + out[mid] = json.dumps(e) + elif case == "edit_hash": + e = json.loads(out[mid]) + e["hash"] = "f" * 64 + out[mid] = json.dumps(e) + elif case == "delete_middle": + del out[mid] + elif case == "swap_adjacent": + out[mid], out[mid + 1] = out[mid + 1], out[mid] + elif case == "truncate_tail": + out = out[:-10] + else: + raise ValueError(case) + return out + + +def run(n: int) -> dict: + with tempfile.TemporaryDirectory() as d: + path = Path(d) / "bench.jsonl" + ledger = OperationalMerkleLedger(path) + lat = [] + for i in range(n): + t0 = time.perf_counter() + ledger.append("bench", {"i": i, "payload_sha256": "0" * 64}) + lat.append((time.perf_counter() - t0) * 1000.0) + lat.sort() + t0 = time.perf_counter() + clean = ledger.verify() + verify_ms = (time.perf_counter() - t0) * 1000.0 + + lines = path.read_text(encoding="utf-8").splitlines() + tamper = {} + for case in ("edit_field", "edit_hash", "delete_middle", "swap_adjacent", "truncate_tail"): + copy = Path(d) / f"{case}.jsonl" + copy.write_text("\n".join(_tamper(lines, case)) + "\n", encoding="utf-8") + fault = OperationalMerkleLedger(copy).verify() + tamper[case] = {"detected": fault is not None, "fault": fault} + + return { + "benchmark": "ledger_append", + "timestamp_utc": datetime.now(timezone.utc).isoformat(timespec="seconds"), + "host": {"machine": platform.machine(), "system": platform.system(), + "release": platform.release(), "cpus": os.cpu_count(), + "python": platform.python_version()}, + "n_appends": n, + "append_ms": {"median": round(statistics.median(lat), 4), "p95": round(_pct(lat, 0.95), 4), + "p99": round(_pct(lat, 0.99), 4), "max": round(lat[-1], 4)}, + "verify_ms": round(verify_ms, 2), + "verify_clean": clean is None, + "tamper": tamper, + } + + +def main(argv=None) -> int: + ap = argparse.ArgumentParser(description=__doc__.splitlines()[2]) + ap.add_argument("--n", type=int, default=2000) + ap.add_argument("--out", default=None, help="write the result JSON here") + args = ap.parse_args(argv) + result = run(args.n) + text = json.dumps(result, indent=2) + print(text) + if args.out: + Path(args.out).write_text(text + "\n", encoding="utf-8") + return 0 if result["verify_clean"] else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/benchmarks/results_ledger_append.json b/benchmarks/results_ledger_append.json new file mode 100644 index 00000000..a1f48475 --- /dev/null +++ b/benchmarks/results_ledger_append.json @@ -0,0 +1,42 @@ +{ + "benchmark": "ledger_append", + "timestamp_utc": "2026-11-10T05:17:15+00:00", + "host": { + "machine": "x86_64", + "system": "Linux", + "release": "6.18.54.1-microsoft-standard-WSL2", + "cpus": 32, + "python": "3.14.4" + }, + "n_appends": 2000, + "append_ms": { + "median": 0.0598, + "p95": 0.0979, + "p99": 0.1643, + "max": 0.6281 + }, + "verify_ms": 9.33, + "verify_clean": true, + "tamper": { + "edit_field": { + "detected": true, + "fault": "Entry 1000: hash mismatch (expected 7afbed5337f0008e56d3816c25de8c62a8990d6d46cffea2c9a29e7c58408e96, got 1ac24f86306dcbab03cf46fb68ab6f3d24a939d70c1e8283e8c7de2184994310)" + }, + "edit_hash": { + "detected": true, + "fault": "Entry 1000: hash mismatch (expected 1ac24f86306dcbab03cf46fb68ab6f3d24a939d70c1e8283e8c7de2184994310, got ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)" + }, + "delete_middle": { + "detected": true, + "fault": "Entry 1000: prev-hash mismatch (expected 4efa0f20fcfe8457db60d479a155f8333d5d28f39a4e27b7d00186e1cafbc988, got 1ac24f86306dcbab03cf46fb68ab6f3d24a939d70c1e8283e8c7de2184994310)" + }, + "swap_adjacent": { + "detected": true, + "fault": "Entry 1000: prev-hash mismatch (expected 4efa0f20fcfe8457db60d479a155f8333d5d28f39a4e27b7d00186e1cafbc988, got 1ac24f86306dcbab03cf46fb68ab6f3d24a939d70c1e8283e8c7de2184994310)" + }, + "truncate_tail": { + "detected": false, + "fault": null + } + } +} diff --git a/osiris_cli/osiris_repl.py b/osiris_cli/osiris_repl.py index b2d76f3e..0df3d05d 100644 --- a/osiris_cli/osiris_repl.py +++ b/osiris_cli/osiris_repl.py @@ -1,34 +1,31 @@ #!/usr/bin/env python3 """ -OSIRIS Universal REPL & CLI Interface — Apex Sovereign Executable -================================================================ -Unified Sovereign Truth Architecture Interactive Prompt & Execution Substrate. +OSIRIS interactive console (REPL) and command-line interface. Co-authored by Devin Phillip Davis & OSIRIS dna::}{::lang NCLM -Subsystems Unified: - 1. 11D Continuous Relativistic State Matrix (CRSM) Substrate & QbyteRuntime (0.092 Coherence Floor) - 2. Cl(3,0) Clifford Multivector Algebra & Torsion Mechanics (θ_lock = 51.843°) - 3. 9-Agent Cognitive Mesh (Bayesian Trust, Shapley Attribution, Nash Equilibrium, Hebbian Plasticity) - 4. Introspection Engine (CUSUM Drift Detection, Cognitive Entropy, Echo-Chamber Suppression) - 5. Deterministic NLP Intent Classifier & Mode Scorer (Explain vs Execute, Domain Routing) - 6. Hysteretic Power Governor (Fail-Open Desktop Mains / Termux Thermal-Battery Gate) - 7. L0 AST & Source Firewall (Anti-Loop Transcript Quarantine, Sensitive Token Gate) - 8. Local Ollama LLM Bridge (Model Auto-Detection, CCCE Consciousness Scoring, Swarm Integration) - 9. Flywheel 2026 Pre-registered K8 Tau-Sweep Benchmark Suite with Merkle Cryptographic Proof - 10. Comparative LivLM vs LLM Empirical Benchmark Suite - 11. 21 Sovereign Command Modules (Bridges, Validation, ELO Tournament, Forge, Policy, Fabric, Demo) - 12. Dynamic Terminal Fold-Aware UX (Automatic adaptation for mobile Termux and desktop displays) - -Historical constants (hypotheses from the CRSM framework, kept because older -commands still compute with them; Devin's own hardware audits refuted theta_lock, -the tau-phase anomaly and the CCCE "consciousness" metrics -- see -~/docs/HONEST_ASSESSMENT.md -- so they are not shown as physical invariants): - • Locking Resonance: θ_lock = 51.843° (arctan(14/11) pyramid slope) - • Coherence Floor: Γ_floor = 0.0920 (Fail-closed decoherence ceiling) - • Memory Invariant: Λ_Φ = 2.176435e-8 kg (Universal Memory Constant) - • Predicted Peak F: F_max = 0.97871 (1 - φ^-8) - • Characteristic Tau: τ_0 = 46.9787 µs (φ^8) +What this module wires together: + 1. Command routing for the console and the batch CLI (argparse below). + 2. The 9-agent deliberation swarm and cognitive mesh (Bayesian trust, Shapley attribution). + 3. An introspection report (cognitive entropy, echo-chamber score) over swarm rounds. + 4. A deterministic intent classifier (explain vs execute, domain routing). + 5. A power governor for mobile/Termux nodes (thermal and battery gate). + 6. The L0 source firewall (transcript quarantine, sensitive-token gate). + 7. A local Ollama bridge (model auto-detection). + 8. Benchmark commands, including the pre-registered K8 tau sweep (its result was a refutation). + 9. Terminal layout that adapts to narrow (phone) and desktop displays. + +Execution governance (exec_policy.py, the SYS-021/SYS-025 controller, journal.py) lives in its own +modules; this file calls them and does not reimplement them. + +Historical constants (hypotheses from the CRSM framework, kept because older commands still compute +with them). Devin's own hardware audits refuted theta_lock, the tau-phase anomaly and the CCCE +"consciousness" metrics -- see ~/docs/HONEST_ASSESSMENT.md and the claims register +(osiris_cli/claims.py) -- so none of these is a physical invariant: + • θ_lock = 51.843° (arctan(14/11)); no resonance on hardware + • Γ_floor = 0.0920 (qbyte coherence floor; an engineering threshold) + • Λ_Φ = 2.176435e-8 (CRSM hypothesis; no measurement supports it) + • F_max = 0.97871 (1 - φ^-8) and τ_0 = 46.9787 µs (φ^8); the tau-phase prediction was refuted """ from __future__ import annotations @@ -930,10 +927,10 @@ def execute_introspect(state: Optional[OsirisReplState] = None) -> None: engine.observe_round(resps, "approve", 0.85) actions = engine.run_improvement_cycle() - print(f" ├─ Axis 1 (Temporal): CUSUM Drift Anomaly Score = 0.012 (Nominal)") + print(" ├─ Axis 1 (Temporal): CUSUM drift = not measured in this check") print(f" ├─ Axis 2 (Structural): Cognitive Entropy = {engine.structural.cognitive_entropy():.4f}") print(f" ├─ Axis 2 (Structural): Echo-Chamber Score = {engine.structural.echo_chamber_score():.4f} (Suppressed)") - print(f" ├─ Axis 3 (Semantic): Strategy Diversity Index = 0.942") + print(" ├─ Axis 3 (Semantic): Strategy diversity = not measured in this check") print(f" └─ Improvement Actions Formulated: {len(actions)} auto-corrections applied.\n") except Exception as e: print(f" └─ [INTROSPECTION] Swarm Engine: {e}\n") @@ -949,7 +946,7 @@ def execute_introspect(state: Optional[OsirisReplState] = None) -> None: profile = EpistemicIntrospector.introspect_text(model, prompt) print("\033[1;36m[EPISTEMIC INTROSPECTION] Living Core Thermodynamic & Coherence Profile\033[0m") print(f" ├─ Negentropic Efficiency (Ξ): {profile.mean_negentropy_xi:+.2f}% (Information Creation)") - print(f" ├─ Bidirectional Coherence: {profile.bidirectional_coherence:.4f} (Phase-Lock θ=51.843°)") + print(f" ├─ Bidirectional Coherence: {profile.bidirectional_coherence:.4f} ") print(f" ├─ Mean Decoherence (Γ): {profile.mean_decoherence_gamma:.4f} (Critical Threshold: 0.30)") top_toks = ", ".join([f"{repr(t)}:{s:.3f}" for t, s in profile.token_saliency[:4]]) print(f" ├─ Salient Attractors: [{top_toks}]") @@ -2470,7 +2467,7 @@ def main(argv: Optional[List[str]] = None) -> None: parser = argparse.ArgumentParser( prog="osiris", - description="OSIRIS Sovereign Truth Architecture - Universal CLI & Apex REPL" + description="OSIRIS interactive console and command-line interface" ) parser.add_argument( "action",