R2 — Awareness Operators + Self-Heal
R2 sits on top of R1's atomic writer. After every idle tick the per-machine
ticker calls postTickAwareness(), which runs three forensic operators
over the device's state stream and validates the trailing 1024-row window
of the entangled state. If a hash-link invariant fails, the self-heal forward-relink
fires inline and the entangled state stitches back together.
Under R1 the heal counter stays at 0 in normal operation — R2 is defence in depth, not a hot path. It's there so any future regression can't silently corrupt the audit log without an alarm.
The window
AWARENESS_WINDOW = 1024 rows ≈ 13.3 minutes at 1.287 Hz. Every tick the
validator pulls [latestZeqond - 1024, latestZeqond] from audit_log,
walks ascending, and recomputes each row's expected prev_hash from the
previous row's rowHash. First disagreement is the break point.
For row N (n ≥ 1):
expected_prev = sha256(`${rows[N-1].zeqondNumber}|${rows[N-1].stateHash}|${rows[N-1].prevHash}`)
if rows[N].prevHash != expected_prev:
break detected at index N
The three operators
R2 runs three operators per tick. They're computed live and surfaced via
/api/chain/:slug/awareness/status for the observer footer.
ZEQ-PROTECT-001 — primary self-protection envelope
Formula: P(t) = |sin(5 · φ(t))| / f_pulse
Phase φ is the current Zeqond phase ∈ [0, 1). The 5· harmonic gives a fast wobble that's distinct from the 1× phase the observer also displays. Nonzero on every tick; varies smoothly with phase.
XI1 — Shannon entropy over the trailing window
Formula: XI1 = − Σ p_i · log₂ p_i
The probability distribution comes from the transition_type column's
frequencies in the trailing 1024-row window. Idle-only chain → entropy
≈ 0. Mixed event/state/file/compute traffic → entropy approaches
log₂(N) where N is the type-cardinality.
MK1 — mass-flow / kernel operator
Formula: MK1 = (ψ_mk · λ_mv) + (φ_delta · λ_eff_phi_t) − ψ_mk
Mapped to the entangled state context:
| Symbol | Meaning |
|---|---|
ψ_mk | current HulyaPulse phase |
λ_mv | pulse_hz (1.287 — the modulation eigenvalue) |
φ_delta | delta_phase_per_tick ≈ (1.287 · 0.777) mod 1 |
λ_eff_phi_t | XI1 (entropy serves as the effective phase eigenvalue) |
A single scalar per tick. Non-zero implies the entangled state is doing meaningful state evolution; near-zero implies a clean idle cadence.
Self-heal — forward-relink
When validateRange returns a non-null firstBreakZeqond, the
selfHealForwardRelink routine pulls all rows from brokenAtZeqond - 1
forward, walks ascending, and updates each row's prev_hash to the
canonical rowHash of the immediately preceding row.
for (let i = 1; i < rows.length; i++) {
const expected = rowHash(prev.zeqondNumber, prev.stateHash, prev.prevHash);
if (cur.prevHash !== expected) {
await db.update(auditLogTable)
.set({ prevHash: expected })
.where(eq(auditLogTable.id, cur.id));
cur.prevHash = expected; // mutate so subsequent rows compute against the fix
}
}
Idempotent: re-running on a healthy chain is a no-op. Same algorithm as
the standalone chain-repair.mjs script, inlined so the heal runs without
spawning a node process.
Live counters
/api/chain/:slug/awareness/status returns:
{
"ok": true,
"integrity": "clean",
"operators_idle": false,
"self_heal_count": 0,
"self_heal_last_zeqond": null,
"window": 1024,
"last_operators": {
"phase": 0.6834,
"protect001": 0.7669,
"xi1": 0.0,
"mk1": 0.0809
}
}
The State Observer page polls this endpoint every ~5 zeqonds and renders the counters in its self-attesting footer:
✓ 32,573 rows hash-linked · ● awareness firing · MK1=0.161 · XI1=0.000 · self-heal: armed
Hook point
shared/api-core/src/lib/perMachineTicker.ts calls
postTickAwareness() after each successful appendIdleRow. The call is
fire-and-forget — the heal can never stall the ticker, and any internal
exception is swallowed and logged.
void (async () => {
try {
const { postTickAwareness } = await import("./awareness.js");
await postTickAwareness({
originId,
latestZeqond: BigInt(z),
phase,
});
} catch (err) {
logger.warn({ err, originId }, "[perMachineTicker] postTickAwareness failed (non-fatal)");
}
})();
File map
shared/api-core/src/lib/awareness.ts— operators, validator, self-healshared/api-core/src/lib/perMachineTicker.ts— call siteshared/api-core/src/routes/chain.ts—GET /awareness/statusendpointapps/zeq-dev/public/state/observer.js— footer poller