homelab-codex-ws/hosts/piha/jobs.yaml
oskar ae16deb8d3 feat(mail-sync): scheduler PIHA, takt kb-ingest, runbook i dokumentacja
Domkniecie Kroku 7. Realizuje Decyzje (d) reconu (host schedulera + korekta
kadencji indeksowania) i doklada dokumentacje wg konwencji OKF.

Scheduler (NIEAKTYWOWANY — wlacza operator):
- jobs/mail-imap-sync/systemd/{service,timer,run.sh} — wzorzec 1:1 z kb-ingest,
  OnCalendar=hourly, Persistent=true, log do pliku (nigdy sam journal).
- hosts/piha/jobs.yaml — deklaracja jednostek host-level na PIHA. Nowy plik, bo
  services.yaml jest dla kontenerow (supervisor dopasowuje jego wpisy do world-state
  i wpis niekontenerowy dryfowalby wiecznie jako missing_service). Nic tego pliku
  nie czyta — istnieje po to, zeby "shadow-deploy family" z otwartego pytania 5
  reconu multiagentowego byla spisana, a nie tylko na nodzie.

Takt indeksowania (Decyzja (d), recon §3.3):
- kb-ingest.timer: 03:30 raz na dobe -> co 2 h. O 03:30 SOLARIA prawie na pewno spi
  (potwierdzone odczytem kb_ingest_embed_skipped 1 z 2026-08-06), a tick dostaje
  teraz etap mailowy: ~60 nowych chunkow na dobe pomijanych kazdej nocy sprawiloby,
  ze backlog rosnie monotonicznie i KbEmbedBacklogGrowing zapala sie NA STALE.
  Co 2 h zamiast stalej godziny — probe Ollamy sam wybiera okno, wiec ktorys tick
  w nie trafi niezaleznie od nawykow operatora.
- cyclic_ingest: etap mailowy (mail_body_ingest --only-unchunked), import miekki,
  wiec venv bez tego pakietu pomija etap zamiast wywracac wrapper. Predykat bledu
  JEST luzniejszy niz wlasne main() tamtego joba i to jedyne takie miejsce w tym
  wrapperze: pojedynczy trwale nieparsowalny mail nie moze zamrozic
  last_success_timestamp i zapalic KbIngestStale na zawsze. Bledy per-mail sa
  publikowane jako kb_ingest_mail_parse_errors, nie chowane.

Obserwowalnosc: KbMailSyncStale (6 h bez udanego ticku). Alert na cisze w skrzynce
ODRZUCONY (decyzja operatora, zgodna z reconem §3.4) — zero nowych maili to legalny
stan skrzynki, a alert zapalajacy sie na zdrowym systemie zostaje wyciszony
i przestaje dzialac wtedy, gdy jest potrzebny.

Dokumentacja:
- kb/services/job-mail-imap-sync.md (OKF), kb/runbooks/mail-sync-run.md — 9 krokow
  pierwszego uruchomienia, w tym checklista 4 punktow [do weryfikacji na zywo]
  z reconu (polityki dostawcow — do sprawdzenia, nie do zgadniecia) oraz pomiar
  STATUS (MESSAGES) na Fastmailu, na ktorym zapada ODLOZONA decyzja o historii.
- kb-mail-pillar.md: KOREKTA JMAP -> IMAP dla Fastmaila jako decyzja 2026-08-06;
  stary zapis zostaje jako historia z data. Zamkniete "unifikacja adaptera"
  i "sizing Gmaila"; otwarte zostaje "sizing Fastmaila" — celowo, bo rozstrzyga
  je pomiar, nie dyskusja.
- kb-m5-faza-mailowa.md: Krok 7 IN PROGRESS + tabela zakresu wdrozonego,
  kb-m5-faza3.md: korekta harmonogramu i sekwencji wrappera,
  pkg-kb-mail.md: rozpisany ze stubu, kb-postgres.md: lista migracji + 005.

Testy: 642 passed (calosc kb-mail, kb-retrieval i jobs). systemd-analyze verify
na timerze przechodzi, OnCalendar=0/2:00:00 normalizuje sie do co 2 h.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 15:30:57 +02:00

49 lines
2.3 KiB
YAML

# Host-level systemd units on PIHA — declaration only.
#
# These are NOT docker-compose services, so they do not belong in services.yaml (whose
# entries the supervisor matches against world-state service keys; adding a non-container
# entry there would drift forever as missing_service). Nothing reads this file: it exists so
# the units installed outside the compose pipeline are written down in the repo rather than
# living only on the node and in a runbook.
#
# This is the "shadow-deploy family" the multiagent recon flags in its open question 5
# (kb/subsystems/recon-multiagent.md) — units installed outside GitOps drift detection.
# kb-mail-sync joins that list knowingly, not by oversight. When question 5 is settled, this
# file is the inventory to settle it against.
#
# Installation and activation are always operator steps. A `git pull` never starts a timer.
host: piha
systemd_units:
kb-ingest:
unit: kb-ingest.timer
service: kb-ingest.service
source: jobs/documents-ingest/systemd/
schedule: "0/2:00:00" # every 2 h — see the note in the .timer file
runs_as: oskar
environment_file: /opt/homelab/kb/.env
log_path: /opt/homelab/logs/kb-ingest/
metrics: /opt/homelab/state/node-exporter/kb-ingest.prom
state: active # installed and enabled since 2026-07-30
description: >
Cyclic KB ingest: paperless adapter, chunk+embed, summarize, embed summaries, and
(since 2026-08-06) the mail body stage that drains the unchunked-envelope queue
mail-imap-sync fills. Both embed stages are gated on an Ollama@SOLARIA probe.
kb-mail-sync:
unit: kb-mail-sync.timer
service: kb-mail-sync.service
source: jobs/mail-imap-sync/systemd/
schedule: hourly
runs_as: oskar
environment_file: /opt/homelab/kb/.env
log_path: /opt/homelab/logs/kb-mail-sync/
metrics: /opt/homelab/state/node-exporter/kb-mail-sync.prom
state: declared # NOT installed, NOT enabled — operator activates
runbook: kb/runbooks/mail-sync-run.md
description: >
Incremental IMAP fetch for gmail (\All) and fastmail (INBOX, Archive, Sent) into the
.eml archive and the envelope table. Network-bound, no GPU — which is why it lives on
PIHA (24/7) and is decoupled from the embedding stages on SOLARIA (~16 h/day off).