Phase 2: hosted profile (P2-8a)

- src/interp/host.zig: real console, files (scope checked before any
  host call, positional reads/writes, append from file size) and TCP
  through std.Io; monotonic clock and host CSPRNG; host errors mapped
  to the closed io_error set; open handles released at the end of the
  instance
- interpreter dispatches intrinsics to the host or the deterministic
  world; never reports blocked in the hosted profile
- CLI: --profile hosted; the program owns stdout/stderr, the run record
  goes to --result-file, otherwise a human summary on stderr
- spec 11 §8.0: host error mapping table
- tests/hosted/smoke.py (file copy, scope denial, stdin->stdout, TCP
  echo on a free port) runs in CI
- works around Zig 0.17 net.Stream.read not compiling by using
  readWithControl
This commit is contained in:
dev committed 2026-10-04 14:46:40 +03:00
1 parent 008654999e
commit 36e91be84c
10 files changed
+530 -51

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ Non-normative. How the reference implementation is tested. Policy (what must be
| Schedule stress | via runner flags (from P3) | `zig build conformance -- --schedules=N` | randomized and systematic interleavings |
| Native parity | (from P7) | `zig build parity` | interpreter and native backend agree on the whole corpus |
Unit and conformance exist today; conformance covers accept, reject and run tests.
Unit, conformance and hosted smoke tests exist today; conformance covers accept, reject and run tests in the deterministic profile, and `tests/hosted/smoke.py` checks observable effects (files, streams, sockets) of hosted runs.
## Conformance tests
@@ -32,11 +32,11 @@ Out: tasks, threads, async I/O (P3); FFI to native code (P7).
| P2-5 | done | Capability verifier: unforgeability, narrowing, transfer rules (E3201, E3202, instantiation) | P2-1 | `src/verifier/caps.zig` | E3201, E3202 accept/reject |
| P2-6 | done | Linear resource and typestate verifier | P2-3 | `src/verifier/resource.zig` | E3001, E3002 accept/reject; leak on an error path detected |
| P2-7 | done | Unsafe boundary verifier (RFC 0009: assume, borrow.index.unchecked, trusted, unsafe report) | P2-3 | `src/verifier/unsafe.zig` | E6001 accept/reject |
| P2-8 | doing | Runtime intrinsics in the interpreter; virtual filesystem and loopback network for the `deterministic` profile | P2-2 | `src/runtime/` | intrinsic unit tests pass under both profiles; deterministic profile output identical across runs |
| P2-8 | done | Runtime intrinsics in the interpreter; virtual filesystem and loopback network for the `deterministic` profile | P2-2 | `src/runtime/` | intrinsic unit tests pass under both profiles; deterministic profile output identical across runs |
| P2-9 | doing | Entry-point capability instantiation (`--grant` done; `aji.toml` `[capabilities]` pending) | P2-5 | `src/runtime/host.zig` | missing grant fails instantiation, not execution (spec 05 §6) |
| P2-10 | todo | Reports: effect graph, capability requirements, unsafe sites | P2-4, P2-5, P2-7 | `src/report/` | deterministic JSON report; snapshot test |
| P2-11 | done | Reference programs: hello (real `io.write` if deferred from P0), file-copy, tcp-echo (single task) | P2-8 | `tests/programs/` | all three run; cleanup on every error path verified |
| P2-8a | todo | (after heap and regions, unsafe) Hosted profile: real console, files and TCP; run record through `--result-file` (spec 11 §8) | P2-8 | `src/interp/host.zig` | hello, file-copy and tcp-echo run against the real OS in CI |
| P2-8a | done | Hosted profile: real console, files and TCP; run record through `--result-file` (spec 11 §8) | P2-8 | `src/interp/host.zig` | hello, file-copy and tcp-echo run against the real OS in CI |
| P2-12 | todo | Phase exit review | all | plan status | exit criterion passes |
## Conformance tests to add
+19
View File
@@ -138,6 +138,25 @@ environment outcome: not_instantiated, limit_exceeded, blocked
**Result channel.** In the `hosted` profile the program owns stdout and stderr, so the run record cannot share them unambiguously. The machine-readable record goes to a separate channel: `aji run --profile hosted --result-file PATH` (a `--result-fd N` form may follow; `ajid` has its own control channel). Without `--result-file` the CLI may print a human-readable summary on stderr after the program ends; that summary is not a machine interface.
### 8.0 Host errors in the hosted profile
The `hosted` profile maps host failures to `io_error` (spec 06 §7) as follows; anything not listed is `other`, and no host error number is observable by the program:
| Host condition | `io_error` |
|---|---|
| file or path component not found, not a directory | `not_found` |
| access or permission denied, read-only file system | `permission_denied` |
| path already exists (exclusive creation) | `already_exists` |
| bad or too long path name, path is a directory | `invalid_input` |
| no space left, disk quota exceeded | `no_space` |
| broken pipe | `broken_pipe` |
| connection refused | `connection_refused` |
| connection reset by peer | `connection_reset` |
| address in use | `address_in_use` |
| address not available | `address_unavailable` |
Paths outside a capability's scope and malformed paths or addresses are rejected before any host call (`permission_denied`, `invalid_input`), exactly as in the `deterministic` profile. Host handles still open when the execution instance ends are released by the runtime; this is not observable by the program (spec 06 §6, invariant 2).
### 8.1 Deterministic random generator
The `deterministic` profile uses xoshiro256\*\* with SplitMix64 seeding. All arithmetic is on unsigned 64-bit integers, wrapping modulo 2^64; `rotl(x, k)` is `(x << k) | (x >> (64 − k))`.