Files
patriothacks/.omo/evidence/coherence-audit/fairshare.md
T
OmO Orchestrator 93101cf237 docs: add 13-mini-app concept-execution coherence audit evidence
Full read-only audit of all 13 mini-apps against README's problem-mapping
table + each module's own doc comments. 6 COHERENT (lightclock, fairdraw,
healthpost, theclimb, sky, mentor), 7 GAP-FOUND and fixed in prior commits
(fairshare, waterwatch, tunnelsafety, housing, assembly, findfamily, farms).
2026-11-20 17:58:56 -05:00

11 KiB

Fair Share (ma-fairshare) coherence audit

Scope: src/miniapps/fairshare/*, src/lib/fairshare.ts, src/lib/ceeiSpike.ts, plus the cross-app writers in src/miniapps/waterwatch/corroboration.ts and src/lib/farms.ts.

README claim under test (Problem-to-mini-app table, P1/P2/P3 row):

Fair Share (ma-fairshare): Competitive-Equilibrium-from-Equal-Incomes (CEEI) allocator across power, water, food, and cooling; envy-free, Pareto-efficient, with a real allocation-history trend as the honest early-warning signal (no fabricated sensor)

Verdict: GAP-FOUND (one real, narrow gap; everything else is COHERENT). The gap is not a fabrication risk — the code is honest where it falls short — but the README's trend claim overstates what two of the four resources can ever show.


Clause 1 — Is there a genuine CEEI algorithm, not a stand-in?

COHERENT. src/lib/ceeiSpike.ts implements two cross-validated Fisher-market solvers: solveCeeiPriceSearch (bisection tâtonnement over javascript-lp-solver LPs, 2-good spike) and solveCeeiWaterFilling (proportional-response dynamics, arbitrary agents/goods — lines 182-234). Proportional-response dynamics is a textbook algorithm that provably converges to the Fisher (CEEI) equilibrium for linear utilities; ceeiSpike.test.ts cross-checks it against a closed-form 2-good instance.

The production engine, computeFairshareAllocation in src/lib/fairshare.ts (lines 299-427), calls solveCeeiWaterFilling directly (never the 2-good-only solveCeei orchestrator), with every agent given an equal budget of 1 (line ~397: const budgets = agents.map(() => 1)) — that single shared per-agent budget spent jointly across whichever resources have residual supply is exactly the "equal income" half of CEEI; the water-filling fixed point is the "competitive equilibrium" half. This is a real convex-program solver, not a simplified proportional-split stand-in.

Clause 2 — Does it allocate across all 4 named resources?

COHERENT. FAIRSHARE_RESOURCES = ["power", "water", "food", "cooling"] (src/lib/fairshare.ts line 59). computeFairshareAllocation builds the utilityMatrix / supplyVector over whatever subset of these four has positive residual supply after floor reservation (lines ~380-410) and feeds them to the same water-filling solve as one joint market — not four independent single-good solves. ResourceTiles.tsx renders all four tiles (RESOURCE_META covers power/water/food/cooling) and ResourceTiles.test.tsx's "4-resource allocation cycle" test seeds all four and asserts correct allocation on each tile.

Clause 3 — Is the allocation-history trend real, not fabricated?

COHERENT for water and food; GAP for power and cooling. getAllocationHistory / computeAllocationTrend (src/lib/fairshare.ts lines 470-537) replay only real, signed fairshare.allocation.cycle events in Lamport order and honestly report "no-trend-yet" below 2 points — no interpolation, no synthesized default, no random number. TrendChart.tsx renders exactly those points and only shows the "declining" early-warning badge when a real negative OLS slope exists (never for no-trend-yet or a flat/rising trend). This part of the claim is real.

But fairshare.allocation.cycle events are only ever appended from two places in non-test code (confirmed by grep -rln 'fairshare.allocation.cycle' src | grep -v '.test.'):

  • src/miniapps/waterwatch/corroboration.ts → settleCorroboratedReading (resource "water" only, line ~282), wired to the UI via ReportReadingForm.tsx line 84.
  • src/lib/farms.ts → settleFarmsForecast (resource "food" only, line ~396), wired to the UI via FarmsScreen.tsx's useEffect (lines ~47-69).

No code path anywhere — not ResourceTiles.tsx, not the admin seed panel (src/admin/seedEvents.ts), not fairshare.ts itself — ever appends a fairshare.allocation.cycle event for "power" or "cooling". postFairshareNeed (src/lib/fairshare.ts line 225) only writes a fairshare.need event; it never records a cycle. postFairshareFloor only writes fairshare.floor. seedEvents.ts writes seed.resource.<resource> baselines for all four resources but no fairshare.allocation.cycle for any of them. So TrendChart for power and for cooling is structurally guaranteed to render "no-trend-yet" forever in the shipped app, no matter how many needs/seeds are posted — confirmed by ResourceTiles.test.tsx's own coverage, which only ever drives power through the tile-allocation assertions (lines 63-110), never through a trend-chart assertion, and no test anywhere seeds a power/cooling fairshare.allocation.cycle.

This means the README's "real allocation-history trend as the honest early-warning signal" genuinely holds for 2 of the 4 resources it's claimed across (water via Water Watch, food via Farms) but is dead code for power and cooling — the two resources P1/P3 (warn before power cuts; keep lower levels livable) most directly concern. It degrades gracefully (an honest empty state, never a fabricated line), so this is not a "no fabricated data" violation, but it is a scope gap against the literal README claim.

Concrete fix: add a cycle-recording call inside ResourceTiles.tsx (or a shared helper in fairshare.ts, e.g. settleAllocationCycle(resource, entries) mirroring settleCorroboratedReading/settleFarmsForecast's shape) that fires once per resource whenever computeFairshareAllocation's totalAllocated for that resource changes meaningfully (same "new value, not a re-render echo" guard FarmsScreen.tsx already uses via lastSettledForecastRef), driven off the admin seed panel's seed.resource.power / seed.resource.cooling writes the same way Water Watch/Farms drive water/food. That is a same-shape, in-repo pattern extension, not a new mechanism.

Clause 4 — Real cross-app wiring from Water Watch and Farms?

COHERENT. Both chains are live, not just claimed:

  • Water Watch: applyCorroboratedReadingToFairshare (corroboration.ts line ~227) appends a real seed.resource.water event only on a corroborated "alert" GateEvent (an uncorroborated "clean"/"corroborating" reading is a provable no-op per the function's own guard). settleCorroboratedReading then re-reads the full log, re-solves via computeFairshareAllocation, and appends the water fairshare.allocation.cycle. This is called from the real UI in ReportReadingForm.tsx line 84 — not just a library function left unwired.
  • Farms: applyFarmsForecastToFairshare (src/lib/farms.ts line 341) appends a real fairshare.contribution (additive, never overwriting, per fairshare.ts's FairshareContributionPayload doc) only when the LP optimizer reaches status: "optimal" with real entered temperature/plot/crop data. settleFarmsForecast then re-solves and appends the food fairshare.allocation.cycle. Called from FarmsScreen.tsx's useEffect (fires only on a genuinely new totalForecastYieldKg, guarded by lastSettledForecastRef so it never re-fires on an unchanged value across re-renders).

coreLoopHonestyAnchor.test.tsx (Water Watch) and coreLoopFoodIntegration.test.tsx (Farms) exercise these full chains end-to-end against the real fairshare.ts engine; all 30 relevant tests pass (npx vitest run src/lib/fairshare.test.ts src/lib/ceeiSpike.test.ts src/miniapps/waterwatch/coreLoopHonestyAnchor.test.tsx src/miniapps/farms/coreLoopFoodIntegration.test.tsx → 4 files, 30 tests, all passed).

Clause 5 — Would a real device/browser API strengthen this concept?

Honest answer: no, and the README already says so correctly. Resource-allocation math (CEEI over reported needs/supplies) has no sensor to attach — a CEEI solve runs over typed need/supply numbers, and no phone API measures "need for food" or "ambient livability." The README's own "What this does NOT do" section is explicit that Light Clock is the only mini-app with a real device sensor (motion/actigraphy), and that nothing else gets a fabricated one. Network/battery status (navigator.onLine, Battery Status API — now largely deprecated/removed from most browsers) could theoretically flavor an "early warning" banner during an outage, but would add a cosmetic indicator unconnected to the actual CEEI math or the signed event log, and the Battery Status API is not available in current Chromium/Firefox for most origins — forcing it in would be exactly the kind of invented sensor fit the project's own anti-pattern list forbids. Correctly, no sensor API is used or claimed here, and none should be added.

Clause 6 — Does the UI/data flow deliver the claims coherently, no dead ends?

COHERENT except for the clause-3 gap already named. ResourceTiles.tsx:

  • Resource-credit balance: read verbatim from ledger.ts's computeBalances/balanceOf (never reimplemented locally) — honest "No balance yet" / "--" states, no fabricated 0.
  • Per-resource tiles: read verbatim from computeFairshareAllocation's live-replayed allocation/supply, bar-fill fraction computed from real numbers, honest "No allocation yet" when the signed-in agent has never reported a need.
  • "Report your need" form: calls real postFairshareNeed → signed fairshare.need append; useEventLogEntries's Dexie liveQuery means the whole screen (tiles, trend charts) reacts immediately once that event lands — not a stale/cached read.
  • Trend charts: real for water/food (see Clause 3), honestly empty for power/cooling rather than a dead button or a silently-broken chart — no copy asserts a trend exists when it cannot.

No button submits to nowhere, no claimed feature is literally unimplemented; the one gap is a narrower scope for the trend signal than the README's four-resource framing implies.


Summary verdict

GAP-FOUND, narrow and non-fabrication: the CEEI allocator itself (Clauses 1, 2, 4, 6) and the "no fabricated sensor" honesty (Clause 5) are fully coherent and well-evidenced in real code and passing tests. The one real gap is Clause 3: fairshare.allocation.cycle — the event type the trend/early-warning mechanism is built on — is only ever written for water (via Water Watch) and food (via Farms); no code path writes it for power or cooling, so those two resources' trend charts are permanently stuck at the honest "no trend yet" empty state in the shipped app. Since P1 ("warn before power cuts") is squarely a power-resource claim, this materially narrows the README's stated early-warning mechanism for exactly the problem it's positioned to answer. Fix: wire a fairshare.allocation.cycle write for power/cooling the same way Water Watch/Farms already do for water/food — e.g. from ResourceTiles.tsx or a shared fairshare.ts helper, triggered off a genuinely new computeFairshareAllocation total per resource (reusing the lastSettledForecastRef-style "new value only" guard already proven in FarmsScreen.tsx). This is a same-shape extension of an existing, tested pattern, not a new mechanism or an invented sensor.