Add phase-1 observability bridge that turns provider observations into normal Gitea issues and control-plane incident_links rows. Dry-run is default; apply creates/links through sanctioned Gitea issue paths only. Raw incidents remain non-assignable; the #600 allocator sees bridge work only as ordinary Gitea issues. Builds on #613 substrate and #600 allocator. Closes #612
4.0 KiB
4.0 KiB
Control-plane DB substrate (#613)
Status: Implemented (SQLite single-writer MVP)
ADR: mcp-allocator-control-plane-observability-adr.md
Module: control_plane_db.py
Architecture statement
DB coordinates, Gitea records, Sentry/GlitchTip observe; the bridge is the only path that turns observations into Gitea work.
What this ships
| Capability | Notes |
|---|---|
| Schema | sessions, work_items, leases, assignments, terminal_locks, events, incident_links |
| Atomic assign+lease | ControlPlaneDB.assign_and_lease — one BEGIN IMMEDIATE transaction |
| Mutation gate | require_valid_assignment — live lease + allowed action + non-terminal work + non-stale head |
| Heartbeat / release / expire | Lease lifecycle helpers |
| Terminal-lock index | Routing signal for #600 (terminal path first) |
incident_links |
Provider-neutral link model for #612 — not assignable work; scope keys NULL-safe |
Hard rules (enforced in code)
- Assignable
work_items.kind∈ {issue,pr} only — never raw Sentry/GlitchTip incidents. - Two concurrent sessions cannot both receive an active assignment on the same open work item (second gets
wait). - Merged/closed work items return
no_safe_workat assign time, andrequire_valid_assignmentfails closed if the work item becomes terminal later. - Assignments pin
expected_head_sha; mutations fail closed if the work item head drifts. - SQLite path is the single-writer MVP (
GITEA_CONTROL_PLANE_DB, default under~/.cache/gitea-tools/control-plane/). Multi-session multi-host production requires Postgres or a single allocator daemon (ADR §6). incident_linksoptional scope fields are stored as empty strings (never NULL) so UNIQUE is canonical across minimal upserts.- Legacy
incident_linksmigration collapses NULL-scope duplicates only when Gitea targets and all meaningful observation metadata agree (fingerprint, status, event_count, permalink, timestamps, linked PRs, etc.). Conflicting metadata fails closed — no silent discard.
Dependency chain
#613 control-plane DB (this) → #600 allocator API → #612 incident bridge
- #600 must call this substrate (not file locks / comment-only leases alone) for completion.
- #612 must write
incident_linkshere and create Gitea issues; the allocator assigns those issues, not raw incidents.
Allocator API (#600)
Module: allocator_service.py · MCP tool: gitea_allocate_next_work
- Workers call
gitea_allocate_next_work(apply=false|true)instead of self-selecting work. apply=falsereturns a dry-run selection (outcome=preview) with skip reasons.apply=truereserves viaControlPlaneDB.assign_and_lease(atomic assignment+lease).- Coordination source is always the control-plane DB — not file locks or comment-only leases.
- Routing follows ADR §5.3 (REQUEST_CHANGES → author, terminal path first, foreign lease → wait).
- Raw monitoring incidents are never candidates.
Incident bridge (#612)
Module: incident_bridge.py · MCP tools: gitea_observability_*
- Bridge converts Sentry/GlitchTip observations → normal Gitea issues +
incident_links. - Phase-1:
gitea_observability_reconcile_incident(apply=false|true)with JSON observation. - Dry-run performs no Gitea mutation and no DB write.
- Apply reuses existing links or creates one Gitea issue; never invents
work_items.kind=incident. - Config:
GITEA_OBSERVABILITY_PROJECTS_JSONorGITEA_OBSERVABILITY_PROJECTS_FILE. - Provider tokens never appear in issue bodies, links, or tool results.
- Allocator sees bridge work only after a Gitea issue exists.
Non-goals (intentionally deferred)
- Full unsupervised watchdog auto-filing (prefer explicit reconcile first)
- Assuming GlitchTip writeback API equals Sentry without verification
- Gitea comment/label mirror writers for every assignment (optional later)
Tests
python3 -m pytest tests/test_control_plane_db.py -q