interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / crumb-visible / CRUMB_READER_CONTRACT.md

179 lines · 8743 bytes Raw Blame History Source

Crumb Reader Contract: CRB1 visible record

Status: Stable (extracted from the running implementation; no new format features) Contract version: 1.0.0 Wire schema version: 1 (the schema_version field below) License: Community Specification License 1.0 Reference implementation: aien-sovereign-core, crates/crumbs/src/visible.rs (VisibleCrumb::from_bytes), Rust Other implementations: omega, src/crumbline/cl_crumb.c (cl_crumb_decode), C. Future: an Omega-compiled reader. Conformance corpus: vectors/ with vectors/expected.txt

1. Purpose

A crumb lesson file is the only thing a learner sees of a crumb: an ordered list of opaque INPUT -> OUTPUT examples plus the minimum structure needed to parse them. This contract states, in language-neutral terms, which byte strings are valid CRB1 records, what a reader must extract from them, and which numbered refusal a reader must return for every invalid byte string. Any reader that passes the shared corpus with zero differences may stand in for any other.

The contract is the byte format and the outcome, never a language type. No Rust enum, struct layout or serialization crosses it.

2. Reader interface

A reader is a pure function of one read-only byte buffer, given as a pointer and a length (or the language's equivalent). The caller owns the buffer; the reader borrows it for the duration of one call and keeps no reference. The reader returns exactly one of:

A reader performs no I/O, allocation visible to the caller, clock reads or randomness that can change the outcome. On refusal it exposes no partial record and no content of the input (codes are bare numbers).

3. Byte format (schema 1)

All integers are unsigned little-endian. Offsets are from the start of the buffer.

OffsetSizeFieldValid values
04magicASCII CRB1 (43 52 42 31)
42schema_version1
61encoding1 = decimal UTF-8 lanes, 2 = raw little-endian lanes
71flagsbit 0 = budget present; bits 1..7 must be 0
81in_aritylanes per input, 1..8
91out_aritylanes per output, 1..8
101in_lane_bytesencoding 1: 0; encoding 2: 1, 2, 4 or 8
111out_lane_bytessame rule as in_lane_bytes
124nnumber of examples, 1..64
16...examplesn times: u32 in_len, in_len bytes, u32 out_len, out_len bytes; each length at most 168
...16budget (only if flags bit 0)max_candidates u32, max_depth u32, max_oracle_queries u32, max_program_ops u32

The buffer ends exactly after the last example, or after the budget when present. No trailing bytes.

Lane fields. An example field holds arity lane values.

Every valid record has exactly one byte encoding, so re-encoding an accepted record reproduces the input buffer byte for byte.

4. Decoded record

On accept the reader yields: encoding, in_arity, in_lane_bytes, out_arity, out_lane_bytes, n, for each example the in_arity input lane values and out_arity output lane values as unsigned 64-bit integers, and the four budget values when flags bit 0 is set.

5. Refusal codes

Zero means accept. A refusal is a negative integer from this table, and only from this table.

CodeNameMeaning
-1MAGICfirst four bytes are not CRB1
-2VERSIONschema_version is not 1
-3SHAPEencoding, arity or lane-bytes value outside its valid set
-4LANEa lane field has the wrong length, the wrong number of decimal parts, invalid UTF-8, or a decimal value above 2^64 - 1
-5LENGTHthe buffer ends before a field it must contain, n is 0 or above 64, an example length is above 168, or bytes remain after the record
-6NONCANONICALflags has a reserved bit set, or a decimal part is not canonical (empty, a non-digit character, or a leading zero)

6. Check order (determines the code)

A reader refuses with the code of the first failing check in this order. Reading past the end of the buffer at any step is LENGTH (-5), including inside the magic.

  1. Read 4 bytes (magic). Not CRB1: MAGIC.
  2. Read u16 schema_version. Not 1: VERSION.
  3. Read u8 encoding. Not 1 or 2: SHAPE.
  4. Read u8 flags. Any bit other than bit 0 set: NONCANONICAL.
  5. Read all four of in_arity, out_arity, in_lane_bytes, out_lane_bytes, then check: arity outside 1..8: SHAPE; lane bytes invalid for the encoding: SHAPE.
  6. Read u32 n. n = 0 or n > 64: LENGTH.
  7. For each example in order: read u32 in_len (above 168: LENGTH), read in_len bytes; read u32 out_len (above 168: LENGTH), read out_len bytes. Only after both fields of this example are read, validate the input lanes, then the output lanes:
    • raw: length differs from lane_bytes * arity: LANE.
    • decimal: not valid UTF-8: LANE; number of space-separated parts differs from arity: LANE; then for each part in order: empty, contains a byte other than 0..9, or has a leading zero: NONCANONICAL; value above 2^64 - 1: LANE.
  8. If flags bit 0: read four u32 budget values.
  9. Bytes remain: LENGTH.

Note for implementers: step 7 distinguishes invalid UTF-8 (LANE) from valid UTF-8 that is not a digit (NONCANONICAL), because the reference checks UTF-8 validity before canonical form. An implementation without a UTF-8 validator must reproduce this split to conform (vectors r031 and r032).

7. Determinism rule

For the same input bytes every conforming reader, on every run, returns the same outcome: the same accept or refuse, the same refusal code, and the same decoded values. The outcome is compared through one canonical text line, which is also the corpus manifest format:

ok enc=E in=AxB out=CxD n=N[ budget=C1,C2,C3,C4] | i1 i2 -> o1 | ...
refuse CODE

A/C are in/out arity, B/D in/out lane bytes, lane values in base 10, one | ins -> outs group per example in order. The budget group appears only when flags bit 0 is set.

8. Conformance corpus

vectors/expected.txt lists every vector as <file> <outcome line>. Lines starting with # are comments. The manifest is plain text so C, shell and Omega harnesses can read it without a JSON parser.

GroupFilesSource
Family vectorsv001.crb .. v122.crbcrumbs vectors DIR (one per registered crumb family, seed 7), byte-identical to omega tests/crumbline/vectors at contract 1.0.0
Edge positivesp001.crb .. p005.crbbuilt byte by byte by tools/make-vectors.sh: budget present, decimal 0 and 2^64 - 1, raw 1/2/8-byte lanes, 64 examples
Refusalsr001.crb .. r044.crbbuilt byte by byte by tools/make-vectors.sh; each names its expected code; includes check-order cases r037..r040

Regenerate with tools/make-vectors.sh <path to crumbs binary> vectors. The script is shell only. Every expected outcome is checked by the reference reader (crates/crumbs/tests/visible_conformance.rs), so a hand-written expectation that the reference disagrees with fails CI.

A conforming harness prints one summary line:

CRUMB_VISIBLE_V1_CONFORMANCE impl=<rust|c|osc> pass=N fail=0

9. Versioning

10. Ownership switch (from the migration plan)

An implementation may replace the current one inside a consumer only after it passes 100% of this corpus with zero differences in outcome lines, and after the agreed differential fuzz shows zero disagreements against the reference. The replaced implementation stays one release as a differential reference.