Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat(ci): auto-apply triage labels on PR open and review (2/5) (#3858)

LearningCircuit8cc0184cbee7
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index cedeb030ea..c7f9b7f460 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -2,7 +2,9 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
# Global owners - these people are automatically requested for review on all PRs
-# and their approval is required for merging to protected branches
+# and their approval is required for merging to protected branches.
+# NOTE: this list is mirrored in .github/workflows/pr-triage.yml (CODEOWNERS const).
+# Keep both in sync when the maintainer roster changes.
* @LearningCircuit @hashedviking @djpetti
# Critical infrastructure and release files require maintainer approval
diff --git a/.github/workflows/pr-triage.yml b/.github/workflows/pr-triage.yml
new file mode 100644
index 0000000000..0f8479d4f4
--- /dev/null
+++ b/.github/workflows/pr-triage.yml
@@ -0,0 +1,166 @@
+name: PR triage labels
+
+# Auto-applies author-class labels at PR open and toggles lifecycle labels
+# on review/synchronize events. Labels are defined in .github/labels.yml
+# and synced by .github/workflows/labels-sync.yml.
+#
+# Uses pull_request (not pull_request_target) — fork PRs get a read-only
+# token, so label calls return 403. The script catches 403 and continues
+# so fork PRs don't show a failing check; maintainers can apply labels
+# manually for fork PRs that need them. We accept the no-op behavior on
+# forks vs the security cost of pull_request_target running with secrets
+# on fork code.
+#
+# CODEOWNERS list below is mirrored in .github/CODEOWNERS global owners
+# (line 6) — keep both in sync when the maintainer roster changes.
+
+on:
+ pull_request:
+ types: [opened, synchronize, ready_for_review]
+ pull_request_review:
+ types: [submitted, dismissed]
+
+# No concurrency group — intentionally omitted.
+# Previous attempt (#3554, reverted #3599) used cancel-in-progress which
+# killed in-progress PR runs before they produced useful results. Race
+# between synchronize and pull_request_review can produce transient
+# label flapping in rare cases; maintainers can correct manually.
+
+permissions: {} # Minimal top-level for OSSF Scorecard Token-Permissions
+
+jobs:
+ triage:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ permissions:
+ issues: write # PR labels live on the underlying issue resource
+ steps:
+ - name: Harden the runner (Audit all outbound calls)
+ uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
+ with:
+ egress-policy: audit
+
+ - name: Apply triage labels
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ // Keep CODEOWNERS list in sync with .github/CODEOWNERS line 6.
+ const CODEOWNERS = ['LearningCircuit', 'hashedviking', 'djpetti'];
+ // Known AI-bot accounts that don't carry the [bot] suffix.
+ const KNOWN_BOTS = ['moltenbot000', 'mseep-ai', 'Nexus-Digital-Automations'];
+
+ const pr = context.payload.pull_request;
+ const issueNumber = pr.number;
+ const author = pr.user.login;
+ const association = pr.author_association;
+ const isBot = author.endsWith('[bot]') || KNOWN_BOTS.includes(author);
+ const isInternal = ['OWNER', 'MEMBER', 'COLLABORATOR'].includes(association);
+
+ // 403 on label calls is the expected outcome for fork PRs —
+ // pull_request gives forks a read-only token by design. We
+ // log and continue so the workflow run stays green and a
+ // maintainer can apply labels manually instead of seeing
+ // a red check on every fork contribution.
+ const isReadOnlyTokenError = (err) => {
+ if (err.status !== 403) return false;
+ console.log(`Label call returned 403 (read-only token, likely a fork PR). Skipping.`);
+ return true;
+ };
+
+ const addLabels = async (labels) => {
+ if (!labels.length) return;
+ try {
+ await github.rest.issues.addLabels({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issueNumber,
+ labels,
+ });
+ } catch (err) {
+ if (!isReadOnlyTokenError(err)) throw err;
+ }
+ };
+
+ const removeLabel = async (name) => {
+ try {
+ await github.rest.issues.removeLabel({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issueNumber,
+ name,
+ });
+ } catch (err) {
+ if (err.status === 404) return; // label wasn't applied
+ if (!isReadOnlyTokenError(err)) throw err;
+ }
+ };
+
+ const action = context.payload.action;
+ const eventName = context.eventName;
+
+ if (eventName === 'pull_request' && action === 'opened') {
+ const labels = [];
+ if (isBot) labels.push('bot');
+ if (!isInternal && !isBot) labels.push('external-contributor');
+ if (association === 'FIRST_TIME_CONTRIBUTOR') labels.push('first-time-contributor');
+ if (!isInternal) labels.push('needs-codeowner-review');
+ await addLabels(labels);
+ return;
+ }
+
+ if (eventName === 'pull_request' && (action === 'synchronize' || action === 'ready_for_review')) {
+ const current = pr.labels.map((l) => l.name);
+ if (current.includes('awaiting-author')) {
+ await removeLabel('awaiting-author');
+ await addLabels(['awaiting-codeowner']);
+ }
+ return;
+ }
+
+ if (eventName === 'pull_request_review' && action === 'submitted') {
+ const review = context.payload.review;
+ const reviewer = review.user.login;
+ // Strict CODEOWNERS-only check. The hardcoded list above must
+ // mirror .github/CODEOWNERS line 6. We deliberately do NOT
+ // accept any OWNER/MEMBER/COLLABORATOR association as a
+ // codeowner: branch protection here may later adopt
+ // require_code_owner_reviews=true, at which point clearing
+ // needs-codeowner-review on a non-codeowner MEMBER review
+ // would be a security-relevant mislabel.
+ if (!CODEOWNERS.includes(reviewer)) return;
+
+ if (review.state === 'approved') {
+ await removeLabel('needs-codeowner-review');
+ await removeLabel('awaiting-codeowner');
+ // Also clear awaiting-author: a codeowner can resolve
+ // their own changes_requested review by approving without
+ // an intervening synchronize (e.g., the author convinced
+ // them via comments).
+ await removeLabel('awaiting-author');
+ } else if (review.state === 'changes_requested') {
+ await removeLabel('needs-codeowner-review');
+ await removeLabel('awaiting-codeowner');
+ await addLabels(['awaiting-author']);
+ }
+ // 'commented' → no-op.
+ return;
+ }
+
+ if (eventName === 'pull_request_review' && action === 'dismissed') {
+ // GitHub sets review.state to "dismissed" on this event — the
+ // original state is not preserved (github/docs#20216). Use the
+ // awaiting-author label as the discriminator: it's only set by
+ // a codeowner's changes_requested review, so its presence is
+ // proof the dismissal is the one we care about. Dismissals of
+ // approval/comment reviews are naturally no-ops because
+ // awaiting-author won't be present.
+ const review = context.payload.review;
+ if (!CODEOWNERS.includes(review.user.login)) return;
+
+ const current = pr.labels.map((l) => l.name);
+ if (current.includes('awaiting-author')) {
+ await removeLabel('awaiting-author');
+ await addLabels(['needs-codeowner-review']);
+ }
+ return;
+ }
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 53eb58fc56..90ad1470d2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -256,6 +256,13 @@ repos:
files: ^(package\.json|src/local_deep_research/__version__\.py)$
pass_filenames: false
description: "Ensure package.json version matches src/local_deep_research/__version__.py"
+ - id: check-codeowners-sync
+ name: Check CODEOWNERS Sync
+ entry: .pre-commit-hooks/check-codeowners-sync.py
+ language: script
+ files: ^\.github/(CODEOWNERS|workflows/pr-triage\.yml)$
+ pass_filenames: false
+ description: "Ensure pr-triage.yml CODEOWNERS const matches .github/CODEOWNERS global owners"
- id: check-golden-master-settings
name: Check Golden Master Settings Sync
entry: .pre-commit-hooks/check-golden-master-settings.py
diff --git a/.pre-commit-hooks/check-codeowners-sync.py b/.pre-commit-hooks/check-codeowners-sync.py
new file mode 100755
index 0000000000..7c7eb7b86d
--- /dev/null
+++ b/.pre-commit-hooks/check-codeowners-sync.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+"""Check that the hardcoded CODEOWNERS list in pr-triage.yml matches
+the global owners line in .github/CODEOWNERS."""
+
+import re
+import sys
+from pathlib import Path
+
+
+def main():
+ root = Path(__file__).parent.parent
+ codeowners_file = root / ".github" / "CODEOWNERS"
+ workflow_file = root / ".github" / "workflows" / "pr-triage.yml"
+
+ if not codeowners_file.exists() or not workflow_file.exists():
+ return 0
+
+ try:
+ codeowners_text = codeowners_file.read_text()
+ workflow_text = workflow_file.read_text()
+ except OSError as e:
+ print(f"ERROR: Could not read file: {e}")
+ return 1
+
+ global_owners = None
+ for line in codeowners_text.splitlines():
+ stripped = line.strip()
+ if not stripped or stripped.startswith("#"):
+ continue
+ if stripped.startswith("* "):
+ global_owners = re.findall(r"@([A-Za-z0-9][A-Za-z0-9-]*)", stripped)
+ break
+
+ if not global_owners:
+ print(
+ "ERROR: Could not find a '* @owner...' global owners line "
+ "in .github/CODEOWNERS"
+ )
+ return 1
+
+ match = re.search(
+ r"const\s+CODEOWNERS\s*=\s*\[([^\]]*)\]",
+ workflow_text,
+ )
+ if match is None:
+ print(
+ "ERROR: Could not find 'const CODEOWNERS = [...]' "
+ "in .github/workflows/pr-triage.yml"
+ )
+ return 1
+
+ js_owners = re.findall(
+ r"['\"]([A-Za-z0-9][A-Za-z0-9-]*)['\"]", match.group(1)
+ )
+
+ co_set = {u.lower() for u in global_owners}
+ js_set = {u.lower() for u in js_owners}
+
+ if co_set != js_set:
+ print("ERROR: CODEOWNERS list mismatch between files.")
+ print(f" .github/CODEOWNERS global owners: {sorted(global_owners)}")
+ print(f" pr-triage.yml CODEOWNERS const: {sorted(js_owners)}")
+ only_in_co = co_set - js_set
+ only_in_js = js_set - co_set
+ if only_in_co:
+ print(f" Only in CODEOWNERS: {sorted(only_in_co)}")
+ if only_in_js:
+ print(f" Only in pr-triage.yml: {sorted(only_in_js)}")
+ print(
+ "Update both lists so they share the same maintainers "
+ "(comments in each file note this requirement)."
+ )
+ return 1
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())