Skip to content

Latest commit

 

History

History
366 lines (296 loc) · 22.7 KB

agent_governance.md

File metadata and controls

366 lines (296 loc) · 22.7 KB

ABACUS Agent Governance

This document is the shared development and review contract for human contributors, general AI agents, CodeRabbit, and GitHub CI. AGENTS.md is the short entry point; this file is the complete rule source for implementation and review.

Entry Points

The repository-root AGENTS.md is the short entry point. A module directory under source/ (e.g., source/source_esolver/, source/source_io/) may carry its own AGENTS.md describing module-specific design constraints and conventions. When working in, or reviewing, such a directory, read the module file together with the root file; module-level rules refine the root baseline and never override it.

Source Materials

The governance rules consolidate project guidance from @mohanchen's coding rules, the developer guide, contribution guide, PR template, existing CI, and historical Chinese development notes. Historical notes are used only after path modernization and rule grading; they are not copied directly into automated checks.

Diff Scope

Automated checks default to the PR diff:

  • New files.
  • Diff-added lines.
  • Newly introduced symbols or includes.
  • Changed text files for line-ending checks.

Untouched historical code is not a default blocker. Review tools may mention historical debt when it is relevant to the changed area, but they must separate that from blocking findings on new changes.

When a PR edits code near historical violations, reviewers should identify which findings are new deterministic problems and which are pre-existing context. Fix only the new deterministic problems unless the PR intentionally includes a focused cleanup.

Core Coding Rules

  • Do not introduce new cross-layer control through GlobalV, GlobalC, or PARAM. Prefer explicit parameters or narrow local interfaces.
  • Do not store workflow switches in mutable member variables that can be changed implicitly from multiple places.
  • Keep header dependencies clean and explicit; avoid unnecessary includes in headers, and do not replace #include directives with forward declarations just to silence header include warnings.
  • Avoid adding .hpp implementation headers and avoid including .hpp files from other headers unless the PR explains why header-only implementation is needed.
  • Do not add default arguments to existing interfaces. Update call sites explicitly or design a clearer overload/configuration object.
  • Add short, focused tests for key functionality, bug fixes, INPUT behavior changes, heterogeneous kernels, and core-module refactors.
  • Keep default and general-purpose C++ changes compatible with the repository C++11 baseline. Backend-specific or dependency-constrained paths may use the higher standard already selected by existing CMake configuration.
  • Prefer explicit types over auto in C++ declarations.
  • Use LF line endings for text files. .bat and .cmd are the CRLF exception.
  • Place ModuleBase::timer::start/end at the beginning and end of a function, not around isolated statements inside the function body. Use the enclosing function name (or constructor name) as the timer label so the timer scopes the whole unit of work.
  • Do not use #pragma once in header files; use traditional #ifndef/#define/#endif include guards instead.
  • Put unit tests under source/ in a flat unittests/ directory and name each test source test_<file under test>.cpp (.cu likewise). Headers there are free-named; subdirectories of unittests/ hold test data only and contain no .c/.cc/.cpp/.cxx/.cu/.h/.hh/.hpp/.hxx/.cuh files. Legacy test directories (test/, tests/, test_serial/, test_parallel/, test_gpu/, ...) accept no new files, and a test source modified there must be migrated into unittests/; deleting files, and editing a legacy CMakeLists.txt, header, or data file, stays allowed.
  • Follow docs/developers_guide/cmake_guidelines.md for CMake edits: format changed CMake files with cmake-format; do not reintroduce removed legacy symbols (${math_libs}, USE_LIBXC, ENABLE_RAPIDJSON, ENABLE_LIBCOMM) or remove_definitions(); keep package discovery (find_package, find_library) and directory-scoped compile/include/link commands out of source/; stage unit-test files with abacus_copy_test_files() instead of install() or file(COPY ...); and keep cmake/CollectBuildInfoVars.cmake and source/CMakeLists.txt synchronized when adding options or external dependencies.

AI agents have additional workflow obligations:

  • Inspect existing interfaces before using them.
  • State uncertainty instead of inventing business rules or APIs.
  • Report exact verification results and any checks that could not be run.

Rule Grading Matrix

The first implementation phase separates deterministic mechanical checks from review-only rules. "Phase-one mechanical" means the local hook or CI checker can act on the PR diff without semantic judgment. "AI review" and "human confirmation" items must be reviewed, but the checker does not hard-code those decisions.

