From a164b2b27cad7f2dc18b514acfff495ebc01d193 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 6 Nov 2026 18:19:40 -0600 Subject: [PATCH] Specify shared-state Omega Node and verify control invariants in Lean --- design/omega-node/NodeModel.lean | 182 ++++++++++++++++++ design/omega-node/README.md | 144 ++++++++++++++ design/omega-node/controls/RejectFalse.lean | 4 + design/omega-node/lean-output.txt | 15 ++ design/omega-node/lean-toolchain | 1 + design/omega-node/negative-control-output.txt | 3 + 6 files changed, 349 insertions(+) create mode 100644 design/omega-node/NodeModel.lean create mode 100644 design/omega-node/README.md create mode 100644 design/omega-node/controls/RejectFalse.lean create mode 100644 design/omega-node/lean-output.txt create mode 100644 design/omega-node/lean-toolchain create mode 100644 design/omega-node/negative-control-output.txt diff --git a/design/omega-node/NodeModel.lean b/design/omega-node/NodeModel.lean new file mode 100644 index 0000000..9e6f29a --- /dev/null +++ b/design/omega-node/NodeModel.lean @@ -0,0 +1,182 @@ +import Std + +/-! An abstract specification for Omega Node, not a proof of a deployed runtime. + Transitions are serialized. Natural numbers do not wrap. Timing assumptions + are explicit hypotheses; OS scheduling and storage are outside this model. -/ +namespace OmegaNode + +inductive Phase where + | ready | running | canceled | review + deriving DecidableEq, Repr + +structure Task where + epoch : Nat + owner : Option Nat + phase : Phase + deriving DecidableEq, Repr + +structure Ticket where + epoch : Nat + worker : Nat + deriving DecidableEq, Repr + +def Authorized (s : Task) (t : Ticket) : Prop := + s.epoch = t.epoch ∧ s.owner = some t.worker ∧ s.phase = .running + +instance (s : Task) (t : Ticket) : Decidable (Authorized s t) := + inferInstanceAs (Decidable (_ ∧ _ ∧ _)) + +def claim (s : Task) (worker : Nat) : Task := + if s.phase = .ready then ⟨s.epoch + 1, some worker, .running⟩ else s + +def cancel (s : Task) : Task := ⟨s.epoch + 1, none, .canceled⟩ + +def complete (s : Task) (t : Ticket) : Task := + if Authorized s t then {s with phase := .review} else s + +theorem one_authorized_worker (s : Task) (a b : Ticket) + (ha : Authorized s a) (hb : Authorized s b) : a.worker = b.worker := by + exact Option.some.inj (ha.2.1.symm.trans hb.2.1) + +theorem stale_completion_unchanged (s : Task) (t : Ticket) + (h : s.epoch ≠ t.epoch) : complete s t = s := by + simp [complete, Authorized, h] + +theorem cancel_rejects_every_completion (s : Task) (t : Ticket) : + complete (cancel s) t = cancel s := by + simp [complete, Authorized, cancel] + +theorem cancel_invalidates_old_ticket (s : Task) (t : Ticket) + (h : t.epoch ≤ s.epoch) : (cancel s).epoch ≠ t.epoch := by + simp only [cancel]; omega + +theorem claim_does_not_replace_running_owner (s : Task) (worker : Nat) + (h : s.phase = .running) : claim s worker = s := by + simp [claim, h] + +theorem claim_epoch_monotone (s : Task) (worker : Nat) : + s.epoch ≤ (claim s worker).epoch := by + unfold claim + split <;> simp_all + +/- Bounded admission for outstanding work credits (queued plus active). + A successful finish releases a credit. Duplicate finishes must be excluded + by the task state machine before calling release. -/ +inductive CreditEvent where + | request | release + deriving Repr + +def creditStep (cap q : Nat) : CreditEvent → Nat + | .request => if q < cap then q + 1 else q + | .release => q - 1 + +theorem credits_step_bounded (cap q : Nat) (e : CreditEvent) + (h : q ≤ cap) : creditStep cap q e ≤ cap := by + cases e with + | request => simp only [creditStep]; split <;> omega + | release => simp only [creditStep]; omega + +def creditsRun (cap : Nat) : Nat → List CreditEvent → Nat + | q, [] => q + | q, e :: es => creditsRun cap (creditStep cap q e) es + +theorem credits_all_traces_bounded (cap q : Nat) (events : List CreditEvent) + (h : q ≤ cap) : creditsRun cap q events ≤ cap := by + induction events generalizing q with + | nil => exact h + | cons e es ih => exact ih _ (credits_step_bounded cap q e h) + +/- Work holds its credit until review is resolved, not merely until inference + finishes. These are abstract valid lifecycle events; runtime task IDs must + exclude duplicate or mismatched events. -/ +structure Pool where + free : Nat + busy : Nat + review : Nat + deriving Repr + +def total (p : Pool) : Nat := p.free + p.busy + p.review + +inductive PoolEvent where + | admit | finish | resolve + +def poolStep (p : Pool) : PoolEvent → Pool + | .admit => if p.free > 0 then ⟨p.free - 1, p.busy + 1, p.review⟩ else p + | .finish => if p.busy > 0 then ⟨p.free, p.busy - 1, p.review + 1⟩ else p + | .resolve => if p.review > 0 then ⟨p.free + 1, p.busy, p.review - 1⟩ else p + +theorem pool_step_conserves (p : Pool) (e : PoolEvent) : + total (poolStep p e) = total p := by + cases e <;> simp only [poolStep] <;> split <;> simp_all [total] <;> omega + +def poolRun : Pool → List PoolEvent → Pool + | p, [] => p + | p, e :: es => poolRun (poolStep p e) es + +theorem pool_trace_conserves (p : Pool) (events : List PoolEvent) : + total (poolRun p events) = total p := by + induction events generalizing p with + | nil => rfl + | cons e es ih => + exact (ih (poolStep p e)).trans (pool_step_conserves p e) + +theorem review_backlog_bounded (cap : Nat) (events : List PoolEvent) : + (poolRun ⟨cap, 0, 0⟩ events).review ≤ cap := by + have h := pool_trace_conserves ⟨cap, 0, 0⟩ events + simp only [total, Nat.add_zero] at h + omega + +/- Control handlers consume bounded integer time ticks. This proves only the + algebraic bound once the implementation supplies valid measured/worst-case + bounds and prevents other work from interleaving ahead of the batch. -/ +theorem handler_sum_bounded (costs : List Nat) (budget : Nat) + (h : ∀ c ∈ costs, c ≤ budget) : costs.sum ≤ costs.length * budget := by + induction costs with + | nil => simp + | cons c cs ih => + have hc := h c (by simp) + have hs : ∀ x ∈ cs, x ≤ budget := by + intro x hx + exact h x (by simp [hx]) + have hi := ih hs + simp only [List.sum_cons, List.length_cons, Nat.add_mul, Nat.one_mul] + omega + +theorem control_batch_bound (costs : List Nat) (budget n block jitter elapsed : Nat) + (hcost : ∀ c ∈ costs, c ≤ budget) (hcount : costs.length ≤ n) + (htime : elapsed ≤ block + jitter + costs.sum) : + elapsed ≤ block + jitter + n * budget := by + have hs := handler_sum_bounded costs budget hcost + have hm := Nat.mul_le_mul_right budget hcount + omega + +/- A negative control: authorization by display name alone accepts an old + attempt after the same worker is reassigned. -/ +def brokenAuthorized (s : Task) (t : Ticket) : Prop := + s.owner = some t.worker ∧ s.phase = .running + +theorem broken_name_only_accepts_stale : + brokenAuthorized ⟨2, some 7, .running⟩ ⟨1, 7⟩ ∧ + ¬ Authorized ⟨2, some 7, .running⟩ ⟨1, 7⟩ := by + simp [brokenAuthorized, Authorized] + +def brokenRequest (q : Nat) : Nat := q + 1 +theorem broken_admission_exceeds_capacity : brokenRequest 3 > 3 := by decide + +#print axioms one_authorized_worker +#print axioms stale_completion_unchanged +#print axioms cancel_rejects_every_completion +#print axioms cancel_invalidates_old_ticket +#print axioms claim_does_not_replace_running_owner +#print axioms claim_epoch_monotone +#print axioms credits_step_bounded +#print axioms credits_all_traces_bounded +#print axioms pool_step_conserves +#print axioms pool_trace_conserves +#print axioms review_backlog_bounded +#print axioms handler_sum_bounded +#print axioms control_batch_bound +#print axioms broken_name_only_accepts_stale +#print axioms broken_admission_exceeds_capacity + +end OmegaNode diff --git a/design/omega-node/README.md b/design/omega-node/README.md new file mode 100644 index 0000000..c92d95b --- /dev/null +++ b/design/omega-node/README.md @@ -0,0 +1,144 @@ +# Omega Node: shared state, coordinated pulses, checked decisions + +Design for [Omega Node #205](https://github.com/aien-dev/omega-harness/issues/205). +Drake's direction: build in Omega, work as one hive, and investigate a shared rhythm rather +than repeated conversations between agents. This directory contains a checked abstract model +and the proposed engineering design. No native runtime or physical-wave computer is claimed. + +## The design + +Keep one versioned shared work state. Each worker reads the same immutable revision, computes +only the work affected by a change, and proposes a delta with its source revision and task ticket. +Publish accepted deltas in short pulses. A pulse is a revision becoming visible; it is not a barrier +requiring every worker to finish. Slow workers can finish later and have their result validated +against the current revision. Conflicting changes require explicit reconciliation. + +On one machine, investigate shared read-only mappings and bounded publication descriptors. +Readers reuse the underlying artifacts rather than receiving another serialized chat history. +Across machines, transmit missing content and versioned deltas. A notification that content changed +does not transfer that content. Shared memory still incurs cache/coherence traffic and a remote +machine still needs a physical communication channel. A rhythm coordinates computation; its +frequency does not encode arbitrary task meaning by itself. + +This combines established shared-buffer and incremental-dataflow ideas in an Omega implementation. +It is a design synthesis, not a claim to have invented those underlying algorithms: +- [LMAX Disruptor](https://lmax-exchange.github.io/disruptor/user-guide/): shared bounded buffer, + publication sequences, dependencies and slow-reader handling. +- [Naiad](https://www.microsoft.com/en-us/research/publication/naiad-a-timely-dataflow-system-2/): + logical progress and incremental work with asynchronous execution. + +The first runtime experiment must compare this design with simple event-driven delivery. Pulsing +adds waiting time and can waste work if readers poll unchanged state. Sleep when there is no new +revision; wake through a notification; coalesce only replaceable observations. Preserve every +authority mutation and required audit record. Operator stop/steering bypasses pulse batching. + +## Keep control responsive + +The control receiver never waits synchronously for a model, a full log, an artifact hash, or disk +synchronization. It hands bounded work to the appropriate process and continues receiving input. +There is one authoritative state writer. A received command, a durably committed command, and a +completed external effect are distinct acknowledgements. A stalled disk must be visible; it must +not produce a false committed acknowledgement. A prompt stop signal is not proof of remote rollback. + +Model a control batch in integer time ticks. If its remaining nonpreemptible work is at most B, +aggregate scheduling/interference delay at most J, there are at most N handlers through the target +command, and each handler costs at most C, then: + + elapsed <= B + J + N*C + +`control_batch_bound` proves the arithmetic implication, including a proof that the sum of handler +costs is bounded. The runtime must establish those hypotheses. General-purpose Linux does not +automatically give a finite hard scheduling-jitter bound. Disk completion, network transport, +browser paint, and actual worker shutdown are outside this particular receiver bound. + +Illustrative assumptions only: B=500 us, J=500 us, N=8, C=500 us gives 5000 us = 5 ms. +Wolfram evaluated `500+500+8*500` and `(500+500+8*500)/1000`, returning 5000 and 5. +These are design-budget calculations, not measurements of Omega. + +For sustained arrivals, [network calculus](https://leboudec.github.io/netcal/latex/netCalBook.pdf), +Figure 1.10, gives a complementary result. For a leaky-bucket arrival bound b+r*t and a guaranteed +rate-latency service R*max(0,t-T), with r<=R, the virtual-delay bound is T+b/R and the backlog bound +is b+r*T. Use bounded work units, not unbounded message counts. This general service-curve theorem +is cited background; this Lean file does not formalize network calculus. + +## Bound the unfinished work, including review + +Every admitted task holds a work credit until an explicit terminal decision. Finishing inference +transfers the credit to review; it does not release it: + + free + busy + review = capacity + +`pool_trace_conserves` proves conservation for every finite trace in the model; +`review_backlog_bounded` proves the review count cannot exceed capacity. This closes the loop around +the operator's ability to evaluate results. A separate bounded pending-offer policy must refuse or +defer excess offers without building an unbounded hidden queue. Separate resource budgets are still +needed for bytes, model context, GPU memory, and process count. + +Wolfram admission example: capacity 12, outstanding 9, offered 7 -> admit `Min[7,12-9]=3`, defer 4. +Capacity is a tunable limit, not a predicted optimum for Drake's hardware. + +Wolfram also checked a simple M/M/1 illustration: with mean service time one second, utilization +1/2, 4/5, 19/20 gives mean waiting 1, 4, 19 seconds via rho/(1-rho). Real LLM services need not have +exponential times or independent arrivals. This illustrates why utilization alone is a bad objective; +it is not a fitted performance model of the hive. Optimize accepted, verified progress under latency +and resource constraints. Measure the workload before picking concurrency or pulse frequency. + +## What Lean checked + +`NodeModel.lean` was checked with official Lean 4.35.0 on x86_64 Linux, release commit +`eb6cafb7290e8bd5f2937522d8d804f58f02bafc`. It imports only Std, not Mathlib. All 15 theorem +declarations passed. The printed dependencies are empty or a subset of `propext` and `Quot.sound`. +There are no admitted proofs, custom axioms, native-evaluation proofs, or proof-check disabling options. + +| Property | Scope | +| --- | --- | +| One authorized worker | Two valid tickets for one modeled task must name the same worker | +| Stale completion rejected | Wrong epoch leaves the modeled state unchanged | +| Cancellation respected | A canceled modeled state rejects completion; cancellation advances epoch | +| Running owner preserved | Claim cannot replace a currently running modeled task | +| Bounded admission | Capacity holds for every finite request/release trace | +| Credit conservation | Free, busy and review counts sum to the initial capacity for every modeled trace | +| Bounded review backlog | Review count never exceeds total capacity in that model | +| Conditional receiver latency | The bound follows from bounded handler costs, batch length and overhead | +| Broken-design witnesses | Name-only authorization accepts a stale ticket; unconditional admission overflows | + +The separately compiled `controls/RejectFalse.lean` fails with exit 1 because its false arithmetic +claim cannot be proved. It is intentionally excluded from the successful model. Outputs are retained +in `lean-output.txt` and `negative-control-output.txt`. + +Reproduce with the official pinned toolchain available as `lean`: + +```sh +cd design/omega-node +lean --version +lean NodeModel.lean +# Expected nonzero exit for this deliberately invalid file: +lean controls/RejectFalse.lean +``` + +## Connection to Omega and remaining proof obligations + +These are prospective model proofs, not verification of `seed/authority` or PR #204. +Source inventory: omega-mv `7caba0c0094628b384abf8961a33bd95ae9412cc`, with existing `.om` +process, networking, polling, memory-mapping, file-locking and authority code. No native `.om` +implementation was compiled or exercised by this proof run. + +Before claiming implementation correctness: +1. Map every modeled transition to an identified `.om` function and frozen source/compiler digest. +2. Enforce finite-width overflow refusal. Lean Nat never wraps; machine counters can. +3. Authenticate tickets and serialize the validate/commit boundary. A matching integer is not proof + of caller identity. The single-task proof does not establish distributed consensus. +4. Couple credits to actual task IDs and attempts; exclude duplicate finish/resolve events. The pool + model proves conservation of abstract valid events, not the correctness of that coupling. +5. Prove publication/reclamation ordering for shared buffers. A slow reader must never observe a + reused generation; use a bounded snapshot/resync policy instead of blocking every other reader. +6. Define which deltas commute, when a result is stale, and when merging requires explicit review. + Arbitrary code patches and authority changes cannot be coalesced like a progress display. +7. Add crash/replay, disk failure, authentication, hostile worker, and clock-interference tests. + Emergency control remains responsive while durable commitment can be pending or unavailable. +8. Measure notification traffic, bytes copied, CPU utilization, accepted tasks, control latency and + output equivalence against the simple baseline. Keep the pulsed design only where it wins. + +There is no theorem here that agents think as one mind, a physical vibration eliminates communication, +arbitrary changes merge safely, every task finishes, or this architecture is universally optimal. +The practical target is coordinated work on shared state with small, checkable control rules. diff --git a/design/omega-node/controls/RejectFalse.lean b/design/omega-node/controls/RejectFalse.lean new file mode 100644 index 0000000..5ab3fbd --- /dev/null +++ b/design/omega-node/controls/RejectFalse.lean @@ -0,0 +1,4 @@ +import Std + +-- Deliberately invalid. The verification procedure requires a nonzero exit. +example : (1 : Nat) = 2 := by decide diff --git a/design/omega-node/lean-output.txt b/design/omega-node/lean-output.txt new file mode 100644 index 0000000..6d6a1cf --- /dev/null +++ b/design/omega-node/lean-output.txt @@ -0,0 +1,15 @@ +'OmegaNode.one_authorized_worker' does not depend on any axioms +'OmegaNode.stale_completion_unchanged' depends on axioms: [propext] +'OmegaNode.cancel_rejects_every_completion' depends on axioms: [propext] +'OmegaNode.cancel_invalidates_old_ticket' depends on axioms: [propext, Quot.sound] +'OmegaNode.claim_does_not_replace_running_owner' depends on axioms: [propext] +'OmegaNode.claim_epoch_monotone' depends on axioms: [propext, Quot.sound] +'OmegaNode.credits_step_bounded' depends on axioms: [propext, Quot.sound] +'OmegaNode.credits_all_traces_bounded' depends on axioms: [propext, Quot.sound] +'OmegaNode.pool_step_conserves' depends on axioms: [propext, Quot.sound] +'OmegaNode.pool_trace_conserves' depends on axioms: [propext, Quot.sound] +'OmegaNode.review_backlog_bounded' depends on axioms: [propext, Quot.sound] +'OmegaNode.handler_sum_bounded' depends on axioms: [propext, Quot.sound] +'OmegaNode.control_batch_bound' depends on axioms: [propext, Quot.sound] +'OmegaNode.broken_name_only_accepts_stale' depends on axioms: [propext] +'OmegaNode.broken_admission_exceeds_capacity' does not depend on any axioms diff --git a/design/omega-node/lean-toolchain b/design/omega-node/lean-toolchain new file mode 100644 index 0000000..a6aff06 --- /dev/null +++ b/design/omega-node/lean-toolchain @@ -0,0 +1 @@ +leanprover/lean4:v4.35.0 diff --git a/design/omega-node/negative-control-output.txt b/design/omega-node/negative-control-output.txt new file mode 100644 index 0000000..941920f --- /dev/null +++ b/design/omega-node/negative-control-output.txt @@ -0,0 +1,3 @@ +design/omega-node/controls/RejectFalse.lean:4:30: error: Tactic `decide` proved that the proposition + 1 = 2 +is false