Skip to content

Complete Logtalk to Elixir rule migration - #996

Merged
hyperpolymath merged 3 commits into
mainfrom
arena/82ed8898-hypatia
Nov 1, 2026
Merged

hyperpolymath merged 3 commits into
mainfrom
arena/82ed8898-hypatia

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

Completes the Logtalk -> Elixir semantic migration for Hypatia's canonical rule system (lib/rules/*.ex):

  • Transcribes ECHIDNA security_learning.lgt alert semantics into Hypatia.Rules.SecurityErrors (alert_category/1, explicit catch-all severities, validate_alert/1, CWE-915, Logtalk banned -> Elixir).
  • Transcribes the audit-training AP001-AP015 Logtalk blocks into Hypatia.Rules.AuditPrevention or points each at its existing canonical checker.
  • Replaces generated Logtalk learned-rules output with schema'd JSON (schemas/learned-security-rules.schema.json).
  • Fixes active consumers/docs (integration/robot-repo-automaton, INTENT.contractile, hooks language policy, guides, generated catalogue).
  • Adds scripts/check-no-active-logtalk.sh + exact-path shrink-only .logtalk-allowlist, wired into CI and proven by mutant locally (planted .lgt + report_format: logtalk -> red; removed -> green).
  • Prepares sibling coordination packets for ECHIDNA, epistemic-types (including a ready-to-land epistemic-types_chora.deed with :report-format "json"), and standards.

Proof status (stated exactly)

  • New finite correspondence model: verification/proofs/agda/LogtalkMigration.agda.
  • Mathesis Grade 3 target, currently recorded as AGDA-PENDING in verification/PROOF-STATUS.adoc until this PR's strict-profile Agda receipt exists. The verify-proofs workflow now installs the official pinned Agda 2.8.0.2 release and runs agda --safe --without-K --cubical-compatible LogtalkMigration.agda as a hard failure (never a skip).
  • VerisimdbConnector.idr: statement superseded from the retired Logtalk fact format to FindingFact (canonical JSON finding projection); proof term unchanged, no runtime-refinement claim.
  • No Grade 2/1, reconciliation, or runtime-refinement claim is made.

Local validation

Authoring sandbox has no BEAM/prover binaries and its egress blocks their installers, so local evidence is static only (guard, proof-status/trusted-base scripts, JSON/shell checks, Elixir syntax parse). This PR's CI runs are the compile/ExUnit/Idris/Agda receipts; PROOF-STATUS.adoc will be updated from them before this leaves draft.

Ledger: docs/rules/logtalk-migration.adoc.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Summary

Summary by CodeRabbit

  • New Features
    • Added audit-prevention checks covering security practices such as input limits, vulnerability auditing, CI tests and property-injection risks.
    • Security alerts can now be validated with category, severity, fix guidance and prevention-workflow details. Learned security rules are exported in a structured JSON format.
  • Updates
    • Elixir is now the active rule system; Logtalk is no longer supported as an active rule language or report format.
  • Documentation
    • Updated the guides, rule catalogue and migration records to reflect the current rule system and document historical Logtalk rules.

The PR adds Elixir audit-prevention checks and alert validation, changes learned security-rule exports from Logtalk to schema-defined JSON, and adds a guard against active Logtalk sources. It also updates migration documentation and adds an Agda model for selected Logtalk-to-Elixir alert correspondences.

Changes: Rule migration and retirement

