Chapters · Chapter 8

The Engine's Opinion: Interoception

Part III — The Signals That Run While You Sleep · seven builds, seven receipts

These are running-statistics exercises: you instrument the engine's interoceptive channel, replay its Welford and \(\kappa\) receipts, and stress the contract at both ends of the \(n\)-axis. The receipt class is a Prometheus scrape, a passing test, or a printed line that matches one of my BLD-CH8-* numbers within floating-point grain.

Run it live — GQL console

Point at the public read-only instance (no key needed) or your own engine (start it with GIGI_CORS_ORIGIN=* for browser access — dev only).

E8.1Reproduce the two-record formality

Build

Stand up a fresh sensors bundle, write the prologue's two records (S-001 at temp 22.5/humidity 60.1; S-002 at temp 19.3/humidity 71.4), and dump FieldStats for both numeric fibers plus scalar_curvature(bundle).

Receipt

Your run prints K(S-001) = K(S-002) = 0.0442500000, confidence = 0.9576250898, and scalar_curvature(bundle) = 0.2500000000 — byte-identical to BLD-CH8-KAPPA-2REC.

Bonus

Add a third record at the midpoint \((20.9, 65.75)\) and show that the bundle's scalar curvature drops off \(0.25\) exactly because \(\mathrm{Var}/\mathrm{range}^2\) is no longer on its two-symmetric-points limit.

E8.2Replay the 100K calibration

Build

Generate 100{,}000 synthetic sensor records with temperature \(\sim \mathcal{N}(22.5, 1.0)\), write them through BundleStore::insert, then point-query one record near the mean and one record at \(\mu + 3\sigma\) and read confidence off the response meta.

Receipt

Typical record returns \(\kappa \approx 7.5\times 10^{-7}\) with confidence \(\approx 1.0\); the \(3\sigma\) record returns \(\kappa \approx 6.1 \times 10^{-2}\) with confidence \(\approx 0.9423\) — matching BLD-CH8-KAPPA-100K to three significant figures.

Bonus

Plot \(\kappa\) as a function of \(|x - \mu|/\sigma\) and check the five-orders-of-magnitude spread the chapter claims is enough headroom to route on.

E8.3Stress Welford against the naive accumulator

Build

Run the BLD-CH8-WELFORD-100M regime — 100{,}000{,}000 values, each near \(10^{8}\) — through two accumulators side by side: the Welford pair \((\mu, M_2)\) from src/bundle.rs:747-787 and a naive \((\Sigma x, \Sigma x^2)\) that computes variance as \(\Sigma x^2 / n - (\Sigma x / n)^2\).

Receipt

Welford mean within \(1.5\times 10^{-2}\) and variance within \(1.8\times 10^{-4}\) of the closed form (commit b30cc99 territory); the naive accumulator returns variance that is negative, zero, or off by sixteen significant digits. Print both side by side as a single log line.

Bonus

Reproduce the 5.87 ns/op figure — single-thread, release profile — and post the timing as a comment on the ch8_welford_100M harness entry if your number disagrees.

E8.4Time the 22-nanosecond opinion

Build

Replicate the BLD-CH8-INSERT-COST three-way benchmark from harvest/book_ch8_interoception.rs: time FieldStats::update alone, then BundleStore::insert alone, then insert with record_k_for and confidence riding along. Release profile, single thread, same 100K-record workload.

Receipt

Three numbers in the same shape as the chapter: A on the order of 10 ns/op, B on the order of 800 ns/op, C \(-\) B \(\approx 22\) ns/op. Append your CPU model and the C \(-\) B delta to the receipt file.

Bonus

Push the delta below 22 ns/op by inlining the confidence map next to the \(\kappa\) accessor and show the optimization is loss-less against BLD-CH8-KAPPA-100K.

E8.5Forge the gameable counterexample

Build

Construct bundles A and B from BLD-CH8-K-GAMEABLE: A is a 1{,}000-record uniform AP on \([0,1]\); B is a 100{,}000-record two-point distribution at \(\{0, 1\}\) with weight \(p\) solving \(p(1-p) = K_A\). Run both through scalar_curvature and print the agreement.

Receipt

\(|K_A - K_B| \le 3.2\times 10^{-6}\) as in the chapter, with A's mean near \(0.5\) and B's mean near \(0.092\). A single test that asserts \(K\) alone cannot distinguish them.

Bonus

Shrink the gap to machine epsilon by increasing \(n_B\) and re-tuning \(p\), then extend the harness to compute \(\lambda_1\) on each bundle and show the spectrum does separate them — a head-start on the Chapter 9 invariant.

E8.6Wire the CONFIDENCE verb

Build

Behind the kahler feature flag, call the CONFIDENCE brain verb registered at src/bin/gigi_stream.rs:14576-14601 against a bundle of your choosing. Compare the verb's return against the confidence field on a POST /v1/profile response for the same bundle.

Receipt

Both surfaces return the same scalar to the last bit, with the verb's payload exposing the contributing FieldStats (count, mean, \(M_2\), range) so an audit consumer can re-derive \(\kappa\) themselves.

Bonus

Add a Prometheus counter that scrapes CONFIDENCE once per minute on a long-running bundle and watch it converge as \(n\) grows — the named-verb analog of putting in the season.

E8.7Refute the never-stale claim

Build

Try to construct a write pattern — interleaved INSERTs, concurrent readers, schema reloads, anything — that returns a row whose confidence field reflects a \(\kappa\) computed from FieldStats older than the last committed write to that bundle.

Receipt

Either a failing test that exhibits the stale read (with the row, the expected \(\kappa\), and the actual \(\kappa\) printed side by side — file it against the README's “O(1) read, never stale” claim), or a passing adversarial test that proves you tried and the engine kept the contract.

Bonus

If you find a stale read, isolate whether it is in the accessor on src/curvature.rs:36-38 or in the FieldStats update path on src/bundle.rs:747-787, and propose the smallest patch that closes it.

← Chapter 7 exercisesChapter 9 exercises →