interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex

2f5f763 pin: omega-mv 2ee0a70d / omc 26540e6d (pin-follow) Drake Stapleton committed 2026-11-13
.github/
evidence/
om/
spec/
tests/
tools/
.gitignore8
AUDIT_SCOPE.md8622
DEPENDENCIES.md3769
LICENSE12278
PIN126
README.md12662
REPIN646
SECURITY.md2940
build.sh2317
check.sh3178

README.md

Cortex in Omega

A re-implementation of the Cortex memory server (cortex-rs 0.1.0) in seeded Omega. It answers the same HTTP API with the same bytes (spec/CORTEX-API.md) and keeps its data in an append-only log instead of SQLite. The server and the importer are single static aarch64 binaries built by the pinned Omega compiler; nothing else runs in production (DEPENDENCIES.md).

Status

  • Implemented and exercised on a host (Linux aarch64). All local gates pass on a copy of a real Cortex database (6,327 entities): wire parity 4642/4642 records identical except masked timing fields (elapsedMs, timestamps, runtime string; 3726 masked values, 48 renamed UUIDs; evidence/parity), the negative-control mutant is caught (172 failing records), and every acknowledged write survived kill -9 and restart in the load test (evidence/load).
  • Not deployed. No running Cortex uses it yet. spec/CUTOVER.md is a draft plan, not executed.
  • No CI: the gates below are run by hand (check.sh). The evidence files name the exact binaries and inputs they were produced with.
  • Company Brain (Omega extension, 2026-11-11): implemented and exercised on a host, not deployed. Dated, owned, append-only entries with supersede links, read before (ranked live entries with their citations), write after, contract and party records with a human confirmation gate and an expiry/renewal alert query, and a plain-file export/import. It uses the same log, FTS index and server as the rest (spec/CORTEX-API.md "Company Brain"; gates brain, brainmut, brainload). No language model is involved: an answer is the ranked, cited entries.
  • Linux aarch64 only (the compiler emits aarch64 ELF).
  • Limits: up to 262,144 FTS documents, 16 Mi index tokens and 64 MiB of short strings (four 16 MiB pools; about 305 bytes per entity on real data). Connections are served concurrently: a pool of long-lived handler processes (at most S_MAXH) forwards each whole request to the single state process, so a slow client holds only its own handler (evidence/conc). A handler keeps the memory its relay buffers reached (up to about 24 MiB for the largest request and answer it passed) until it exits; at least two stay alive, extra ones leave after 10 s without a connection. Globals take 992 of the compiler's 1024 MiB (the FTS term lists hold 128 MiB of it).
  • Speed (evidence/brain/bench, tests/brain/bench.sh, the stats in evidence/brain/stats.txt): the FTS index is kept incremental by every write (term lists, per-term row counts, per-space row lists; ftsIndexMismatches in /brain/usage compares it with a rebuild), so a query reads only the rows that can match in its own space instead of scanning the whole store, and answers are unchanged (fts and parity gates). On a 111,000-entity store, Omega's ranked search, plain search with the substring fallback and read before are faster than the cortex-rs 0.1.0 oracle on the same store and host at 1,000, 10,000 and 100,000 entities in the space (the oracle has no read before; its search is the comparison). What is left grows with the rows that match: read before in a space where every entry shares words with the task ranks every entry, and the substring fallback reads every entry of the space, as SQLite does.

Build

sh build.sh                                # omc from the local Radicle storage of omega-mv
OMEGA_REPO=/path/to/omega-mv sh build.sh   # or from a clone of rad:z6do9WDBhuSnvopDkgFdFr1yWA62

The compiler pin is written in one place, PIN (omega-mv <revision>, omc-sha256 <sha256>; the one pin of this repository since 2026-11-11, before that 91b3c932). tools/omc.sh reads it, extracts seed/out/omc at that revision into build/omc-<sha256> and refuses any other sha256; build.sh first compiles tools/pincheck.om and fails when any tracked file restates the pin (records under evidence/ excepted), then writes build/cortex, build/cortex-import and build/SHA256SUMS, whose compiler line is read from PIN. A compile is accepted only with exit 0 and empty stderr. To move the pin, edit PIN and run check.sh.

Import a cortex-rs database

sqlite3 'file:/path/to/cortex.db?mode=ro' '.backup /tmp/cortex-snapshot.db'
build/cortex-import /tmp/cortex-snapshot.db /path/to/cortex.log

The importer reads the SQLite file (and its WAL) read-only, writes the log to a temporary file, syncs it and renames it into place; it never overwrites an existing log.

Run

CORTEX_TOKEN=... build/cortex --port PORT --log /path/to/cortex.log --encoder-url URL

Options: --host (default 127.0.0.1), --port, --log, --encoder-url, --tokens FILE (space-scoped extra tokens). Without CORTEX_TOKEN the token is read from the same per-user file as cortex-rs (spec/CORTEX-API.md). GET /health answers without a token.

Company Brain routes are under /api/cortex/brain/ (spec/CORTEX-API.md). The plain-file export runs beside the server and only reads the log:

build/cortex --log /path/to/cortex.log --brain-export DIR

Local gates

sh check.sh /path/to/cortex-snapshot.db

runs, one at a time and at lowest CPU/IO priority:

stepscriptwhat it proves
buildbuild.shboth binaries compile with the omc named in PIN; tools/pincheck.om finds no tracked file restating the pin
pintests/pin/run.shthe tree passes pincheck; restating the revision or the omc sha256 is refused, records under evidence/ and other hashes are not judged, a malformed PIN and a binary with another sha256 are refused; with a fixture PIN whose revision and sha256 start with 8 digits, 8-, 12- and 16-character, upper-case and full restatements are refused while dates, counts and near misses pass, and five mutants of the prefix comparison are each caught
pageunittests/pageunit/run.shtools/pageunit/enc.om units print their page back byte for byte up to 200000 lines; refusals, old compiler, mutant and wrong compiler caught; arena alarm
jsontests/json/run.shJSON parsing, error texts and float/number text match serde_json/ryu/zmij bit for bit; mutants caught
ftstests/fts/run.shtokenizer, bm25, log and LIKE match SQLite 3.45.0 and glibc, the searches under each plan of the incremental index (space scan, term lists, every row, without the term-count loop) and after deletes and re-inserts; the index equals a rebuild; negative controls caught (12, four of them skipped index updates)
importtests/import/run.shthe SQLite reader and importer match sqlite3 on real and synthetic files, WAL included; corruption detected
paritytests/parity/run.shthe wire gate against the cortex-rs binary (spec/PARITY.md)
mutanttests/parity/mutant.shthe gate fails when one score constant changes
loadtests/load/run.shread-mix latency of both servers and the kill -9 durability check
bigtests/big/run.sha snapshot padded past 16 MiB of short strings loads and reads back
conctests/conc/run.sh16 concurrent clients plus slow clients, against the latency gate; after kill -9 of the state process while slow clients hold handlers, a new server takes the port within 3 s
claimstests/claims/gen.sh via the parity runnerclaim create/upsert/retract parity
braintests/brain/run.shCompany Brain answers equal the expected answers (parity rule) in three phases: entries, supersede, read before with citations, refusals, the append-only guard, contract records, the confirmation gate, alert window boundaries; export, unchanged import and re-export give one tree hash; a hand-corrected file imports as a superseding entry; the live supersede index and the incremental FTS index each equal a full rebuild. tests/brain/expected-*.rec and expected.sha are written only by BRAIN_RECORD=1 sh tests/brain/run.sh (review the diff before committing), never edited
brainmuttests/brain/mutant.shthirteen one-line mutants (om/brain.om: supersede filter, citations, confirmation gate, date kinds, import idempotence, both window ends, guard, live index update; om/fts.om: a write that does not count its terms, link them or count its row in its space) are each caught by the brain gate
brainloadtests/brain/load.shwrite-after and read-before latency on the load fixture, the incremental FTS index equal to a rebuild after the import and 2000 writes, the capacity alarm (fails when a store capacity is 50 percent full; its control must fire at 1 percent) and kill -9 during Brain writes loses no acknowledged entry

