interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / spec / PARITY.md

87 lines · 5502 bytes Raw Blame History Rendered
1# Wire parity gate: Omega Cortex against cortex-rs
2
3`sh tests/parity/run.sh SRC.db` replays one fixed request corpus against the cortex-rs oracle and the
4Omega server, each on its own copy of the same data, and compares the two answer streams record by
5record. Exit 0 only when every record is exact or differs only as this file allows.
6`sh tests/parity/mutant.sh SRC.db` is the negative control. `check.sh` runs both.
7
8## Setup
9
10| side | binary | port | data |
11|---|---|---|---|
12| oracle | `cortex-rs` 0.1.0 (sha256 `91ccba94…98afe`) | 18180 | `sqlite3 .backup` copy of SRC.db |
13| Omega | `build/cortex` | 18190 | the second copy, imported by `build/cortex-import` into `cx.log` |
14
15Both run with `CORTEX_TOKEN=paritytok` and `--encoder-url http://127.0.0.1:9`, a closed port, so every
16recall takes the no-embedding path on both sides. SRC.db is opened read-only. The oracle runs first and
17the Omega server second; each sees the identical sequence, so write-phase state evolves the same way.
18
19## Corpus (`tests/parity/gen.sh`, `gen.om`, `fixed.tsv`)
20
21One request per line: `CLASS<TAB>METHOD<TAB>PATH<TAB>FLAGS<TAB>BODY`. `~HEX` in PATH is sent
22percent-encoded; FLAGS select the auth header, content type, origin and similar
23(see `tests/parity/pdrive.om`). The generated part comes from the data itself: sqlite3
24extracts 40 FTS vocabulary terms by frequency stride, 30 title words, 15 identifier-like words,
2515 two-word phrases and 152 entities (50 per large space by stride and every row of the small
26spaces). `gen.om` expands them into GET/POST search, recall, get and traverse requests with several
27spaces, limits, `include_retracted` values and query shapes, including operators (` OR `, ` NOT `,
28` AND `, `*`, `-x`, `(x`, `x)`) and malformed or empty queries. `fixed.tsv` adds 365 hand-written
29cases: /health and HEAD, CORS preflights and origins, auth (missing, wrong, case, padding), unknown
30routes and wrong methods, content types, query-string and body errors (axum Query/Json rejections,
31oversize bodies), the write phase (create, read back, search, upsert, claim, traverse, retract, with
32client-supplied ids), and the visitor-memory shapes the chat client sends (remember, list, forget for
33a `v-<64 hex>` space, with and without explicit ids).
34
35The corpus is deterministic for a given SRC.db; its sha256 is in `evidence/parity/summary.txt`.
36POST /api/cortex/delete and `--tokens` are Omega-only extensions (spec/CORTEX-API.md) and are not
37in the corpus.
38
39## Equivalence rule (`tests/parity/pcmp.om`)
40
41A record passes when all of these hold:
42
431. The status lines are byte-equal.
442. The header lines are equal as a multiset, ignoring `date` (order differs: the oracle sends
45 `connection` before `date`).
463. `content-length` is equal, with three exceptions: the body needed one of the masks in 4; the
47 request is a HEAD of /health or /status, both bodies are empty and Omega's length is exactly the
48 oracle's plus one (the masked `runtime` value below is one byte longer); or the request is a HEAD
49 of /api/cortex/search or /api/cortex/recall, both bodies are empty and the lengths differ by at
50 most 24 bytes (the unseen body holds the masked `elapsedMs` number, whose text is at most 24
51 bytes; observed: 727.0010540000001 from the oracle against 1.990726 from Omega).
524. The body bytes are equal except for these values:
53 - an `elapsedMs` number (wall time);
54 - a `committedAt`, `createdAt` or `updatedAt` string when both values are fresh (at or after the
55 run start, compared on the first 19 bytes) and have the same shape;
56 - server-generated UUIDs, which must follow one consistent one-to-one renaming learned only from
57 `targetId`, a receipt `id` and `spaceId`; an unknown UUID anywhere else fails;
58 - the /health field `"runtime"`, exactly `"native-arm64-rust"` in the oracle and
59 `"native-arm64-omega"` in Omega. The Omega server reports its own runtime by decision; this is
60 the only intentional difference on the wire.
61
62Everything else, including score digits, key order, float text, ordering of ties and error texts,
63must be byte-equal. Both streams must hold exactly one record per corpus line, and a transport error
64on either side fails the record.
65
66## Result (`evidence/parity/`)
67
68`summary.txt` holds the corpus sha256, the three binary sha256s, the import summary and the per-class
69counts; `report.txt` holds one PASS/FAIL line per record. The committed run: 4642 records, 4642 pass,
700 fail, 3726 masked values, 48 renamed UUIDs.
71
72## Negative control (`tests/parity/mutant.sh`)
73
74The mutant changes one line of the server unit, the LIKE-fallback score in `o_search_row`
75(`s = 0.7` to `s = 0.71`), rebuilds it with the pinned omc and runs the whole gate with scratch work
76and evidence directories. The gate must exit 1 with FAIL records. `evidence/parity/mutant.txt`
77records the result: gate rc 1, 172 failing records across search, error.query and route classes.
78
79## Fixes the gate found
80
81- Search FTS: the live binary returns rows only from the quoted-phrase attempt
82 (spec/ORACLE-OBSERVED.md); the Omega server dropped the operator and AND-joined attempts.
83- Empty-query list: shifting entries during the ordered insert left stale result kinds, so later rows
84 printed a previous request's score instead of 0.4.
85- Comparator: byte loops over the 1.2 MB corpus and multi-megabyte bodies now run in 65,536-byte
86 chunks (an Omega loop traps after 1,000,000 passes), and a mismatch inside a string value is
87 located from its opening quote.