openvibers/openvibe-git docsci.md
ci.md
| 1 | # Forge CI |
| 2 | |
| 3 | `git.openvibe.codes` runs the tests for a push to an OpenVibers repository on the shared node (since 2026-11-19; |
| 4 | it was the workstation), in a sandbox, and reports the verdict on the commit. GitHub Actions stays exactly as it is: this is the first-party path that runs |
| 5 | beside it, not a replacement yet. Nothing in this document turns a GitHub workflow off. |
| 6 | |
| 7 | ## What runs, and when |
| 8 | |
| 9 | A run is made only when all of these are true: |
| 10 | |
| 11 | - the push is to a **branch** (`refs/heads/…`, never a tag or a deletion); |
| 12 | - the repository is an **official** OpenVibers mirror on the forge (its owner is in `GIT_OFFICIAL_OWNERS`, by |
| 13 | default `openvibers`, and it mirrors `OpenVibers/<name>` on GitHub); |
| 14 | - the **push event's pusher** is the owning GitHub account, a login in `GIT_CI_MEMBERS`, or a collaborator GitHub |
| 15 | says has `admin`, `maintain` or `write` on that repository. GitHub's answer is cached for 10 minutes; |
| 16 | - the repository has a CI entry (the runner registers the repositories it is configured for, see below). |
| 17 | |
| 18 | It never runs for a pull request, a pull request from a fork, a push to a fork, a tag, a bot, or a non-member. |
| 19 | A repository with no CI entry is not tested here. The checks intake from GitHub (`server/checks-intake.js`) keeps |
| 20 | copying GitHub's check-runs, so a change can show both `test` (GitHub) and `forge/test` (here). When a run ends, the |
| 21 | runner also posts the same `forge/test` status to GitHub through the workstation's `gh` login (the forge host has no |
| 22 | GitHub token and is not given one), so the **pull request** on GitHub shows the forge's result too, with the run on |
| 23 | the forge as its target. The GitHub post is best effort: a missing `gh` login, a commit GitHub does not know (a |
| 24 | forge-only push) or a GitHub outage is logged, and the forge status stays final either way. `"githubStatus": false` |
| 25 | in `git-ci.json` turns the GitHub copy off. |
| 26 | |
| 27 | **One run per branch is live** (per repository until 2026-11-19, when two open pull requests in one repository kept |
| 28 | superseding each other). A newer push to a branch supersedes that branch's queued or running run: the older run becomes |
| 29 | `superseded`, its runner sees that on the next heartbeat (every 15 s), kills its sandbox and reports no verdict. |
| 30 | The newer run then starts. The repository's `forge/test` status is pending from enqueue, and success, failure or |
| 31 | error when the runner reports; a timed-out run is a failure. |
| 32 | |
| 33 | ## What a run does |
| 34 | |
| 35 | 1. The runner claims one queued run from `POST /api/v1/ci/runs/claim` (its own token). |
| 36 | 2. It clones **the pushed commit** from the forge (`https://git.openvibe.codes/<owner>/<name>.git`), retrying |
| 37 | while the mirror catches up with the webhook. |
| 38 | 3. **Install phase** — inside the sandbox, with one writable path (`/workspace`, the per-run directory) and the |
| 39 | network only through the runner's proxy, which allows exactly `registry.npmjs.org` and `codeload.github.com` |
| 40 | (the pinned OpenVibe tarballs). Everything else is refused, including private and link-local addresses. A |
| 41 | dependency whose postinstall downloads with Node's own `fetch` (mediasoup's worker, onnxruntime's CUDA package) |
| 42 | does not see that proxy, so those binaries are baked into a local image instead of fetched during the run. |
| 43 | 4. **Test phase** — a fresh sandbox with **no network at all** (`--network=none` / an empty network namespace), |
| 44 | the same workspace, no proxy socket mounted. |
| 45 | 5. The log streams to the forge while it runs; the verdict goes back with the duration and is written as the |
| 46 | `forge/test` commit status. The runner then posts the same status to GitHub with `gh` (outside the sandbox), |
| 47 | so the pull request shows it. The log is on `/<owner>/<name>/ci/<run>` and its JSON is |
| 48 | `GET /api/v1/repos/<owner>/<name>/ci/runs/<id>`. |
| 49 | |
| 50 | The commands, image and limit are per repository, registered by the runner from `~/.config/openvibe/git-ci.json`. |
| 51 | The defaults are `npm ci --no-audit --no-fund` then `npm test`, the image `docker.io/library/node:22-bookworm`, and |
| 52 | 30 minutes. The first five repositories use three local images on top of the node image: |
| 53 | |
| 54 | - `localhost/openvibe-ci-node22:1` — node 22 + pnpm 10.6.5 (`OpenVibe.Games`), because Corepack downloads pnpm with |
| 55 | Node's `fetch`, which has no proxy. |
| 56 | - `localhost/openvibe-ci-node22-ffmpeg:1` — the pnpm image + ffmpeg (`OpenVibe.Chat`), matching GitHub's |
| 57 | `apt-packages: ffmpeg`. |
| 58 | - `localhost/openvibe-ci-node22-mediasoup:1` — node 22 + the mediasoup 3.25.0 prebuilt worker, kernel6 asset |
| 59 | (`OpenVibe.Live`); `MEDIASOUP_WORKER_BIN` points at it, so the postinstall does not fetch from GitHub. Live's |
| 60 | install also sets `ONNXRUNTIME_NODE_INSTALL=skip`: the CUDA package is not needed on this CPU-only host and |
| 61 | would fetch from NuGet. |
| 62 | |
| 63 | The runner's own relay and proxy socket live in the container's `/run` tmpfs, never in the checkout: a |
| 64 | repository's linter must not see them. `OpenVibe.Games`' pnpm store is `node_modules/.pnpm-store` for the same |
| 65 | reason. |
| 66 | |
| 67 | ## How it is contained |
| 68 | |
| 69 | | | | |
| 70 | |---|---| |
| 71 | | engine | rootless **podman** if `podman info` says rootless, else **bubblewrap** (the workstation has both; podman is used) | |
| 72 | | identity | a new user namespace; container root is not host root. The podman user namespace keeps the host uid (`--userns=keep-id`); bubblewrap uses uid/gid 1000 inside its own namespace | |
| 73 | | filesystem | read-only root (`--read-only`), a tmpfs `/tmp`, and **one** host path: the per-run work directory bind-mounted at `/workspace`. No home, no `/etc/openvibe`, no git checkout of the runner, no Docker socket, no SSH agent | |
| 74 | | secrets | none. The runner's own token is not mounted; no repository secret is passed; the container environment is an allowlist (HOME, PATH, locale, npm cache inside the workspace). The GitHub status is posted by the runner process after the sandbox exits, using the workstation's own `gh` login; no GitHub token is in the runner's config or in a container. | |
| 75 | | network | install: loopback only, with the proxy on a Unix socket (the sandbox has no route anywhere else). test: no network namespace route at all | |
| 76 | | limits | `--cpus 4`, `--memory 6144m` (swap the same), `--pids-limit 2048`, 30 minutes wall clock (configurable 30 s–1 h). A run past it is killed and reported `timed_out`; a runner that disappears is reaped by the service a minute after its limit | |
| 77 | | capabilities | all dropped, `no-new-privileges`, a new session; bubblewrap also disables nested user namespaces | |
| 78 | | concurrency | one live run per branch (the forge's rule); `concurrency` runs at once per runner (1 by default, 2 on the shared node, at most 8). Pull request branches are claimed before default-branch checks, oldest first within each | |
| 79 | |
| 80 | **What is not contained, and why.** A container is not a virtual machine: a kernel or runtime escape is still a |
| 81 | host compromise, and the workstation is the busiest machine in the estate (it also runs the portal and agent jobs). |
| 82 | The design reduces what an escape reaches (no secrets, no home, no socket, no host network in the test phase), but |
| 83 | it does not make the host disposable. The repositories are public and accept forks, which is why forks and pull |
| 84 | requests never reach this runner; the trigger is a same-repository branch push by a person GitHub says may push. |
| 85 | The full `test:pg` path (PostgreSQL + PgBouncer + Valkey containers) is not run here — there is no Docker socket |
| 86 | inside the sandbox, so the runner runs the repository's `npm test` (PGlite). For those suites GitHub Actions remains |
| 87 | the gate. If the machine is ever dedicated to CI, a disposable VM per run is the next step (see |
| 88 | `research-2026-11-10/forge-first.md` §4). |
| 89 | |
| 90 | ## Adding a repository |
| 91 | |
| 92 | 1. It must already be an official mirror on the forge (the official mirrors seed creates one for every public |
| 93 | `OpenVibers` repository). Check: `GET https://git.openvibe.codes/api/v1/repos/openvibers/<name>`. |
| 94 | 2. Add an entry to the runner's `repos` in `~/.config/openvibe/git-ci.json`: |
| 95 | |
| 96 | ```json |
| 97 | "openvibers/openvibe.example": { |
| 98 | "install_command": "npm ci --no-audit --no-fund", |
| 99 | "test_command": "npm test", |
| 100 | "timeout_seconds": 1800 |
| 101 | } |
| 102 | ``` |
| 103 | |
| 104 | Optional: `image`, `cpus` (1–8), `memory_mb` (512–12288). Only official repositories are accepted. |
| 105 | 3. Restart the runner: `systemctl --user restart openvibe-git-ci`. On start it registers the entry through |
| 106 | `POST /api/v1/ci/repos`; the forge now queues its member pushes. |
| 107 | 4. Push to a branch, or start one by hand as the owner: |
| 108 | `POST /api/v1/repos/openvibers/<name>/ci/runs` with `{"branch":"main"}` (a signed-in owner, or the runner token). |
| 109 | The run appears at `https://git.openvibe.codes/openvibers/<name>/ci`. |
| 110 | |
| 111 | Removing an entry stops new runs; it does not delete past runs or their statuses. |
| 112 | |
| 113 | ## Running it on the shared node (2026-11-19) |
| 114 | |
| 115 | The owner: "handle CI with our own system interconnected with git.openvibe.codes … modular, optimized, efficient … |
| 116 | using the shared node and making use of the RAM". The runner moved from the workstation (one run at a time, four |
| 117 | repositories) to `ov-node-01` (8 cores, 15 GB): |
| 118 | |
| 119 | - **Every repository with tests.** All 68 official repositories with a `package.json` and a test script are |
| 120 | registered with `auto` commands: the checkout decides (`pnpm-lock.yaml` → `pnpm install --frozen-lockfile`, an npm |
| 121 | lockfile → `npm ci`, a `package.json` alone → `npm install`; then `npm test`). A repository with no test script |
| 122 | reports "Nothing to test here" instead of failing. A repository that needs more names its commands (Live skips |
| 123 | onnxruntime's CUDA download; Games runs typecheck and lint like its workflow). |
| 124 | - **Two runs at once** (`concurrency`, up to 8). The forge keeps one live run per repository, so they are always |
| 125 | different repositories. Each worker claims as `<host>/<n>`. Three was tried first: three full suites on the node's |
| 126 | four cores took Live 14 minutes and Network 18 (GitHub: 8 and 12), so it runs two. The test phase sets |
| 127 | `OV_TEST_TIMEOUT_SCALE=2` (`testTimeoutScale`; openvibe-shared's test runner 4.323.0 and later stretch each file's |
| 128 | limit by it), since a file's limit was set on GitHub's machines. |
| 129 | - **Same files, same verdict.** A push whose tree is exactly that of a run that already passed (a pull request merged |
| 130 | onto an unmoved main) is recorded as passed at once, pointing at that run; nothing is tested twice. A run started by |
| 131 | hand always runs. |
| 132 | - **Merging on it.** The ship script (`merge-after-ci.sh`) merges on a green `forge/test` without waiting for GitHub |
| 133 | Actions, and refuses on a red one once the repository's main has passed on the forge (before that, a suite that |
| 134 | cannot pass without the network does not block a merge GitHub would allow). The board is `/ci`. |
| 135 | - **Work in memory.** The work directories are a tmpfs (`/var/lib/ovci/work`, 8 GB at most): an install's tens of |
| 136 | thousands of files never touch the disk, and a run's directory is gone when it ends. |
| 137 | - **Installs kept per lockfile** (`runner/deps-cache.js`). After an install phase succeeds, what it made (every |
| 138 | `node_modules` outside another one, and any file it wrote outside them) is kept, keyed by the repository, its |
| 139 | lockfile(s), the root `package.json`'s install scripts and package manager, the install command, the image, the |
| 140 | engine and the runner's Node. A later run with the same key copies it back and has **no install phase**; most |
| 141 | pushes change code, not the lockfile. The copy is taken before any test runs, so no test can change what a later |
| 142 | run gets. The store is on disk (`depsCache`, 40 GB at most, least recently used first): the page cache keeps the |
| 143 | busy entries in memory and gives it back when the node needs it. |
| 144 | - **Download caches shared.** npm's and pnpm's caches (`sharedCache`) are mounted at `/cache` in the install phase |
| 145 | only, so a pin bump (every lockfile changes) still downloads only what changed. npm and pnpm check each tarball |
| 146 | against the lockfile's integrity, so one run cannot hand another a different package. The test phase never sees it. |
| 147 | - **Node's own fetch uses the proxy** (`NODE_USE_ENV_PROXY=1`, Node 22.21 and later): a postinstall that downloads a |
| 148 | prebuilt binary (mediasoup's worker) works through the same allowlist, which on the node also has `github.com`, |
| 149 | `objects.githubusercontent.com` and `release-assets.githubusercontent.com`. |
| 150 | - **The verdict** is the forge's `forge/test` status; the node has no GitHub login, so it does not post to GitHub |
| 151 | (`"githubStatus": false`). The ship scripts read the forge's verdict directly. |
| 152 | |
| 153 | - **GitHub's security checks, in the run** (`runner/security.js`, 2026-11-19): a gitleaks scan of the pushed commit's |
| 154 | files (the repository's own `.gitleaks.toml` or `.github/gitleaks.toml`; no network) before the install, and |
| 155 | `npm audit` / `pnpm audit` for every lockfile through the install proxy after it, failing at the repository's |
| 156 | `audit_fail_level` (critical by default, as openvibe-shared's security.yml: high is reported, not enforced; or |
| 157 | `high`, or `none`). Findings fail the run after the tests have run, and the description names them. gitleaks is |
| 158 | the version and checksum security.yml pins, installed at /usr/local/bin by `node-setup.sh`. |
| 159 | |
| 160 | - **The suite on PostgreSQL too** (`testPg`, 2026-11-19): a repository's `test:pg` runs after its tests pass, with |
| 161 | PostgreSQL 18, PgBouncer and Valkey started inside the sandbox by its own `openvibe-sdk/scripts/test-services.sh` |
| 162 | from the host's packages (no Docker; each sandbox has its own loopback, so runs side by side do not share ports). |
| 163 | It catches what PGlite cannot (a pooled connection runs un-awaited work out of order). The shared node runs it on |
| 164 | the default branch, after a merge (`testPg: "main"`), so a pull request's verdict is not twice as slow; `all` runs it |
| 165 | everywhere once there are more machines. Services that do not start are reported, not counted. |
| 166 | |
| 167 | Each run's description says where the time went: `Forge runner passed in 2m 10s (install 3s from the cache, tests |
| 168 | 2m 4s)`. |
| 169 | |
| 170 | ```sh |
| 171 | # on the node, from a checkout of OpenVibe.Git (or scp the script): root, idempotent |
| 172 | sudo deploy/ci/node-setup.sh <git ref> |
| 173 | # then, once: the runner token (0600) and git-ci.json into /var/lib/ovci/.config/openvibe, and run it again |
| 174 | sudo -u ovci XDG_RUNTIME_DIR=/run/user/$(id -u ovci) journalctl --user -u openvibe-git-ci -f |
| 175 | ``` |
| 176 | |
| 177 | `node-setup.sh` makes the `ovci` system user (its own systemd user manager, so the runs' cgroup scopes have their |
| 178 | memory and CPU caps), the tmpfs mount unit, the cache folders, pnpm in `/usr`, and a root-owned checkout of this |
| 179 | repository at `/var/lib/ovci/runner` (the runner reads it and cannot change it), then installs |
| 180 | `deploy/systemd-user/openvibe-git-ci-node.service` and restarts it. Updating the runner is the same command with the |
| 181 | new ref. |
| 182 | |
| 183 | ## Running it on the workstation |
| 184 | |
| 185 | ```sh |
| 186 | # from a checkout of OpenVibe.Git, as the workstation user (no sudo) |
| 187 | deploy/ci/install.sh --start |
| 188 | systemctl --user status openvibe-git-ci |
| 189 | journalctl --user -u openvibe-git-ci -f |
| 190 | ``` |
| 191 | |
| 192 | `install.sh` checks the sandbox engine, pulls `node:22-bookworm`, keeps a checkout at `~/openvibe/git-ci`, |
| 193 | copies `deploy/ci/git-ci.example.json` to `~/.config/openvibe/git-ci.json` if there is none, installs |
| 194 | `deploy/systemd-user/openvibe-git-ci.service` into the user manager and (with `--start`) enables it. |
| 195 | |
| 196 | The workstation's shared podman store is on the offload disk (`/mnt/120gb`), which ran out of **inodes**, not bytes. |
| 197 | The runner therefore gets its own store under `~/.local/share/openvibe-git-ci/containers/storage` on the home |
| 198 | filesystem, passed to every podman call with `--root`/`--runroot` and with its own `containers.conf` and |
| 199 | `containers-storage.conf` in `~/.config/openvibe` (libpod's database names the same graph root). `install.sh` writes |
| 200 | both files when they are absent and pulls the image into that store. Nothing global is changed. |
| 201 | |
| 202 | The token is made once, on the workstation: |
| 203 | |
| 204 | ```sh |
| 205 | node runner/token.js --out ~/.config/openvibe/git-ci.token # prints the scrypt line, not the token |
| 206 | # put that line in deploy/ci/runner-token, commit, deploy, restart the runner |
| 207 | ``` |
| 208 | |
| 209 | The service holds only the scrypt hash of the token (`deploy/ci/runner-token`, or `GIT_CI_RUNNER_TOKEN` in |
| 210 | `/etc/openvibe/git.env`). To rotate: make a new token, put the new line in the repository, deploy, restart the |
| 211 | runner. The old token stops working when the new line is live. |
| 212 | |
| 213 | ## Measured (2026-11-11 UTC) |
| 214 | |
| 215 | Same commit per row; forge time is claim → verdict, GitHub time is `run_started_at` → `updated_at`. Both include |
| 216 | install and tests; GitHub's queue is not included. |
| 217 | |
| 218 | | repository | head | forge | GitHub | |
| 219 | |---|---|---|---| |
| 220 | | OpenVibe.Shared | `58934cc` | **1m 35s** success | 10m 53s success (the same head also had a 12m 59s failure) | |
| 221 | | OpenVibe.Games | `4070e5f` | **3m 46s** success | 13m 56s success | |
| 222 | | OpenVibe.Network | `ea86dc2` | **11m 29s** success | 22m 52s success | |
| 223 | | OpenVibe.Chat | `85d60a8` | **20m 13s** success | 18m 30s success | |
| 224 | | OpenVibe.Live | `9e4c000` | **7m 56s** success | 10m 59s success | |
| 225 | |
| 226 | Chat is the one slower forge run (20m 13s against 18m 30s): the old i7-4770K runs the 134-file suite serially, while |
| 227 | GitHub's runner is a newer 4-vCPU machine, and the forge run has no warm cache. The other four are faster, mostly |
| 228 | because there is no install cache on GitHub and no queue here. |
| 229 | |
| 230 | ## The service side |
| 231 | |
| 232 | - `migrations/0008_ci_runs.sql` — `git_ci_repos` (enabled, commands, image, limits) and `git_ci_runs` (state, log, |
| 233 | timings), with a partial unique index that keeps one live run per branch (`0013_ci_live_per_branch`). |
| 234 | - `server/ci.js` — the member rule, enqueue and supersede, claim/heartbeat/log/finish, the reaper and the |
| 235 | `forge/test` status on the forge. |
| 236 | - `server/ci-auth.js` — the runner token's scrypt hash and the constant-time check. |
| 237 | - `server/http/api.js` — `/api/v1/ci/*` (runner token) and `/api/v1/repos/:owner/:name/ci*` (public reads, owner |
| 238 | manual runs). |
| 239 | - `server/views/ci.js`, `server/http/pages.js` — the CI tab, the run list and the log page. |
| 240 | - `runner/` — `index.js` (poll), `run.js` (clone, phases, verdict), `sandbox.js` (podman/bubblewrap), |
| 241 | `proxy.js` (the install allowlist), `process.js` (the wall clock), `config.js`, `api.js`, `token.js`, and |
| 242 | `github-status.js` (the verdict on the GitHub pull request, through `gh`, outside the sandbox). |
| 243 |