tests/brain/bench.sh (not a check.sh step: it writes 111,000 entities through the oracle) measures read before and ranked search of two Omega binaries and the oracle on one store and checks that their answers agree; tests/brain/scale.sh measures read before of two binaries alone.

The parity and load steps need the cortex-rs 0.1.0 binary on PATH (or CORTEX_ORACLE) and use ports 18180 and 18190 (set PARITY_ORACLE_PORT and PARITY_OMEGA_PORT when those are taken); the brain steps use ports 18232 to 18234. The json and fts steps need their offline oracles (DEPENDENCIES.md). Logs and fresh evidence go to build/check/; the committed evidence/ is not touched. Exit 0 only when every step passes.

Tools

tools/pageunit/enc.om stores page text as native Omega: it reads a page on stdin and writes an om2 unit on stdout with the page as text tN "..." records (one per line, a long line split every 4096 bytes; tab, quote, backslash and newline escaped) and a main that writes the same bytes back, so compiling and running the unit reproduces the page exactly. Build and use it with tools/pageunit/omc.sh, which runs tools/omc.sh (the compiler named in PIN): `OMC=$(sh tools/pageunit/omc.sh); "$OMC" < tools/pageunit/enc.om > enc; ./enc < page.txt > page.om; "$OMC" < page.om > page; ./page | cmp - page.txt`. Exit codes: 0 ok, 2 read error, 4 control byte (below 32 other than tab and newline, or 127), 6 write error. enc streams (one 64 KiB input block, one 64 KiB output buffer), so it has no size refusal of its own, and on a nonzero exit its output is incomplete and must be discarded. The 8000-line and 1000000-byte refusals it had until 2026-11-11 are gone: the lines came from the old compiler pin's fixed tables (8192 texts per unit), the bytes from enc's own fixed pools. What a page still meets is the memory of the compiler that builds its unit. Measured 2026-11-11 with the compiler pinned then (a fixed arena of 16777216 8-byte words): a unit stopped at about 524000 records (1 MiB of two-byte lines), about 226000 lines of 120 bytes (27 MB) or about 64 MB of long lines. The gate alarms (prints the arena record and fails) when a real page passed to it (sh tests/pageunit/run.sh page.txt ..., or PAGEUNIT_PAGES=dir for its *.txt, also through check.sh) yields a unit that puts as many words in the compiler's arena as the threshold ALARMAT in tests/pageunit/gen.om, or more, measured with omc's usage mode. The threshold is a stated number (80 percent of that fixed arena), so it also holds with a compiler whose arena grows; the gate prints it as alarm-at= beside every record it judges. Throughput, measured 2026-11-11 on Linux aarch64 on one shared core (load 14), process start included: 189 MB/s on a 900000-byte page (the earlier whole-page enc: 199 MB/s in the same run) and 264 MB/s on a 32 MiB page, which the earlier enc refused. Gate: sh tests/pageunit/run.sh.

Layout

  • om/ server and importer modules (order in build.sh; ownership in spec/BUILD-CONTRACT.md)
  • spec/ contracts: API, build, parity rule, observed oracle behaviour, cutover draft
  • tests/ the gates; evidence/ their committed results
  • tools/ compiler pins and pageunit/ (page text to an om2 unit, above)

License: Apache-2.0 WITH LLVM-exception (LICENSE).

Human-Directed Agentic Engineering

Development follows Human-Directed Agentic Engineering (HDAE): humans define goals, architecture, constraints, acceptance criteria, and stopping points; agents implement, execute checks, diagnose failures, and revise within those boundaries. Human review retains responsibility for claims, acceptance, and release decisions.

For the documented method and a systems-software case study, see Gregory M. Kurtzer, [*Ginux: Building an Independent Kernel That Runs Linux Userspace through Human-Directed Agentic Engineering* (2026)](https://doi.org/10.5281/zenodo.23682548). This citation describes the development method, not runtime autonomy or an endorsement.