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 Source

INTERPLANE Forge v1: forge

The merge decision of INTERPLANE Forge and the gate runner that feeds it, in seeded Omega (forge.om). Spec: docs/FORGE.md. Host dependencies: DEPENDENCIES.md.

Agents express intent. The forge retains authority. An agent proposes a patch, an independent reviewer writes a verdict for one exact head, forge gate runs the gate and its negative control in fresh clones of that head and writes a receipt. forge decide is the only step that turns those three objects into MERGE, and it says HOLD for anything it cannot prove.

Build and test

OMC=~/work/flux/omega-mv/seed/out/omc          # omega-mv f4df8239, sha256 3ad9f10f…3194
"$OMC" < forge/forge.om > /tmp/forge && chmod +x /tmp/forge
OMC="$OMC" sh forge/tests/run.sh                # every check, then every mutant; exit 0 only when all pass

run.sh refuses any omc whose sha256 is not the pin (prints NOT_RUN, exit 3). It needs git for the gate fixture.

Commands

forge decide [--json] <patch-head> <verdict-file> <gate-receipt>
forge status <RID> [reviews-dir [receipts-dir]]
forge gate <RID> <head> [--name N] [--out DIR] [--timeout S] --author A --neg ARGV.. -- ARGV..

Any other subcommand prints the usage on stderr and exits 2.

forge decide

Prints exactly one line, MERGE OK (exit 0) or HOLD <CODE> (exit 1). With --json (first argument after decide) it prints exactly one line holding one JSON object instead, with the same exit codes:

{"schema":"forge-decision/1","head":"<40 lowercase hex>","decision":"MERGE","reason":"OK"}
{"schema":"forge-decision/1","head":"<40 lowercase hex>","decision":"HOLD","reason":"<CODE>"}
{"schema":"forge-decision/1","head":null,"decision":"HOLD","reason":"USAGE"}

The keys always appear in that order with no spaces. head is the patch head argument when it is 40 lowercase hex and the argument count is right, else null (USAGE, BAD_HEAD). reason is one of the codes in the table below.

forge status

Runs rad patch list --all --repo <RID> and rad patch show <id> --repo <RID> for every patch and prints one line per patch, then a summary:

patch <id7> status=<rad status> head=<40 hex> verdict=<file|none> receipt=<file|ambiguous|none> decision=<MERGE OK|HOLD <CODE>|NOT_RUN no verdict file>
forge status <RID> patches=N decided=K merge=A hold=B not_run=C

For each patch head H, the verdict is the one file in reviews-dir named *-<first 8 hex of H>.verdict.txt (two or more such files give HOLD VERDICT_AMBIGUOUS), and the receipt is the one file in receipts-dir named *-<first 8 hex of H>.receipt.txt, the name forge gate writes (two or more give receipt=ambiguous and HOLD RECEIPT_AMBIGUOUS; none gives receipt=none and HOLD RECEIPT_UNREADABLE). Defaults: $HOME/handoffs/hive/manager/reviews and $HOME/handoffs/hive/forge/receipts. Names are followed through symlinks. status is a report and exits 0 when rad ran; a rad failure prints forge: rad failed, exit N and exits 2. It decides at most the first 512 listed patches: when rad lists more, it prints the summary for those, then TRUNCATED patches=N examined=512, and exits 2. It never merges or writes anything.

forge gate

