Error log, retry notice, a waiting counter that keeps counting
- generation_errors: every failed attempt (model, attempt, outcome, duration); admin Hibanapló page and GET /v1/admin/errors; kept 90 days - The waiting page counts from when the text was asked for (requested_at), not from the page load, so a reload no longer restarts it - It says when an attempt failed and is retried, and when a failed text's unit was given back; admins see the error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { GenerationError } from "@/lib/types";
|
||||
|
||||
const PAGE = 100;
|
||||
|
||||
const SOURCES: Record<string, string> = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" };
|
||||
const KINDS: Record<string, string> = {
|
||||
summary: "összefoglaló",
|
||||
natal: "képletelemzés",
|
||||
synastry: "kapcsolati",
|
||||
forecast: "előrejelzés",
|
||||
question: "válasz",
|
||||
};
|
||||
const OUTCOMES: Record<GenerationError["outcome"], { label: string; tone: string }> = {
|
||||
retry: { label: "újrapróbálva", tone: "neutral" },
|
||||
fallback: { label: "tartalék modell vette át", tone: "neutral" },
|
||||
failed: { label: "végleg sikertelen", tone: "tense" },
|
||||
};
|
||||
|
||||
interface Page {
|
||||
errors: GenerationError[];
|
||||
total: number;
|
||||
last_day: number;
|
||||
}
|
||||
|
||||
/** The admin error log with filters and paging. */
|
||||
export function ErrorLog() {
|
||||
const [source, setSource] = useState("");
|
||||
const [outcome, setOutcome] = useState("");
|
||||
const [errors, setErrors] = useState<GenerationError[] | null>(null);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [lastDay, setLastDay] = useState(0);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(
|
||||
async (offset: number) => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const params = new URLSearchParams({ limit: String(PAGE), offset: String(offset) });
|
||||
if (source) params.set("source", source);
|
||||
if (outcome) params.set("outcome", outcome);
|
||||
try {
|
||||
const page = await api<Page>(`/admin/errors?${params}`);
|
||||
setErrors((all) => (offset === 0 ? page.errors : [...(all ?? []), ...page.errors]));
|
||||
setTotal(page.total);
|
||||
setLastDay(page.last_day);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
},
|
||||
[source, outcome],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
load(0);
|
||||
}, [load]);
|
||||
|
||||
return (
|
||||
<section className="card" style={{ gap: 12 }}>
|
||||
<div className="row" style={{ gap: 12, flexWrap: "wrap", alignItems: "flex-end" }}>
|
||||
<div className="field">
|
||||
<label htmlFor="error-source">Mi</label>
|
||||
<select id="error-source" className="inp" value={source} onChange={(e) => setSource(e.target.value)}>
|
||||
<option value="">mind</option>
|
||||
{Object.entries(SOURCES).map(([v, l]) => (
|
||||
<option key={v} value={v}>
|
||||
{l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="error-outcome">Következmény</label>
|
||||
<select id="error-outcome" className="inp" value={outcome} onChange={(e) => setOutcome(e.target.value)}>
|
||||
<option value="">mind</option>
|
||||
{Object.entries(OUTCOMES).map(([v, o]) => (
|
||||
<option key={v} value={v}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<p className="hint" style={{ margin: 0 }}>
|
||||
{total} bejegyzés, ebből {lastDay} az elmúlt 24 órában
|
||||
</p>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => load(0)} disabled={busy}>
|
||||
Frissítés
|
||||
</button>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{errors === null ? (
|
||||
<p className="muted">Betöltés…</p>
|
||||
) : errors.length === 0 ? (
|
||||
<p className="muted">Nincs hiba. 🎉</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="error-log">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Időpont</th>
|
||||
<th>Mi</th>
|
||||
<th>Modell</th>
|
||||
<th>Kísérlet</th>
|
||||
<th>Következmény</th>
|
||||
<th>Hiba</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{errors.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td className="num">{formatDate(e.created_at, true)}</td>
|
||||
<td>
|
||||
{SOURCES[e.source] ?? e.source}
|
||||
{e.source !== "question" && ` (${KINDS[e.kind] ?? e.kind})`}
|
||||
{e.user && <span className="hint">{e.user}</span>}
|
||||
<code className="hint" title={e.item_id}>
|
||||
{e.item_id.slice(0, 8)}
|
||||
</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{e.model}</code>
|
||||
</td>
|
||||
<td className="num">
|
||||
{e.attempt}.{e.seconds !== null && <span className="hint">{e.seconds} mp</span>}
|
||||
</td>
|
||||
<td>
|
||||
<span className={`outcome tone-${OUTCOMES[e.outcome].tone}`}>{OUTCOMES[e.outcome].label}</span>
|
||||
</td>
|
||||
<td className="error-text">{e.error}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{errors && errors.length < total && (
|
||||
<button type="button" className="btn btn-sm" onClick={() => load(errors.length)} disabled={busy}>
|
||||
{busy ? "Betöltés…" : "Régebbiek"}
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { ErrorLog } from "./ErrorLog";
|
||||
|
||||
export const metadata: Metadata = { title: "Hibanapló" };
|
||||
|
||||
export default async function AdminErrorsPage() {
|
||||
const me = await requireMe("/admin/hibak");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/hibak" />
|
||||
<div className="page-head">
|
||||
<h1>Hibanapló</h1>
|
||||
<p className="muted">
|
||||
Az elemzések, válaszok és prompt-próbák minden sikertelen próbálkozása, a legújabb elöl. A worker írja; 90 napig
|
||||
őrizzük.
|
||||
</p>
|
||||
</div>
|
||||
<ErrorLog />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -647,3 +647,13 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.job-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
|
||||
.job-row > span:first-child { display: flex; flex-direction: column; min-width: 0; }
|
||||
@media (max-width: 640px) { .job-row { grid-template-columns: minmax(0, 1fr) auto; } .job-row .model-price { grid-column: 1 / -1; align-items: flex-start; } }
|
||||
.retry-notice { display: flex; flex-direction: column; gap: 4px; }
|
||||
.retry-notice p { margin: 0; }
|
||||
|
||||
/* admin: error log */
|
||||
.error-log { width: 100%; border-collapse: collapse; font-size: 14px; }
|
||||
.error-log th, .error-log td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
|
||||
.error-log td > .hint, .error-log td > code { display: block; }
|
||||
.error-log .error-text { overflow-wrap: anywhere; max-width: 460px; }
|
||||
.error-log .outcome { white-space: nowrap; }
|
||||
.error-log .outcome.tone-tense { color: var(--tense); font-weight: 600; }
|
||||
|
||||
@@ -5,6 +5,7 @@ const PAGES = [
|
||||
{ href: "/admin/meghivok", label: "Meghívók" },
|
||||
{ href: "/admin/promptok", label: "Promptok" },
|
||||
{ href: "/admin/modellek", label: "Modellek" },
|
||||
{ href: "/admin/hibak", label: "Hibanapló" },
|
||||
];
|
||||
|
||||
/** Switches between the admin pages. */
|
||||
|
||||
@@ -4,13 +4,31 @@ import { useEffect, useState } from "react";
|
||||
|
||||
import { ZodiacWheel } from "./ZodiacWheel";
|
||||
|
||||
/** Slowly turning wheel with the elapsed time, while the LLM writes. */
|
||||
export function AnalysisLoading({ title, text, compact = false }: { title?: string; text: string; compact?: boolean }) {
|
||||
const [seconds, setSeconds] = useState(0);
|
||||
/**
|
||||
* Slowly turning wheel with the elapsed time, while the LLM writes. The time
|
||||
* counts from `since` (when the text was asked for), so it does not start
|
||||
* again from zero after a reload; without it, from when the wheel appeared.
|
||||
*/
|
||||
export function AnalysisLoading({
|
||||
title,
|
||||
text,
|
||||
compact = false,
|
||||
since,
|
||||
}: {
|
||||
title?: string;
|
||||
text: string;
|
||||
compact?: boolean;
|
||||
since?: string;
|
||||
}) {
|
||||
const [start] = useState(() => {
|
||||
const t = since ? Date.parse(since) : NaN;
|
||||
return Number.isNaN(t) ? Date.now() : Math.min(t, Date.now());
|
||||
});
|
||||
const [seconds, setSeconds] = useState(() => Math.floor((Date.now() - start) / 1000));
|
||||
useEffect(() => {
|
||||
const t = setInterval(() => setSeconds((s) => s + 1), 1000);
|
||||
const t = setInterval(() => setSeconds(Math.floor((Date.now() - start) / 1000)), 1000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
}, [start]);
|
||||
const elapsed = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
||||
|
||||
return (
|
||||
@@ -21,7 +39,7 @@ export function AnalysisLoading({ title, text, compact = false }: { title?: stri
|
||||
<p className="muted" role="status">
|
||||
{text}
|
||||
</p>
|
||||
<p className="hint" aria-hidden="true">
|
||||
<p className="hint" aria-hidden="true" suppressHydrationWarning>
|
||||
{elapsed}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { Question, UnitBalance } from "@/lib/types";
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { PackageChooser } from "./PackageCards";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { RetryNotice } from "./RetryNotice";
|
||||
import { Paragraphs } from "./Rich";
|
||||
|
||||
const MAX_CHARS = 600;
|
||||
@@ -139,12 +140,21 @@ export function AnalysisQuestions({
|
||||
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
|
||||
)}
|
||||
<p className="msg msg-error" role="alert">
|
||||
Erre most nem sikerült válaszolni{q.credits_charged > 0 ? ", a kérdést visszaadtuk" : ""}. Kérdezz újra
|
||||
egy kicsit később.
|
||||
Erre többszöri próbálkozás után sem sikerült válaszolni
|
||||
{q.credits_charged > 0 ? ". A kérdést visszaadtuk, így ingyen újra felteheted" : ""}. Kérdezz újra egy
|
||||
kicsit később.
|
||||
</p>
|
||||
{isAdmin && q.error && <p className="hint">Hiba: {q.error}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<AnalysisLoading compact text="Készül a válasz, ez általában fél perc…" />
|
||||
<>
|
||||
<AnalysisLoading
|
||||
compact
|
||||
text="Készül a válasz, ez általában fél perc…"
|
||||
since={q.requested_at ?? q.created_at}
|
||||
/>
|
||||
<RetryNotice status={q.status} error={q.error} nextAttemptAt={q.next_attempt_at} isAdmin={isAdmin} />
|
||||
</>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { Analysis } from "@/lib/types";
|
||||
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { RetryNotice } from "./RetryNotice";
|
||||
import { Rich } from "./Rich";
|
||||
import { openTab } from "./Tabs";
|
||||
|
||||
@@ -102,7 +103,21 @@ export function ChartSummary({
|
||||
Az összefoglaló most nem készült el. Töltsd újra az oldalt egy kicsit később.
|
||||
</p>
|
||||
) : (
|
||||
<AnalysisLoading compact text="Az összefoglalód készül, ez néhány másodperc…" />
|
||||
<>
|
||||
<AnalysisLoading
|
||||
compact
|
||||
text="Az összefoglalód készül, ez néhány másodperc…"
|
||||
since={summary?.requested_at ?? summary?.created_at}
|
||||
/>
|
||||
{summary && (
|
||||
<RetryNotice
|
||||
status={summary.status}
|
||||
error={summary.error}
|
||||
nextAttemptAt={summary.next_attempt_at}
|
||||
isAdmin={isAdmin}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { AnalysisQuestions } from "./AnalysisQuestions";
|
||||
import { PackageChooser } from "./PackageCards";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { RetryNotice } from "./RetryNotice";
|
||||
import { AnalysisView } from "./AnalysisView";
|
||||
|
||||
const POLL_MS = 5000;
|
||||
@@ -172,7 +173,15 @@ export function DetailedAnalysis({
|
||||
return (
|
||||
<section className="analysis-card" aria-label={t.eyebrow} aria-busy="true">
|
||||
<span className="eyebrow">{t.eyebrow}</span>
|
||||
<AnalysisLoading title={t.loadingTitle} text={t.loading} />
|
||||
<AnalysisLoading title={t.loadingTitle} text={t.loading} since={analysis?.requested_at ?? analysis?.created_at} />
|
||||
{analysis && (
|
||||
<RetryNotice
|
||||
status={analysis.status}
|
||||
error={analysis.error}
|
||||
nextAttemptAt={analysis.next_attempt_at}
|
||||
isAdmin={isAdmin}
|
||||
/>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -186,9 +195,15 @@ export function DetailedAnalysis({
|
||||
<p className="muted">{t.about}</p>
|
||||
<p className="ai-line">{AI_SHORT}</p>
|
||||
{analysis?.status === "failed" && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
Az előző kérés nem sikerült{isAdmin ? "" : ", az elemzést visszaadtuk a keretedbe"}. Próbáld újra.
|
||||
</p>
|
||||
<div className="msg msg-error" role="alert">
|
||||
<p style={{ margin: 0 }}>
|
||||
Az elemzés többszöri próbálkozás után sem készült el.
|
||||
{isAdmin || analysis.credits_charged === 0
|
||||
? " Próbáld újra."
|
||||
: " A felhasznált egységet visszaadtuk, így ingyen újra kérheted."}
|
||||
</p>
|
||||
{isAdmin && analysis.error && <p className="hint">Hiba: {analysis.error}</p>}
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Shown while a text is being written again after a failed attempt: it is
|
||||
* retried on its own, nothing to do. Admins also see the error.
|
||||
*/
|
||||
export function RetryNotice({
|
||||
status,
|
||||
error,
|
||||
nextAttemptAt,
|
||||
isAdmin = false,
|
||||
}: {
|
||||
status: string;
|
||||
error?: string | null;
|
||||
nextAttemptAt?: string;
|
||||
isAdmin?: boolean;
|
||||
}) {
|
||||
if (!error || (status !== "pending" && status !== "running")) return null;
|
||||
const wait = nextAttemptAt ? Math.round((Date.parse(nextAttemptAt) - Date.now()) / 60_000) : 0;
|
||||
return (
|
||||
<div className="msg retry-notice" role="status">
|
||||
<p>
|
||||
Az előző próbálkozás nem sikerült, ezért automatikusan újrapróbáljuk. Nem kell újra kérned, és nem kerül
|
||||
többe.
|
||||
{status === "pending" && wait >= 1 ? ` A következő próbálkozás kb. ${wait} perc múlva indul.` : ""}
|
||||
</p>
|
||||
{isAdmin && <p className="hint">Hiba: {error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -77,6 +77,9 @@ export interface Question {
|
||||
credits_charged: number;
|
||||
created_at: string;
|
||||
completed_at: string | null;
|
||||
attempts?: number;
|
||||
next_attempt_at?: string;
|
||||
requested_at?: string;
|
||||
}
|
||||
|
||||
export interface PublicConfig {
|
||||
@@ -232,6 +235,26 @@ export interface Analysis {
|
||||
credits_charged: number;
|
||||
created_at: string;
|
||||
completed_at: string | null;
|
||||
/** Attempts so far, and when the next one starts (while it is retried). */
|
||||
attempts?: number;
|
||||
next_attempt_at?: string;
|
||||
/** When the current text was asked for: the waiting page counts from here. */
|
||||
requested_at?: string;
|
||||
}
|
||||
|
||||
/** Admin: one failed attempt in the error log. */
|
||||
export interface GenerationError {
|
||||
id: number;
|
||||
created_at: string;
|
||||
source: "analysis" | "question" | "preview";
|
||||
item_id: string;
|
||||
kind: string;
|
||||
model: string;
|
||||
attempt: number;
|
||||
outcome: "retry" | "fallback" | "failed";
|
||||
error: string;
|
||||
seconds: number | null;
|
||||
user: string | null;
|
||||
}
|
||||
|
||||
export interface AdminUser {
|
||||
|
||||
Reference in New Issue
Block a user