ADR-0003 — Reconciliation state in the runtime DB
Status: Accepted
Context
Section titled “Context”Discord resources have no labels or annotations. To know that channels.general in YAML is
channel 1182… in Discord, a persistent mapping is required (the “Terraform state” problem).
Options: state file in git, remote state file, name matching, markers hidden in topics.
Decision
Section titled “Decision”- Stable keys: every resource in YAML has a key distinct from its display name. Renaming in YAML is a rename in Discord, never a recreate. All references use keys.
- Resource map in the runtime DB:
(server, kind, key) → Discord ID, owner. No state file in git (no commit loops, no merge conflicts on state). - Drift detection in real time from gateway events, plus a periodic full diff.
- Per-server
syncPolicy:selfHeal(defaultfalse): revert manual changes instead of only reporting them;prune(defaultfalse): delete resources that were managed and have been removed from config;deletionProtection(defaulttrue): refuse any deletion, even withprune.
- Ownership: never-declared resources are never touched. Resources created by plugins at runtime are owned by their plugin instance and ignored by the reconciler.
- Recovery:
cicord adoptrebuilds the map by matching display names, with confirmation.cicord importgenerates YAML from an existing server and fills the map.
Consequences
Section titled “Consequences”- The DB must be backed up; losing it is recoverable (
adopt) but needs a human check. - “The runtime DB” is SQLite in the data dir by default or PostgreSQL (
--database-url); the resource map has the same schema and semantics on both (see Backups and secrets for backup and restore). cicord planin CI needs the runtime (--remote) for an exact diff; an offline plan is only a schema/semantic check.