forge gate rad:z6do9WDBhuSnvopDkgFdFr1yWA62 215ea39afdc0cf1914cfadf43bbb6d23ce68c920 \
  --author "t_04379749" --out ~/handoffs/hive/forge/receipts \
  --neg <command that must fail> -- <the repository's gate command>
  1. Checks the arguments: RID is rad: and 1 to 60 ASCII letters and digits; head is 40 lowercase hex; --author (required) is 1 to 256 bytes with a printable ASCII byte and no control byte; --name is 1 to 100 bytes of A-Z a-z 0-9 . _ - not starting with .; each option at most once; --timeout is 1 to 5 decimal digits giving 1 to 86400 seconds (default 1800); both commands are 1 to 40 arguments, at most 1024 bytes joined, no CR or LF, and a first argument that is not empty, does not start with - and holds no =.
  2. Reads HOME (required), PATH (default /usr/local/bin:/usr/bin:/bin), OMC and RAD_HOME. The storage is $RAD_HOME/storage/<RID without rad:>, else $HOME/.radicle/storage/…. When OMC is set, its file's SHA-256 is recorded as omc= (an unreadable OMC is an error); unset, omc=none. The name is --name, else the name of rad inspect <RID> --payload.
  3. Makes /tmp/forge-gate-<pid>-<16 random hex> (mode 0700) and, twice, a fresh clone of exactly head from the storage (git init, fetch --no-tags, checkout --detach), with git's system and global config off. Each clone's HEAD must equal head.
  4. Runs the gate command in one clone and the negative control in the other, each through /usr/bin/env with only HOME, PATH and (when set) OMC in the environment, stdin /dev/null, stdout and stderr to <name>-<head8>.gate.log / <name>-<head8>.negctl.log in the out dir. An exit code is the command's status, or 128 + the signal number when it was killed. Each command runs in its own process group (the child calls setpgid(0, 0) before chdir, and forge sets the same group from the parent, so there is no race) with its own timeout of --timeout seconds (default 1800), measured on the monotonic clock and polled every 100 ms. A command still running at its timeout is killed with its whole process group (SIGKILL to -pid) and by its pid (so a direct child that moved to another group is killed too), reaped (forge stops waiting for the reap 10 s after the kill, so forge itself stays bounded), its exit code recorded as 124, and the line forge: timeout after S s, process group killed with SIGKILL, exit status recorded as 124 appended to its log, so the log hash covers it; the receipt and logs are then written as usual, and decide gives HOLD GATE_TIMEOUT. Limits: a grandchild that leaves the group (setsid, setpgid) escapes the kill; a direct child stuck in uninterruptible sleep is not reaped by forge (it is left to init after the 10 s reap deadline, and could still finish a write it was in); a command that exits 124 by itself is indistinguishable from a timeout and also holds as GATE_TIMEOUT (fail closed: both are HOLD); background processes a command leaves running after it exits are not killed.
  5. Hashes both logs (SHA-256, first-party Omega) and creates the out files: the logs, then the receipt <name>-<head8>.receipt.txt, then removes the temp dir. The command logs live in the 0700 temp dir (gate.log, negctl.log), created with `O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW| O_CLOEXEC` (557249) and opened a second time read-only (557056), both fds checked to be the same file. The commands write through the first fd (duplicated to stdout and stderr, never reopened by name); forge hashes and copies through the second, so a log renamed or swapped while a gate runs changes neither the out log nor log_sha256. Out files are created only at the end, with the same O_EXCL|O_NOFOLLOW flags: forge never replaces or follows an out file. A name already taken (file or symlink) is refused before the gate runs; one that appears during the run makes the run exit 2, and the out files it had created are removed, so a refused run leaves no file. The out dir must exist and be writable (checked first). The flag values are aarch64 Linux, the only target the pinned omc emits; tests/run.sh reports NOT_RUN (exit 3) on any other machine, and x86 is not supported.

It prints forge gate <RID> head=<head> gate_rc=N negctl_rc=M receipt=<path> and exits 0 when gate_rc is 0 and negctl_rc is neither 0 nor 124, 1 when the receipt records anything else (decide would HOLD), 2 on an error, with a message on stderr and no receipt: bad arguments (including a bad --timeout), unknown head, clone failure, unreadable OMC, no HOME, or an out directory that does not exist or cannot be written. The out directory defaults to $HOME/handoffs/hive/forge/receipts; the forge never creates directories. gate decides nothing: the receipt is evidence for forge decide.

Verdict file (the desk format, read as is)

Gate receipt, forge-receipt v1 (format defined here)

forge gate writes every key, in this order:

