betterwithage commited on
Commit
99fa558
·
verified ·
1 Parent(s): b034ed9

chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)

Browse files

Automated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): a11oy_harvest_endpoints.py
Deleted (gone from the repo + Dockerfile COPY set): (none)

Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.

Files changed (1) hide show
  1. a11oy_harvest_endpoints.py +106 -16
a11oy_harvest_endpoints.py CHANGED
@@ -6,9 +6,13 @@
6
  Doctrine (binding):
7
  - NO free-energy / over-unity. Harvests ALREADY-WASTED grid energy (negative-price /
8
  curtailed-renewable windows on PUBLIC free feeds). Does NOT create energy.
9
- - joules_label ALWAYS "sample" off-box. The API NEVER emits joules_label other than
10
- "sample". The box is the only place that flips it to "measured" (on-box NVML).
11
- This API does NOT run on the box.
 
 
 
 
12
  - All feeds are FREE and PUBLIC — no token, no key, open data.
13
  - Reactive turns are NEVER gated by harvest posture.
14
  - Λ = Conjecture 1 (NEVER a theorem). Locked-8 untouched.
@@ -81,10 +85,66 @@ except Exception: # pragma: no cover - defensive: doctrine default is always sa
81
  def _joules_truth_evidence(_exporter_sample, now=None): # type: ignore
82
  return {}
83
 
84
- # This off-box API never has a real NVML exporter sample. Passing None to the
85
- # single source of truth ALWAYS yields ("sample", {}) — doctrine-clean + verifiable.
 
 
86
  _NO_EXPORTER_SAMPLE = None
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # ---------------------------------------------------------------------------
89
  # Feed citation table (used in /index response)
90
  # ---------------------------------------------------------------------------
