cortex
aien-dev/cortex
Brought by drakestapleton
| 1 | # Cutover plan: cortex-rs to the Omega Cortex (PROPOSED, NOT EXECUTED) |
| 2 | |
| 3 | Status: PROPOSED. Nothing here has been run against a production instance. Each step that stops, |
| 4 | switches or restarts a production Cortex needs the operator's approval. Host-specific details |
| 5 | (ports, service names, paths, credentials) live in the operator's private runbook, not in this |
| 6 | public repository. |
| 7 | |
| 8 | ## Blockers before any switch |
| 9 | |
| 10 | - **Short-string pool runway (fixed on this branch).** Every logged revision's short fields live |
| 11 | in the string space `hs` (om/store.om). An omc pool holds at most 16,777,216 elements, so `hs` |
| 12 | is now four 16 MiB pools behind one byte accessor (`hsg`/`hsp`), 64 MiB in total. On 2026-10-26 |
| 13 | the primary instance's 6641 entities used 2,022,373 bytes (about 305 bytes each); at 60-70 new |
| 14 | entities an hour the 64 MiB space lasts about 127-148 days (modeled; the single 16 MiB pool |
| 15 | lasted about 29-34 days). When the space is full the server still traps while loading its log, |
| 16 | so the remaining margin must be watched. `tests/big` pads a snapshot past 16 MiB of short |
| 17 | strings and reads the last entity back; the old single-pool build exits 109 on the same log. |
| 18 | - **Ranked search speed.** Until 2026-11-11 ranked search and recall took about 1.35x the |
| 19 | oracle's wall time; since the incremental FTS index they are faster than the oracle on the |
| 20 | same store at 1,000 to 100,000 entities per space (README "Speed", evidence/brain/bench), and |
| 21 | get and traverse stay faster. |
| 22 | - **Shadow.** At least 24 h of read-only shadow comparison against the live instance, with zero |
| 23 | unexplained differences. |
| 24 | |
| 25 | ## Order |
| 26 | |
| 27 | One instance at a time. The primary instance goes first; any further instance only after the first |
| 28 | has run on Omega for a quiet week, and only with the operator's explicit approval (an instance that |
| 29 | runs under a separate system user needs a new privileged launch rule, which is a new trust path). |
| 30 | |
| 31 | ## Steps per instance |
| 32 | |
| 33 | 1. **Checkpointed import.** Snapshot without touching the live writer: |
| 34 | `sqlite3 'file:DB?mode=ro' '.backup SNAP.db'`, then `cortex-import SNAP.db NEW.log` |
| 35 | (refuses an existing OUT; prints `IMPORT OK spaces=… entities=… claims=… fts=…`). Compare the |
| 36 | counts with `SELECT count(*)` on SNAP.db. |
| 37 | 2. **Side-port run.** Start the Omega server on a free side port with the same token source and |
| 38 | encoder URL as the production instance, under the operator's process supervisor or by hand. |
| 39 | 3. **Shadow comparison.** Replay real read traffic to both ports and compare with |
| 40 | `tests/parity/pcmp` (same equivalence rule as spec/PARITY.md). `tests/shadow/run.sh` takes a |
| 41 | fresh read-only snapshot for every round and discards a round when the live data changed |
| 42 | between the snapshot and the end of the live replay, so writes are covered by re-snapshotting, |
| 43 | not mirrored. Gate: zero byte differences (identical except the masked timing fields: |
| 44 | `elapsedMs`, timestamps and the `/health` runtime string) over at least one day of rounds. |
| 45 | PROPOSED, not built: a tee in the MCP bridge that sends each real write to both instances in |
| 46 | commit order, which would let reads that follow a write be compared without waiting for the |
| 47 | next snapshot. Writes themselves are checked by the write-path gates in step 4. |
| 48 | 4. **Write-path checks on the build being switched in.** The wire parity gate and its mutant from a |
| 49 | clean clone (`check.sh`), the concurrent writers-plus-readers load test with kill -9 mid-run |
| 50 | (`tests/load/`), and claims create/upsert/retract on real-shaped data. |
| 51 | 5. **Switch.** Pause writers, take the final snapshot and import (step 1), stop cortex-rs (do not |
| 52 | delete it or its database), start the Omega server on the production port. Clients keep their |
| 53 | URL. |
| 54 | 6. **Rollback.** cortex-rs, its launch configuration and its SQLite file stay untouched during and |
| 55 | after the switch. Rollback = stop the Omega server, start cortex-rs again. Writes accepted by |
| 56 | Omega after the switch are not in SQLite: re-send them as `/api/cortex/write` requests (they are |
| 57 | the log records after the switch time) or accept their loss explicitly. |
| 58 | |
| 59 | ## Known differences a client can see |
| 60 | |
| 61 | - `/health` reports `"runtime":"native-arm64-omega"`. |
| 62 | - POST `/api/cortex/delete` and `--tokens` exist only in the Omega server (spec/CORTEX-API.md). |
| 63 | - A client that "forgets" by retracting keeps the retracted row on disk, as with cortex-rs; delete |
| 64 | removes it from the log. |