interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / forge / README.md

246 lines · 16696 bytes Raw Blame History Rendered
1# INTERPLANE Forge v1: `forge`
2
3The merge decision of INTERPLANE Forge and the gate runner that feeds it, in seeded Omega
4(`forge.om`). Spec: `docs/FORGE.md`. Host dependencies: `DEPENDENCIES.md`.
5
6Agents express intent. The forge retains authority. An agent proposes a patch, an independent
7reviewer writes a verdict for one exact head, `forge gate` runs the gate and its negative control in
8fresh clones of that head and writes a receipt. `forge decide` is the only step that turns those
9three objects into MERGE, and it says HOLD for anything it cannot prove.
10
11## Build and test
12
13```sh
14OMC=~/work/flux/omega-mv/seed/out/omc # omega-mv f4df8239, sha256 3ad9f10f…3194
15"$OMC" < forge/forge.om > /tmp/forge && chmod +x /tmp/forge
16OMC="$OMC" sh forge/tests/run.sh # every check, then every mutant; exit 0 only when all pass
17```
18
19`run.sh` refuses any omc whose sha256 is not the pin (prints `NOT_RUN`, exit 3). It needs `git` for
20the gate fixture.
21
22## Commands
23
24```
25forge decide [--json] <patch-head> <verdict-file> <gate-receipt>
26forge status <RID> [reviews-dir [receipts-dir]]
27forge gate <RID> <head> [--name N] [--out DIR] [--timeout S] --author A --neg ARGV.. -- ARGV..
28```
29
30Any other subcommand prints the usage on stderr and exits 2.
31
32### `forge decide`
33
34Prints exactly one line, `MERGE OK` (exit 0) or `HOLD <CODE>` (exit 1). With `--json` (first
35argument after `decide`) it prints exactly one line holding one JSON object instead, with the same
36exit codes:
37
38```
39{"schema":"forge-decision/1","head":"<40 lowercase hex>","decision":"MERGE","reason":"OK"}
40{"schema":"forge-decision/1","head":"<40 lowercase hex>","decision":"HOLD","reason":"<CODE>"}
41{"schema":"forge-decision/1","head":null,"decision":"HOLD","reason":"USAGE"}
42```
43
44The keys always appear in that order with no spaces. `head` is the patch head argument when it is
4540 lowercase hex and the argument count is right, else `null` (`USAGE`, `BAD_HEAD`). `reason` is
46one of the codes in the table below.
47
48### `forge status`
49
50Runs `rad patch list --all --repo <RID>` and `rad patch show <id> --repo <RID>` for every patch and
51prints one line per patch, then a summary:
52
53```
54patch <id7> status=<rad status> head=<40 hex> verdict=<file|none> receipt=<file|ambiguous|none> decision=<MERGE OK|HOLD <CODE>|NOT_RUN no verdict file>
55forge status <RID> patches=N decided=K merge=A hold=B not_run=C
56```
57
58For each patch head H, the verdict is the one file in `reviews-dir` named `*-<first 8 hex of H>.verdict.txt`
59(two or more such files give `HOLD VERDICT_AMBIGUOUS`), and the receipt is the one file in
60`receipts-dir` named `*-<first 8 hex of H>.receipt.txt`, the name `forge gate` writes (two or more
61give `receipt=ambiguous` and `HOLD RECEIPT_AMBIGUOUS`; none gives `receipt=none` and
62`HOLD RECEIPT_UNREADABLE`). Defaults: `$HOME/handoffs/hive/manager/reviews` and
63`$HOME/handoffs/hive/forge/receipts`. Names are followed through symlinks. `status` is a report and
64exits 0 when rad ran; a rad failure prints `forge: rad failed, exit N` and exits 2. It decides at
65most the first 512 listed patches: when rad lists more, it prints the summary for those, then
66`TRUNCATED patches=N examined=512`, and exits 2. It never merges or writes anything.
67
68### `forge gate`
69
70```sh
71forge gate rad:z6do9WDBhuSnvopDkgFdFr1yWA62 215ea39afdc0cf1914cfadf43bbb6d23ce68c920 \
72 --author "t_04379749" --out ~/handoffs/hive/forge/receipts \
73 --neg <command that must fail> -- <the repository's gate command>
74```
75
761. Checks the arguments: `RID` is `rad:` and 1 to 60 ASCII letters and digits; `head` is 40
77 lowercase hex; `--author` (required) is 1 to 256 bytes with a printable ASCII byte and no
78 control byte; `--name` is 1 to 100 bytes of `A-Z a-z 0-9 . _ -` not starting with `.`; each
79 option at most once; `--timeout` is 1 to 5 decimal digits giving 1 to 86400 seconds (default
80 1800); both commands are 1 to 40 arguments, at most 1024 bytes joined, no CR or LF, and a first
81 argument that is not empty, does not start with `-` and holds no `=`.
822. Reads `HOME` (required), `PATH` (default `/usr/local/bin:/usr/bin:/bin`), `OMC` and `RAD_HOME`.
83 The storage is `$RAD_HOME/storage/<RID without rad:>`, else `$HOME/.radicle/storage/…`. When
84 `OMC` is set, its file's SHA-256 is recorded as `omc=` (an unreadable `OMC` is an error); unset,
85 `omc=none`. The name is `--name`, else the `name` of `rad inspect <RID> --payload`.
863. Makes `/tmp/forge-gate-<pid>-<16 random hex>` (mode 0700) and, twice, a fresh clone of exactly
87 `head` from the storage (`git init`, `fetch --no-tags`, `checkout --detach`), with git's system
88 and global config off. Each clone's `HEAD` must equal `head`.
894. Runs the gate command in one clone and the negative control in the other, each through
90 `/usr/bin/env` with only `HOME`, `PATH` and (when set) `OMC` in the environment, stdin
91 `/dev/null`, stdout and stderr to `<name>-<head8>.gate.log` / `<name>-<head8>.negctl.log` in the
92 out dir. An exit code is the command's status, or 128 + the signal number when it was killed.
93 Each command runs in its own process group (the child calls `setpgid(0, 0)` before `chdir`, and
94 forge sets the same group from the parent, so there is no race) with its own timeout of
95 `--timeout` seconds (default 1800), measured on the monotonic clock and polled every 100 ms.
96 A command still running at its timeout is killed with its whole process group (`SIGKILL` to
97 `-pid`) and by its pid (so a direct child that moved to another group is killed too), reaped
98 (forge stops waiting for the reap 10 s after the kill, so forge itself stays bounded), its exit
99 code recorded as **124**, and the line
100 `forge: timeout after S s, process group killed with SIGKILL, exit status recorded as 124`
101 appended to its log, so the log hash covers it; the receipt and logs are then written as usual,
102 and `decide` gives `HOLD GATE_TIMEOUT`. Limits: a grandchild that leaves the group (`setsid`,
103 `setpgid`) escapes the kill; a direct child stuck in uninterruptible sleep is not reaped by forge
104 (it is left to init after the 10 s reap deadline, and could still finish a write it was in);
105 a command that exits 124 by itself is indistinguishable from a
106 timeout and also holds as `GATE_TIMEOUT` (fail closed: both are HOLD); background processes a
107 command leaves running after it exits are not killed.
1085. Hashes both logs (SHA-256, first-party Omega) and creates the out files: the logs, then the
109 receipt `<name>-<head8>.receipt.txt`, then removes the temp dir. The command logs live in the
110 0700 temp dir (`gate.log`, `negctl.log`), created with `O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|
111 O_CLOEXEC` (557249) and opened a second time read-only (557056), both fds checked to be the same
112 file. The commands write through the first fd (duplicated to stdout and stderr, never reopened
113 by name); forge hashes and copies through the second, so a log renamed or swapped while a gate
114 runs changes neither the out log nor `log_sha256`. Out files are created only at the end, with
115 the same `O_EXCL|O_NOFOLLOW` flags: forge never replaces or follows an out file. A name already
116 taken (file or symlink) is refused before the gate runs; one that appears during the run makes
117 the run exit 2, and the out files it had created are removed, so a refused run leaves no file.
118 The out dir must exist and be writable (checked first).
119 The flag values are aarch64 Linux, the only target the pinned omc emits; `tests/run.sh`
120 reports NOT_RUN (exit 3) on any other machine, and x86 is not supported.
121
122It prints `forge gate <RID> head=<head> gate_rc=N negctl_rc=M receipt=<path>` and exits **0** when
123`gate_rc` is 0 and `negctl_rc` is neither 0 nor 124, **1** when the receipt records anything else (`decide`
124would HOLD), **2** on an error, with a message on stderr and no receipt: bad arguments (including a
125bad `--timeout`), unknown head, clone failure, unreadable `OMC`, no `HOME`, or an out directory that does not exist or cannot be
126written. The out directory defaults to `$HOME/handoffs/hive/forge/receipts`; the forge never creates
127directories. `gate` decides nothing: the receipt is evidence for `forge decide`.
128
129## Verdict file (the desk format, read as is)
130
131- Line 1 is exactly `VERDICT <KIND> head=<40 lowercase hex>`, with `KIND` one of `MERGE`,
132 `MERGE_AFTER_FIX`, `REJECT`, ended by a newline or the end of the file. Anything else (uppercase
133 hex, a short head, CRLF, a trailing byte, a trailing space, a second word such as
134 `VERDICT MERGE head=<sha> REJECT`, lowercase `verdict`) is `VERDICT_MALFORMED`.
135- No later line may start with `VERDICT` (`VERDICT_MALFORMED`): a file holds one verdict.
136- At most one line starting `reviewer=` (two are `VERDICT_MALFORMED`). A value with a control byte
137 (below 32 other than tab, or 127; NUL included) is `VERDICT_MALFORMED`. No such line, or a value
138 without a printable ASCII byte (33..126), so empty or only spaces and tabs, is `NO_REVIEWER`.
139- Other lines are free text. Files of 65536 bytes or more are `VERDICT_UNREADABLE`.
140
141## Gate receipt, `forge-receipt v1` (format defined here)
142
143`forge gate` writes every key, in this order:
144
145```
146FORGE-RECEIPT v1
147rid=<rad: and 1 to 60 ASCII letters and digits>
148clone=<40 lowercase hex: HEAD of the fresh clone the gate ran in>
149tree=<40 lowercase hex: that clone's HEAD^{tree}>
150omc=<64 lowercase hex: SHA-256 of $OMC, or none>
151gate_cmd=<free text: the gate arguments joined with single spaces (not shell-quoted)>
152gate_rc=<0..255: exit status of the gate; 124 when forge killed it at the timeout>
153negctl_cmd=<free text: the negative-control arguments, joined the same way>
154negctl_rc=<0..255: exit status of the negative control; 124 when forge killed it at the timeout>
155author=<the patch author: a printable ASCII byte (33..126), no control byte>
156started=<YYYY-MM-DDTHH:MM:SSZ, UTC, after both clones, just before the gate runs>
157finished=<YYYY-MM-DDTHH:MM:SSZ, UTC, after both runs>
158log_sha256=<64 lowercase hex: SHA-256 of the gate log>
159negctl_log_sha256=<64 lowercase hex: SHA-256 of the negative-control log>
160```
161
162`decide` requires only `clone`, `gate_rc` and `author` (and `negctl_rc`, else `NO_NEGCTL`); the
163other keys are optional, so receipts written by hand in the v0 key set stay valid. Line 1 is
164exactly `FORGE-RECEIPT v1`. Every other line is `key=value` with a key from the list, in any order,
165each at most once, no empty lines (the final newline is optional); exit codes are 1 to 3 decimal
166digits. An unknown key, a duplicate, an empty line, a missing required key, a value that is not of
167its form (including uppercase hex or a hash of the wrong length) or a number above 255 is
168`RECEIPT_MALFORMED`. Times are checked as a digit pattern, not as a calendar date. Files of 4096
169bytes or more, and missing files, are `RECEIPT_UNREADABLE`. `decide` does not compare `rid`, `tree`,
170`omc` or the log hashes with anything; they let a reader check a receipt against the repository,
171the compiler and the logs.
172
173## Decision and reason codes
174
175Checks run in this order; the first that fails is the reason.
176
177| Exit | Line | Meaning |
178|---|---|---|
179| 0 | `MERGE OK` | every check below passed |
180| 1 | `HOLD USAGE` | `decide` without exactly three arguments (after `--json`) |
181| 1 | `HOLD BAD_HEAD` | the patch head is not 40 lowercase hex |
182| 1 | `HOLD VERDICT_UNREADABLE` | verdict file missing, empty or too large |
183| 1 | `HOLD VERDICT_MALFORMED` | verdict file breaks the format above |
184| 1 | `HOLD VERDICT_MERGE_AFTER_FIX` | the reviewer asked for fixes; only `MERGE` merges |
185| 1 | `HOLD VERDICT_REJECT` | the reviewer rejected the patch |
186| 1 | `HOLD HEAD_MISMATCH` | verdict head is not the patch head (all 40 hex compared) |
187| 1 | `HOLD NO_REVIEWER` | no `reviewer=` line, or one without a printable ASCII byte |
188| 1 | `HOLD RECEIPT_AMBIGUOUS` | `status` only: more than one receipt file for the head |
189| 1 | `HOLD RECEIPT_UNREADABLE` | receipt missing, empty or too large |
190| 1 | `HOLD RECEIPT_MALFORMED` | receipt breaks the format above |
191| 1 | `HOLD NO_NEGCTL` | the receipt has no negative control |
192| 1 | `HOLD CLONE_MISMATCH` | the gate ran on another head than the patch head |
193| 1 | `HOLD GATE_TIMEOUT` | `gate_rc` or `negctl_rc` is 124: a run was killed at the `forge gate` timeout, so its evidence is incomplete (checked before its result) |
194| 1 | `HOLD GATE_FAIL` | `gate_rc` is not 0 |
195| 1 | `HOLD NEGCTL_PASSED` | `negctl_rc` is 0: the control did not fail, so the gate proves nothing |
196| 1 | `HOLD SELF_REVIEW` | the normalized reviewer text contains the normalized receipt author |
197| 1 | `HOLD VERDICT_AMBIGUOUS` | `status` only: more than one verdict file for the head |
198
199**Self-review normalization.** Both the reviewer value and the author are folded to ASCII lower
200case; tab, `_` and `-` count as spaces and every run of them becomes one space; then ASCII
201punctuation (`!"#$%&'()*+,./:;<=>?@[\]^`{|}~`) and spaces are stripped from both ends. The
202reviewer text is then searched for the author as a substring. `Manager reviewer agent` as author
203matches `reviewer= MANAGER reviewer agent (relayed)`, and the authors `"Manager reviewer agent"`,
204`Manager_reviewer_agent`, `manager-reviewer-agent.` all match it. An author that normalizes to
205nothing (only punctuation) is contained in every reviewer text, so it is `SELF_REVIEW`. Punctuation
206inside a name is kept. Bytes of 128 and above are compared as they are: no Unicode case folding, and
207no folding of Unicode punctuation or look-alike letters. Identities are unsigned text until signed
208receipts land.
209
210## Test fixtures (`tests/`)
211
212- `verdicts/`: copies of three real review verdicts from `~/handoffs/hive/manager/reviews/`
213 (sha256 checked equal when copied, 2026-11-07), except one edit: in
214 `aien-architecture-mv-6daec174` a home-directory path `/home/<user>/work/…` is replaced by
215 `$HOME/work/…`. `omega-mv-215ea39a` (MERGE, omega-mv patch 4dd099d), `CUDApp-9714eba8` (MERGE,
216 CUDApp #373) and `aien-architecture-mv-6daec174` (MERGE_AFTER_FIX, arch #382, held).
217- `receipts/<head>.receipt`: TRANSCRIBED. No forge receipt existed before v0; these three restate in
218 `forge-receipt v1` the gate and negative-control exit codes that the reviewer recorded in each
219 verdict's EXERCISED section (omega-mv: run-tape.sh rc 0, control C2 rc 1; CUDApp:
220 `make test-om-encoder-ldg` rc 0, control NC1 rc 11; arch: doctrine gate rc 0, wrong-omc control
221 rc 3). `author` is the lane that wrote the patch (t_04379749; the hive-ng gpu lane whose bundle
222 is `~/handoffs/hive-ng/gpu/CUDApp-373/`; omp-queen-ng).
223- `receipts/*.receipt` with descriptive names: synthetic, one defect each.
224- Derived verdicts and receipts: `run.sh` makes them at test time with one `sed` edit each, from
225 the real omega-mv verdict, from `receipts/self-review.receipt` (case, whitespace, punctuation,
226 `_`, `-`, blank and control-byte values), or by appending the gate-written keys to the real
227 omega-mv receipt (valid, and one defect each), and fails if an edit changes nothing.
228- `json-*` cases in `cases.txt` run `decide --json`.
229- `status` runs: `run.sh` puts a fake `rad` first on `PATH` that lists 512, then 513 patches, then
230 one patch with zero, one and two receipts for its head.
231- `gate` runs: `run.sh` makes a git repository with two commits (100000 random bytes, then a second
232 file) in a Radicle-shaped storage under a temp `RAD_HOME`, with a fake `rad inspect`, and checks
233 every receipt key against independent tools (`git rev-parse`, `sha256sum` at 0, 55, 56, 63, 64,
234 65, 1000 and 100000 bytes, `date -u`), clone isolation (the gate's marker file is absent from the
235 negative control's clone), exit codes 0/1/2, killed commands, the default out dir, and that
236 every error writes no receipt. A receipt the gate wrote must give `MERGE OK` with a verdict.
237 Timeout runs: a gate and a negative control that are each `sh` with a background child
238 `sleep 20`, at `--timeout 1`: exit 1, rc 124, the receipt written, the log ending in the timeout
239 line and hashed, `HOLD GATE_TIMEOUT` (text and JSON), done in under 10 s, and the child sleeper
240 gone (the group kill); a direct child that joins forge's own group (`tests/joinpg.om`, then a
241 20 s sleep) still ends at `--timeout 1` with rc 124 in under 6 s and is gone (the kill by pid);
242 a run that ends inside `--timeout 5` is unaffected; `--timeout 86400` is
243 accepted and `0`, `86401`, `1x`, empty, 8 digits and a repeated `--timeout` are refused.
244- `mutants.txt`: one-line mutants of `forge.om`, each removing or weakening one invariant; each runs
245 the whole suite. `run.sh` checks the original line first, so a stale list fails, and counts a
246 mutant that does not compile as not caught.