Elffuss BraidHub

kikocis/utopia public

dev · 8.3 KiBSourceRawPermalink

0005 · The alert center

The problem

Failure state was scattered over six places with no single view: jobs.status='failed' + jobs.last_error (no UI at all), documents.status='failed', documents.graph_status='failed', sources.last_sync_status='failed', source_sync_runs.status='failed', and the log. It had been patched once, by adding graph_error to documents: one column per failure class. With reasoning, execution, OCR and lakehouse connections still to come, that road ends with a dozen error columns and no answer to "what is wrong right now".

The real harm is silent failure. Drop in 100 PDFs, 12 of them scans, and the UI shows 100 green rows; the user finds out when an answer lacks that contract, and never suspects ingestion.

Boundary with Review. Review holds what needs a decision (merge these two entities?); the alert center holds what a person needs to know (this document did not get in). Review guards the correctness of knowledge; alerts guard the health of the system. extraction_drops (11 drop reasons, shown per document on the library row) is a third channel: something in this document did not land. None of it goes to Review.

Decisions

  1. Aggregation belongs to the view. 100 PDFs with 12 scans must read as one line, "12 documents have no text layer", or the alert center is ignored within two weeks. But a stored aggregate is live and must be cleared when things recover, or it lies. So: one row per failure, never updated; the read side folds adjacent rows of the same (kb, kind) in SQL (gaps and islands, two row_number() subtractions), because paging is by group and a client-side fold would split a run at a page boundary. Counts are computed and never stale; a different failure in between is a different episode.
  2. "Is it fixed?" is a question the alert center does not answer. Every failure is a new row. Once the fault is fixed there are no new rows; read ones sink and the badge goes dark; a recurrence two months later is a new alert. No success signal, no probe, no time constant. The cost is rows (a broken hourly source writes 24 a day), purged after alerting::RETAIN_DAYS (30). Whether something is still broken is on the source page and in document status; an alert's job is to make someone look.
  3. Read state is per person. alert_reads is a two-column table; unread means "visible to me and not clicked by me". Reading says whether I have seen it, nothing about whether it is over. Nobody can read an alert away for someone else, as with GitHub notifications and Slack unread.
  4. Visibility reuses the KB role chain. kb_id IS NULL marks a system-level alert (the three LLM kinds), visible to users.is_admin only; a KB-level alert is visible to roles ≥ min_role in that KB, and admins see everything, as in access::kb_role(). min_role lives on the row: configuration alerts go to admins, content alerts (parse, extraction, source sync) to editors and above, because whoever uploaded the 12 scans needs to know more than the admin does.
  5. A row names one subject and carries no display text. subject_id is a single column, and detail keeps the subject's name so the alert renders after the subject is deleted. Titles are assembled on the client by kind (0004), so search matches KB name, detail and the kind code, never the title.
  6. Push is one global stream with no data and no permission check. The per-KB SSE route cannot carry a cross-KB badge, so /alerts/events rides the existing AppEvent broadcast (kind alert) and only tells clients to refetch; the list query decides visibility once. Someone without permission is woken for nothing, and the push path holds no permission logic.
  7. Classification is a pure function on error types. alert_for decides the kind from the error's type, never its text, and has unit tests; job failures reach it through observe_job_failure only once retries are exhausted. llm.unreachable means "no parseable answer from the endpoint": connection refused, or a proxy answering HTML. A clean 4xx is the API saying the key or quota is wrong, another person's problem (rate_limited, out_of_credit).
  8. A bell with a popover, because a page pulls people away from their work and then nobody goes. The badge is a red dot ("something unseen" is binary; a count jumps with every retry); a click marks read, hovering does not.

Dead ends

Revisions

Open questions