Files
aji/docs/evaluation/protocol.md
T
dev 6eceb4405b E0-1: Agent Reference Bundle and Phase 2 baseline
- docs/agent/bundle.txt: minimal AIR reference by file and section
  (grammar, instructions, types, traps, verifier rules, resources,
  effects, capabilities, intrinsics, heap/regions, unsafe, runtime
  contract, diagnostics and registries); syntax-example.air verifies
  and runs
- zig build agent-reference: deterministic bundle and report (files,
  sections, bytes, lines, words); section extraction ignores fenced code
- tools/agent_bundle_tokens.py: cl100k_base, o200k_base and Qwen2.5 BPE
  counts; growth warnings >10 % and review >20 % against history.json
- baseline after Phase 2: 104 250 bytes, 16 197 words, ~27.3k tokens
- CI builds the bundle and counts tokens (non-blocking)
- evaluation protocol 0.2: benchmark families, Aji/AIR and Aji/source
  conditions, 36-run engineering smoke test, order of work
- RFC template and AGENTS.md: report bundle growth
2026-10-04 15:44:26 +03:00

1650 lines
25 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Aji Agent Language Evaluation Protocol
Version: 0.2
Status: Proposed
Changes in 0.2: T01–T10 are benchmark families (§9); Aji conditions `Aji/AIR` and `Aji/source` (§2); engineering smoke test before the pilot (§39a); stage order (§30a).
Purpose: empirical validation of the Aji language hypothesis (spec 14)
# 1. Goal
The benchmark answers five primary questions:
```text
Does Aji increase correctness?
Does Aji reduce repair work?
Does Aji allow weaker models to perform like stronger models?
Does the advantage survive maintenance and refactoring?
Does this reduce the economic cost of correct software?
```
Performance of generated binaries is measured separately.
The benchmark is not intended to show that Aji can merely implement the test programs.
---
# 2. Experimental variables
Three dimensions are varied independently.
## Language
Primary comparison:
```text
Aji
Rust
Zig
```
Secondary comparison:
```text
C
```
C is useful as a low-level baseline but is not required for every experiment.
Aji is evaluated as two separate conditions:
```text
Aji/AIR the agent writes text AIR directly
Aji/source the agent writes .aji source lowered to AIR (from Phase 6)
```
Results MUST be labelled with the condition. Comparing the two answers whether an agent needs a high-level source language at all, or whether AIR is the better agent-facing interface while `.aji` serves humans.
## Model capability
At least four capability classes:
```text
F — frontier
S — strong
M — mid
L — small/local
```
Model classes are assigned before Aji evaluation.
Parameter count alone MUST NOT determine capability class.
At least one locally runnable model SHOULD be included.
## Task
Tasks cover:
```text
memory safety
binary parsing
resource ownership
persistent storage
networking
regions
concurrency
synchronization
atomics
maintenance
```
---
# 3. Experimental unit
One experimental run is:
```text
one model
+
one language
+
one task
+
one fresh repository
+
one fresh agent context
```
Runs share no conversation state.
The model cannot inspect another run.
---
# 4. Agent environment
All languages receive equivalent facilities:
```text
repository access
editor
compiler
test runner
local language documentation
shell
benchmark runner
```
The agent may not:
```text
access hidden tests
access another language's reference implementation
modify the evaluator
access previous benchmark runs
use the public internet during the run
```
Aji receives its released Agent Reference Bundle.
Rust and Zig receive pinned local official/reference documentation appropriate to the tested version.
---
# 5. Agent scaffold
The same agent loop SHOULD be used wherever technically possible.
The scaffold controls:
```text
repository inspection
file editing
compiler execution
test execution
termination
token budget
tool-call budget
```
Language-specific instructions may explain how to invoke the toolchain but MUST NOT contain solution hints.
Scaffold tuning occurs only on the development set.
The test set is not used for scaffold tuning.
---
# 6. Repetition
Development experiments:
```text
3 runs per cell
```
Full evaluation:
```text
>= 6 independent runs per
model × language × task
```
Headline comparisons SHOULD be repeated:
```text
>= 12 runs per cell
```
when cost permits.
---
# 7. Benchmark corpus
The benchmark has three sets.
```text
dev
validation
test
```
## dev
Visible to Aji developers.
Used for:
```text
tooling development
scaffold tuning
benchmark debugging
```
## validation
Used before releases.
Tasks are visible, hidden tests are not.
## test
Private held-out corpus.
Neither task solutions nor hidden tests are used during language design.
A task is retired from the hidden set after public disclosure.
---
# 8. Task acceptance review
Every benchmark task must pass human review before entering the test set.
Reviewers verify:
- requirements are unambiguous;
- more than one valid implementation is possible;
- hidden tests test the stated requirements;
- tests do not require unspecified behavior;
- one language is not given an accidental structural advantage;
- acceptance criteria are deterministic;
- baseline solutions exist in all compared languages.
Broken tasks are removed before results are examined.
---
# 9. Benchmark families
T01–T10 below are **benchmark families**, not concrete tasks. Each family names the properties it exercises and gives an illustrative task. The private corpus contains concrete tasks that instantiate a family with different wire formats, storage models, requirements and hidden mutations (for example a family T03 task might be "A17 Segmented Journal"). The published descriptions are therefore never the evaluated tasks, which keeps this protocol public without disclosing the held-out corpus (§7, §29).
## T01 — Binary Frame Decoder
Purpose:
```text
bounds
initialization
integer handling
slices
malformed input
```
### Task
Implement a streaming decoder for this binary frame:
```text
magic u32 little-endian
version u8
flags u8
payload_len u32 little-endian
payload payload_len bytes
checksum u32
```
Requirements:
- maximum payload: 1 MiB;
- truncated input returns an error;
- invalid magic returns an error;
- unsupported version returns an error;
- payload length must never cause out-of-bounds access;
- arbitrary input must never crash or trap;
- decoder may receive a frame in arbitrary chunks;
- successful decoding must reproduce the exact payload.
Hidden evaluation:
```text
valid corpus
truncation at every byte boundary
oversized lengths
integer edge cases
100k+ generated malformed inputs
round-trip tests
```
Mutation tasks:
```text
add optional extension field
support two protocol versions
reduce allowed scratch memory
```
---
## T02 — Region-Bound Tree Processor
Requires Aji regions/heap milestone.
Purpose:
```text
Own<T>
Region
allocation budget
borrowing
lifetime
```
### Task
Read a sequence of tree-building commands and construct an in-memory tree.
Operations:
```text
NODE parent value
RESET
SUM node
DEPTH node
```
Requirements:
- nodes between RESET operations must use region storage;
- RESET releases the entire current tree;
- no reference from an old tree may survive RESET;
- memory grant: 4 MiB;
- allocation failure must be handled;
- processing continues after a reset.
Hidden evaluation:
```text
deep trees
wide trees
repeated resets
near-budget allocation
budget exhaustion
invalid parent identifiers
```
Mutations:
```text
add subtree deletion
return a computed immutable snapshot
change value from scalar to structure
```
---
## T03 — Durable Append Log
Purpose:
```text
resources
I/O
failure paths
bounded memory
recovery
```
### Task
Implement an append-only record log.
Record:
```text
sequence
length
checksum
payload
```
Requirements:
- monotonically increasing sequence;
- max payload 64 KiB;
- append;
- sync;
- reopen;
- recovery;
- torn final record must not make previous records unreadable;
- corrupted completed record must be reported;
- working memory <= 2 MiB.
Hidden evaluator injects interruption after selected write boundaries.
Mutations:
```text
add log rotation
add record type
add batch append
change checksum algorithm
```
---
## T04 — Framed TCP Relay
Purpose:
```text
network resources
partial I/O
resource closing
capabilities
protocol parsing
```
### Task
Implement a TCP service using a length-prefixed request protocol.
For every request:
```text
u32 length
payload
```
server returns:
```text
u32 length
transformed payload
```
Requirements:
- fragmented receives;
- fragmented sends;
- maximum frame size;
- clean disconnect;
- malformed client isolation;
- every listener and stream consumed exactly once.
Deterministic loopback network is used in the primary evaluation.
Mutations:
```text
add request identifier
add connection limit
add graceful shutdown
```
---
## T05 — Bounded Processing Pipeline
Requires structured concurrency.
Purpose:
```text
tasks
channels
backpressure
cancellation
linear resources
```
### Task
Create three stages:
```text
reader
↓
parser
↓
writer
```
All queues are bounded.
Requirements:
- no unbounded allocation;
- configurable queue capacity;
- downstream failure cancels upstream work;
- all tasks terminate;
- no resource leaks;
- output ordering is defined by the task specification.
Hidden evaluator varies:
```text
queue capacity
producer speed
consumer speed
failure point
cancellation point
schedule
```
Mutations:
```text
add fourth stage
change ordering requirement
add retryable failure
```
---
## T06 — Parallel Histogram
Purpose:
```text
safe parallelism
disjoint memory
structured tasks
determinism
```
### Task
Compute a 256-bin histogram over a large byte buffer using N worker tasks.
Requirements:
- N is configurable;
- input is immutable;
- mutable state may not be unsafely shared;
- result must equal sequential reference implementation;
- task completion must be structured;
- output must be identical for every scheduler interleaving.
Mutations:
```text
support u16 symbols
dynamic worker count
process data in chunks
```
---
## T07 — Concurrent Sharded KV Store
Purpose:
```text
shared mutable state
mutexes
lock ordering
resource lifetime
concurrent APIs
```
Operations:
```text
GET
PUT
DELETE
COMPARE_AND_SWAP
```
Requirements:
- configurable shard count;
- concurrent clients;
- operations on the same key behave linearly;
- no data races;
- no deadlocks in tested schedules;
- bounded memory.
Hidden evaluation includes concurrent operation histories.
Mutations:
```text
add TTL
change shard function
add snapshot
reduce memory budget
```
---
## T08 — Atomic SPSC Ring Buffer
Purpose:
```text
atomics
memory ordering
weak-memory reasoning
```
### Task
Implement a bounded single-producer/single-consumer ring buffer.
Restrictions:
```text
no mutex
no channel
fixed capacity
```
Requirements:
- no lost values;
- no duplicated values;
- FIFO ordering;
- wrap-around correctness;
- deterministic interleaving exploration must find no invalid history.
The task intentionally tests whether Aji's atomic model and verifier reduce reasoning errors.
Mutations:
```text
batch push
batch pop
64-bit sequence counters
```
MPMC is NOT part of the initial task.
---
## T09 — Mini Message Broker
Purpose:
```text
networking
tasks
bounded queues
backpressure
resource ownership
cancellation
```
Features:
```text
publish
subscribe
bounded topic queue
multiple clients
disconnect cleanup
```
Requirements:
- bounded memory;
- slow consumers create backpressure according to specification;
- disconnect cannot leak resources;
- one failed client cannot terminate unrelated clients;
- deterministic execution must be replayable.
Mutations:
```text
multiple topics
consumer groups
queue retention limit
```
---
## T10 — Mini Storage Engine
This is the final integration benchmark.
Components:
```text
TCP protocol
KV API
memtable
WAL
immutable segments
recovery
concurrent clients
```
Required operations:
```text
GET
PUT
DELETE
SYNC
```
Requirements:
- bounded memory;
- recovery after interruption;
- concurrent clients;
- deterministic test execution;
- valid resource ownership;
- no unsafe code unless explicitly permitted by the track.
Later variants add:
```text
compaction
snapshots
background maintenance
```
This task is not used until the required Aji features are stable.
---
# 10. Maintenance benchmark
Generation from scratch is insufficient.
Every core program receives modification tasks.
Primary modification categories:
## M1 — Feature addition
Add externally visible functionality without breaking previous behavior.
## M2 — API migration
Change an internal interface used by multiple modules.
## M3 — Memory constraint
Reduce allowed memory without changing observable behavior.
## M4 — Concurrency conversion
Convert sequential processing to parallel/concurrent processing.
## M5 — Capability reduction
Reduce authority granted to one component while preserving functionality.
## M6 — Fault handling
Introduce a new failure mode and ensure complete cleanup.
## M7 — Bug repair
Provide a failing public reproduction but keep regression tests hidden.
## M8 — Structural refactor
Change storage/layout/ownership representation while preserving behavior.
---
# 11. Independent vs cumulative maintenance
Two modes are measured.
## Independent
Every mutation begins from the same known-good baseline.
Measures:
```text
ability to perform one change
```
## Cumulative
Mutations are applied sequentially:
```text
v1
↓
M1
↓
M2
↓
M3
↓
...
```
Measures:
```text
architectural degradation
context growth
regression accumulation
long-term maintainability
```
---
# 12. Seeded bug benchmark
Canonical implementations receive deliberately inserted defects.
Bug classes:
```text
out-of-bounds access
use-after-move
resource leak
double close
lifetime escape
allocation budget bypass
authority misuse
missing error edge
deadlock
incorrect atomic ordering
```
The agent receives only:
```text
repository
bug report
observable failure when appropriate
```
Metrics measure whether the defect is:
```text
caught before execution
correctly diagnosed
correctly repaired
repaired without regression
```
Aji verifier-detected bugs and test-detected bugs are reported separately.
---
# 13. Primary correctness metric
A run is accepted only if all mandatory gates pass:
```text
compiler/verifier accepts
public tests pass
hidden functional tests pass
hidden regression tests pass
fuzz corpus passes
resource checks pass
required deterministic runs agree
```
For concurrency tasks:
```text
schedule exploration passes
```
For tasks with resource limits:
```text
memory/fuel limits pass
```
There is no partial success in the primary metric.
Primary result:
```text
Verified Success Rate
=
accepted runs / all runs
```
---
# 14. First-generation metric
Record the state before the first compiler-driven repair.
Metrics:
```text
first check accepted
first build accepted
first public test pass
first hidden test pass
```
This separates:
```text
generation quality
```
from:
```text
repair-loop quality
```
---
# 15. Repair metrics
For every run record:
```text
compiler/verifier invocations
failed verifier cycles
failed test cycles
number of patches
total generated tokens
total context tokens
tool calls
elapsed agent time
```
Key metric:
```text
Repair Cycles to Accepted Solution
```
---
# 16. Context efficiency
For maintenance tasks measure:
```text
repository tokens inspected
documentation tokens inspected
files opened
functions inspected
```
Aji's context hypothesis is supported if correct modifications require materially less context.
---
# 17. Economic metrics
For API models:
```text
input cost
output cost
cached-input cost
tool/model cost
```
For local models:
```text
GPU-seconds
energy if available
wall time
generated tokens
```
Primary economic measure:
```text
Expected Cost per Correct Solution
=
total cost of all runs
/
number of accepted runs
```
Failed attempts therefore contribute to cost.
This prevents cheap but unreliable models from appearing artificially inexpensive.
---
# 18. Model Capability Compression metric
Primary evidence is direct cross-tier comparison.
Example:
```text
M + Aji
versus
S + Rust
M + Aji
versus
S + Zig
```
A **one-tier compression result** occurs when the lower-tier Aji configuration is non-inferior in Verified Success Rate to the higher-tier baseline configuration.
Recommended non-inferiority margin:
```text
5 percentage points
```
Stronger evidence:
```text
M + Aji >= F + baseline
```
or:
```text
L + Aji >= S + baseline
```
---
# 19. Capability curves
For each language, fit:
```text
P(success)
=
f(model capability, task difficulty)
```
The important observation is horizontal shift.
Conceptually:
```text
success
1.0 | Aji
| /
| /
| Rust/
| / /
| Zig / /
0.0 +-----------------
model capability
```
If Aji's curve is consistently shifted toward weaker models, the Model Capability Compression hypothesis is supported.
---
# 20. Statistical analysis
Report at minimum:
```text
success proportion
95% confidence interval
median repair cycles
median cost
cost per accepted solution
```
Task-level bootstrap SHOULD be used for aggregate confidence intervals.
A mixed-effects logistic model MAY be used:
```text
success
~
language
* model
+ task-family random effect
```
No headline metric should rely on one task family.
---
# 21. Fixed-budget track
Each configuration receives the same execution envelope:
```text
maximum agent turns
maximum tool calls
maximum wall-clock duration
```
This measures engineering capability under comparable operational constraints.
---
# 22. Economic track
Each configuration instead receives the same maximum monetary or compute budget.
Example:
```text
$1
$5
$20
```
or equivalent local-compute budget.
Question:
> Which language/model pair produces the highest probability of a correct solution per unit cost?
This is the main track for testing Aji's economic hypothesis.
---
# 23. Unconstrained diagnostic track
A smaller experiment allows the agent to continue until:
```text
success
or
hard safety limit
```
This is used to understand failure modes and repair convergence.
It is not the main leaderboard.
---
# 24. Runtime performance
Correct implementations are subsequently benchmarked for:
```text
throughput
latency
peak memory
binary size
startup time
```
Runtime performance is secondary to correctness during early Aji development.
An incorrect program receives no performance score.
---
# 25. Unsafe code
Report separately:
```text
unsafe blocks
unsafe instructions
FFI boundaries
raw memory operations
```
A baseline solution using unsafe facilities is not automatically invalid, but the amount of unsafe code is recorded.
Aji tasks MAY define:
```text
unsafe forbidden
```
when testing safe-language guarantees.
---
# 26. Negative controls
Include tasks where Aji should have little structural advantage:
```text
pure arithmetic
simple transformation
straightforward sorting
small deterministic algorithms
```
If Aji appears dramatically superior on every negative-control task, investigate benchmark or scaffold bias.
---
# 27. Failure classification
Every failed run receives one primary category:
```text
SPEC_UNDERSTANDING
SYNTAX
TYPE
OWNERSHIP
BORROW
RESOURCE
BOUNDS
FUNCTIONAL
CONCURRENCY
DEADLOCK
ATOMIC_ORDERING
PERFORMANCE
BUDGET
TIMEOUT
AGENT_GAVE_UP
TOOL_FAILURE
```
For Aji additionally record:
```text
caught_by_verifier
caught_by_runtime
caught_by_test
```
This measures where reasoning was externalized.
---
# 28. Reproducibility record
Every run stores:
```text
task id/version
hidden evaluator hash
language
compiler version/commit
model exact identifier
provider
model parameters
agent scaffold commit
system prompt hash
task prompt hash
token limits
tool limits
hardware
seed
all tool calls
all patches
all compiler diagnostics
all test results
final repository
cost
```
---
# 29. Benchmark integrity
The hidden test corpus must not be committed into the public Aji repository.
Store:
```text
task spec
evaluator
reference implementation
hidden tests
```
in a separate private benchmark repository.
Published results include evaluator hashes.
When a test set is disclosed, it is retired and replaced.
---
# 30. Stage A — Phase 2 validation
Run after:
```text
heap
regions
resources
capabilities
effects
deterministic I/O
```
Tasks:
```text
T01 Binary Frame Decoder
T02 Region-Bound Tree
T03 Durable Append Log
T04 Framed TCP Relay
```
Primary hypotheses:
```text
H1 correctness
H2 repair
H4 early model compression
```
No claims about concurrency yet.
---
# 30a. Order of work
```text
E0-1 Agent Reference Bundle, baseline after Phase 2
↓
Phase 3 structured concurrency
↓
second bundle measurement
↓
private benchmark repository (in parallel, outside this repository)
↓
E0-3 harness
↓
engineering smoke test (§39a)
↓
Stage A pilot on Aji/AIR (§39)
```
The full Stage A is deliberately run after the basic Phase 3, so that early benchmark work does not start shaping the language before its concurrency model exists.
---
# 31. Stage B — Phase 3 validation
After structured concurrency:
```text
T05 Pipeline
T06 Parallel Histogram
T07 Concurrent KV
```
Add:
```text
schedule exploration
cancellation tests
deadlock analysis
```
This is the first serious test of Aji's concurrency thesis.
---
# 32. Stage C — Atomic validation
After the atomic memory model is stable:
```text
T08 SPSC Ring
```
Also run small litmus-test repair tasks.
Do not add complex lock-free reclamation until Aji has explicit support for it.
---
# 33. Stage D — Systems integration
Run:
```text
T09 Message Broker
T10 Mini Storage Engine
```
These become the primary end-to-end language benchmark.
---
# 34. Stage E — Maintenance campaign
For T03, T07, T09 and T10 run all M1–M8 mutation classes.
This stage is more important than additional greenfield examples.
A language for AI development must remain effective when an agent changes code it did not create in the current context.
---
# 35. Initial success criteria
Before running the private test set, freeze these thresholds.
## Evidence for H1
For mid and small models:
```text
Aji Verified Success Rate
>=
best Rust/Zig baseline + 15 percentage points
```
on safety-heavy tasks.
## Evidence for H2
Median repair cycles:
```text
Aji <= 70% of best baseline
```
## Evidence for H3
For successful maintenance runs:
```text
median context consumed by Aji
<= 70% of best baseline
```
## Evidence for H4
At least one lower model tier using Aji is non-inferior within 5 percentage points to the next higher model tier using Rust or Zig across the aggregate test set.
Strong evidence requires this to hold across multiple task families.
## Evidence for H5
Expected Cost per Correct Solution:
```text
Aji lower-tier model
<= 50%
```
of the higher-tier baseline model it matches in correctness.
## Evidence for H6
Aji's correctness advantage remains positive on the independent and cumulative maintenance tracks.
---
# 36. Strong confirmation criterion
The core Aji thesis is strongly supported if all are observed:
```text
Mid + Aji
>=
Strong + Rust/Zig
```
for correctness,
while:
```text
cost(Mid + Aji)
<
cost(Strong + Rust/Zig)
```
and the advantage persists on:
```text
greenfield
maintenance
concurrency
fault repair
```
tasks.
---
# 37. Falsification criteria
The hypothesis should be considered weakened if:
- Aji only helps frontier models;
- weaker models repeatedly fail to understand Aji-specific semantics;
- verifier errors cause long repair loops;
- Aji advantage disappears on maintenance tasks;
- benefits only occur on examples already present in the specification;
- correctness gains require substantially more inference cost;
- language complexity grows until the Agent Reference Bundle approaches conventional language complexity.
A negative result must be retained and reported.
---
# 38. Decision rules for language development
Benchmark failures SHOULD be classified before changing the language.
Possible causes:
```text
model limitation
documentation problem
diagnostic problem
tooling problem
language semantic complexity
missing abstraction
benchmark defect
```
A language feature should be added only when repeated failures show that the semantic model itself is responsible.
Do not add syntax or instructions merely because one model struggled with one task.
---
# 39a. Engineering smoke test
Before the pilot, a small run checks the infrastructure, not the hypothesis:
```text
2 families (e.g. binary frame decoding, append log)
× 3 languages (Aji/AIR, Rust, Zig)
× 3 model classes
× 2 runs
= 36 runs
```
It verifies that task statements are equivalent across languages, the harness works, the Agent Reference Bundle is sufficient, token and cost accounting is right, traces are stored completely and prompts carry no bias. No result of the smoke test is reported as evidence.
---
# 39. First concrete experiment
After the smoke test (§39a), run a pilot:
```text
tasks:
T01
T02
T03
T04
languages:
Aji
Zig
Rust
models:
1 frontier
1 mid
1 small/local
runs:
3 per cell
```
Total:
```text
4 × 3 × 3 × 3
=
108 runs
```
Purpose:
```text
debug benchmark
estimate effect size
identify impossible/ambiguous tasks
measure cost
validate instrumentation
```
Do not use this pilot as headline evidence.
---
# 40. First confirmatory experiment
After fixing the benchmark based only on the pilot:
```text
8 held-out tasks
3 languages
4 model classes
6 independent runs
```
Total:
```text
576 runs
```
This should be the first meaningful published Aji language evaluation.
---
# 41. Central benchmark question
The most important table produced by the project should eventually look like:
| Model class | Zig | Rust | Aji |
|---|---:|---:|---:|
| Frontier | success % | success % | success % |
| Strong | success % | success % | success % |
| Mid | success % | success % | success % |
| Small/local | success % | success % | success % |
Immediately beside it:
| Model + language | Cost / correct solution | Repair cycles | Context consumed |
|---|---:|---:|---:|
| Frontier + Rust | … | … | … |
| Mid + Aji | … | … | … |
| Small + Aji | … | … | … |
That comparison directly tests the Aji thesis.
---
# 42. Final principle
The benchmark does not ask:
> Can an AI write Aji?
It asks:
> How much model intelligence does Aji make unnecessary while preserving correctness?
That is the primary experimental question of the project.