Layer / File(s) Summary
Elixir audit rules and alert semantics
lib/rules/audit_prevention.ex, lib/rules/security_errors.ex, test/rules/*, test/security_errors_test.exs, docs/rules/catalogue.adoc, docs/wiki-pages/Rule-Catalogue.md, .github/workflows/ci.yml, lib/rules/README.adoc, lib/rules/rules.ex, lib/rules/learning.ex
Adds AP001–AP015 rule records and implemented checks, alert-category and validation functions, severity entries, and CWE mappings. Adds rule and alert tests and updates the rule catalogues.
Learned-rule JSON export
lib/mix/tasks/hypatia.batch_security_scan.ex, schemas/learned-security-rules.schema.json, integration/robot-repo-automaton/config.yml, docs/rules/logtalk-migration.adoc
Replaces the Logtalk export with JSON generated from alert validation. The payload includes version and generation metadata and follows a new schema. The integration config points to the JSON export and schema.
Logtalk retirement guard
scripts/check-no-active-logtalk.sh, .logtalk-allowlist, .github/workflows/ci.yml, hooks/lib/common.sh, lib/rules/README.adoc, docs/rules/logtalk-migration.adoc, .audittraining/security-errors/*, integration/robot-repo-automaton/config.yml
Adds a repository guard with exact-path exemptions and runs it in CI. The language policy bans Logtalk and maps it to Elixir. Retained audit-training blocks are labelled as historical material.
Migration records and system documentation
docs/rules/logtalk-migration.adoc, docs/rules/migration/*, docs/rules/migration/epistemic-types_chora.deed, docs/guides/*, docs/architecture/*, docs/security/*, docs/integration/a2ml-k9.adoc, docs/DEBT-REGISTER.adoc, docs/EXPLAINME.adoc, docs/api/*, docs/quickstart/*, docs/specs/ada-tui-audit-spec.adoc, docs/testing/audit.adoc, .machine_readable/INTENT.contractile, cli/man/hyper.1
Adds a migration ledger and issue packets. Updates architecture, developer guidance, integration descriptions, and other documentation to identify Elixir as the active rule system and document JSON contracts and migration status.
Agda correspondence model and proof records
verification/proofs/agda/LogtalkMigration.agda, .github/workflows/verify-proofs.yml, verification/PROOF-STATUS.adoc, verification/README.adoc, verification/proofs/idris2/VerisimdbConnector.idr
Adds a finite model and proofs for selected alert categories, severities, auto-fixability, fix presence, and prevention mappings. Adds an Agda CI check and records the model’s scope and pending proof status.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant BatchSecurityScan
  participant SecurityErrors
  participant LearnedRulesJSON
  BatchSecurityScan->>SecurityErrors: validate_alert/1 for each alert type
  SecurityErrors-->>BatchSecurityScan: category, severity, fix, auto-fixability, prevention workflow
  BatchSecurityScan->>LearnedRulesJSON: write versioned payload
Loading

Possibly related PRs

  • hyperpolymath/hypatia#994: Defines the Agda checking policy and proof-status limits used by the new migration model and CI check.
  • hyperpolymath/hypatia#956: Introduces the Elixir compile job that this PR extends with rule tests and the Logtalk guard.

Suggested reviewers: claude

Merge Risk: Moderate · up to 40182

The learned-rules export can write an invalid category for unrecognised alerts. The new guard against active Logtalk sources has gaps, and the governance baseline check currently fails. A few documentation and proof statements overstate or contradict the code. Resolve the export bug, the CI failure, and the guard gaps before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@hyperpolymath
hyperpolymath marked this pull request as ready for review November 1, 2026 16:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T17:02:34.053713Z 4428672 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4018290eaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +494 to +496
files = Map.get(evidence, :files, [])
contents = Map.get(evidence, :contents, %{})
repo_tags = Map.get(evidence, :repo_tags, [])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate checks on all of their required evidence

When callers intentionally supply only a subset of evidence, these defaults turn absent evidence into negative evidence. For example, check_all(%{repo_tags: ["cryptography"], required_reviews: 2}) passes an empty file list to AP010 and incorrectly reports that fuzz targets are missing; similarly, supplying :files without :contents can make AP003 report that no workflow runs cargo audit. This contradicts the documented contract that missing evidence yields no finding and can produce high-severity false positives, so each check should run only when all of its required keys are present.

Useful? React with 👍 / 👎.

'#'*) return 0 ;;
';'*) return 0 ;;
'//'*) return 0 ;;
'--'*) return 0 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Distinguish CLI option lines from language comments

In shell scripts and YAML run blocks, a continued command-line option commonly begins with --, but this branch treats every such line as a comment regardless of file type. Consequently, an active command such as reporter \\ followed by --format logtalk is matched and then discarded; check-no-active-logtalk.sh --all still exits successfully, allowing exactly the retired output setting this CI guard is intended to reject. Comment syntax should be selected by file type rather than globally treating -- as a comment prefix.

Useful? React with 👍 / 👎.

# Guarded forms.
# ---------------------------------------------------------------------------
active_re='\[source,logtalk\]|:-[[:space:]]*(object|end_object|protocol|category)[[:space:]]*\(|logtalk_load[[:space:]]*\(|logtalk_(tester|doclet)|report-format[[:space:]]*=[[:space:]]*["'"'"']?logtalk|:report-format[[:space:]]+"logtalk"|(report[-_]?format|format)[[:space:]]*:[[:space:]]*["'"'"']?logtalk|--format([[:space:]]+|=)logtalk|^[[:space:]]*(loader|output_path|output|path|file|rules?)[[:space:]]*[:=].*\.lgt'
codegen_re='\.lgt(["'"'"'[:space:],)\]]|$)|security_rule[[:space:]]*\('

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Repair the delimiter class for Logtalk file references

The .lgt alternative only matches references at end of line because the intended delimiter character class is malformed and does not match even a following quote or space. As a result, an executable line such as logtalk engine/loader.lgt --quiet passes check-no-active-logtalk.sh --all, as do the quoted .lgt references already present in poc-scanner.sh, despite the guard's stated coverage of non-comment references in executable files. Correct the character class so references followed by whitespace, quotes, commas, or brackets are rejected.

Useful? React with 👍 / 👎.

String.starts_with?(path, ".github/workflows/"),
do: content

audited? = Enum.any?(workflow_contents, fn content -> String.contains?(content, "cargo audit") end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require an executed cargo audit command

Any textual mention of cargo audit anywhere in a workflow is treated as proof that the audit runs. A Rust workflow containing only # TODO: add cargo audit, an explanatory step name, or an echo therefore suppresses AP003 even though CI never performs a vulnerability audit. Since this rule is specifically meant to require execution in CI, inspect active run commands rather than using an unrestricted substring search over the whole YAML document.

Useful? React with 👍 / 👎.

Comment on lines +154 to +155
||| The repo/file/category/severity projection of a finding: the fields a
||| canonical JSON finding (schema/findings.ncl) carries for every result.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Model fields that actually exist in the findings schema

The retargeted proof says schema/findings.ncl carries repo, file, category, and severity on every finding, but that schema's escript finding has no repo or category fields and its bash finding likewise has no repo or category. Moreover, toFact populates the purported category from Pattern.description. The unchanged equality proof therefore establishes preservation for an invented record rather than the canonical JSON contract it now claims to model, making the new verification statement misleading; the model should use the schema's real fields and mappings.

Useful? React with 👍 / 👎.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@hyperpolymath
hyperpolymath merged commit 90781d8 into main Nov 1, 2026
89 of 92 checks passed
@hyperpolymath
hyperpolymath deleted the arena/82ed8898-hypatia branch November 1, 2026 17:00

Copy link
Copy Markdown
Owner Author

Final receipt note (the PR body above predates the last two commits):

  • At merged head 4428672, the Grade 3 receipt is recorded in verification/PROOF-STATUS.adoc: pinned Agda 2.8.0.2, agda --safe --without-K --cubical-compatible LogtalkMigration.agda, Verify Proofs run 41328302925 / job 124912804344 at 4018290, source SHA-256 bbd18e2747c84e2eda7ff5a778a2df7f8960a1ef47b1c253f316b9d97b9902a0. This is Mathesis Grade 3 / AGDA-VERIFIED for the finite model only; no Grade 2/1 or runtime-refinement claim.
  • The Idris2 FindingFact supersession was re-checked in the same Verify Proofs run (job 124912804086); Elixir compile/ExUnit/guard evidence is CI run 41328303014 (Elixir Compile job 124912999773). At 4428672, Verify Proofs and CI were green again and Governance "Validate Hypatia Baseline" passed after the two exact SD022 exemptions.
  • Post-merge SonarCloud findings in the new guard script + HTTPS redirect policy are in follow-up PR Address Sonar findings in Logtalk guard #997; there Sonar, Exemption ratchet, Baseline, Elixir, and Agda are green.
  • Remaining Governance failure is only standards "Allowlist Preflight" on the pre-existing ClusterFuzzLite action refs at the pinned standards revision; that belongs in the standards allowlist/pin process, not this migration.

hyperpolymath added a commit that referenced this pull request Nov 1, 2026
Follow-up to #996 (merged at `4428672` before these post-merge check
findings were addressed).

- Refactor `scripts/check-no-active-logtalk.sh` to use Bash `[[ ... ]]`
conditional expressions, assign positional parameters to locals, and
give each `case` an explicit default branch (SonarCloud annotations on
#996).
- Force HTTPS (including redirects) for the pinned official Agda release
download in `verify-proofs.yml`.
- No semantic change to the guard: `bash -n`,
`scripts/check-no-active-logtalk.sh --all` (1,100 files, 14 allowlisted,
0 violations), and `git diff --check` pass locally.

This also supplies the standards exemption-ratchet declaration for the
two SD022 entries added in #996:

Ratchet-exception: .hypatia-ignore — two exact SD022 entries remove a
foreign-tree false positive in sibling migration packets that quote
epistemic-types' own src paths; delete each entry when its packet is
removed after sibling landing.

Known unrelated failure: Governance "Allowlist Preflight" rejects the
pre-existing ClusterFuzzLite action refs because they are not covered by
the standards allowlist at the pinned standards revision; that needs the
standards allowlist/pin process and is not changed here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants