interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / hive-task

78f40e0 hive: read the lease clock after the write lock (#925 round 4) Drake Stapleton committed 2026-11-07
..
README.md9018
cases.tsv5131
drive.om59242
task.om11730

README.md

om/hive-task: forge task transition rules

task.om is the source of truth for the forge task state machine of the hive cockpit (#925, DRA-288, DRA-162). crates/spark-hive/src/store.rs is the host adapter: each mutation is one conditional UPDATE ... RETURNING whose predicate is the rule in task.om, stepped to completion so a failed commit is reported instead of lost. drive.om drives the real spark-cockpit-rs binary over HTTP and checks that the adapter does what the rules say. store.rs and the forge handlers in crates/spark-cockpit-rs/src/main.rs stay host adapters for now; #925 itself tracks moving the store logic into .om (successor: this directory).

Pinned compiler: omega-mv seed omc, sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f (the omega MCP pin, omega-mv e5b32567; the same pin as om/residency).

Rules (task.om)

States: open, claimed, submitted, verified, failed. Operations: claim, renew (heartbeat), submit, verify, reap (reclaim of expired leases), dberr (classification of a store error), command id.

OperationAllowed fromEffectRefused when
claimopen, failed, claimed with an expired leaseclaimed, generation + 1, new attempt idlive lease (HELD), submitted or verified (BADSTATE), generation at 2^53-1 (EXHAUST), ttl outside 1..86400 (BADTTL, HTTP 400)
renewclaimed by the same attempt and generation, lease not expirednew leaseother attempt or generation (STALE), expired (EXPIRED), other state (BADSTATE), bad ttl (400)
submitsame as renewsubmitted, records branch, pr_url, artifactas renew
verifysubmitted, same generation and artifact digestverified or failed, records verifier and notesother state (BADSTATE), other generation or artifact (MISMATCH)
reapclaimed with an expired leaseopenanything else is left alone
dberrbusy or locked: RETRY (HTTP 503, retryable); anything else: DBFAIL
command idany write that carries command_ida new id proceeds; a known id with the same request digest replays the recorded answer; a known id with another digest is 409 command_conflictan id that is empty, over 128 bytes, or has a byte outside A-Z a-z 0-9 . _ : - (400 invalid)

Only claim changes the generation. A lease is expired when now >= expiry. The default lease is 300 seconds.

Clock after lock (#925 round 4): every write (claim, heartbeat, submit, verify, reclaim, with or without a command id) first takes the SQLite write lock with BEGIN IMMEDIATE, and only then reads now. Expiry checks and the new expiry (now + ttl) use that reading. A request that waited up to the 5 s busy timeout behind another writer is therefore judged at the moment it can write: a claim gets a lease that is live when granted, and a heartbeat or submit whose lease ran out during the wait is refused (409, row unchanged, nothing recorded).

Command ids (#925 acceptance 2, DRA-288 "or a defined idempotent replay"): the digest covers the operation, the task id and every normalized request field. Only an allowed outcome is recorded, in the same BEGIN IMMEDIATE transaction as the change it answers, so a refusal, a 404, a 400, a busy database or a failure is decided again when retried with the same id. A replay changes nothing (a replayed heartbeat does not extend the lease; a replayed reclaim does not sweep again). A replayed answer is the historical receipt of the original request, returned as it was then: the lease, status and generation it shows may have changed since, so a client reads the task to learn its current state.

Order of checks in the adapter: command id shape, then ttl, then the database. A JSON body that does not parse or lacks a required field is 400 {"code":"invalid"}, like every other bad input.

Deployment rules

  • Every process that opens one hive.db must run this build. An older binary's claim writes no lease_expires_ms, and the new rules treat such a lease as expired, so another process can take the task at once. The migration is a coordinated cutover, not a rolling upgrade: stop every old writer, then start the new build on the file. The migrate check runs it that way (the old cockpit is stopped first); mixed old and new writers on one file are not tested.
  • The store requires SQLite WAL mode and refuses to open a database it cannot switch to WAL.
  • The cockpit no longer falls back to an in-memory store when the hive store does not open; it prints Cockpit refused to start: hive store: ... and exits 1. A private in-memory store would grant leases no other process sees.

Running

OMC=<pinned omc>
$OMC < om/hive-task/task.om  > task.bin  && chmod +x task.bin
$OMC < om/hive-task/drive.om > drive.bin && chmod +x drive.bin
./drive.bin MODE ./task.bin COCKPIT SCRATCH om/hive-task $OMC MAIN_COCKPIT

COCKPIT is the spark-cockpit-rs build under test, SCRATCH an empty directory, MAIN_COCKPIT a build of main (used by migrate to make an old-schema database). Every cockpit runs on an ephemeral 127.0.0.1 port outside 18000-18999, with a scratch HOME, HIVE_DB_PATH and a throwaway token; the live cockpit and its database are never touched. Output is one line per check (PASS|FAIL <name> http=<code>) and a SUMMARY line; exit 0 only when nothing failed.

ModeWhat it checks
casestask.om against the 88 hand-written expectations in cases.tsv (including the negative cases).
httpCreate, T1 verify(open), T2 claim(verified), T3 submit(verified), verify bound to generation and artifact, persisted branch/pr_url/artifact/verifier/notes, stale attempt (same agent name, older generation), expired heartbeat and submit (row unchanged), generation exhaustion, ttl bounds (400 invalid), a bad JSON body and a missing field (400 invalid), a held write lock (503 busy, retryable, then the retry is granted), command id replay of claim, heartbeat, submit, verify and reclaim (same body, row unchanged), command conflict (409), id length and byte checks, a refused request decided again, one record per id, a 400-trial race of two cockpit processes on one database file (exactly one grant in every trial; loser codes tallied), one id sent to both processes (replay and conflict), a 40-trial race of one id on both processes (one record, same body), a write lock held for 2 s by another connection while a request with a 1 s lease waits (a claim with and without an id must get a lease still live after the grant; a heartbeat with and without an id and a submit whose lease ran out during the wait must be 409 with the row unchanged; a retry of the refused heartbeat id is 409 again and the id is not recorded), and a rollback-journal database with a held reader (the cockpit must not serve it).
tableCross-check: every relevant (operation, state, generation, attempt, expiry, artifact, verdict) combination, and 60 command id combinations (prior request or none, id shape, same or other request, task open, verified or absent), is set up in a fresh database, sent to the cockpit, and the observed outcome is compared with what task.om decides. Then 29 mutants of task.om (one rule line changed each) are compiled and must each be killed by cases or table.
migrateThe main build creates an old-schema (13 column) database with an open, a claimed and a submitted task; the build under test must migrate it to 21 columns, add forge_commands, keep the claimed lease held, turn the legacy submitted row (no artifact digest) into failed with verified_by = 'migration' so it can be claimed again, and reopen the migrated file unchanged.

Host tools on the test path

These run only in the test driver; neither ships.

  • /usr/bin/sqlite3 3.45.1 (3.45.1 2024-01-30 16:01:20 e876e51a...alt1 (64-bit)): seeds rows the API cannot create (a chosen generation, status, expiry or legacy row), dumps rows for the cross-check, holds BEGIN IMMEDIATE for the busy check, and holds a reader on a rollback-journal file for the commit check. The forge API intentionally has no call that writes arbitrary state, so a fixture writer outside it is needed.
  • /usr/bin/env (GNU coreutils 9.4): execprog starts children with an empty environment, and the cockpit needs HOME, HIVE_DB_PATH, AIEN_COCKPIT_TOKEN and AIEN_COCKPIT_ADDR. cockexec in drive.om passes them through env. This is a temporary bridge: once omega-mv#1074 (execenv) is merged and pinned, cockexec drops the env argument and passes the variables as the environment packet.

Not covered by drive.om

  • A commit that fails after a successful UPDATE ... RETURNING step inside the cockpit: the cockpit refuses the only database setup that produces it on demand (rollback journal with a held reader). The Rust unit test test_update_returning_reports_commit_failure in store.rs shows query_row losing that failure and update_returning reporting it.