Files
CatoandClaude f55c127901 feat(research): runs record what their search backends did, and /api/health/web says it now (#376)
* feat(research): runs record what their search backends did, and /api/health/web says it now

The event sweep and producer sourcing failed for a day on production with
nothing on /data/freshness but "no search reached a search backend".

- Each sweep and sourcing run records its search backends' outcome in
  ai-kit's own words (search_note, e.g. "searxng unreachable"); migration
  018 adds the column. /data/freshness shows it beside a failing run.
- /api/health/web searches once for a fixed phrase and reports which
  backends are configured (names only) and what each did. One probe per
  ten minutes, shared by concurrent callers.
- docs/operations/auto-updates.md: what runs, when, what it needs, where
  it leaves a trace, and what to do when a run is failing.

Claude-Session: https://claude.ai/code/session_019MDtmuvTGrpo3VChP3skH8

* fix(data-layer): read double-quoted identifiers in migrations

declaredObjects read `CREATE TABLE IF NOT EXISTS "users"` as a table named
"if", so 017-accounts.sql looked incomplete on any database that predates
the ledger: it would be re-run, and the ownership hand-over would miss its
real tables. CI's real-Postgres test caught it once 017 stopped being the
newest file ("must be owner of table accounts").

Tables, indexes, ALTER TABLE targets and added columns may now be quoted.

Claude-Session: https://claude.ai/code/session_019MDtmuvTGrpo3VChP3skH8

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 08:16:31 +01:00

36 lines
1.3 KiB
TypeScript

/**
* A run's search note: what the search backends did, in ai-kit's own words
* (`describeAttempts`: "searxng unreachable; brave 6"). The sweep and producer
* sourcing keep one per run (scripts/db/018-search-notes.sql) and
* /data/freshness shows it beside a failing feed, so "no search reached a
* backend" comes with which backend and how.
*/
import { describeAttempts, type WebSearchResult } from '@bitbaum/ai-kit/web';
export type SearchReport = Pick<WebSearchResult, 'status' | 'attempts'>;
/** The note for one search: "searxng timeout", or "no backend" when none was tried. */
export function searchNote(result: SearchReport): string {
return (describeAttempts(result.attempts) || 'no backend').slice(0, 300);
}
const RANK: Record<WebSearchResult['status'], number> = { found: 0, nothing: 1, could_not_look: 2 };
/**
* Collects the notes of a run's searches and keeps the one that explains the
* most: the latest search that could not look, else the latest that found
* nothing, else the latest that found pages.
*/
export function searchNotes() {
let kept: { rank: number; note: string } | null = null;
return {
add(result: SearchReport) {
const rank = RANK[result.status];
if (!kept || rank >= kept.rank) kept = { rank, note: searchNote(result) };
},
get note(): string | null {
return kept?.note ?? null;
},
};
}