AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(cla): preserve self-signatures across maintainer base merges
xerj-org476690869200
diff --git a/.github/workflows/cla-field-report-exempt.yml b/.github/workflows/cla-field-report-exempt.ymlindex 9c8ae6f07..d2f326a53 100644--- a/.github/workflows/cla-field-report-exempt.yml+++ b/.github/workflows/cla-field-report-exempt.yml@@ -6,8 +6,11 @@ name: CLA field-report exemption# 1. A field-report-only PR: its ENTIRE diff is agent field reports — markdown# files under user-feedback/16-agent-field-reports/.# 2. A self-CLA-signature PR: its ENTIRE diff is `.contributors` gaining ONE-# entry, the PR author's own login, with every commit authored by that-# author (scripts/check_cla_coauthors.py --is-self-cla-signature).+# entry, the PR author's own login, with a commit by that author. Other+# commits may only merge the pinned base (or an ancestor) into the branch,+# authored by someone already signed at the merge base. This preserves the+# original signature when a maintainer resolves an append conflict+# (scripts/check_cla_coauthors.py --is-self-cla-signature).## Why a separate job at all: `verification/cla-signed` is normally posted by the# external cla-bot GitHub App, which matches commit AUTHORS against .contributorsdiff --git a/scripts/check_cla_coauthors.py b/scripts/check_cla_coauthors.pyindex ea72760f2..f8345a3b8 100755--- a/scripts/check_cla_coauthors.py+++ b/scripts/check_cla_coauthors.py@@ -47,7 +47,8 @@ Usage (CI):check_cla_coauthors.py --is-self-cla-signature --pr <n> --base-sha <sha> --head-sha <sha>Exits 0 iff the PR, evaluated at exactly --head-sha, is a CLA signature byits own author: the only change is `.contributors` gaining the author's own- login, every commit is authored by the PR author, and no Co-authored-by+ login, the PR author has a commit, and all other commits are base-branch+ merges by already-signed authors. No Co-authored-bytrailer names an unsigned contributor. Everything (changed files, commits,both `.contributors` versions) is read pinned to --base-sha...--head-sha, sothe status the CI job posts on --head-sha describes that commit and no@@ -185,7 +186,9 @@ def is_self_cla_signature(SHA being judged.base_contributors / head_contributors: parsed `.contributors` at the mergebase and at the head SHA.- commits: [{"sha", "message", "author_login"}] — every commit in the PR.+ commits: [{"sha", "message", "author_login", "merges_base"?}] — every+ commit in the PR. `merges_base` is set only after the API confirms that+ a two-parent commit's second parent is an ancestor of the pinned base.Rejects a PR that:- changes any file other than `.contributors`, or reaches it by a rename@@ -195,7 +198,8 @@ def is_self_cla_signature(- adds anything other than exactly ONE entry, that entry being a validGitHub login equal (ASCII case-insensitively) to the PR author;- comes from an author who is already signed (nothing to sign);- - has no commits, or any commit not authored by the PR author; or+ - has no commit authored by the PR author, or any other commit except+ a proven base-branch merge by an author signed at the merge base; or- carries a Co-authored-by trailer that is unresolvable or unsigned."""if not is_contributors_only_change(files):@@ -230,10 +234,18 @@ def is_self_cla_signature(if not commits or len(commits) > MAX_SIGNATURE_COMMITS:return False+ signed_base = {c.lower() for c in base_contributors}+ has_own_commit = Falsefor commit in commits:login = commit.get("author_login")- if not _is_login(login) or login.lower() != author:+ if not _is_login(login):return False+ if login.lower() == author:+ has_own_commit = True+ elif not (login.lower() in signed_base and commit.get("merges_base") is True):+ return False+ if not has_own_commit:+ return Falseif check_commits(commits, head_contributors, resolve):return Falsereturn True@@ -341,6 +353,31 @@ def _fetch_contributors_at(repo, sha):_SHA_RE = re.compile(r"^[0-9a-f]{40}$")+def _merges_pinned_base(repo, commit, base_sha):+ """Prove a normal merge of the base branch into the contributor branch.++ A message saying 'Merge main' or two parents alone proves nothing. Read+ the immutable second parent's ancestry relative to the pinned base. An+ unrelated branch, an octopus merge, missing data or an API error refuses+ the exception. The first-parent signature stays in the checked PR range.+ """+ parents = commit.get("parents")+ if not isinstance(parents, list) or len(parents) != 2:+ return False+ if not all(isinstance(p, dict) and isinstance(p.get("sha"), str)+ and _SHA_RE.fullmatch(p["sha"]) for p in parents):+ return False+ parent = parents[1]["sha"]+ if parent == base_sha:+ return True+ try:+ ancestry = _gh_api_one(f"repos/{repo}/compare/{parent}...{base_sha}")+ return (ancestry.get("status") in ("ahead", "identical")+ and (ancestry.get("merge_base_commit") or {}).get("sha") == parent)+ except (subprocess.CalledProcessError, AttributeError, KeyError, ValueError, TypeError):+ return False++def _self_cla_signature_main(args):"""--is-self-cla-signature: judge the PR at exactly args.head_sha."""if args.pr is None or not args.base_sha or not args.head_sha:@@ -366,7 +403,8 @@ def _self_cla_signature_main(args):f"repos/{args.repo}/compare/{args.base_sha}...{args.head_sha}")raw_commits = cmp.get("commits") or []- if cmp.get("total_commits") != len(raw_commits):+ if (cmp.get("total_commits") != len(raw_commits)+ or len(raw_commits) > MAX_SIGNATURE_COMMITS):return 1 # truncated list: cannot prove every commit was checkedmerge_base = (cmp.get("merge_base_commit") or {}).get("sha") or ""if not _SHA_RE.match(merge_base):@@ -377,6 +415,10 @@ def _self_cla_signature_main(args):"sha": c["sha"],"message": c["commit"]["message"],"author_login": (c.get("author") or {}).get("login"),+ "merges_base": (+ ((c.get("author") or {}).get("login") or "").lower() != pr_author.lower()+ and _merges_pinned_base(args.repo, c, args.base_sha)+ ),}for c in raw_commits]diff --git a/scripts/test_cla_coauthors.py b/scripts/test_cla_coauthors.pyindex d6efe7ee2..2d1a6c3e8 100755--- a/scripts/test_cla_coauthors.py+++ b/scripts/test_cla_coauthors.py@@ -16,6 +16,7 @@ import contextlibimport ioimport pathlibimport re+import subprocessimport sysimport unittestfrom unittest import mock@@ -231,7 +232,8 @@ class SelfClaSignatureExitCodeTests(unittest.TestCase):BASE_SHA = "a" * 40HEAD_SHA = "b" * 40- def _run(self, files, head_contributors, broken_base=False):+ def _run(self, files, head_contributors, broken_base=False, merge_parent=None,+ ancestry=None):base_contributors = None if broken_base else ["xerj-org", "dependabot[bot]"]pr = {"head": {"sha": self.HEAD_SHA},@@ -250,11 +252,19 @@ class SelfClaSignatureExitCodeTests(unittest.TestCase):],"files": files,}+ if merge_parent is not None:+ cmp["commits"].append({+ "sha": self.HEAD_SHA,+ "commit": {"message": "Merge main"},+ "author": {"login": "xerj-org"},+ "parents": [{"sha": "c" * 40}, {"sha": merge_parent}],+ })+ cmp["total_commits"] += 1args = argparse.Namespace(pr=1, base_sha=self.BASE_SHA, head_sha=self.HEAD_SHA, repo="o/r")with mock.patch.object(- check_cla_coauthors, "_gh_api_one", side_effect=[pr, cmp]+ check_cla_coauthors, "_gh_api_one", side_effect=[pr, cmp, ancestry]), mock.patch.object(check_cla_coauthors,"_fetch_contributors_at",@@ -281,6 +291,17 @@ class SelfClaSignatureExitCodeTests(unittest.TestCase):rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"])self.assertEqual(rc, 0)+ def test_signature_with_maintainer_base_merge_exits_0(self):+ rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"],+ merge_parent=self.BASE_SHA)+ self.assertEqual(rc, 0)++ def test_foreign_branch_merge_does_not_get_a_success_status(self):+ rc, _ = self._run([CONTRIB], ["xerj-org", "dependabot[bot]", "todie"],+ merge_parent="d" * 40,+ ancestry={"status": "diverged"})+ self.assertEqual(rc, 1)+def test_a_broken_base_file_is_not_this_pr_fault(self):# The merge base is `main`'s own file: a defect there is not something# the contributor's diff can repair, so the job must not fail on it.@@ -293,6 +314,50 @@ class SelfClaSignatureExitCodeTests(unittest.TestCase):self.assertNotIn("::error::", err)+class BaseMergeProofTests(unittest.TestCase):+ BASE = "a" * 40+ PARENT = "b" * 40+ COMMIT = {"parents": [{"sha": "c" * 40}, {"sha": PARENT}]}++ def test_exact_pinned_base_needs_no_lookup(self):+ with mock.patch.object(check_cla_coauthors, "_gh_api_one") as api:+ self.assertTrue(check_cla_coauthors._merges_pinned_base(+ "o/r", self.COMMIT, self.PARENT))+ api.assert_not_called()++ def test_ancestor_is_proven_with_pinned_comparison(self):+ result = {"status": "ahead", "merge_base_commit": {"sha": self.PARENT}}+ with mock.patch.object(check_cla_coauthors, "_gh_api_one", return_value=result) as api:+ self.assertTrue(check_cla_coauthors._merges_pinned_base(+ "o/r", self.COMMIT, self.BASE))+ api.assert_called_once_with(f"repos/o/r/compare/{self.PARENT}...{self.BASE}")++ def test_non_ancestor_and_missing_proof_refuse(self):+ for result in (None, {}, {"status": "ahead"},+ {"status": "ahead", "merge_base_commit": {"sha": self.BASE}},+ {"status": "diverged", "merge_base_commit": {"sha": self.PARENT}},+ {"status": "behind", "merge_base_commit": {"sha": self.PARENT}}):+ with self.subTest(result=result), mock.patch.object(+ check_cla_coauthors, "_gh_api_one", return_value=result):+ self.assertFalse(check_cla_coauthors._merges_pinned_base(+ "o/r", self.COMMIT, self.BASE))++ def test_bad_parent_metadata_never_gets_an_exception(self):+ for parents in (None, [], [{"sha": self.PARENT}], self.COMMIT["parents"] * 2,+ [None, {"sha": self.BASE}], [{"sha": self.BASE}, {"sha": "main"}]):+ with self.subTest(parents=parents), mock.patch.object(+ check_cla_coauthors, "_gh_api_one") as api:+ self.assertFalse(check_cla_coauthors._merges_pinned_base(+ "o/r", {"parents": parents}, self.BASE))+ api.assert_not_called()++ def test_lookup_error_refuses(self):+ with mock.patch.object(check_cla_coauthors, "_gh_api_one",+ side_effect=subprocess.CalledProcessError(1, "gh")):+ self.assertFalse(check_cla_coauthors._merges_pinned_base(+ "o/r", self.COMMIT, self.BASE))++class ContributorsOnlyChangeTests(unittest.TestCase):"""The CLI separates "a signature PR whose file is broken" (exit 2, loud)from "some other PR" (exit 1, cla-bot's call). That split is this shape@@ -540,6 +605,36 @@ class SelfClaSignatureTests(unittest.TestCase):def test_too_many_commits_is_rejected(self):self.assertFalse(self._ok(commits=self.COMMITS * 21))+ def test_signed_base_merge_preserves_the_contributors_signature(self):+ merge = dict(sha="deadbeef", message="Merge main to resolve signature conflict",+ author_login="xerj-org", merges_base=True)+ self.assertTrue(self._ok(commits=self.COMMITS + [merge]))++ def test_base_merge_cannot_replace_the_contributors_own_commit(self):+ merge = dict(sha="deadbeef", message="Merge main",+ author_login="xerj-org", merges_base=True)+ self.assertFalse(self._ok(commits=[merge]))++ def test_base_merge_exception_still_requires_a_signed_author(self):+ merge = dict(sha="deadbeef", message="Merge main",+ author_login="unsigned", merges_base=True)+ self.assertFalse(self._ok(commits=self.COMMITS + [merge]))++ def test_signed_author_without_proven_base_merge_is_rejected(self):+ merge = dict(sha="deadbeef", message="Merge main",+ author_login="xerj-org")+ for proof in (None, False, "true", 1):+ self.assertFalse(self._ok(commits=self.COMMITS + [dict(merge, merges_base=proof)]))++ def test_base_merge_does_not_exempt_mixed_diff_or_unsigned_trailers(self):+ merge = dict(sha="deadbeef", message="Merge main",+ author_login="xerj-org", merges_base=True)+ self.assertFalse(self._ok(+ commits=self.COMMITS + [merge],+ files=[CONTRIB, {"filename": "x.rs", "status": "modified"}]))+ merge["message"] += "\n\nCo-authored-by: Unsigned <[email protected]>"+ self.assertFalse(self._ok(commits=self.COMMITS + [merge]))+def test_invalid_pr_author_is_rejected(self):self.assertFalse(self._ok(pr_author=""))self.assertFalse(self._ok(pr_author="todie[bot]",