Schema downgrade drops the older version's tables (no guard against migrating below active)
### Summary
Rolling back to an older schema-version binary causes the garbage collector to **drop the older version's ClickHouse tables**, destroying the rollback target. Schema downgrades are unsafe: there is no guard against migrating to a version below the active one.
### Expected behavior
A binary whose embedded `SCHEMA_VERSION` is *below* the current active version should refuse to run and must never mark its version `migrating` — mirroring the indexer's existing outdated-binary guard. A downgrade should be a fast, safe no-op, not a destructive operation.
### Actual behavior
Deploying an older binary (embedded v72) while active is v76 makes the dispatcher enter the migration path, create v72 tables, and mark **v72 `migrating`**. That flips v72 out of the `retired` GC keep-set, and because `72 < active(76)` it also fails the `migrating AND version > active` protection — so the next GC pass drops every `v72_*` table and marks v72 `dropped`. The rollback deletes the very data it was trying to revert to.
### Steps to reproduce
1. Have active schema version = N (e.g. 76), with version N-k (e.g. 72) present and `retired`.
2. Deploy a binary whose embedded `SCHEMA_VERSION` = N-k (a rollback).
3. Its dispatcher runs `schema::migration::run_if_needed`, hits the mismatch arm, and calls `write_migrating_version(N-k)`.
4. Within ~1 GC cycle, `reconcile_dead_versions` runs `DROP TABLE IF EXISTS v{N-k}_*` and marks it `dropped`. The v(N-k) tables are gone.
### Environment
- Observed in production (orbit-prd), ClickHouse Cloud 26.4.1.
- Applies to any deployment; not environment-specific.
### Logs
<details><summary>Expand logs</summary>
```
2026-07-02T20:07:14Z "marking schema version as migrating" version=72 (dispatcher on v72 image)
gkg_schema_version: version=72 status=dropped created_at=2026-07-02 20:08:22
system.tables: 0 rows matching v72_% (all v72 tables dropped, past UNDROP window)
```
</details>
### Workaround
Do **not** roll back a schema version by deploying an older binary. To move off a bad version, roll *forward* (new version) or restore from a ClickHouse Cloud backup. There is currently no safe in-place downgrade.
### Additional context
Root cause is the missing downgrade guard in `crates/indexer/src/schema/migration.rs:97-113`; the GC keep-set in `crates/indexer/src/orchestrator/scheduled/migration_completion.rs:101-119` only protects `migrating` versions above the active one. Full walkthrough below.
### Checklist
- [x] Used latest available version of gkg
- [x] Searched existing issues for duplicates
- [x] Included minimal, reliable reproduction steps
- [x] Attached relevant logs and environment details
- [x] Removed sensitive information from logs/configs
<details>
<summary><b>Agent context</b> — extended analysis, hypothesis chains, file walkthroughs</summary>
**Chain of events (prod, 2026-07-02):**
1. `schema::migration::run_if_needed` (`migration.rs:68-115`) matches on the active version. The `Some(active_version)` arm (`:97-113`) treats **any** `active_version != *SCHEMA_VERSION` as "schema version mismatch detected — starting migration" and calls `run_migration`. It never checks whether `*SCHEMA_VERSION > active_version`, so a downgrade takes the same path as an upgrade.
2. `run_migration` creates the embedded version's tables and calls `write_migrating_version(*SCHEMA_VERSION)` (`migration.rs:158`) → inserts `(72, 'migrating')`.
3. Marking 72 `migrating` removes it from `status='retired'` (it had been the single retained retired version; `schema.max_retained_versions: 2` in `config/default.yaml:178` → `retired_slots = 1`).
4. The GC keep-set `LIST_DEAD_VERSION_OBJECTS` (`migration_completion.rs:101-119`) = active ∪ newest `retired_slots` retired ∪ (`migrating` **WHERE version > active**). v72 is none of these (not active; no longer retired; migrating but `72 < 76`), so all `v72_*` objects are "dead."
5. `reconcile_dead_versions` (`migration_completion.rs:537-634`) runs `DROP TABLE IF EXISTS v72_*` then `mark_version_dropped(72)`.
**Contrast — the indexer already guards this:** `schema::version::classify_readiness` (`version.rs:323-339`) returns `Outdated` when `active > embedded`, and `wait_until_ready` fails fast ("binary is outdated and must not process", `version.rs:354-358`). The dispatcher's migration path has no equivalent.
**Recommended fix:**
- Primary: in `run_if_needed`'s `Some(active_version)` arm, if `*SCHEMA_VERSION < active_version`, return an error (downgrade refused) and do **not** call `run_migration` / `write_migrating_version`. Only migrate when `*SCHEMA_VERSION > active_version`.
- Defense-in-depth: relax the GC keep-set to protect **all** `migrating` versions (drop the `version > active` restriction), so an in-progress migration is never GC'd regardless of ordering.
**Acceptance criteria:**
- An integration test with active = embedded+1 shows `run_if_needed` refuses (errors), writes no `migrating` row for the embedded version, and does not drop the higher version's tables.
- The guard is symmetric with the indexer's `Outdated` classification.
</details>
<!-- Don't edit below -->
issue
GitLab AI Context
Project: gitlab-org/orbit/knowledge-graph
Instance: https://gitlab.com
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://gitlab.com/gitlab-org/orbit/knowledge-graph/-/raw/main/CONTRIBUTING.md — contribution guidelines
- https://gitlab.com/gitlab-org/orbit/knowledge-graph/-/raw/main/README.md — project overview and setup
- https://gitlab.com/gitlab-org/orbit/knowledge-graph/-/raw/main/AGENTS.md — AI agent instructions
Repository: https://gitlab.com/gitlab-org/orbit/knowledge-graph
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD