The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
Close three review findings: a fail-open probe, divergence, and comments\n\nAll three are the gate failing open or failing wrong, which for a gate whose\nwhole purpose is to stop silent drift is worse than not having it.\n\n**The submodule probe walked up to the superproject (Codex P1).**\n`git -C vendor/tinymemory rev-parse --git-dir` does not answer "is this a\nchecked-out submodule". Git walks upward, so from an uninitialised — or\nmerely empty — directory it answers the SUPERPROJECT's `.git` and exits 0.\nThe probe reported "present" having checked nothing, enabling a case whose\nCLI then failed for exactly the reason the probe was meant to detect. That\nis this gate's own failure mode reproduced inside its test helper.\n\nReplaced with `--show-toplevel`, which answers the root of whichever\nrepository owns the directory: only when that root IS the directory is the\nsubmodule really there. Extracted as `toplevelProvesSubmodule` so it is\ntestable rather than living in a test-local helper, and compared through\n`realpathSync` on both sides — macOS resolves /tmp to /private/tmp, and\ncomparing a resolved path against an unresolved one is its own false\nnegative.\n\n**A divergent pin was classified as forward (Codex P2).**\n`merge-base --is-ancestor head base` exiting 1 means "head is not an\nancestor of base", which covers BOTH a genuine fast-forward and two commits\nthat have diverged — a side branch, or a submodule whose history was\nrebased. Reading the single failed query as forward let divergence through.\nDivergence drops whatever the base branch had just as surely as a rewind\ndoes; it only does it sideways, and a rewind onto a sibling is one rebase\naway from 3fd1de32e's shape.\n\nBoth directions are asked now, in `classifyMove`, and only a genuine\ndescendant is forward. A divergent move is reported as SIDEWAYS with the\ncount of base-side commits the new pin cannot reach.\n\n**A comment in `ALL` swallowed the record beneath it (CodeRabbit).**\n`parseAllList` split on commas and then filtered tokens beginning with `//`,\nso a standalone comment line and the record under it shared one token and\nboth were discarded. A dropped record reads downstream as "missing from\nPIN_MAP" — CI fails while pointing at the wrong thing entirely. Comments are\nstripped before splitting now. `ALL` carries no comments today so this was\nlatent, not live; the records it lists are individually well commented and\nthe list is where a "why is this one eager" note would naturally go.\n\n24 tests. Each fix revert-checked, and each failure names its own\nassertion: the probe on "must not read as a checked-out submodule", the\nclassifier on 'forward' where 'divergent' was expected, and the parser on\nthe deep-equal of the record list.\n
M3gA-Mindb7c1ba40f44e
diff --git a/scripts/__tests__/module-pins.test.mjs b/scripts/__tests__/module-pins.test.mjsindex dd49d04555..7af2e67903 100644--- a/scripts/__tests__/module-pins.test.mjs+++ b/scripts/__tests__/module-pins.test.mjs@@ -4,7 +4,7 @@// the real tree, including the two commits that actually shipped a regression.import assert from 'node:assert/strict';import { execFileSync, spawnSync } from 'node:child_process';-import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';import { test } from 'node:test';@@ -12,6 +12,8 @@ import { fileURLToPath } from 'node:url';import {checkPinMapCoverage,+ classifyMove,+ toplevelProvesSubmodule,classifyPin,parseAllList,parseArtifactCapabilitiesPin,@@ -32,11 +34,29 @@ const run = (cli, args = [], env = {}) =>env: { ...process.env, ...env },});-/** Is `path` a checked-out submodule? Several cases need one and must skip, not lie. */+/**+ * Is `vendor/tinymemory` really a checked-out submodule?+ *+ * NOT `rev-parse --git-dir`: git walks UPWARD, so from an uninitialised — or+ * merely empty — `vendor/tinymemory` that command happily answers the+ * SUPERPROJECT's `.git` and exits 0. The probe reported "present" having checked+ * nothing, enabling a case whose CLI then failed for precisely the reason the+ * probe was meant to detect. That is the fail-open shape this whole gate exists+ * to prevent, reproduced inside its own test helper. Raised by Codex on #5812.+ *+ * `--show-toplevel` is the honest question: it answers the root of whichever+ * repository owns that directory. Only when that root IS the submodule path is+ * the submodule genuinely checked out. Compared through `realpathSync` because+ * macOS resolves `/tmp/...` to `/private/tmp/...`.+ */function submodulesPresent() {+ const path = join(REPO_ROOT, 'vendor/tinymemory');try {- execFileSync('git', ['rev-parse', '--git-dir'], { cwd: join(REPO_ROOT, 'vendor/tinymemory'), stdio: 'ignore' });- return true;+ const top = execFileSync('git', ['-C', path, 'rev-parse', '--show-toplevel'], {+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ }).trim();+ return toplevelProvesSubmodule(realpathSync(top), realpathSync(path));} catch {return false;}@@ -289,3 +309,71 @@ test('the monotonicity gate fails when run outside a git repo rather than passinrmSync(root, { recursive: true, force: true });}});++// ── Review findings from #5812 ────────────────────────────────────────────────++test('a comment inside ALL does not swallow the record beneath it', () => {+ // CodeRabbit on #5812: splitting on commas before stripping comments puts the+ // comment and the next record in one token, and filtering tokens beginning+ // with `//` dropped both. A dropped record reads downstream as "missing from+ // PIN_MAP" — CI fails while pointing at the wrong thing.+ const src = [+ 'pub const ALL: &[ModuleRecord] = &[',+ ' // the codecs',+ ' TINYDOCS,',+ ' TINYWALLET, // lazy',+ ' // Eager, unlike the two codecs above.',+ ' TINYMEMORY,',+ '];',+ ].join('\n');+ assert.deepEqual(parseAllList(src), ['TINYDOCS', 'TINYWALLET', 'TINYMEMORY']);+});++test('a divergent pin is not forward', () => {+ // Codex on #5812: asking only "is head an ancestor of base?" reads the single+ // failed query as forward, so siblings — a side branch, or a rebased submodule+ // history — sail through. Divergence loses the base's commits exactly as a+ // rewind does, and a rewind onto a sibling is one rebase away from 14a23b994.+ assert.equal(classifyMove({ headIsAncestorOfBase: true, baseIsAncestorOfHead: false }), 'rewind');+ assert.equal(classifyMove({ headIsAncestorOfBase: false, baseIsAncestorOfHead: true }), 'forward');+ assert.equal(classifyMove({ headIsAncestorOfBase: false, baseIsAncestorOfHead: false }), 'divergent');+});++test('the submodule probe is not fooled by the superproject above it', () => {+ // Codex on #5812. `rev-parse --git-dir` walks upward and succeeds from any+ // directory inside a repository, submodule or not — so it cannot answer this.+ const root = mkdtempSync(join(tmpdir(), 'module-pins-super-'));+ try {+ execFileSync('git', ['init', '-q', root], { stdio: 'ignore' });+ const notASubmodule = join(root, 'vendor', 'tinymemory');+ mkdirSync(notASubmodule, { recursive: true });++ // The old probe: succeeds, answering the SUPERPROJECT's git dir.+ const walked = execFileSync('git', ['-C', notASubmodule, 'rev-parse', '--git-dir'], {+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ }).trim();+ assert.ok(walked.length > 0, 'precondition: --git-dir does walk up, which is why it cannot be used');++ // The probe actually used: the toplevel is the superproject, not the path,+ // so this correctly reports "not a checked-out submodule".+ const top = execFileSync('git', ['-C', notASubmodule, 'rev-parse', '--show-toplevel'], {+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ }).trim();+ assert.equal(+ toplevelProvesSubmodule(realpathSync(top), realpathSync(notASubmodule)),+ false,+ 'a directory that merely sits inside a repo must not read as a checked-out submodule',+ );++ // ...and the positive case: the superproject root IS its own toplevel.+ const superTop = execFileSync('git', ['-C', root, 'rev-parse', '--show-toplevel'], {+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ }).trim();+ assert.equal(toplevelProvesSubmodule(realpathSync(superTop), realpathSync(root)), true);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});diff --git a/scripts/ci/check-submodule-monotonic.mjs b/scripts/ci/check-submodule-monotonic.mjsindex 49162627e0..ea360b7d0f 100755--- a/scripts/ci/check-submodule-monotonic.mjs+++ b/scripts/ci/check-submodule-monotonic.mjs@@ -37,7 +37,7 @@// Defaults: origin/$GITHUB_BASE_REF (or origin/main) .. HEADimport { execFileSync } from 'node:child_process';-import { parseGitlinks, rewindDeclared } from '../lib/module-pins.mjs';+import { classifyMove, parseGitlinks, rewindDeclared } from '../lib/module-pins.mjs';// Any throw below is a check that could not be COMPLETED, which is not the same// as a check that passed. Report it as a failure with a legible message rather@@ -146,24 +146,43 @@ for (const { path, baseSha, headSha } of moved) {}if (!haveBoth) continue;- let backwards = false;+ /** `merge-base --is-ancestor` answers 0 (yes) or 1 (no); anything else is broken. */+ const isAncestor = (a, b) => {+ try {+ execFileSync('git', ['merge-base', '--is-ancestor', a, b], { cwd: path, stdio: 'ignore' });+ return true;+ } catch (error) {+ if (error.status === 1) return false;+ throw new Error(`ancestry query failed (exit ${error.status})`);+ }+ };++ // BOTH directions. Asking only "is head an ancestor of base?" and reading a+ // failed query as forward mistakes a DIVERGENT pin — head and base on sibling+ // branches, or a rebased submodule history — for a fast-forward. Divergence+ // loses the base's commits exactly as a rewind does, so it is not forward.+ let move;try {- execFileSync('git', ['merge-base', '--is-ancestor', headSha, baseSha], { cwd: path, stdio: 'ignore' });- backwards = true;+ move = classifyMove({+ headIsAncestorOfBase: isAncestor(headSha, baseSha),+ baseIsAncestorOfHead: isAncestor(baseSha, headSha),+ });} catch (error) {- // Exit 1 is the honest "not an ancestor". Anything else is a broken query.- if (error.status !== 1) {- failures.push(`${path}: ancestry query failed (exit ${error.status}) — treating as unverified.`);- continue;- }+ failures.push(`${path}: ${error.message} — treating as unverified, not as forward.`);+ continue;}- if (backwards) {+ if (move === 'rewind' || move === 'divergent') {const oldSubject = (() => { try { return run(['log', '--format=%h %ad %s', '--date=short', '-1', baseSha], path); } catch { return baseSha.slice(0, 9); } })();const newSubject = (() => { try { return run(['log', '--format=%h %ad %s', '--date=short', '-1', headSha], path); } catch { return headSha.slice(0, 9); } })();const behind = (() => { try { return run(['rev-list', '--count', `${headSha}..${baseSha}`], path); } catch { return '?'; } })();+ const headline =+ move === 'rewind'+ ? `${path} moved BACKWARDS by ${behind} commit(s).`+ : `${path} moved SIDEWAYS — the new pin and the base pin have diverged, and ` ++ `${behind} commit(s) on the base side are not reachable from it.`;failures.push(- `${path} moved BACKWARDS by ${behind} commit(s).\n` ++ `${headline}\n` +` base : ${oldSubject}\n` +` head : ${newSubject}\n` +` The new pin is an ancestor of the one on the base branch, so everything\n` +@@ -180,8 +199,9 @@ for (const { path, baseSha, headSha } of moved) {}if (failures.length > 0 && declaredRewind) {- const rewinds = failures.filter((f) => f.includes('moved BACKWARDS'));- const other = failures.filter((f) => !f.includes('moved BACKWARDS'));+ const isMove = (f) => f.includes('moved BACKWARDS') || f.includes('moved SIDEWAYS');+ const rewinds = failures.filter(isMove);+ const other = failures.filter((f) => !isMove(f));if (other.length === 0) {console.log('Submodule monotonicity check OK — backwards move(s) declared with [pin-rewind]:\n');for (const r of rewinds) console.log(` ~ ${r.split('\n')[0]}`);diff --git a/scripts/lib/module-pins.mjs b/scripts/lib/module-pins.mjsindex 82aaff6355..8d9865dad6 100644--- a/scripts/lib/module-pins.mjs+++ b/scripts/lib/module-pins.mjs@@ -4,14 +4,26 @@// git tree; the two CLIs in scripts/ci/ own the git calls and the process exit.// See scripts/ci/check-module-pins.mjs for what the gate is for.-/** The record names listed in `pub const ALL`, in order. */+/**+ * The record names listed in `pub const ALL`, in order.+ *+ * Line comments are stripped BEFORE splitting on commas, not filtered out after.+ * Splitting first puts a standalone `// …` line and the record beneath it in the+ * SAME token, so filtering tokens that begin with `//` discarded the record with+ * the comment. `ALL` carries no comments today, so this was latent rather than+ * live — but the records it lists are heavily commented individually, the list is+ * where a "why is this one eager" note would naturally go, and a dropped record+ * reads downstream as "missing from PIN_MAP": the gate would fail CI while+ * pointing at the wrong thing entirely. Raised by CodeRabbit on #5812.+ */export function parseAllList(src) {const block = src.match(/pub const ALL: &\[ModuleRecord\] = &\[([\s\S]*?)\];/);if (!block) throw new Error('registry.rs: could not find `pub const ALL`');return block[1]+ .replace(/\/\/[^\n]*/g, '').split(',').map((s) => s.trim())- .filter((s) => s.length > 0 && !s.startsWith('//'));+ .filter((s) => s.length > 0);}/** Every `const NAME: ModuleRecord = ModuleRecord { … };`, keyed by NAME. */@@ -151,3 +163,42 @@ export function parseGitlinks(lsTreeOutput) {export function rewindDeclared(text) {return /\[pin-rewind\]/i.test(text ?? '');}++/**+ * Classify a submodule pin move from BOTH ancestry answers.+ *+ * "Not an ancestor" is not the same as "forward". When the new commit and the+ * base commit are siblings — a side branch, or a submodule whose history was+ * rebased — neither is an ancestor of the other, and a check that asks only+ * `is-ancestor head base` sees its single query fail and calls the move forward.+ *+ * A divergent pin drops whatever the base branch had just as surely as a rewind+ * does; it simply does it sideways. Since the whole point of this gate is that a+ * pin must not silently lose commits, treating divergence as forward would+ * defeat it: a rewind onto a sibling — 14a23b994's shape, one rebase away —+ * would walk straight through.+ *+ * So both directions are asked and only a genuine descendant is forward.+ */+export function classifyMove({ headIsAncestorOfBase, baseIsAncestorOfHead }) {+ if (headIsAncestorOfBase) return 'rewind';+ if (baseIsAncestorOfHead) return 'forward';+ return 'divergent';+}++/**+ * Does `toplevel` prove that `path` is a checked-out submodule?+ *+ * `git -C <path> rev-parse --git-dir` cannot answer this: git walks UPWARD, so+ * from an uninitialised or merely empty `vendor/<x>` it answers the+ * SUPERPROJECT's `.git` and exits 0 — reporting "present" having checked+ * nothing. `--show-toplevel` answers the root of whichever repository owns the+ * directory, and only when that root IS the directory is it a real checkout.+ *+ * Both sides must already be realpath-resolved by the caller: macOS resolves+ * `/tmp/...` to `/private/tmp/...`, and comparing one resolved path against one+ * unresolved path is its own quiet false negative.+ */+export function toplevelProvesSubmodule(resolvedToplevel, resolvedPath) {+ return Boolean(resolvedToplevel) && resolvedToplevel === resolvedPath;+}