diff --git a/CHANGELOG.md b/CHANGELOG.md index 590434a..e17a324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.18.0] - 2026-11-12 + +A tidier admin area. + +### Added +- **Log page** (`/admin/log`): everything that is failing right now, newest + first. Each entry shows when it happened, what failed (crosspost, response + check, outgoing webmention, reply-context fetch, WebSub delivery, + notifications, refused silo credentials), a link to the affected post and + the error message, with Retry / Check now where that applies. It reads the + error columns the workers already keep, so an entry goes away once the + next attempt succeeds. The admin nav shows the error count. +- **Settings page** (`/admin/settings`) for site-wide settings. Notification + status and the test button live here now. +- Webmentions, Log and Settings links in the admin nav. + +### Changed +- The Webmentions page no longer has the Back to Dashboard button or the + Notifications section, and links to the Log instead of counting response + check errors. + ## [2.17.1] - 2026-11-12 ### Fixed diff --git a/docs/architecture/syndication-architecture.md b/docs/architecture/syndication-architecture.md index 2eac4bc..a2d02c9 100644 --- a/docs/architecture/syndication-architecture.md +++ b/docs/architecture/syndication-architecture.md @@ -139,8 +139,8 @@ again with the new content. `_fail()` does the same. a Threads container in `ERROR`/`EXPIRED`, and Graph API auth/permission errors (codes 10, 190, 200). - Other errors retry after `min(30 s × 2^attempts, 6 h)`. After 8 attempts - the row becomes `failed`. The error is shown on the edit page with a - Retry button. When a row finally fails, the owner also gets a `problems` + the row becomes `failed`. The error is shown on the edit page and on the + admin Log page (v2.18.0), both with a Retry button. When a row finally fails, the owner also gets a `problems` notification (ADR-074). - `RemoteGone` (404, or Graph error 100/33) during an update means the copy was deleted remotely, so a new one is created. During a delete it counts as @@ -273,7 +273,7 @@ reposts) that are due, each under a lease (`backfeed_claimed_until`): (`site_state.backfeed_backfill_last`). Start and finish times are in `site_state`. - **Refused credentials.** A 401/403 (or Graph auth error) puts the target - in `backfeed.denied` until restart; the admin Webmentions page says which + in `backfeed.denied` until restart; the admin Log page says which scopes are needed, and a `problems` notification is sent. Crossposting is unaffected. diff --git a/starpunk/__init__.py b/starpunk/__init__.py index bfefebc..0536eeb 100644 --- a/starpunk/__init__.py +++ b/starpunk/__init__.py @@ -468,5 +468,5 @@ def create_app(config=None): # Package version (Semantic Versioning 2.0.0) # See docs/standards/versioning-strategy.md for details -__version__ = "2.17.1" -__version_info__ = (2, 17, 1) +__version__ = "2.18.0" +__version_info__ = (2, 18, 0) diff --git a/starpunk/error_log.py b/starpunk/error_log.py new file mode 100644 index 0000000..1343f1e --- /dev/null +++ b/starpunk/error_log.py @@ -0,0 +1,127 @@ +""" +Error log for the admin Log page (v2.18.0) + +Collects what is failing right now from the tables that already record it: +crossposts, response checks (backfeed), outgoing webmentions, reply-context +fetches, WebSub deliveries and notifications. Nothing new is stored. An entry +disappears once the next attempt succeeds, so the page lists only problems +that still need attention. + +Each entry is a dict: + when -- timestamp text (UTC) or "" when unknown + area -- short label, e.g. "Crosspost to Bluesky" + note -- the affected Note, or None for site-wide problems + detail -- extra context (a URL or "retrying"), may be "" + error -- the recorded error message + action -- optional (endpoint, id, label) for a retry button +""" + +from flask import current_app + +from starpunk.database import get_db + +SILOS = {"gotosocial": "GoToSocial", "bluesky": "Bluesky", "threads": "Threads"} + + +def _silo(target: str) -> str: + return SILOS.get(target, target) + + +def _notes(ids) -> dict: + """Load the affected notes once each (deleted notes come back as None)""" + from starpunk.notes import get_note + + return {i: get_note(id=i) for i in set(ids) if i is not None} + + +def entries() -> list: + """Every current error, newest first; site-wide problems come first""" + from starpunk import backfeed, notifications + + db = get_db(current_app) + rows = [] + + for r in db.execute( + "SELECT id, note_id, target, state, last_error, updated_at FROM syndications " + "WHERE last_error IS NOT NULL AND state != 'synced'" + ): + rows.append({ + "when": r["updated_at"], "area": f"Crosspost to {_silo(r['target'])}", + "note_id": r["note_id"], "detail": "retrying" if r["state"] == "pending" else "", + "error": r["last_error"], + "action": ("admin.retry_syndication", r["id"], "Retry"), + }) + + for r in db.execute( + "SELECT id, note_id, target, backfeed_error, backfeed_checked_at, remote_url FROM syndications " + "WHERE backfeed_error IS NOT NULL" + ): + rows.append({ + "when": r["backfeed_checked_at"], "area": f"Response check on {_silo(r['target'])}", + "note_id": r["note_id"], "detail": r["remote_url"] or "", "error": r["backfeed_error"], + "action": ("admin.check_syndication_responses", r["id"], "Check now"), + }) + + for r in db.execute( + "SELECT source_note_id, target_url, status, last_error, COALESCE(started_at, created_at) AS at " + "FROM webmention_queue WHERE last_error IS NOT NULL AND status IN ('pending', 'failed')" + ): + rows.append({ + "when": r["at"], "area": "Webmention sent", "note_id": r["source_note_id"], + "detail": r["target_url"] + (" (retrying)" if r["status"] == "pending" else ""), + "error": r["last_error"], "action": None, + }) + + for r in db.execute( + "SELECT n.id AS note_id, rc.url, rc.fetch_error, rc.fetched_at, rc.created_at " + "FROM reply_contexts rc JOIN notes n ON n.in_reply_to = rc.url " + "WHERE rc.fetch_status = 'error' AND n.deleted_at IS NULL" + ): + rows.append({ + "when": r["fetched_at"] or r["created_at"], "area": "Reply context fetch", + "note_id": r["note_id"], "detail": r["url"], "error": r["fetch_error"] or "fetch failed", + "action": None, + }) + + for r in db.execute( + "SELECT topic, callback, last_error, COALESCE(last_success_at, verified_at, created_at) AS at " + "FROM websub_subscriptions WHERE last_error IS NOT NULL" + ): + rows.append({ + "when": r["at"], "area": "WebSub delivery", "note_id": None, + "detail": f"{r['topic']} → {r['callback']}", "error": r["last_error"], "action": None, + }) + + rows.sort(key=lambda e: str(e["when"] or ""), reverse=True) + + site = [] + for silo, message in backfeed.denied.items(): + site.append({"when": "", "area": f"Response checks on {_silo(silo)}", "note_id": None, + "detail": "paused", "error": message, "action": None}) + notify_error = notifications.last_error(db) + if notify_error: + when, _, message = notify_error.partition(" UTC ") + site.append({"when": when if message else "", "area": "Notifications", "note_id": None, + "detail": "", "error": message or notify_error, "action": None}) + + entries = site + rows + notes = _notes(e["note_id"] for e in entries) + for e in entries: + e["note"] = notes.get(e.pop("note_id")) + return entries + + +def count() -> int: + """Cheap total for the admin nav badge""" + from starpunk import backfeed, notifications + + db = get_db(current_app) + total = db.execute( + "SELECT (SELECT COUNT(*) FROM syndications WHERE last_error IS NOT NULL AND state != 'synced')" + " + (SELECT COUNT(*) FROM syndications WHERE backfeed_error IS NOT NULL)" + " + (SELECT COUNT(*) FROM webmention_queue WHERE last_error IS NOT NULL AND status IN ('pending', 'failed'))" + " + (SELECT COUNT(*) FROM reply_contexts rc JOIN notes n ON n.in_reply_to = rc.url" + " WHERE rc.fetch_status = 'error' AND n.deleted_at IS NULL)" + " + (SELECT COUNT(*) FROM websub_subscriptions WHERE last_error IS NOT NULL)" + ).fetchone()[0] + return total + len(backfeed.denied) + (1 if notifications.last_error(db) else 0) diff --git a/starpunk/routes/admin.py b/starpunk/routes/admin.py index 8a41b99..8546f05 100644 --- a/starpunk/routes/admin.py +++ b/starpunk/routes/admin.py @@ -25,6 +25,20 @@ from starpunk.notes import ( bp = Blueprint("admin", __name__, url_prefix="/admin") +@bp.context_processor +def _admin_nav(): + """Error count for the Log link in the admin nav (v2.18.0)""" + if not getattr(g, "me", None): + return {} + from starpunk import error_log + + try: + return {"error_count": error_log.count()} + except Exception as e: # never break an admin page over the badge + logger.warning(f"Could not count errors for the admin nav: {e}") + return {"error_count": 0} + + @bp.route("/") @require_auth def dashboard(): @@ -530,7 +544,6 @@ def webmentions(): status_filter=status_filter, origin_filter=origin_filter, backfeed=backfeed.status(), - notify=_notify_status(), page=page, total_pages=total_pages, user_me=g.me @@ -698,7 +711,7 @@ def revoke_token(token_id): def _notify_status() -> dict: - """Notification settings and last error for the Webmentions page (v2.14.0)""" + """Notification settings and last error for the Settings page (v2.14.0)""" from starpunk import notifications from starpunk.database import get_db @@ -711,6 +724,22 @@ def _notify_status() -> dict: } +@bp.route("/settings") +@require_auth +def settings(): + """Site settings: notifications (v2.18.0). Template: templates/admin/settings.html""" + return render_template("admin/settings.html", notify=_notify_status(), user_me=g.me) + + +@bp.route("/log") +@require_auth +def error_log(): + """Current errors with the affected note (v2.18.0). Template: templates/admin/log.html""" + from starpunk import error_log as log + + return render_template("admin/log.html", entries=log.entries(), user_me=g.me) + + @bp.route("/notifications/test", methods=["POST"]) @require_auth def notifications_test(): @@ -722,7 +751,7 @@ def notifications_test(): notifications._record(current_app.config["DATABASE_PATH"], ok, error) flash("Test notification sent" if ok else f"Test notification failed: {error or 'unknown error'}", "success" if ok else "error") - return redirect(url_for("admin.webmentions")) + return redirect(url_for("admin.settings")) @bp.route("/backfeed/backfill", methods=["POST"]) diff --git a/static/css/style.css b/static/css/style.css index 025fd6d..e2be129 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -465,6 +465,13 @@ small { display: block; margin-top: var(--spacing-xs); color: var(--color-text-l .badge-like { background: #FECACA; color: #991B1B; } .badge-repost { background: #D1FAE5; color: #065F46; } .badge-bookmark { background: #FEF3C7; color: #92400E; } +.badge-error { background: var(--color-error); color: #fff; } + +/* Admin Log (v2.18.0) */ +.log-table td { vertical-align: top; } +.log-table .button { white-space: nowrap; } +.log-error code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.85rem; } +.backfeed-status { margin-bottom: var(--spacing-lg); } .badge-mention { background: #E5E7EB; color: #374151; } .status-badge { diff --git a/templates/admin/base.html b/templates/admin/base.html index fed5482..2db0cfa 100644 --- a/templates/admin/base.html +++ b/templates/admin/base.html @@ -8,7 +8,10 @@