Rule category Typical rule Phase-one status Default executor Severity Default action Detection scope Notes
Basic text format LF line endings phase-one mechanical hook + CI medium block full changed text file .bat and .cmd keep CRLF
Header include guard New #pragma once in a header phase-one mechanical hook + CI high block added header lines (.h/.hh/.hpp/.hxx/.cuh) Use #ifndef/#define/#endif guards; no exception allowed
Language baseline C++11 compatibility build/toolchain CI high block build/static tooling Actual compiler/toolchain result wins
Global dependency budget Net increase of GlobalV/GlobalC/PARAM references in code diff phase-one mechanical + AI review CI + AI review high block on net increase, warn on non-increasing added usage added and removed code lines Historical untouched usage and documentation mentions are not blocked; migration-neutral moves require reviewer rationale
New default parameter Header declaration adds a default argument phase-one mechanical warning + AI review CI + AI review high warn header diff High misuse risk; the single-line heuristic is not reliable enough to block, so AI and human review confirm
.hpp propagation New .hpp or header includes .hpp phase-one mechanical warning CI + AI review medium warn new files and added includes Exception can be recorded in PR
Header dependency growth Header diff adds includes phase-one mechanical warning + AI review CI + AI review medium warn added header includes Necessity is semantic and not mechanically decided
Member variable workflow switch Key flow state hidden as mutable member state AI review + human confirmation AI + human review high human confirmation semantic review Static matching is unreliable
Timer placement timer::start/end wrap a whole function body AI review AI + human review low warn semantic review Mechanical matching is unreliable for scopes; label should name the enclosing function
Module path and build linkage New source path and CMakeLists.txt linkage phase-one mechanical CI medium block new source files and build-script diff Deterministic path/build check only
CMake formatting Changed CMake files pass cmake-format phase-one mechanical hook + CI medium block PR-changed CMakeLists.txt and *.cmake files Enforced via the diff-scoped cmake-format job in .github/workflows/precommit.yml
CMake deprecated patterns No new ${math_libs}, USE_LIBXC, ENABLE_RAPIDJSON, ENABLE_LIBCOMM, or remove_definitions() phase-one mechanical hook + CI high block added non-comment lines in main-build CMake files Excludes standalone python/pyabacus/; use abacus::linalg_libs, __LIBXC, ENABLE_JSON, ENABLE_LIBRI, and abacus_disable_feature_definitions()
CMake directory-scoped commands under source/ No new add_definitions, add_compile_definitions, add_compile_options, include_directories, link_directories, link_libraries, find_package, or find_library under source/ phase-one mechanical hook + CI high block added non-comment lines in source/ CMake files Use target-scoped target_*() commands, cmake/CompilerConfiguration.cmake, source/CMakeLists.txt _abacus_feature_definitions, and cmake/modules/Find*.cmake
CMake test file preparation Unit-test CMake files use abacus_copy_test_files(), not install() or file(COPY ...) phase-one mechanical hook + CI medium block added non-comment lines in unit-test CMake files under source/ Configure-time staging keeps tests runnable without make install
CMake option and dependency sync New root option/cmake_dependent_option or cmake/modules/ module updates cmake/CollectBuildInfoVars.cmake phase-one mechanical warning + AI review hook + CI + AI review medium warn root CMakeLists.txt diff and new cmake/modules/*.cmake files Reviewers also check _abacus_feature_definitions (__XXX) and abacus_add_target_compile_requirements() in source/CMakeLists.txt
Unit test directory layout New unit tests go in a flat unittests/; legacy test directories accept no new files phase-one mechanical hook + CI high block added, renamed, copied, and modified paths under source/ Added files in legacy test directories block; modified .c/.cc/.cpp/.cxx/.cu there block; code files in unittests/ subdirectories block; deletions never block
Unit test file naming Sources in unittests/ start with test_ phase-one mechanical + AI review hook + CI + AI review medium block added, renamed, copied, and modified sources directly in unittests/ Headers are exempt; reviewers confirm the rest of the name matches the file under test
Module semantic ownership Best module/submodule placement AI review + human confirmation AI + human review medium human confirmation semantic review Final call belongs to maintainers
Heterogeneous code linkage CUDA/ROCM/kernel source and CMakeLists.txt linkage phase-one mechanical CI + AI review medium block new heterogeneous files and linkage Mechanical path/linkage only
Heterogeneous test evidence CUDA/ROCM/kernel change has test evidence or reason phase-one mechanical warning + AI review CI + AI review high warn changed paths and PR body Sufficiency is human-reviewed
Test existence Source change has test evidence or reason phase-one mechanical warning + AI review CI + AI review high warn PR body and changed paths Sufficiency is human-reviewed
Test sufficiency Tests cover important behavior AI review + human confirmation AI + human review medium human confirmation semantic review Not mechanically blocked
Integration test driver Integration test uses an Autotest case, not a standalone add_test() script AI review + human confirmation AI + human review medium human confirmation tests/**/CMakeLists.txt and new scripts under tests/ Standalone drivers need a stated reason Autotest cannot express the check; see Integration Test Drivers
INPUT behavior linkage Parameter metadata/default/type/parser behavior updates YAML and docs phase-one mechanical + AI review CI + AI review high warn behavior-field diff plus docs/PR body Comment-only parameter-file changes are not blocked
Documentation sync Behavior/interface docs updated phase-one mechanical warning + AI review CI + AI review medium warn changed paths and PR body Major behavior changes escalate to reviewers
PR metadata completeness Issue, tests, behavior, INPUT, core impact, exceptions phase-one mechanical CI or GitHub bot medium warn PR template fields Not run by local hook
AI workflow Interface lookup, uncertainty, verification report AI review AI review high warn review transcript/output Applies to AI agents
Exceptions Reason, scope, risk, follow-up plan human confirmation human review + CI high human confirmation PR exception section + approval label CI downgrades a covered blocker to a warning only when the section is complete and a maintainer applied the governance-exception-approved label

