Files
aji/docs/plan/README.md
T
dev 0972ed2a5e P6A-9 results and Phase 6A exit review (PASS)
- docs/evaluation/results/2026-10-05-p6a-9.md: 12 paired cells on
  p6a-candidate, criteria fixed before the runs (output-token criterion
  reported as not met), owner's assessment and hypothesis statuses
- phase 6 plan: P6A-9 and P6A-10 done, exit review; plan README: P6A done,
  P4/P5 unpaused, next held-out benchmark Rust/Zig/Aji-source with three
  difficulty levels, Aji/AIR only as a control
- checkpoint note renamed to its actual date (2026-10-05)
2026-10-05 21:37:04 +03:00

160 lines
14 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.
# Implementation Plan
Non-normative. The order in which the Zig reference implementation is built, and how work is split into tasks. The spec defines what to build; this plan defines when.
## Sequencing principles
1. **Semantics before speed.** Interpreter and verifier define the language. No native code until the conformance corpus is stable (DD-007).
2. **AIR before source.** AIR is the conformance format. The `.aji` frontend comes after the core semantics are executable.
3. **Spec gate first in every phase.** Each phase opens by resolving its open questions (`../design/open-questions.md`) and writing the instruction contracts (spec 07 §4) for the opcodes it introduces. Code that implements unspecified behavior is not merged.
4. **Tests before code.** Every verifier rule lands with an `accept`/`reject` conformance pair and a stable diagnostic code.
5. **Exit criteria are executable.** A phase is done when its exit criterion passes in `zig build conformance`, not when its tasks are ticked.
6. **One task, one change.** A task is sized for one agent session and one reviewable change.
## Milestones
| Milestone | Phases | Result |
|---|---|---|
| M1 — Verified core | P0, P1, P2 | Single-threaded Aji: ownership, regions, effects, capabilities and resources verified; file-copy and TCP echo run in the interpreter |
| M2 — Concurrent Aji | P3, P4, P5 | Structured tasks, channels, locks, islands and atomics with deterministic and randomized scheduling |
| M3 — Source language | P6 | All reference programs written as `.aji` |
| M4 — Native | P7 | LLVM backend; interpreter and native agree on the whole corpus |
| M5 — Agent-ready | P8 | `ajid` protocol and benchmark; candidate for Aji 0.1 |
## Phases
| Phase | File | Goal | Exit criterion | Blocking questions |
|---|---|---|---|---|
| P0 | [phase-0-semantic-skeleton.md](phase-0-semantic-skeleton.md) | AIR model, text parser, CFG/SSA/type verifier, interpreter | AIR `hello` and arithmetic tests execute identically across runs | resolved except Q-016 (floats reserved) |
| P1 | [phase-1-ownership-and-memory.md](phase-1-ownership-and-memory.md) | Frame storage, second-class borrows, arrays/slices, init tracking, bounds (RFC 0005) | file-copy core on a local buffer; alias/dangling/escape/uninit/OOB rejected | resolved (Q-009, Q-010) |
| P2 | [phase-2-effects-capabilities-resources.md](phase-2-effects-capabilities-resources.md) | Effects, capabilities, heap (`Own`), regions, linear resources, runtime intrinsics | safe file-copy and basic TCP echo | Q-011, Q-012, Q-018 |
| P3 | [phase-3-structured-concurrency.md](phase-3-structured-concurrency.md) | Task scopes, Send/Share, channels, mutex, cancellation, deterministic scheduler | parallel-map and channel ownership-transfer examples | Q-013, Q-014 |
| P4 | [phase-4-islands.md](phase-4-islands.md) | Islands, `iref`, transfer, freeze, `Frozen`, `Arc` | cyclic graph moves between tasks with no deep copy and no shared mutation | — |
| P5 | [phase-5-atomics-and-memory-model.md](phase-5-atomics-and-memory-model.md) | Atomics, orderings, fences, weak-memory interpreter, schedule exploration, replay | atomic publication litmus/conformance tests | Q-015, Q-017 |
| P6 | [phase-6-source-language.md](phase-6-source-language.md) | `.aji` parser, lowering, generics, contracts, formatter | all reference programs authored primarily as `.aji` | — |
| P7 | [phase-7-native-backend.md](phase-7-native-backend.md) | LLVM lowering, native runtime, three targets, ABI tests | interpreted and native executions pass the same corpus | — |
| P8 | [phase-8-agent-protocol.md](phase-8-agent-protocol.md) | `ajid`, inspect/trace, verification report; benchmark harness per the evaluation protocol | external agent implements/repairs a reference task using only protocol + spec | — |
## Dependency graph
```text
P0 ──► P1 ──► P2 ──► P3 ──► P4
│ │
└──────┴──► P5 ──► P6 ──► P7 ──► P8
```
Allowed overlap:
- spec-gate tasks of a later phase may start any time;
- P6 grammar work (P6-1) may start after P2, since syntax does not affect AIR semantics;
- P8 protocol design (P8-1) may start after P2; `ajid` wraps `check.zig`, which exists from P0.
## Error code coverage
Every registry code (`../reference/error-codes.md`) has a phase that must implement it with an accept/reject pair.
| Code | Phase | | Code | Phase |
|---|---|---|---|---|
| E1001 type.mismatch | P0 | | E3101 effect.undeclared | P2 |
| E1002 type.invalid_cast | P0 | | E3201 capability.missing | P2 |
| E1010 init.read_uninitialized | P1 | | E3202 capability.widen | P2 |
| E2001 ownership.use_after_move | P2 | | E4001 concurrency.not_send | P3 |
| E2002 ownership.double_consume | P2 | | E4002 concurrency.not_share | P3 |
| E2101 borrow.mutable_alias | P1 | | E4101 concurrency.possible_data_race | P3 |
| E2102 borrow.outlives_owner | P1 | | E4201 atomic.invalid_order | P5 |
| E2103 memory.out_of_bounds | P1 | | E4301 task.live_child_escape | P3 |
| E2104 memory.region_generation | P2 | | E4302 task.borrow_escape | P3 |
| E2110 island.escape | P4 | | E4303 io.buffer_in_flight | P7 (reserved) |
| E2111 island.foreign_mutable_edge | P4 | | E5001 air.invalid_ssa | P0 |
| E3001 resource.use_after_consume | P2 | | E5002 air.invalid_cfg | P0 |
| E3002 resource.leak | P2 | | E5101 verifier.resource_limit | P0 |
| E6001 unsafe.required | P2 | | E6101 abi.unaligned_reference | P7 |
| E2105 borrow.not_ended | P1 | | E2106 borrow.use_after_end | P1 |
| E2107 borrow.not_owned | P1 | | E2108 borrow.escapes_frame | P1 |
| E0001–E0006, E1003 | P0 | | T0001–T0007 P0, T0008 | P1 |
## Cross-cutting tracks
These run through all phases rather than belonging to one.
| Track | Rule |
|---|---|
| Spec | Each phase's first tasks update `../spec/` and the open-questions log. RFCs are proposed for acceptance in the phase that implements them (0001 in P1, 0002 in P3, 0003 in P5; 0004 was accepted after P0); acceptance integrates their rules into the spec in the same change. New constructs extend format 0 only under spec 07 §8.7. |
| Diagnostics | New codes are added to `../reference/error-codes.md` and `src/diag.zig` together; structured fields per code are documented in the spec section that defines the rule. |
| Determinism | Every run test is executed twice and compared from P0-12 on; concurrency tests add schedule stress from P3. |
| Audit reports | Each phase that adds an auditable fact (unsafe sites, effects, capabilities, weak atomics, eliminated checks) extends the report in `src/report/` (spec 10 §6, spec 13 §5). |
| Features | Every phase from P1 publishes its feature bundles (`../reference/air-features.md`) when their semantics are specified, and adds them to `supported` when implemented. `aji features` is the discovery interface for agents. |
| Packages | Minimal `aji.toml` reading for capabilities in P2; dependencies, lockfile and sandboxed build extensions in P8 (spec 12). |
## Evaluation track (spec 14, `../evaluation/protocol.md`)
Evaluation runs alongside the phases; each stage starts when the language features it needs are implemented.
| ID | Status | Task | Depends | Done when |
|---|---|---|---|---|
| E0-1 | done | Define the Agent Reference Bundle (spec 14 §3.7) and a deterministic size measurement (bytes and tokens) recorded per release | — | `docs/agent/bundle.txt`, `zig build agent-reference`, `tools/agent_bundle_tokens.py`; Phase 2 baseline recorded; measured in CI |
| E0-2 | todo | (owner, outside this repository and outside the language developer's conversation) Private benchmark repository: a benchmark-authoring agent in a clean context designs the two smoke tasks from the brief in `docs/evaluation/benchmark-authoring.md`; later T01–T04; dev/validation/test split | — | evaluator hashes published; nothing hidden in this repository |
| E0-3 | done | Language-neutral agent scaffold and run recorder (protocol §5, §28) | — | `tools/eval/`, `docs/evaluation/harness.md`; one loop drives Aji, Rust and Zig (self-tests on `dev-echo`); every run record complete |
| E0-4 | todo | Rust and Zig baseline solutions and pinned local documentation | E0-2 | baselines pass the hidden tests |
| E-C | todo | Model calibration: models labelled M1–M3 run 5–10 neutral coding tasks unrelated to Aji in `tools/eval`; classes assigned from scores; live `dev-echo` per model (protocol §2, §39a) | E0-3 | calibration report; model IDs, endpoints and reasoning modes frozen |
| E-G | todo | Gate before E-N (and later E-S): private tasks reviewed; evaluator, task and evaluator hashes frozen; Rust, Zig and Aji/AIR references written by separate clean agents pass; Aji commit, bundle, toolchains and docs frozen with `ajieval freeze` (checklist in `docs/evaluation/benchmark-authoring.md`) | E0-2, E0-4 | all gates pass |
| E-S | todo | Engineering smoke test, Track A: 2 families (binary/stream parser, concurrent bounded pipeline) × 3 languages × 3 models (M1–M3) × 2 runs = 36 runs on one Aji commit (protocol §39a); plan shape `docs/evaluation/smoke-plan.example.json`; failures classified by cause after the matrix, before any language change | E-C, E-G | harness, bundle sufficiency, accounting and traces verified |
| E-N0 | done | Native dev-echo gate (Aji/AIR): Codex + `gpt-6.1-sol` (effort high), Claude Code + `claude-opus-5-5` (effort high), OpenCode + `zai-coding-plan/glm-5.3-flash` all accepted; networkless shell for all three verified by `dev-netprobe`; context metrics (provider / cumulative / unique reference) | E0-3 | `ajieval native`, `ajieval freeze`, `ajieval journal` |
| E-N | done | Track B native smoke (2026-10-05): 18 runs, 17 accepted; Codex and Claude Code 12/12 (ceiling), OpenCode/GLM Rust 2/2, Zig 2/2, Aji/AIR 1/2 (one BUDGET failure). No compression signal at this difficulty; Aji/AIR costs more time, tool calls and uncached input for every agent (fixed bundle reading ≈30–36k unique tokens per run; Rust runs read no docs). Infrastructure goals met. Not evidence (protocol §39a/§39b) | E-N0, E0-2, E-G | `docs/evaluation/results/2026-10-05-native-smoke.md` (tasks under aliases); analysis per §38 done |
| E-A | todo | Stage A pilot (condition `Aji/AIR`): T01–T04 families × Aji/Rust/Zig × 3 model classes × 3 runs = 108 runs (protocol §39); not headline evidence | E-S, basic Phase 3 | pilot report: effect size, broken tasks, cost, instrumentation |
| E-B | todo | Stage B: T05–T07 | Phase 3 | stage report |
| E-C | todo | Stage C: T08, litmus repair | Phase 5 | stage report |
| E-D | todo | Stage D: T09, T10 | Phases 3–5, stable features | stage report |
| E-E | todo | Stage E: maintenance campaign M1–M8 | E-D | stage report |
| E-1 | todo | First confirmatory experiment: 8 held-out tasks × 3 languages × 4 model classes × 6 runs = 576 runs (protocol §40); thresholds frozen beforehand (§35) | E-A fixes | published evaluation |
Until Phase 6 delivers the source language, Aji runs use the condition `Aji/AIR`; after Phase 6, `Aji/source` is evaluated as a separate condition.
**Roadmap after the native smoke (owner decision, 2026-10-05).** The smoke showed that agents pay mostly for writing compiler IR by hand, not for Aji's semantics:
- SSA and CFG errors dominated;
- AIR is about 3× the size of Rust;
- the ~33k-token bundle is read in full.
Phase 6 therefore comes forward as **Phase 6A**: a minimal `.aji` frontend over the frozen semantics of Phases 0–3, lowering to the same AIR that the same verifier checks. Phases 4 and 5 are paused. The order is:
1. Phase 6A: `.aji` frontend for all of Phases 0–3 (RFC 0013).
2. In parallel, generic improvements without semantic change: an Agent Quick Reference (5–8k tokens) with an index into the full reference; repair-oriented diagnostics (`E0006` canonical header, done).
3. Engineering regression on the old tasks M and C, which are dev material now: `Aji/AIR` vs `Aji/source`. Measure source size, output tokens, tool calls and bundle use. **Done** (P6A-9): IR-form diagnostics 9 → 0, VSR 4/6 → 5/6, cost model-dependent.
4. A new private held-out benchmark (clean-context author), harder by the number of interacting invariants (resource ownership + cancellation + bounded memory + several tasks + failure paths + changing existing code), not by size.
5. Native and controlled runs over the conditions `Rust`, `Zig` and `Aji/source` on Codex, Claude Code and GLM, with a weaker model added if needed; `Aji/AIR` only as a research control (owner decision after P6A-9). `Rust/Zig → Aji/source` measures the effect of the semantics, the verifier and the language.
- Tasks at three levels:
- easy: a ceiling for strong models;
- medium: near the weaker model's limit;
- hard: beyond it.
- H4 is expected on medium tasks where a weaker model understands the task and starts implementing, but fails on memory, resources or concurrency. In P6A-9, task C was hard for GLM: it failed before writing code in both conditions.
Targets for Phase 6A, measured on dev tasks:
| Quantity | Target |
|---|---|
| source size | ≤ 1.5× Rust |
| agent output tokens | ≤ 2× Rust |
| SSA/CFG diagnostics written by the agent | effectively 0 |
| feature-header diagnostics | 0 (the frontend infers the feature closure) |
| safety guarantees | unchanged, because the same AIR is verified | Every Phase 3+ semantic RFC re-measures the Agent Reference Bundle (`docs/agent/README.md`).
## Task conventions
- IDs are `P<phase>-<n>` and never reused. A task split later becomes `P1-4a`, `P1-4b`.
- Status lives in the phase file's task table: `todo`, `doing`, `done`, `dropped`. Update it in the same change that completes the task.
- `Done when` is the acceptance test. If it cannot be checked mechanically, rewrite it.
- Discovered work goes into the current phase file as a new task, or into `../design/open-questions.md` if it is a spec gap.
## Status
| Phase | Status |
|---|---|
| P0 | done; AIR format 0 frozen as the semantic baseline (spec 07 §8.7) |
| P1 | done (exit review in the phase file) |
| P2 | done (exit review in the phase file) |
| P3 | done (exit review in the phase file); P3-10, P3-11 moved to P7 |
| P6A | done (exit review in `phase-6-source-language.md`; P6A-9 [results](../evaluation/results/2026-10-05-p6a-9.md)): the agent-facing source language over AIR is the architecture |
| P4, P5 | unpaused after P6A (owner decision, 2026-10-05) |
| P7, P8 | not started |