aboutsummaryrefslogtreecommitdiff
path: root/api/debug/health.php
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-10-23 14:39:30 +0200
committerAgando <roduccomm@gmail.com>2026-10-23 14:39:30 +0200
commitf6a48a90e374e79b5ca8c0f73d2eb9b3d95868ec (patch)
tree8df5dc38f10dc41585d363735dda97a82de10eb1 /api/debug/health.php
parentb640d13799c3dc98e08b9c9d53b745c4d0d76a3a (diff)
fix(newos4-debug): idempotent ingest, admin-gated reads, honest counts (v4.6.52-53)
Root cause: _syncToBackend() re-sent the whole error DB with cumulative counts every 300s, and ingest.php did count += client count per batch. 33 real signatures had accumulated 116,696 "occurrences" (one self-referential row alone: 46,133). Backend - ingest.php: per-(session,hash) synced map, adds only the delta, resets prev when the client count shrank (cleared localStorage), caps delta at 5000, bounds synced at 500 hashes and sessions at 200, normalises timestamps to +00:00, 30-day retention that also purges dropped hashes from every synced map, returns `accepted` (entries) next to `ingested` (occurrences). - stats.php/dashboard.php: total_errors = occurrences, unique_errors = signatures, last-ingest card. The two numbers were inconsistent by ~3,500x. - health.php: reports self_referential count and status=degraded instead of ok. - Pruned live data: 33 -> 23 records, 116,696 -> 58,759 occurrences, max cluster 110,226 -> 52,387 (archive kept in data/debug/archive/). - nginx: stats/errors/clusters/dashboard/agent-replies now behind auth_request /_wx11_admin_auth (302 without a session); ingest/report/health stay public for telemetry. Verified: reads 302, ingest 200, report 400. Client - module-debug-supervisor.js: sends only hashes whose count changed (persisted webx11_debug_synced), records synced counts only after success, stops auto-filing aborts/timeouts and debug-pipeline requests as bug reports (2 of the last 5 reports were "user aborted a request"). Verified with a scratch php -S copy: same batch POSTed 3x -> count stays 5; count=99999 -> clamped to 1000; retention dropped 10 legacy rows.
Diffstat (limited to 'api/debug/health.php')
-rw-r--r--api/debug/health.php17
1 files changed, 15 insertions, 2 deletions
diff --git a/api/debug/health.php b/api/debug/health.php
index 5a0048f..883588f 100644
--- a/api/debug/health.php
+++ b/api/debug/health.php
@@ -6,11 +6,24 @@ $sessions = load_json(SESSIONS_FILE);
$lastError = !empty($errors) ? end($errors) : null;
+// Self-referential rows mean the debug pipeline is counting itself: the failure mode that
+// turned 33 real errors into 116,696 "occurrences" before 2026-10-23. Surface it instead of
+// reporting a poisoned dataset as healthy.
+$selfRef = 0;
+$occurrences = 0;
+foreach ($errors as $e) {
+ if (stripos($e['message'] ?? '', '/api/debug/') !== false) $selfRef++;
+ $occurrences += (int)($e['count'] ?? 1);
+}
+
json_response([
'success' => true,
- 'status' => 'ok',
+ 'status' => $selfRef > 0 ? 'degraded' : 'ok',
'uptime' => filemtime(__FILE__) ? (time() - filemtime(__FILE__)) : 0,
- 'total_errors' => count($errors),
+ 'total_errors' => $occurrences,
+ 'total_occurrences' => $occurrences,
+ 'unique_errors' => count($errors),
+ 'self_referential' => $selfRef,
'total_sessions' => count($sessions),
'errors_file_size_kb' => file_exists(ERRORS_FILE) ? round(filesize(ERRORS_FILE) / 1024, 1) : 0,
'sessions_file_size_kb' => file_exists(SESSIONS_FILE) ? round(filesize(SESSIONS_FILE) / 1024, 1) : 0,