Implementations must use this matrix as the default baseline. Upgrading warnings to blockers or converting human-confirmation rules into mechanical blockers requires an explicit governance change.

Deterministic errors require a code or documentation fix before merge unless a maintainer-approved exception is recorded. Deterministic warnings require a reviewable rationale or cleanup, but they do not become blockers without an explicit governance change. For header include warnings, the rationale should confirm that the included header is actually used and does not introduce unnecessary or circular dependencies; explicit #include directives are preferred over replacing them with forward declarations.

For global dependencies, the mechanical checker uses a PR-level budget during the legacy migration period. A PR blocks only when the number of code references to GlobalV, GlobalC, or PARAM increases after accounting for deleted references. If a PR adds global references while deleting at least as many elsewhere, the checker warns instead of blocking; reviewers should confirm the change is a migration-neutral move or part of a cleanup path.

Automation Responsibilities

Local hooks:

  • Fix or block deterministic local issues such as mixed line endings.
  • Run staged governance checks with agent_governance_check.py --staged.
  • Do not require PR metadata because it is unavailable locally.

CI:

  • Run diff-level governance checks with PR base/head SHAs.
  • Check PR body completeness and INPUT metadata changes.
  • Publish Markdown summaries that humans and AI reviewers can consume.

AI review:

  • Explain governance findings in actionable terms.
  • Add semantic review for module ownership, header dependency growth, test sufficiency, INPUT metadata consistency, and AI workflow discipline.
  • Use the output format below for actionable findings.

Human review:

  • Approve or reject exceptions.
  • Confirm module boundaries and high-risk design decisions.
  • Decide whether tests are sufficient for the scientific and numerical risk.

Existing Build And Toolchain References

Agents and contributors should reuse ABACUS entry points that already exist in the repository:

  • CMake/CTest builds and test selection used by .github/workflows/test.yml, such as ctest --test-dir build -V -R MODULE_MD for MD-focused changes. Reuse the module's CMake targets and test registration helpers. Keep case-specific setup in the test case when the framework supports it.
  • Development containers and CI images based on Dockerfile.gnu, Dockerfile.intel, Dockerfile.cuda, and ghcr.io/deepmodeling/abacus-*.
  • Dependency and compiler setup under toolchain/, including the GNU, Intel, and CUDA variants already covered by workflow checks.

When a change needs new code from an external library such as LibRI or LibRPA, use a tagged release that contains it. Test against that release and identify the tag in the PR.

Do not add a new container recipe, toolchain path, or agent-specific skill for calculation tasks as part of governance-only work. If a future PR needs one, it must explain why the existing Docker/toolchain paths are insufficient.

Local Runtime And MPI Testing

Use OMP_NUM_THREADS=1 as the default for ABACUS runtime, integration, and MPI tests unless the test explicitly requires another thread count. Agent sandboxes can interfere with process visibility, socket creation, and MPI launch behavior; when those details affect a result, rerun the command outside the restricted sandbox before diagnosing an ABACUS failure.

OpenMPI opal_ifinit: socket() failed errno=1 warnings from sandboxed MPI-linked builds or runs should be treated as sandbox artifacts first, not as project regressions. Do not relax existing integration tests or reference files just to make a failure pass. Update references only when the intended behavior changed and the PR explains why the new reference is correct.

Integration Test Drivers

Use Autotest cases with INPUT, STRU, KPT (when needed) and result.ref, listed in CASES_*.txt and run by Autotest.sh through the suite's CTest entry. Autotest helpers are unaffected.

Store references with the case, outside generated OUT.* directories. Prefer plain text for simple references such as a.txt.ref.

Standalone add_test() drivers that launch ABACUS require a check Autotest cannot express (e.g., nonzero exits or per-rank stderr) and a PR rationale. Keep Autotest-compatible checks in cases. Drivers must:

  • Live in tests/integrate/validation_tools/ with descriptive names (e.g., check_<feature>.py); reserve test_*.py for tool unit tests.
  • Use dedicated fixtures; never rewrite another case's INPUT at run time.
  • Use find_program plus if() for optional interpreters; never REQUIRED.
  • For MPI, forward MPIEXEC_NUMPROC_FLAG, MPIEXEC_PREFLAGS and MPIEXEC_POSTFLAGS; set CTest PROCESSORS to the launched rank count.
  • Set OMP_NUM_THREADS=1 and use temporary scratch space.

