From ce713d98ec556abf29cde32100268642160344a2 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Mon, 17 Aug 2026 14:16:56 +0900 Subject: [PATCH] feat(automation): run pg-llm-batch hourly NVIDIA NIM review repair Add a thin minute-1 caller for ContextualWisdomLab/pg-llm-batch protected main so binder, receipt, and reconcile PRs receive bounded OpenCode + NVIDIA NIM repair. Keep the reusable scheduler product-neutral; bind NVIDIA_NIM_API_KEY on the worker only, never COPILOT_GITHUB_TOKEN. --- .../hourly-nvidia-nim-review-repair.yml | 7 + .../pg-llm-batch-hourly-review-repair.yml | 34 ++++ docs/automation/hourly-review-repair.md | 2 + .../pg-llm-batch-hourly-review-caller.md | 143 +++++++++++++++ .../test_pg_llm_batch_hourly_review_caller.py | 171 ++++++++++++++++++ 5 files changed, 357 insertions(+) create mode 100644 .github/workflows/pg-llm-batch-hourly-review-repair.yml create mode 100644 docs/doctoring/pg-llm-batch-hourly-review-caller.md create mode 100644 tests/test_pg_llm_batch_hourly_review_caller.py diff --git a/.github/workflows/hourly-nvidia-nim-review-repair.yml b/.github/workflows/hourly-nvidia-nim-review-repair.yml index 702942708..4c0a6aee1 100644 --- a/.github/workflows/hourly-nvidia-nim-review-repair.yml +++ b/.github/workflows/hourly-nvidia-nim-review-repair.yml @@ -13,6 +13,7 @@ on: - .github/workflows/github-hourly-review-repair.yml - .github/workflows/governance-risk-compliance-hourly-review-repair.yml - .github/workflows/hourly-nvidia-nim-review-repair.yml + - .github/workflows/pg-llm-batch-hourly-review-repair.yml - .github/workflows/nonnest2-hourly-review-repair.yml - .github/workflows/originweave-hourly-review-repair.yml - .github/workflows/quarantine-sandbox-hourly-review-repair.yml @@ -27,6 +28,7 @@ on: - tests/test_nonnest2_hourly_review_caller.py - tests/test_originweave_hourly_review_caller.py - tests/test_quarantine_sandbox_hourly_review_caller.py + - tests/test_pg_llm_batch_hourly_review_caller.py - tests/test_hourly_autofix_context_quality_gate.py - tests/test_pr_review_conflict_scope.py - tests/test_pr_review_conflict_scope_control_files.py @@ -51,6 +53,7 @@ on: - docs/doctoring/nonnest2-hourly-review-caller.md - docs/doctoring/originweave-hourly-review-caller.md - docs/doctoring/quarantine-sandbox-hourly-review-caller.md + - docs/doctoring/pg-llm-batch-hourly-review-caller.md push: paths: - .github/workflows/pr-review-fix-scheduler.yml @@ -63,6 +66,7 @@ on: - .github/workflows/github-hourly-review-repair.yml - .github/workflows/governance-risk-compliance-hourly-review-repair.yml - .github/workflows/hourly-nvidia-nim-review-repair.yml + - .github/workflows/pg-llm-batch-hourly-review-repair.yml - .github/workflows/nonnest2-hourly-review-repair.yml - .github/workflows/originweave-hourly-review-repair.yml - .github/workflows/quarantine-sandbox-hourly-review-repair.yml @@ -77,6 +81,7 @@ on: - tests/test_nonnest2_hourly_review_caller.py - tests/test_originweave_hourly_review_caller.py - tests/test_quarantine_sandbox_hourly_review_caller.py + - tests/test_pg_llm_batch_hourly_review_caller.py - tests/test_hourly_autofix_context_quality_gate.py - tests/test_pr_review_conflict_scope.py - tests/test_pr_review_conflict_scope_control_files.py @@ -101,6 +106,7 @@ on: - docs/doctoring/nonnest2-hourly-review-caller.md - docs/doctoring/originweave-hourly-review-caller.md - docs/doctoring/quarantine-sandbox-hourly-review-caller.md + - docs/doctoring/pg-llm-batch-hourly-review-caller.md permissions: contents: read @@ -157,6 +163,7 @@ jobs: tests/test_nonnest2_hourly_review_caller.py \ tests/test_originweave_hourly_review_caller.py \ tests/test_quarantine_sandbox_hourly_review_caller.py \ + tests/test_pg_llm_batch_hourly_review_caller.py \ tests/test_pr_review_conflict_scope_control_files.py \ tests/test_hourly_autofix_context_quality_gate.py \ tests/test_pr_review_conflict_scope_git_executable.py \ diff --git a/.github/workflows/pg-llm-batch-hourly-review-repair.yml b/.github/workflows/pg-llm-batch-hourly-review-repair.yml new file mode 100644 index 000000000..cc30e0a71 --- /dev/null +++ b/.github/workflows/pg-llm-batch-hourly-review-repair.yml @@ -0,0 +1,34 @@ +name: pg-llm-batch Hourly Review Repair + +on: + schedule: + # Minute 1 avoids Clearfolio (23), DiskSage (37), fast-mlsirm (49), + # BandScope (53), naruon (11), Inkspan (47), orchestrator (17), + # Wardnet (7), codec-carver (5), pg-erd-cloud (13), Keyverse (29), + # noema (19), Scopeweave (31), Appguardrail (41), newsdom-api (43), + # and semantic-data-portal (59). + - cron: "1 * * * *" + +concurrency: + group: pg-llm-batch-hourly-review-repair + # A later heartbeat must not cancel in-flight batch-receipt RCA. + cancel-in-progress: false + +permissions: + contents: read + +jobs: + dispatch-review-repair: + permissions: + contents: read + id-token: write + uses: ./.github/workflows/pr-review-fix-scheduler.yml + with: + target_repository: ContextualWisdomLab/pg-llm-batch + base_branch: main + max_prs: "50" + max_dispatches: "1" + retry_hours: "2" + secrets: + PR_REVIEW_MERGE_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN }} + OPENCODE_APPROVE_TOKEN: ${{ secrets.OPENCODE_APPROVE_TOKEN }} diff --git a/docs/automation/hourly-review-repair.md b/docs/automation/hourly-review-repair.md index 7f15e42c3..ccdaaa1c5 100644 --- a/docs/automation/hourly-review-repair.md +++ b/docs/automation/hourly-review-repair.md @@ -5,6 +5,8 @@ engine**. - `clearfolio-hourly-review-repair.yml` owns Clearfolio's heartbeat at minute 23 of every hour. +- `pg-llm-batch-hourly-review-repair.yml` owns the batch-engine heartbeat at + minute 1 of every hour. - `pr-review-fix-scheduler.yml` is the reusable, product-neutral scheduler module. It has no product-specific timer and can be called by naruon, contextual-orchestrator, Inkspan, or another CWL service with an explicit diff --git a/docs/doctoring/pg-llm-batch-hourly-review-caller.md b/docs/doctoring/pg-llm-batch-hourly-review-caller.md new file mode 100644 index 000000000..615af3037 --- /dev/null +++ b/docs/doctoring/pg-llm-batch-hourly-review-caller.md @@ -0,0 +1,143 @@ +# pg-llm-batch hourly review-repair caller + +검토 기준일: **2026-08-17** + +## Decision + +ContextualWisdomLab operates one protected hourly caller for +`ContextualWisdomLab/pg-llm-batch` (standalone Apache-2.0 batch engine +with Rust pg_tiktoken token counting and Postgres submit/poll/retrieve). +The caller runs at minute 1, delegates to the product-neutral central +review-fix scheduler, inspects at most 50 open pull requests targeting +protected `main`, and dispatches at most one bounded repair per +heartbeat. + +A paying buyer of the batch engine would feel live pg-llm-batch pull +requests stalling while hourly NVIDIA NIM repair scanned only +Clearfolio, DiskSage, and fast-mlsirm. Live heads such as +ContextualWisdomLab/pg-llm-batch#227 (inspect provenance on binder +evidence), ContextualWisdomLab/pg-llm-batch#222 (collision-free +registry-audit), ContextualWisdomLab/pg-llm-batch#221 (receipt +re-inspection), and ContextualWisdomLab/pg-llm-batch#194 (atomic +streamed-result application) target `main` and never enter those other +callers. + +The caller does not implement review or mutation logic itself. +pg-llm-batch remains standalone; contextual-orchestrator routes BATCH +traffic into it without owning its binder, receipt, or reconcile +validators. Privileged automation stays in `ContextualWisdomLab/.github`. + +## Root-cause analysis and remediation feasibility + +The reusable worker performs exact-head root-cause analysis and tests +remediation feasibility before it edits. The reusable worker must: + +1. Refetch the exact live head, base, reviews, checks, changed paths, and + writer state. +2. Establish the causal chain rather than repeat the terminal symptom. +3. Enumerate materially distinct minimal remedies. +4. Reject remedies that lack writer authority, cross sealed paths, require + unavailable credentials or protected-setting changes, violate stack + order, cannot be verified, or do not alter the diagnosed cause. +5. Dispatch at most one feasible repair. Otherwise leave the tree + unchanged. + +A queued or pending check remains a merge blocker but is not itself a +code finding. The independent non-author approval remains an external +authorization gate and is never synthesized by the repair worker. The +worker cannot approve, merge, release, resolve review findings by +inference, change protection, or manufacture passing checks. + +## Cadence and concurrency + +The caller uses a single concurrency group and `cancel-in-progress: false`. +This preserves an in-flight bounded RCA instead of discarding binder or +receipt evidence when the next hourly heartbeat arrives. The reusable +scheduler cancels only its own superseded short queue scan. + +The caller sets a **two-hour same-head retry floor**. Central OpenCode and +NVIDIA NIM work, plus token-count or reconcile analysis, can +legitimately approach two hours. An hourly redispatch of the same +unchanged head would create duplicate writer pressure rather than faster +remediation. + +GitHub scheduled workflows can be delayed under load and execute only +from the default branch. The cron expression is a heartbeat, not a +real-time SLA. + +## Credential and model boundary + +The caller keeps workflow `GITHUB_TOKEN` at `contents: read` and grants +the reusable job `id-token: write` so the central scheduler can mint the +OpenCode GitHub App token from GitHub OIDC when the mapped PAT is absent +(GitHub, n.d.-c). It maps only `PR_REVIEW_MERGE_TOKEN` and +`OPENCODE_APPROVE_TOKEN`. It never uses `secrets: inherit`, receives +`NVIDIA_NIM_API_KEY`, or introduces `COPILOT_GITHUB_TOKEN`. CWE-250 +forbids executing the caller with write or model privileges it does not +need (MITRE, 2026). + +Model execution remains inside the central worker. The model credential +is the GitHub Secret `NVIDIA_NIM_API_KEY`; the caller does not receive or +forward it. + +Before protected-main activation, the repository variable +`OPENCODE_REPOSITORY_DISPATCH_TARGETS` must contain the exact +`ContextualWisdomLab/pg-llm-batch` target. Missing or mismatched +configuration fails before mutation credential materialization. + +## Security, standalone operation, and modularity + +The caller adds no pg-llm-batch runtime dependency, database object, +network endpoint, tenant authority, or product credential. pg-llm-batch +continues to run as a standalone batch engine. Contextual-orchestrator +and other CWL services may route BATCH jobs into it, but they cannot +weaken its exact-head, approval, or security gates. + +## Verification and rollback + +Machine-checkable contracts require the exact target/base, minute 1 +cadence, non-cancelling single-flight group, one dispatch, two-hour +retry floor, explicit secret mapping, read-only contents plus job-scoped +`id-token: write`, focused path-filter coverage, and absence of model or +Copilot credentials. Independent `pull_request`, `push`, and `compileall` +path blocks must each name the caller, doctoring, or contract they own. + +After source integration, closure requires a scheduled or manual +protected-main consumer run proving the exact pg-llm-batch repository +and `main` base. Source checks alone are not +protected-main operational acceptance. Merge still requires zero +unresolved valid findings and a qualifying independent non-author +approval. + +Rollback removes the pg-llm-batch caller, its focused test, doctoring, +and central path-filter/documentation entries. It must not remove +scheduler dispatch validation or affect independent product callers. + +## APA 7th references + +GitHub, Inc. (n.d.-a). *Events that trigger workflows*. GitHub Docs. +Retrieved August 17, 2026, from +https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule + +GitHub, Inc. (n.d.-b). *Reuse workflows*. GitHub Docs. Retrieved August +17, 2026, from +https://docs.github.com/en/actions/how-tos/sharing-automations/reuse-workflows + +GitHub, Inc. (n.d.-c). *Automatic token authentication*. GitHub Docs. +Retrieved August 17, 2026, from +https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token + +MITRE. (2026). *CWE-250: Execution with unnecessary privileges*. +https://cwe.mitre.org/data/definitions/250.html + +National Institute of Standards and Technology. (2022). *Secure software +development framework (SSDF) version 1.1: Recommendations for mitigating +the risk of software vulnerabilities* (NIST Special Publication 800-218). +https://doi.org/10.6028/NIST.SP.800-218 + +NVIDIA. (n.d.). *NVIDIA NIM for large language models documentation*. +Retrieved August 17, 2026, from +https://docs.nvidia.com/nim/large-language-models/latest/ + +OpenCode. (n.d.). *OpenCode documentation*. Retrieved August 17, 2026, +from https://opencode.ai/docs/ diff --git a/tests/test_pg_llm_batch_hourly_review_caller.py b/tests/test_pg_llm_batch_hourly_review_caller.py new file mode 100644 index 000000000..b5f77a143 --- /dev/null +++ b/tests/test_pg_llm_batch_hourly_review_caller.py @@ -0,0 +1,171 @@ +"""Contract tests for pg-llm-batch's bounded hourly review-repair caller.""" + +from pathlib import Path + + +CALLER = Path(".github/workflows/pg-llm-batch-hourly-review-repair.yml") +DOCTORING = Path("docs/doctoring/pg-llm-batch-hourly-review-caller.md") +QUALITY_WORKFLOW = Path(".github/workflows/hourly-nvidia-nim-review-repair.yml") +SCHEDULER = Path(".github/workflows/pr-review-fix-scheduler.yml") + + +def _read(path: Path) -> str: + """Return one repository contract file as UTF-8 text.""" + return path.read_text(encoding="utf-8") + + +def _yaml_path_entries(block: str) -> set[str]: + """Return dashed YAML path entries from one trigger or compileall block.""" + entries: set[str] = set() + for raw_line in block.splitlines(): + stripped = raw_line.strip() + if stripped.startswith("- "): + entries.add(stripped[2:].strip()) + elif stripped.startswith("tests/") or stripped.startswith("scripts/"): + entries.add(stripped.rstrip(" \\")) + return entries + + +def _trigger_path_block(quality: str, trigger: str) -> str: + """Return the dashed path list under one named workflow trigger.""" + marker = f" {trigger}:\n paths:\n" + start = quality.index(marker) + len(marker) + lines: list[str] = [] + for line in quality[start:].splitlines(): + if line.startswith(" - "): + lines.append(line) + continue + if line.strip() == "": + continue + break + return "\n".join(lines) + + +def _compileall_block(quality: str) -> str: + """Return the compileall argument list from the focused quality job.""" + marker = "python -m compileall -q \\" + start = quality.index(marker) + remainder = quality[start:] + end = remainder.find("\n git ") + return remainder if end < 0 else remainder[:end] + + +def test_pg_llm_batch_caller_is_hourly_bounded_and_non_cancelling() -> None: + """pg-llm-batch receives one batch-engine repair without cancellation.""" + caller = _read(CALLER) + + assert 'cron: "1 * * * *"' in caller + assert "group: pg-llm-batch-hourly-review-repair" in caller + assert "cancel-in-progress: false" in caller + assert "uses: ./.github/workflows/pr-review-fix-scheduler.yml" in caller + assert "target_repository: ContextualWisdomLab/pg-llm-batch" in caller + assert "base_branch: main" in caller + assert 'max_prs: "50"' in caller + assert 'max_dispatches: "1"' in caller + assert 'retry_hours: "2"' in caller + + +def test_pg_llm_batch_caller_preserves_oidc_and_explicit_secret_scope() -> None: + """The queue scanner maps established credentials without model secrets.""" + caller = _read(CALLER) + workflow_scope, jobs_scope = caller.split("\njobs:\n", maxsplit=1) + + assert "\npermissions:\n contents: read\n" in workflow_scope + assert ( + "\n permissions:\n contents: read\n id-token: write\n" + in jobs_scope + ) + assert "PR_REVIEW_MERGE_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN }}" in caller + assert "OPENCODE_APPROVE_TOKEN: ${{ secrets.OPENCODE_APPROVE_TOKEN }}" in caller + assert "secrets: inherit" not in caller + assert "NVIDIA_NIM_API_KEY" not in caller + assert "COPILOT_GITHUB_TOKEN" not in caller + for forbidden in ( + "actions: write", + "contents: write", + "issues: write", + "pull-requests: write", + "statuses: write", + ): + assert forbidden not in caller + + +def test_pg_llm_batch_target_is_not_hard_coded_in_shared_scheduler() -> None: + """Product identity remains in the thin caller rather than the engine.""" + assert "ContextualWisdomLab/pg-llm-batch" not in _read(SCHEDULER) + + +def test_pg_llm_batch_doctoring_records_batch_activation_and_credentials() -> None: + """Operators retain target-allowlist, batch engine, and approval prerequisites.""" + doctoring = _read(DOCTORING) + + for phrase in ( + "ContextualWisdomLab/pg-llm-batch", + "OPENCODE_REPOSITORY_DISPATCH_TARGETS", + "independent non-author approval", + "NVIDIA_NIM_API_KEY", + "COPILOT_GITHUB_TOKEN", + "id-token: write", + "two-hour same-head retry floor", + "root-cause analysis", + "remediation feasibility", + "protected-main operational acceptance", + "APA 7th references", + "ContextualWisdomLab/pg-llm-batch#227", + "ContextualWisdomLab/pg-llm-batch#222", + "ContextualWisdomLab/pg-llm-batch#221", + "ContextualWisdomLab/pg-llm-batch#194", + ): + assert phrase in doctoring + + +def test_path_block_helpers_keep_trigger_and_compileall_sets_disjoint() -> None: + """A path listed only under push or compileall must not satisfy pull_request.""" + quality = ( + "on:\n" + " pull_request:\n" + " paths:\n" + " - .github/workflows/pg-llm-batch-hourly-review-repair.yml\n" + " push:\n" + " paths:\n" + " - docs/doctoring/pg-llm-batch-hourly-review-caller.md\n" + " python -m compileall -q \\\n" + " tests/test_pg_llm_batch_hourly_review_caller.py\n" + " git diff --check\n" + ) + + pull_request_paths = _yaml_path_entries(_trigger_path_block(quality, "pull_request")) + push_paths = _yaml_path_entries(_trigger_path_block(quality, "push")) + compileall_paths = _yaml_path_entries(_compileall_block(quality)) + + assert pull_request_paths == { + ".github/workflows/pg-llm-batch-hourly-review-repair.yml" + } + assert push_paths == {"docs/doctoring/pg-llm-batch-hourly-review-caller.md"} + assert compileall_paths == {"tests/test_pg_llm_batch_hourly_review_caller.py"} + assert "docs/doctoring/pg-llm-batch-hourly-review-caller.md" not in pull_request_paths + assert ( + ".github/workflows/pg-llm-batch-hourly-review-repair.yml" + not in compileall_paths + ) + + +def test_focused_quality_workflow_tracks_pg_llm_batch_contracts() -> None: + """Caller, test, and doctoring edits always rerun the focused gate.""" + quality = _read(QUALITY_WORKFLOW) + pull_request_paths = _yaml_path_entries(_trigger_path_block(quality, "pull_request")) + push_paths = _yaml_path_entries(_trigger_path_block(quality, "push")) + compileall_paths = _yaml_path_entries(_compileall_block(quality)) + caller = ".github/workflows/pg-llm-batch-hourly-review-repair.yml" + doctoring = "docs/doctoring/pg-llm-batch-hourly-review-caller.md" + contract = "tests/test_pg_llm_batch_hourly_review_caller.py" + + assert caller in pull_request_paths + assert doctoring in pull_request_paths + assert contract in pull_request_paths + assert caller in push_paths + assert doctoring in push_paths + assert contract in push_paths + assert contract in compileall_paths + assert caller not in compileall_paths + assert doctoring not in compileall_paths