@@ -136,8 +196,11 @@ _FEED_CITATIONS = [
136
  _DOCTRINE_NOTE = (
137
  "Doctrine (binding): harvests ALREADY-WASTED grid energy only (negative-price / "
138
  "curtailed-renewable windows). NO free-energy / over-unity claim. "
139
- "joules_label ALWAYS 'sample' off-box — MEASURED requires on-box NVML, which this "
140
- "API does not run on. Real data only; if a feed is down, reachable:false is reported "
 
 
 
141
  "honestly. Reactive turns are NEVER gated. Λ = Conjecture 1. Locked-8 untouched."
142
  )
143
 
@@ -197,6 +260,26 @@ def handle_posture() -> dict:
197
  return _unavailable_response("posture")
198
  try:
199
  p = current_harvest_posture()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  return {
201
  "ok": True,
202
  "posture": p.posture,
@@ -209,14 +292,19 @@ def handle_posture() -> dict:
209
  "timestamp_utc": p.timestamp_utc,
210
  "citation": p.citation,
211
  "doctrine": p.doctrine,
212
- # joules honesty via the single source of truth. Off-box there is no real
213
- # exporter sample -> label "sample", evidence {} (never fabricated).
214
- "joules_label": _joules_truth_label(_NO_EXPORTER_SAMPLE),
215
- "joules_evidence": _joules_truth_evidence(_NO_EXPORTER_SAMPLE),
216
- "joules_note": (
217
- "joules_label is always 'sample' off-box; "
218
- "MEASURED requires on-box NVML — this API does not run on the box"
219
- ),
 
 
 
 
 
220
  }
221
  except Exception as exc:
222
  # Never 500: return honest degraded response
@@ -548,7 +636,9 @@ if __name__ == "__main__":
548
  print(f"measured_any : {live_measured}")
549
  print(f"wasted_avail : {posture_resp.get('wasted_energy_available', False)}")
550
  print(f"soak_hard : {posture_resp.get('soak_hard', False)}")
551
- print(f"joules_label : sample (invariant — never changes in this API)")
 
 
552
  print(f"doctrine : {posture_resp.get('doctrine', _DOCTRINE_NOTE)[:80]}...")
553
  print("=" * 70)
554
  print(f"\nok:true checks:{checks}")
 
6
  Doctrine (binding):
7
  - NO free-energy / over-unity. Harvests ALREADY-WASTED grid energy (negative-price /
8
  curtailed-renewable windows on PUBLIC free feeds). Does NOT create energy.
9
+ - joules honesty via the single source of truth (szl_joules_truth). /plan and /receipt
10
+ NEVER claim MEASURED (they have no live NVML reading) so their joules_label stays
11
+ "sample". /posture drives the `energy` 3D surface and consults the ENERGY MEASURED
12
+ channel (szl_energy_measured): it emits joules_label "measured" ONLY when a LIVE
13
+ remote NVML joule meter responds live THIS request via A11OY_JOULE_METER_URLS (the
14
+ same harness JPT/One-Bit use), with monotonic-reset detection and provenance;
15
+ otherwise honest STRUCTURAL-ONLY ("sample") with a clear reason. NEVER fabricates a joule.
16
  - All feeds are FREE and PUBLIC — no token, no key, open data.
17
  - Reactive turns are NEVER gated by harvest posture.
18
  - Λ = Conjecture 1 (NEVER a theorem). Locked-8 untouched.
 
85
  def _joules_truth_evidence(_exporter_sample, now=None): # type: ignore
86
  return {}
87
 
88
+ # This off-box API never has a real NVML exporter sample of its OWN. Passing None to
89
+ # the single source of truth ALWAYS yields ("sample", {}) — doctrine-clean + verifiable.
90
+ # It is the honest fallback for /plan and /receipt (which never claim MEASURED) and for
91
+ # /posture whenever no live meter reading is available this request.
92
  _NO_EXPORTER_SAMPLE = None
93
 
94
+ # ENERGY-surface MEASURED channel. The /harvest/posture body drives the `energy`
95
+ # (Energy · Harvest) 3D surface HUD (joules_label / joules_evidence). Off-box this API
96
+ # has no NVML of its own, but it CAN read the LIVE remote NVML joule meter (engine
97
+ # 'omen' at meter.a-11-oy.com) the SAME way the JPT and One-Bit organs do — via the
98
+ # A11OY_JOULE_METER_URLS env. szl_energy_measured.measured_channel() performs that live
99
+ # read with monotonic-reset detection and lets szl_joules_truth (the single source of
100
+ # truth) decide MEASURED vs sample. When no meter env is set or no meter responds live
101
+ # THIS request, it returns an honest STRUCTURAL-ONLY channel with a clear reason and NO
102
+ # fabricated joule. Guarded so a missing module can never crash the endpoint.
103
+ try:
104
+ from szl_energy_measured import measured_channel as _energy_measured_channel
105
+ _ENERGY_MEASURED_OK = True
106
+ except Exception as _energy_measured_err: # pragma: no cover - honest STRUCTURAL fallback
107
+ _ENERGY_MEASURED_OK = False
108
+ _ENERGY_MEASURED_ERR = repr(_energy_measured_err)
109
+
110
+ def _energy_measured_channel(now=None, meter_urls=None, timeout=None): # type: ignore
111
+ # Module absent -> honest STRUCTURAL-ONLY, never a fabricated measured claim.
112
+ return {
113
+ "joules_label": "sample",
114
+ "measured": False,
115
+ "joules_evidence": {},
116
+ "reason": ("szl_energy_measured unavailable (%s) — STRUCTURAL-ONLY, "
117
+ "no joule fabricated" % _ENERGY_MEASURED_ERR),
118
+ "provenance": {"meter_url": None, "engine": None, "exporter": None,
119
+ "meter_ts": None, "fetched_at": None,
120
+ "method": "module unavailable"},
121
+ "power_w": None, "joules_before": None, "joules_after": None,
122
+ "meter_urls": [],
123
+ }
124
+
125
+
126
+ def _energy_joules_channel() -> dict:
127
+ """Consult the ENERGY-surface MEASURED channel for the posture body.
128
+
129
+ Returns a doctrine-stable dict. MEASURED only when a live remote NVML meter
130
+ responds live THIS request (and szl_joules_truth agrees); otherwise an honest
131
+ STRUCTURAL-ONLY channel with a machine-readable reason + whatever provenance we
132
+ have. NEVER raises, NEVER fabricates a joule.
133
+ """
134
+ try:
135
+ return _energy_measured_channel()
136
+ except Exception as exc: # pragma: no cover - degrade honestly
137
+ return {
138
+ "joules_label": "sample",
139
+ "measured": False,
140
+ "joules_evidence": {},
141
+ "reason": "energy measured channel raised (%s) — STRUCTURAL-ONLY, no joule fabricated"
142
+ % _safe_err(exc),
143
+ "provenance": {"meter_url": None, "engine": None, "exporter": None,
144
+ "meter_ts": None, "fetched_at": None, "method": "exception"},
145
+ "power_w": None, "joules_before": None, "joules_after": None, "meter_urls": [],
146
+ }
147
+
148
  # ---------------------------------------------------------------------------
149
  # Feed citation table (used in /index response)
150
  # ---------------------------------------------------------------------------
 
196
  _DOCTRINE_NOTE = (
197
  "Doctrine (binding): harvests ALREADY-WASTED grid energy only (negative-price / "
198
  "curtailed-renewable windows). NO free-energy / over-unity claim. "
199
+ "joules honesty is decided by szl_joules_truth: /posture emits joules_label 'measured' "
200
+ "ONLY when a LIVE remote NVML joule meter responds live THIS request via "
201
+ "A11OY_JOULE_METER_URLS (with monotonic-reset detection + provenance); otherwise honest "
202
+ "STRUCTURAL-ONLY ('sample'), never a fabricated joule. /plan and /receipt never claim "
203
+ "MEASURED. Real data only; if a feed is down, reachable:false is reported "
204
  "honestly. Reactive turns are NEVER gated. Λ = Conjecture 1. Locked-8 untouched."
205
  )
206
 
 
260
  return _unavailable_response("posture")
261
  try:
262
  p = current_harvest_posture()
263
+ # ENERGY-surface joules channel. Reads the LIVE remote NVML joule meter (engine
264
+ # 'omen') via A11OY_JOULE_METER_URLS this request, with monotonic-reset detection,
265
+ # and lets szl_joules_truth decide MEASURED vs sample. MEASURED ONLY when a meter
266
+ # responds live THIS request; otherwise honest STRUCTURAL-ONLY with a reason and
267
+ # NO fabricated joule. Every number carries provenance (meter url, engine, ts).
268
+ ec = _energy_joules_channel()
269
+ measured = bool(ec.get("measured")) and ec.get("joules_label") == "measured"
270
+ if measured:
271
+ joules_note = (
272
+ "joules_label 'measured' — a LIVE remote NVML meter (engine %s) responded "
273
+ "live THIS request via A11OY_JOULE_METER_URLS; cumulative joules climbing, "
274
+ "monotonic-reset checked. Provenance carried below. %s"
275
+ % (ec.get("provenance", {}).get("engine"), ec.get("reason", ""))
276
+ )
277
+ else:
278
+ joules_note = (
279
+ "joules_label 'sample' (STRUCTURAL-ONLY) — no live NVML meter reading this "
280
+ "request; MEASURED requires a live meter delta via A11OY_JOULE_METER_URLS. "
281
+ "No joule fabricated. reason: %s" % ec.get("reason", "no meter reading")
282
+ )
283
  return {
284
  "ok": True,
285
  "posture": p.posture,
 
292
  "timestamp_utc": p.timestamp_utc,
293
  "citation": p.citation,
294
  "doctrine": p.doctrine,
295
+ # joules honesty via the ENERGY MEASURED channel -> szl_joules_truth (single
296
+ # source of truth). MEASURED only from a live meter reading this request;
297
+ # otherwise honest STRUCTURAL-ONLY. evidence is {} unless measured.
298
+ "joules_label": ec.get("joules_label", "sample"),
299
+ "joules_evidence": ec.get("joules_evidence", {}),
300
+ "joules_measured": measured,
301
+ "joules_reason": ec.get("reason"),
302
+ "joules_provenance": ec.get("provenance", {}),
303
+ "joules_power_w": ec.get("power_w"),
304
+ "joules_before": ec.get("joules_before"),
305
+ "joules_after": ec.get("joules_after"),
306
+ "joules_meter_urls": ec.get("meter_urls", []),
307
+ "joules_note": joules_note,
308
  }
309
  except Exception as exc:
310
  # Never 500: return honest degraded response
 
636
  print(f"measured_any : {live_measured}")
637
  print(f"wasted_avail : {posture_resp.get('wasted_energy_available', False)}")
638
  print(f"soak_hard : {posture_resp.get('soak_hard', False)}")
639
+ print(f"joules_label : {posture_resp.get('joules_label','sample')} "
640
+ f"(measured={posture_resp.get('joules_measured')}; "
641
+ f"reason={str(posture_resp.get('joules_reason'))[:60]})")
642
  print(f"doctrine : {posture_resp.get('doctrine', _DOCTRINE_NOTE)[:80]}...")
643
  print("=" * 70)
644
  print(f"\nok:true checks:{checks}")