openvibers/openvibe-git Commits
Forge CI: one live run per branch; pull request branches first (#121)
Changes
@@@ -24,7 +24,8 @@ the forge as its target. The GitHub post is best effort: a missing `gh` login, aforge-only push) or a GitHub outage is logged, and the forge status stays final either way. `"githubStatus": false`in `git-ci.json` turns the GitHub copy off.--**One run per repository is live.** A newer branch push supersedes the queued or running one: the older run becomes++**One run per branch is live** (per repository until 2026-11-19, when two open pull requests in one repository kept++superseding each other). A newer push to a branch supersedes that branch's queued or running run: the older run becomes`superseded`, its runner sees that on the next heartbeat (every 15 s), kills its sandbox and reports no verdict.The newer run then starts. The repository's `forge/test` status is pending from enqueue, and success, failure orerror when the runner reports; a timed-out run is a failure.@@@ -74,7 +75,7 @@ reason.| 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 || 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 || capabilities | all dropped, `no-new-privileges`, a new session; bubblewrap also disables nested user namespaces |--| concurrency | one run per repository (the forge's rule); `concurrency` runs at once per runner (1 by default, 3 on the shared node, at most 8) |++| 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 |**What is not contained, and why.** A container is not a virtual machine: a kernel or runtime escape is still ahost compromise, and the workstation is the busiest machine in the estate (it also runs the portal and agent jobs).@@@ -215,7 +216,7 @@ because there is no install cache on GitHub and no queue here.## The service side- `migrations/0008_ci_runs.sql` — `git_ci_repos` (enabled, commands, image, limits) and `git_ci_runs` (state, log,-- timings), with a partial unique index that keeps one live run per repository.++ timings), with a partial unique index that keeps one live run per branch (`0013_ci_live_per_branch`).- `server/ci.js` — the member rule, enqueue and supersede, claim/heartbeat/log/finish, the reaper and the`forge/test` status on the forge.- `server/ci-auth.js` — the runner token's scrypt hash and the constant-time check.nnew file mode 100644@@@ -0,0 +1,8 @@++-- phase: expand++-- Forge CI: one live run per branch, not per repository (2026-11-19). With every repository on the shared node's++-- runner, two open pull requests in one repository (a pin bump and a fix) superseded each other's runs, so only the++-- later push ever got a verdict. A newer push still supersedes the queued or running run of its own branch.++-- Relaxing the index is safe for the previous release: it supersedes per repository before inserting, which never++-- leaves two live runs on one branch.++DROP INDEX IF EXISTS git_ci_runs_one_live;++CREATE UNIQUE INDEX git_ci_runs_one_live_branch ON git_ci_runs (repo_id, branch) WHERE state IN ('queued', 'running');@@@ -7,7 +7,7 @@* A run exists only for a push to a branch of an official (OpenVibers) repository, made by a person GitHub says* may push there — the push event's own pusher, checked against the repository's collaborators (10 minutes of* cache) and always against the owning account. A fork, a pull request from a fork, a tag, a bot and a non-member-- * are skipped; those keep GitHub Actions. One run per repository is live: a newer push supersedes the queued or++ * are skipped; those keep GitHub Actions. One run per branch is live: a newer push supersedes the queued or* running one, and the runner sees that on its heartbeat and stops.** The verdict is copied into git_commit_statuses as `forge/test` (the same intake the GitHub check-runs use), and@@@ -127,7 +127,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, clif (!conf) return { skipped: 'not-enabled' };const clean = cleanSha(sha);const ref = cleanBranch(branch);-- const live = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND state IN ('queued', 'running')", [row.id]);++ const live = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')", [row.id, ref]);if (!force && live && live.sha === clean && live.branch === ref) {return { skipped: 'duplicate', run: rowToRun(live, { baseUrl: base(), owner: row.owner_username, name: row.name }) };}@@@ -140,8 +140,8 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl? await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND tree = ? AND state = 'success' ORDER BY finished_at DESC LIMIT 1", [row.id, tree]): null;await store.execute(-- "UPDATE git_ci_runs SET state = 'superseded', description = ?, finished_at = now(), updated_at = now() WHERE repo_id = ? AND state IN ('queued', 'running')",-- [`Superseded by ${clean.slice(0, 12)}`, row.id],++ "UPDATE git_ci_runs SET state = 'superseded', description = ?, finished_at = now(), updated_at = now() WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')",++ [`Superseded by ${clean.slice(0, 12)}`, row.id, ref],);if (same) {const description = text(`Same files as ${same.sha.slice(0, 12)} (${same.branch}), which passed: ${same.description || 'passed'}`, 1000);@@@ -164,7 +164,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl);} catch (err) {if (/duplicate key|unique/i.test(String(err.message))) {-- const current = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND state IN ('queued', 'running')", [row.id]);++ const current = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')", [row.id, ref]);return { skipped: 'duplicate', run: rowToRun(current, { baseUrl: base(), owner: row.owner_username, name: row.name }) };}throw err;@@@ -263,7 +263,10 @@ function createCi({ config, store, checks, git, github, repos, log = console, clasync function claim(runner = 'forge-runner') {const row = await store.maybe(`WITH next AS (-- SELECT id FROM git_ci_runs WHERE state = 'queued' ORDER BY created_at ASC LIMIT 1 FOR UPDATE SKIP LOCKED++ SELECT r.id FROM git_ci_runs r JOIN git_repos g ON g.id = r.repo_id++ WHERE r.state = 'queued'++ ORDER BY (r.branch = COALESCE(g.default_branch, 'main')) ASC, r.created_at ASC++ LIMIT 1 FOR UPDATE OF r SKIP LOCKED)UPDATE git_ci_runs r SET state = 'running', started_at = now(), runner = ?, updated_at = now()FROM next WHERE r.id = next.id RETURNING r.*`,@@@ -1,7 +1,7 @@'use strict';/*** Forge CI: a branch push by a repository's own writer queues a run; a non-member, a fork and a pull request do-- * not. One run per repository, the newer push supersedes the older. The runner claims, writes a log, reports a++ * not. One live run per branch, the newer push supersedes the older; pull request branches are claimed first. The runner claims, writes a log, reports a* verdict and that verdict is the commit status. A run left running past its limit is reaped and reported red.*/const assert = require('assert');@@@ -156,6 +156,23 @@ const ok = (body, status = 200) => ({ ok: status >= 200 && status < 300, status,assert.equal(reapedStatus.json().statuses[0].state, 'failure');assert.match(reapedStatus.json().statuses[0].description, /timed out after 1 minutes/);++ // One live run per branch, and a pull request's branch is claimed before a check of main: a push to main, then++ // one to a feature branch; the feature branch is claimed first and main's run is not superseded by it.++ const author = { name: 'OpenVibers', email: '[email protected]' };++ const mainHead = await t.ctx.git.commitFiles('openvibers', 'live2', { branch: 'main', base: 'main', message: 'Main again', files: [{ path: 'm.txt', content: 'm\n' }], author });++ const mainRun = await t.ctx.ci.onGithubPush(live2.row, push(mainHead.sha, 'OpenVibers', live2.full));++ const featureHead = await t.ctx.git.commitFiles('openvibers', 'live2', { branch: 'feature', base: 'main', message: 'A feature', files: [{ path: 'f.txt', content: 'f\n' }], author });++ const featureRun = await t.ctx.ci.onGithubPush(live2.row, { ...push(featureHead.sha, 'OpenVibers', live2.full), ref: 'refs/heads/feature' });++ assert.equal(featureRun.run.state, 'queued');++ assert.equal((await t.ctx.ci.runFor(live2.row, mainRun.run.id)).state, 'queued', 'a push to another branch leaves main\'s run alone');++ const claimedFeature = (await t.get('/api/v1/ci/runs/claim', { bearer: TOKEN, json: {} })).json();++ assert.equal(claimedFeature.run.id, featureRun.run.id, 'the pull request branch first, though main was queued earlier');++ const claimedMain = (await t.get('/api/v1/ci/runs/claim', { bearer: TOKEN, json: {} })).json();++ assert.equal(claimedMain.run.id, mainRun.run.id);++ for (const id of [claimedFeature.run.id, claimedMain.run.id]) {++ assert.equal((await t.get(`/api/v1/ci/runs/${id}/status`, { bearer: TOKEN, json: { state: 'success' } })).status, 200);++ }++// A push that lands on the forge itself: the network's own service token may run it, a person's token// may not (the forge knows an OpenVibe account, not the GitHub login the member rule is about).const pkt = (line) => `${(Buffer.byteLength(line) + 4).toString(16).padStart(4, '0')}${line}`;
@@ -24,7 +24,8 @@ the forge as its target. The GitHub post is best effort: a missing `gh` login, a
@@ -24,7 +24,8 @@ the forge as its target. The GitHub post is best effort: a missing `gh` login, a
forge-only push) or a GitHub outage is logged, and the forge status stays final either way. `"githubStatus": false`
forge-only push) or a GitHub outage is logged, and the forge status stays final either way. `"githubStatus": false`
in `git-ci.json` turns the GitHub copy off.
in `git-ci.json` turns the GitHub copy off.
-**One run per repository is live.** A newer branch push supersedes the queued or running one: the older run becomes
+**One run per branch is live** (per repository until 2026-11-19, when two open pull requests in one repository kept
+superseding each other). A newer push to a branch supersedes that branch's queued or running run: the older run becomes
`superseded`, its runner sees that on the next heartbeat (every 15 s), kills its sandbox and reports no verdict.
`superseded`, its runner sees that on the next heartbeat (every 15 s), kills its sandbox and reports no verdict.
The newer run then starts. The repository's `forge/test` status is pending from enqueue, and success, failure or
The newer run then starts. The repository's `forge/test` status is pending from enqueue, and success, failure or
error when the runner reports; a timed-out run is a failure.
error when the runner reports; a timed-out run is a failure.
@@ -74,7 +75,7 @@ reason.
@@ -74,7 +75,7 @@ reason.
| 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 |
| 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 |
| 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 |
| 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 |
| capabilities | all dropped, `no-new-privileges`, a new session; bubblewrap also disables nested user namespaces |
| capabilities | all dropped, `no-new-privileges`, a new session; bubblewrap also disables nested user namespaces |
-| concurrency | one run per repository (the forge's rule); `concurrency` runs at once per runner (1 by default, 3 on the shared node, at most 8) |
+| 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 |
**What is not contained, and why.** A container is not a virtual machine: a kernel or runtime escape is still a
**What is not contained, and why.** A container is not a virtual machine: a kernel or runtime escape is still a
host compromise, and the workstation is the busiest machine in the estate (it also runs the portal and agent jobs).
host compromise, and the workstation is the busiest machine in the estate (it also runs the portal and agent jobs).
@@ -215,7 +216,7 @@ because there is no install cache on GitHub and no queue here.
@@ -215,7 +216,7 @@ because there is no install cache on GitHub and no queue here.
## The service side
## The service side
- `migrations/0008_ci_runs.sql` — `git_ci_repos` (enabled, commands, image, limits) and `git_ci_runs` (state, log,
- `migrations/0008_ci_runs.sql` — `git_ci_repos` (enabled, commands, image, limits) and `git_ci_runs` (state, log,
- timings), with a partial unique index that keeps one live run per repository.
+ timings), with a partial unique index that keeps one live run per branch (`0013_ci_live_per_branch`).
- `server/ci.js` — the member rule, enqueue and supersede, claim/heartbeat/log/finish, the reaper and the
- `server/ci.js` — the member rule, enqueue and supersede, claim/heartbeat/log/finish, the reaper and the
`forge/test` status on the forge.
`forge/test` status on the forge.
- `server/ci-auth.js` — the runner token's scrypt hash and the constant-time check.
- `server/ci-auth.js` — the runner token's scrypt hash and the constant-time check.
new file mode 100644
new file mode 100644
@@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
+-- phase: expand
+-- Forge CI: one live run per branch, not per repository (2026-11-19). With every repository on the shared node's
+-- runner, two open pull requests in one repository (a pin bump and a fix) superseded each other's runs, so only the
+-- later push ever got a verdict. A newer push still supersedes the queued or running run of its own branch.
+-- Relaxing the index is safe for the previous release: it supersedes per repository before inserting, which never
+-- leaves two live runs on one branch.
+DROP INDEX IF EXISTS git_ci_runs_one_live;
+CREATE UNIQUE INDEX git_ci_runs_one_live_branch ON git_ci_runs (repo_id, branch) WHERE state IN ('queued', 'running');
@@ -7,7 +7,7 @@
@@ -7,7 +7,7 @@
* A run exists only for a push to a branch of an official (OpenVibers) repository, made by a person GitHub says
* A run exists only for a push to a branch of an official (OpenVibers) repository, made by a person GitHub says
* may push there — the push event's own pusher, checked against the repository's collaborators (10 minutes of
* may push there — the push event's own pusher, checked against the repository's collaborators (10 minutes of
* cache) and always against the owning account. A fork, a pull request from a fork, a tag, a bot and a non-member
* cache) and always against the owning account. A fork, a pull request from a fork, a tag, a bot and a non-member
- * are skipped; those keep GitHub Actions. One run per repository is live: a newer push supersedes the queued or
+ * are skipped; those keep GitHub Actions. One run per branch is live: a newer push supersedes the queued or
* running one, and the runner sees that on its heartbeat and stops.
* running one, and the runner sees that on its heartbeat and stops.
*
*
* The verdict is copied into git_commit_statuses as `forge/test` (the same intake the GitHub check-runs use), and
* The verdict is copied into git_commit_statuses as `forge/test` (the same intake the GitHub check-runs use), and
@@ -127,7 +127,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
@@ -127,7 +127,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
if (!conf) return { skipped: 'not-enabled' };
if (!conf) return { skipped: 'not-enabled' };
const clean = cleanSha(sha);
const clean = cleanSha(sha);
const ref = cleanBranch(branch);
const ref = cleanBranch(branch);
- const live = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND state IN ('queued', 'running')", [row.id]);
+ const live = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')", [row.id, ref]);
if (!force && live && live.sha === clean && live.branch === ref) {
if (!force && live && live.sha === clean && live.branch === ref) {
return { skipped: 'duplicate', run: rowToRun(live, { baseUrl: base(), owner: row.owner_username, name: row.name }) };
return { skipped: 'duplicate', run: rowToRun(live, { baseUrl: base(), owner: row.owner_username, name: row.name }) };
}
}
@@ -140,8 +140,8 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
@@ -140,8 +140,8 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
? await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND tree = ? AND state = 'success' ORDER BY finished_at DESC LIMIT 1", [row.id, tree])
? await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND tree = ? AND state = 'success' ORDER BY finished_at DESC LIMIT 1", [row.id, tree])
: null;
: null;
await store.execute(
await store.execute(
- "UPDATE git_ci_runs SET state = 'superseded', description = ?, finished_at = now(), updated_at = now() WHERE repo_id = ? AND state IN ('queued', 'running')",
- [`Superseded by ${clean.slice(0, 12)}`, row.id],
+ "UPDATE git_ci_runs SET state = 'superseded', description = ?, finished_at = now(), updated_at = now() WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')",
+ [`Superseded by ${clean.slice(0, 12)}`, row.id, ref],
);
);
if (same) {
if (same) {
const description = text(`Same files as ${same.sha.slice(0, 12)} (${same.branch}), which passed: ${same.description || 'passed'}`, 1000);
const description = text(`Same files as ${same.sha.slice(0, 12)} (${same.branch}), which passed: ${same.description || 'passed'}`, 1000);
@@ -164,7 +164,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
@@ -164,7 +164,7 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
);
);
} catch (err) {
} catch (err) {
if (/duplicate key|unique/i.test(String(err.message))) {
if (/duplicate key|unique/i.test(String(err.message))) {
- const current = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND state IN ('queued', 'running')", [row.id]);
+ const current = await store.maybe("SELECT * FROM git_ci_runs WHERE repo_id = ? AND branch = ? AND state IN ('queued', 'running')", [row.id, ref]);
return { skipped: 'duplicate', run: rowToRun(current, { baseUrl: base(), owner: row.owner_username, name: row.name }) };
return { skipped: 'duplicate', run: rowToRun(current, { baseUrl: base(), owner: row.owner_username, name: row.name }) };
}
}
throw err;
throw err;
@@ -263,7 +263,10 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
@@ -263,7 +263,10 @@ function createCi({ config, store, checks, git, github, repos, log = console, cl
async function claim(runner = 'forge-runner') {
async function claim(runner = 'forge-runner') {
const row = await store.maybe(
const row = await store.maybe(
`WITH next AS (
`WITH next AS (
- SELECT id FROM git_ci_runs WHERE state = 'queued' ORDER BY created_at ASC LIMIT 1 FOR UPDATE SKIP LOCKED
+ SELECT r.id FROM git_ci_runs r JOIN git_repos g ON g.id = r.repo_id
+ WHERE r.state = 'queued'
+ ORDER BY (r.branch = COALESCE(g.default_branch, 'main')) ASC, r.created_at ASC
+ LIMIT 1 FOR UPDATE OF r SKIP LOCKED
)
)
UPDATE git_ci_runs r SET state = 'running', started_at = now(), runner = ?, updated_at = now()
UPDATE git_ci_runs r SET state = 'running', started_at = now(), runner = ?, updated_at = now()
FROM next WHERE r.id = next.id RETURNING r.*`,
FROM next WHERE r.id = next.id RETURNING r.*`,
@@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
'use strict';
'use strict';
/**
/**
* Forge CI: a branch push by a repository's own writer queues a run; a non-member, a fork and a pull request do
* Forge CI: a branch push by a repository's own writer queues a run; a non-member, a fork and a pull request do
- * not. One run per repository, the newer push supersedes the older. The runner claims, writes a log, reports a
+ * not. One live run per branch, the newer push supersedes the older; pull request branches are claimed first. The runner claims, writes a log, reports a
* verdict and that verdict is the commit status. A run left running past its limit is reaped and reported red.
* verdict and that verdict is the commit status. A run left running past its limit is reaped and reported red.
*/
*/
const assert = require('assert');
const assert = require('assert');
@@ -156,6 +156,23 @@ const ok = (body, status = 200) => ({ ok: status >= 200 && status < 300, status,
@@ -156,6 +156,23 @@ const ok = (body, status = 200) => ({ ok: status >= 200 && status < 300, status,
assert.equal(reapedStatus.json().statuses[0].state, 'failure');
assert.equal(reapedStatus.json().statuses[0].state, 'failure');
assert.match(reapedStatus.json().statuses[0].description, /timed out after 1 minutes/);
assert.match(reapedStatus.json().statuses[0].description, /timed out after 1 minutes/);
+ // One live run per branch, and a pull request's branch is claimed before a check of main: a push to main, then
+ // one to a feature branch; the feature branch is claimed first and main's run is not superseded by it.
+ const author = { name: 'OpenVibers', email: '[email protected]' };
+ const mainHead = await t.ctx.git.commitFiles('openvibers', 'live2', { branch: 'main', base: 'main', message: 'Main again', files: [{ path: 'm.txt', content: 'm\n' }], author });
+ const mainRun = await t.ctx.ci.onGithubPush(live2.row, push(mainHead.sha, 'OpenVibers', live2.full));
+ const featureHead = await t.ctx.git.commitFiles('openvibers', 'live2', { branch: 'feature', base: 'main', message: 'A feature', files: [{ path: 'f.txt', content: 'f\n' }], author });
+ const featureRun = await t.ctx.ci.onGithubPush(live2.row, { ...push(featureHead.sha, 'OpenVibers', live2.full), ref: 'refs/heads/feature' });
+ assert.equal(featureRun.run.state, 'queued');
+ assert.equal((await t.ctx.ci.runFor(live2.row, mainRun.run.id)).state, 'queued', 'a push to another branch leaves main\'s run alone');
+ const claimedFeature = (await t.get('/api/v1/ci/runs/claim', { bearer: TOKEN, json: {} })).json();
+ assert.equal(claimedFeature.run.id, featureRun.run.id, 'the pull request branch first, though main was queued earlier');
+ const claimedMain = (await t.get('/api/v1/ci/runs/claim', { bearer: TOKEN, json: {} })).json();
+ assert.equal(claimedMain.run.id, mainRun.run.id);
+ for (const id of [claimedFeature.run.id, claimedMain.run.id]) {
+ assert.equal((await t.get(`/api/v1/ci/runs/${id}/status`, { bearer: TOKEN, json: { state: 'success' } })).status, 200);
+ }
+
// A push that lands on the forge itself: the network's own service token may run it, a person's token
// A push that lands on the forge itself: the network's own service token may run it, a person's token
// may not (the forge knows an OpenVibe account, not the GitHub login the member rule is about).
// may not (the forge knows an OpenVibe account, not the GitHub login the member rule is about).
const pkt = (line) => `${(Buffer.byteLength(line) + 4).toString(16).padStart(4, '0')}${line}`;
const pkt = (line) => `${(Buffer.byteLength(line) + 4).toString(16).padStart(4, '0')}${line}`;