CLI Verification

When a usable ABACUS executable is present, INPUT and command-line changes should include the relevant CLI checks in the PR verification record:

./build/abacus --version
./build/abacus -h <parameter>
./build/abacus --check-input

Run --check-input from a directory containing a valid INPUT case. If no local executable or valid case is available, state that explicitly in the PR.

AI PR Review Integration

ABACUS uses a layered review model:

  • Agent Governance is the deterministic GitHub Actions check for low-noise diff rules. Repository maintainers may make this workflow a required check in branch protection.
  • CodeRabbit is a PR-triggered AI reviewer for semantic review hints. Its repository configuration lives in .coderabbit.yaml and uses this document plus AGENTS.md as review guidelines.
  • GitHub Copilot code review is also present on upstream PRs. Repository-level Copilot guidance lives in .github/copilot-instructions.md, and path-level review guidance lives in .github/instructions/*.instructions.md. These files point Copilot back to this governance document and the short AGENTS.md entry point.
  • CodeRabbit and Copilot comments are advisory by default. They do not replace maintainer approval, exception approval, or numerical/test sufficiency review.

To activate CodeRabbit on real PRs, a repository or organization administrator must install the CodeRabbit GitHub App for deepmodeling/abacus-develop and grant it pull request review access. After installation, non-draft pull requests and new commits should receive automatic review according to .coderabbit.yaml; if automatic review does not start, maintainers may request it with @coderabbitai review.

To make Copilot follow the governance baseline, keep the Copilot custom instruction files synchronized with this document whenever the review contract changes. Copilot review behavior still depends on GitHub organization and repository settings, and pull request reviews use the custom instructions from the target base branch. New or changed instruction files therefore take effect for later reviews after they are present on the base branch.

Copilot coding-agent setup steps, Qodo, and PR-Agent are not part of the phase-one baseline. They require separate organization settings, secrets, or setup workflows and should be added only through a later governance change.

INPUT Parameter Changes

Reuse an existing INPUT option or a common default when possible. Explain in the PR why a new option is needed. Follow the naming of related options and aim for names of 15 characters or fewer with at most two underscores.

For scalar INPUT parameters with a fixed set of choices, use item.domain.set_choices(...) so validation errors list the allowed values in a consistent format.

Changes to parameter metadata, default values, type, availability, description, or parsing behavior should update the corresponding C++ Input_Item registrations. The generated YAML and Markdown documentation are build artifacts and should not be edited or committed.

If the diff touches parameter internals but does not require an Input_Item metadata change, the PR should state why. Missing metadata updates trigger a governance warning (not a block), but maintainers may still request updates before merging.

PR Self-Consistency

Before requesting review, check that the PR description matches the diff:

  • New or changed INPUT behavior lists the changed parameters and any corresponding Input_Item metadata updates.
  • Source changes list focused unit, case, or CLI verification commands with the observed result.
  • Header include growth, .hpp propagation, missing tests, or other warnings have either been fixed or have a rationale in the PR body.
  • Exceptions include reason, scope, risk, why the normal rule cannot be followed now, a follow-up cleanup plan, and the requested approver.

Reply to each review comment in its thread, including bot feedback. Link to the fix or explain why the existing behavior is appropriate. Resolve the thread once the discussion is settled.

Exception Template

Use this template in the PR when a rule must be bypassed temporarily:

### Governance Exception
- Rule:
- Reason:
- Scope:
- User or maintenance risk:
- Why the normal rule cannot be followed now:
- Follow-up cleanup plan:
- Requested approver:

Rule names the checker rule(s) being excepted, using the exact rule names from the governance summary (for example Global dependency budget or CMake linkage for new sources). The CI checker handles the section as follows:

  • An incomplete section (any field empty) produces a warning and changes nothing else.
  • A complete section without approval produces a warning that the exception is awaiting approval; blocking findings still fail the check.
  • A complete section plus the governance-exception-approved label, applied by a maintainer other than the PR author, downgrades the blocking findings whose rule appears in Rule to warnings. Findings marked Exception allowed: no (LF line endings, #pragma once) are never downgraded.

Applying or removing the label re-runs the check. The local --staged hook has no PR body or labels and therefore never applies exceptions.

AI Review Finding Format

AI and bot review findings should use this shape:

Rule: <rule name>
Severity: error | warning | info
Location: <file:line>
Reason: <specific trigger>
Suggested action: <concrete next step>
Exception: allowed | not allowed | human approval required