FORGE-RECEIPT v1
rid=<rad: and 1 to 60 ASCII letters and digits>
clone=<40 lowercase hex: HEAD of the fresh clone the gate ran in>
tree=<40 lowercase hex: that clone's HEAD^{tree}>
omc=<64 lowercase hex: SHA-256 of $OMC, or none>
gate_cmd=<free text: the gate arguments joined with single spaces (not shell-quoted)>
gate_rc=<0..255: exit status of the gate; 124 when forge killed it at the timeout>
negctl_cmd=<free text: the negative-control arguments, joined the same way>
negctl_rc=<0..255: exit status of the negative control; 124 when forge killed it at the timeout>
author=<the patch author: a printable ASCII byte (33..126), no control byte>
started=<YYYY-MM-DDTHH:MM:SSZ, UTC, after both clones, just before the gate runs>
finished=<YYYY-MM-DDTHH:MM:SSZ, UTC, after both runs>
log_sha256=<64 lowercase hex: SHA-256 of the gate log>
negctl_log_sha256=<64 lowercase hex: SHA-256 of the negative-control log>

decide requires only clone, gate_rc and author (and negctl_rc, else NO_NEGCTL); the other keys are optional, so receipts written by hand in the v0 key set stay valid. Line 1 is exactly FORGE-RECEIPT v1. Every other line is key=value with a key from the list, in any order, each at most once, no empty lines (the final newline is optional); exit codes are 1 to 3 decimal digits. An unknown key, a duplicate, an empty line, a missing required key, a value that is not of its form (including uppercase hex or a hash of the wrong length) or a number above 255 is RECEIPT_MALFORMED. Times are checked as a digit pattern, not as a calendar date. Files of 4096 bytes or more, and missing files, are RECEIPT_UNREADABLE. decide does not compare rid, tree, omc or the log hashes with anything; they let a reader check a receipt against the repository, the compiler and the logs.

Decision and reason codes

Checks run in this order; the first that fails is the reason.

ExitLineMeaning
0MERGE OKevery check below passed
1HOLD USAGEdecide without exactly three arguments (after --json)
1HOLD BAD_HEADthe patch head is not 40 lowercase hex
1HOLD VERDICT_UNREADABLEverdict file missing, empty or too large
1HOLD VERDICT_MALFORMEDverdict file breaks the format above
1HOLD VERDICT_MERGE_AFTER_FIXthe reviewer asked for fixes; only MERGE merges
1HOLD VERDICT_REJECTthe reviewer rejected the patch
1HOLD HEAD_MISMATCHverdict head is not the patch head (all 40 hex compared)
1HOLD NO_REVIEWERno reviewer= line, or one without a printable ASCII byte
1HOLD RECEIPT_AMBIGUOUSstatus only: more than one receipt file for the head
1HOLD RECEIPT_UNREADABLEreceipt missing, empty or too large
1HOLD RECEIPT_MALFORMEDreceipt breaks the format above
1HOLD NO_NEGCTLthe receipt has no negative control
1HOLD CLONE_MISMATCHthe gate ran on another head than the patch head
1HOLD GATE_TIMEOUTgate_rc or negctl_rc is 124: a run was killed at the forge gate timeout, so its evidence is incomplete (checked before its result)
1HOLD GATE_FAILgate_rc is not 0
1HOLD NEGCTL_PASSEDnegctl_rc is 0: the control did not fail, so the gate proves nothing
1HOLD SELF_REVIEWthe normalized reviewer text contains the normalized receipt author
1HOLD VERDICT_AMBIGUOUSstatus only: more than one verdict file for the head

Self-review normalization. Both the reviewer value and the author are folded to ASCII lower case; tab, _ and - count as spaces and every run of them becomes one space; then ASCII punctuation (!"#$%&'()*+,./:;<=>?@[\]^{|}~`) and spaces are stripped from both ends. The reviewer text is then searched for the author as a substring. Manager reviewer agent as author matches reviewer= MANAGER reviewer agent (relayed), and the authors "Manager reviewer agent", Manager_reviewer_agent, manager-reviewer-agent. all match it. An author that normalizes to nothing (only punctuation) is contained in every reviewer text, so it is SELF_REVIEW. Punctuation inside a name is kept. Bytes of 128 and above are compared as they are: no Unicode case folding, and no folding of Unicode punctuation or look-alike letters. Identities are unsigned text until signed receipts land.

Test fixtures (tests/)