diff options
Diffstat (limited to 'api/debug')
| -rw-r--r-- | api/debug/dashboard.php | 7 | ||||
| -rw-r--r-- | api/debug/ingest.php | 16 | ||||
| -rw-r--r-- | api/debug/report.php | 24 |
3 files changed, 44 insertions, 3 deletions
diff --git a/api/debug/dashboard.php b/api/debug/dashboard.php index 08e6194..9b717c8 100644 --- a/api/debug/dashboard.php +++ b/api/debug/dashboard.php @@ -31,7 +31,8 @@ foreach ($errors as $e) { $hash = $e['hash'] ?? ''; if ($hash) { if (!isset($topErrors[$hash])) { - $topErrors[$hash] = ['hash' => $hash, 'message' => $e['message'] ?? '', 'count' => 0, 'type' => $t]; + $topErrors[$hash] = ['hash' => $hash, 'message' => $e['message'] ?? '', 'count' => 0, 'type' => $t, + 'frame' => $e['frame'] ?? null]; } $topErrors[$hash]['count'] += $e['count'] ?? 1; } @@ -297,7 +298,9 @@ $thread = array_slice($thread, -6); <?php $i = 1; foreach ($topErrors as $e): ?> <tr> <td><?= $i++ ?></td> - <td class="max-w-300"><a href="error.php?hash=<?= urlencode($e['hash'] ?? '') ?>" style="color:var(--text);text-decoration:none;" title="View details"><?= htmlspecialchars(substr($e['message'] ?? '', 0, 80)) ?></a></td> + <td class="max-w-300"><a href="error.php?hash=<?= urlencode($e['hash'] ?? '') ?>" style="color:var(--text);text-decoration:none;" title="View details"><?= htmlspecialchars(substr($e['message'] ?? '', 0, 80)) ?></a> + <?php if (!empty($e['frame'])): ?><div class="hide-sm" style="font-size:.72em;color:var(--muted)"><?= htmlspecialchars($e['frame']) ?></div><?php endif; ?> + </td> <td class="hide-sm"><span class="tag"><?= htmlspecialchars($e['type'] ?? '?') ?></span></td> <td><?= (int)($e['count'] ?? 0) ?></td> </tr> diff --git a/api/debug/ingest.php b/api/debug/ingest.php index 7388bce..98354fe 100644 --- a/api/debug/ingest.php +++ b/api/debug/ingest.php @@ -80,6 +80,20 @@ function norm_ts($s, $fallback) { return gmdate('c', $t); // always +00:00, never Z } +// Where did it happen? Parsed ONCE here so the digest (Python) and the dashboard (PHP) read the +// same value instead of re-implementing this regex twice. Returns 'modules/core/x.js:12:3'. +function first_frame($stack) { + if (!is_string($stack) || $stack === '') return null; + foreach (preg_split('/\R/', $stack) as $i => $line) { + if ($i === 0 || !preg_match('/^\s+at /', $line)) continue; // line 0 is "TypeError: ..." + if (preg_match('#([\w./-]+\.js)(?:\?v=[\w.]+)?:(\d+):(\d+)#', $line, $m)) { + $p = preg_replace('#^.*?/spaces/newos4/#', '', $m[1]); + return $p . ':' . $m[2] . ':' . $m[3]; + } + } + return null; +} + $processed = 0; // entries handled (NOT occurrences) — the client's truncation warning uses this foreach ($errors as $e) { $processed++; @@ -103,6 +117,7 @@ foreach ($errors as $e) { $allErrors[$idx]['ingested_at'] = $now; if (!empty($e['stack'])) { $allErrors[$idx]['stack'] = substr($e['stack'], 0, 2000); + $allErrors[$idx]['frame'] = first_frame($e['stack']) ?? ($allErrors[$idx]['frame'] ?? null); } $ingested += $delta; } @@ -118,6 +133,7 @@ foreach ($errors as $e) { 'source' => $e['source'] ?? '', 'module' => $e['module'] ?? null, 'stack' => isset($e['stack']) ? substr($e['stack'], 0, 2000) : null, + 'frame' => first_frame($e['stack'] ?? null), 'session_id' => $sessionId, 'count' => $delta, 'first_seen' => norm_ts($e['firstSeen'] ?? null, $now), diff --git a/api/debug/report.php b/api/debug/report.php index 5d4fc95..5625ffe 100644 --- a/api/debug/report.php +++ b/api/debug/report.php @@ -29,6 +29,18 @@ $body = (string)($payload['body'] ?? ''); if (mb_strlen($body) > 4000) $body = mb_substr($body, 0, 4000); $diag = (isset($payload['diagnostics']) && is_array($payload['diagnostics'])) ? $payload['diagnostics'] : []; +// Bound every stack: 20 errors x 10 frames of long URLs can otherwise approach the 512 KB ceiling +// and reject a legitimate report. +if (!empty($diag['errors']) && is_array($diag['errors'])) { + foreach ($diag['errors'] as $k => $de) { + if (!is_array($de)) { unset($diag['errors'][$k]); continue; } + if (isset($de['stack'])) { + $diag['errors'][$k]['stack'] = mb_substr((string)$de['stack'], 0, 2000); + } + } + $diag['errors'] = array_values($diag['errors']); +} + // Maintenance thread: lets the in-app agent and the Hermes maintenance job hold a conversation. // `thread` is a client-generated id (thr-xxxxxxxx); `kind` distinguishes agent feedback from // operator bug reports so triage can weight them differently. @@ -62,7 +74,17 @@ foreach ($rate as $k => $v) { save_json(RATE_FILE, $rate); // Dedupe: same title + error set + version within 24h collapses onto the existing report. -$fingerprint = sha1($title . '|' . json_encode($diag['errors'] ?? []) . '|' . (string)($diag['version'] ?? '')); +// Hash only the fields the pre-2026-10-23 payload had. Adding `stack` to json_encode($diag['errors']) +// would change every fingerprint, so an identical error filed today would not dedupe against the +// same error filed yesterday. +$errKey = []; +foreach (is_array($diag['errors'] ?? null) ? $diag['errors'] : [] as $de) { + if (!is_array($de)) continue; + $errKey[] = ['message' => (string)($de['message'] ?? ''), + 'source' => (string)($de['source'] ?? ''), + 'count' => (int)($de['count'] ?? 1)]; +} +$fingerprint = sha1($title . '|' . json_encode($errKey) . '|' . (string)($diag['version'] ?? '')); $existing = glob(REPORTS_DIR . '/RPT-*.json') ?: []; foreach (array_slice(array_reverse($existing), 0, 100) as $f) { $d = json_decode(@file_get_contents($f), true); |