spec: bit-exact PRNG, canonical run record, global quiescence

Owner review of the RFC 0007 implementation:
- spec 11 §8.1: xoshiro256** with SplitMix64 seeding specified bit for
  bit, fill consumes ceil(n/8) outputs LSB first; golden vector; own
  implementation replaces std.Random (whose seeding differs)
- spec 07a: canonical run record; stdout/stderr as UTF-8 strings or
  base64 objects, files always base64 objects
- spec 11 §8: blocked only at global quiescence (no runnable unit, no
  known future event, unfinished execution)
- reserved feature resource_joins; test names are permanent and
  rule-descriptive (renamed resource_*/borrow_* tests)
- plan: remaining Phase 2 order heap/regions -> unsafe -> hosted ->
  reports -> aji.toml
This commit is contained in:
dev committed 2026-10-04 14:07:54 +03:00
1 parent d405d4ea50
commit 7a74be3cf7
18 files changed
+203 -38

No files matched your search

+1 -1
View File
@@ -107,7 +107,7 @@ The resource state of each resource value — `owned`, `consumed by close`, `con
| Rule | Code |
|---|---|
| owned resource live at `ret` (other than the returned one) | `E3002` (`resource.leak`) |
| resource state differs between edges into a block | `E3002` |
| resource state differs between edges into a block | `E3002` (joins with differing states are reserved for the feature `resource_joins`) |
| resource consumed again after any consumption | `E2002` (`ownership.double_consume`) |
| non-consuming use after consumption by a closing intrinsic | `E3001` (`resource.use_after_consume`) |
| non-consuming use after consumption by transfer | `E2001` (`ownership.use_after_move`) |
+8 -1
View File
@@ -242,4 +242,11 @@ Resource types and their consumption rules: spec 06 §6. Resources are used thro
On a trap it reports `{"status":"trapped", "code":…, "kind":…, "function":…, "block":…, "inst":…}` (spec 01 §6).
Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (captured output) and `"files"` (files written in the virtual file system, keyed by path in byte order) in the record of the `deterministic` profile (spec 11 §8). These byte strings are written as JSON strings in which printable ASCII other than `"` and `\` appears as is, `"`, `\` and newline are escaped as `\"`, `\\` and `\n`, and every other byte `b` as `\u00XX`, so any output is valid, deterministic JSON. When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (captured output) and `"files"` (files written in the virtual file system, keyed by path in byte order) in the record of the `deterministic` profile (spec 11 §8).
**Canonical record.** The run record is canonical JSON: UTF-8, no whitespace, fields in the order this section lists them, integers in decimal, no locale dependence. Strings escape `"` as `\"`, `\` as `\\`, the control characters U+0008, U+0009, U+000A, U+000C, U+000D as `\b`, `\t`, `\n`, `\f`, `\r`, and other characters below U+0020 as `\u00xx` (lowercase hex); everything else, including non-ASCII, is written as its UTF-8 bytes. Byte data is encoded unambiguously:
- `stdout`, `stderr`: a JSON string if the bytes are valid UTF-8, otherwise `{"encoding":"base64","data":"…"}`;
- every entry of `files`: always `{"encoding":"base64","data":"…"}`, since file contents are arbitrary bytes.
Base64 is RFC 4648 with padding. Two records are equal exactly when their bytes are equal. When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
+29 -2
View File
@@ -115,9 +115,15 @@ The run record gains fields for observable output. `aji run` uses the **determin
| files | in-memory file system seeded by `--vfs PATH=TEXT`; files written during the run are reported as `"files"` in the run record | real file system, limited by capability scopes |
| network | in-process loopback: `net.connect` to a listening address of the same run queues a connection that `net.accept` returns; sends are buffered; an operation that would wait for an event that can never occur ends the run with the environment outcome `blocked` (below) | real sockets |
| clock | the number of instructions executed so far (1 ns per instruction) | real monotonic clock |
| random | xoshiro256\*\* whose state is initialized by SplitMix64 from `--seed N` (default 0); bytes are taken from successive 64-bit outputs, least significant byte first | host CSPRNG |
| random | the generator of §8.1, seeded by `--seed N` (default 0) | host CSPRNG |
**Quiescence.** In the `deterministic` profile, when an operation would wait, no other execution unit can run, and no future deterministic event can complete the wait, the run ends with the environment outcome
**Quiescence.** `blocked` is a property of the whole execution, never of one operation. In the `deterministic` profile the run ends as `blocked` exactly when all of the following hold at once:
- the execution is unfinished (some execution unit has neither returned nor trapped);
- no execution unit is runnable;
- the runtime knows no future deterministic event (a pending connection, buffered data, an expiring timer, a completing I/O operation, …) that could make one runnable.
An operation that cannot continue now only suspends its execution unit; while another unit is runnable or a future event is known, the run continues. In Phase 2 there is a single execution unit and no timers, so a wait that nothing can satisfy is immediately global quiescence; Phase 3 extends the set of units and event sources without changing this definition. The run then ends with the environment outcome
```json
{"status":"blocked","kind":"no_future_event","function":"…","block":"…","inst":0}
@@ -131,3 +137,24 @@ 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.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))`.
Seeding from `seed`: let `x = seed`; four times, `x = x + 0x9e3779b97f4a7c15`, `z = x`, `z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9`, `z = (z ^ (z >> 27)) * 0x94d049bb133111eb`, output `z ^ (z >> 31)`. The four outputs are the state `s[0]`, `s[1]`, `s[2]`, `s[3]` in that order.
Next output: `result = rotl(s[1] * 5, 7) * 9`; `t = s[1] << 17`; `s[2] ^= s[0]`; `s[3] ^= s[1]`; `s[1] ^= s[2]`; `s[0] ^= s[3]`; `s[2] ^= t`; `s[3] = rotl(s[3], 45)`; return `result`.
`random.fill` of `n` bytes consumes `ceil(n / 8)` outputs in order and writes each output's bytes least significant first; the unused bytes of the last output are discarded, so every call starts at a fresh output. The generator state is shared by all `random.read` capabilities of the run.
Golden vector, `seed = 0`, successive calls of 1, 7, 8 and 17 bytes:
```text
1: b4
7: 2a 45 56 49 78 1f 6e
8: e0 e6 33 49 9d 84 5f 1a
17: 2c 2d 2d 26 f1 94 a5 6a 59 2e 84 1f 4a ad a5 bb ca
```
A conforming implementation MUST produce exactly these bytes.