Repository navigation
fix(trust): make Idris2 escape gate genuinely fail closed (#212) - #242
hyperpolymath wants to merge 4 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c2f18eb30
ℹ️ 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".
| } | ||
| if (pair == "--") break | ||
| if (pair == "{-") { depth++; i++; continue } | ||
| if (ch == "\"") { quoted = 1; continue } |
There was a problem hiding this comment.
Parse character literals before opening strings
When an active escape follows a double-quote character pattern, such as f '"' = believe_me 42, this condition treats the " inside the character literal as the start of a string and discards the remainder of the line. The scanner consequently exits successfully despite executable believe_me, defeating the fail-closed gate; track single-quoted character literals and their escapes before interpreting double quotes.
Useful? React with 👍 / 👎.
| # remains forbidden, with no permissive threshold or implicit waiver. | ||
| awk ' | ||
| function code_of(line, i, pair, ch, out, quoted, escaped) { | ||
| out = ""; quoted = 0; escaped = 0 |
There was a problem hiding this comment.
Preserve state across multiline string literals
When a triple-quoted Idris string contains one of the forbidden names on an interior line, quoted is reset on every call, so that harmless text is scanned as executable code and fails the required workflow. The repository already uses multiline strings extensively (for example, safetyGuarantees in src/Proven/SafeSQL/Proofs.idr), so descriptive text mentioning an escape hatch can spuriously block a legitimate change; maintain multiline-string state across lines and add it to the positive controls.
Useful? React with 👍 / 👎.
| exit 2 | ||
| fi | ||
|
|
||
| mapfile -d '' -t sources < <(find "$source_root" -type f -name '*.idr' -print0 | LC_ALL=C sort -z) |
There was a problem hiding this comment.
Include literate Idris source files in the census
When a trust escape is added in a literate Idris module under src, this census silently ignores it because it only selects *.idr; the hundreds of ordinary sources keep the nonempty check satisfied, so the gate reports success. Idris 2 officially treats .lidr files as compilable literate source files (Idris2 literate programming reference), so such a module can contain executable believe_me while this supposedly fail-closed workflow remains green; include every supported source extension or derive the scanned files from the package/compiler inputs.
Useful? React with 👍 / 👎.
| } | ||
| { | ||
| executable = code_of($0) | ||
| if (executable ~ /(^|[^[:alnum:]_])(really_believe_me|believe_me|idris_crash)([^[:alnum:]_]|$)/) { |
There was a problem hiding this comment.
Reject direct unsafe primitives as well
When code invokes prim__believe_me _ _ value or prim__crash _ message directly, this pattern accepts it: the underscore before believe_me defeats the left token boundary, while prim__crash is absent entirely. Idris2's official Builtin source implements believe_me and idris_crash using exactly these primitives (Builtin source), so the same unsafe cast or crash bypasses the gate without any lexical trick; add the primitive names to the forbidden set and planted controls.
Useful? React with 👍 / 👎.
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a392f10ef
ℹ️ 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".
| exit 2 | ||
| fi | ||
|
|
||
| mapfile -d '' -t sources < <(find "$source_root" -type f -name '*.idr' -print0 | LC_ALL=C sort -z) |
There was a problem hiding this comment.
Follow symlinked Idris sources in the census
When a package-listed source such as src/Evil.idr is a symlink to a tracked .idr file outside src, find -type f omits the symlink even though Idris opens and compiles it; the existing regular sources keep the nonempty check satisfied, so an active believe_me in that target still produces PASS. The repository already uses a source-tree symlink at src/abi, so the census should either follow symlinks safely or reject symlinked source entries explicitly.
Useful? React with 👍 / 👎.
| if (quoted) { | ||
| if (escaped) { escaped = 0; continue } | ||
| if (ch == "\\") { escaped = 1; continue } |
There was a problem hiding this comment.
Scan expressions inside interpolated strings
When a trust escape occurs in an interpolation such as x = "forged: \{believe_me value}", this branch treats \{ as an ordinary string escape and ignores everything through the closing quote, so the gate reports PASS. Idris explicitly permits arbitrary expressions inside interpolation slices and desugars them into executable calls, as documented in the Idris2 string-literal reference; the scanner therefore needs to resume token scanning inside interpolation braces rather than discarding the whole literal.
Useful? React with 👍 / 👎.
| if (quoted) { | ||
| if (escaped) { escaped = 0; continue } | ||
| if (ch == "\\") { escaped = 1; continue } | ||
| if (ch == "\"") { quoted = 0; continue } |
There was a problem hiding this comment.
Honor raw-string closing delimiters
When a valid raw string contains an ordinary quote before harmless forbidden-name text, for example #"quote: " and believe_me text"#, this condition treats that quote as the end of the literal and scans the remaining text as executable code, causing the required workflow to fail. Idris raw strings close with a quote followed by the matching number of # characters, and embedded bare quotes remain literal according to the Idris2 string-literal reference, so the lexer must track the raw delimiter rather than closing every string on ".
Useful? React with 👍 / 👎.



Purpose
Fixes the pre-existing fail-open
believe_meaudit in #212 as an independent P0 Trustfile repair, before new proof-discharge work.The old step counted strings/comments and printed only a warning over 300 matches; it could not fail even if active trust escapes were introduced. The new gate scans tracked Idris2 sources under
src/, ignores documentation/comments/string literals, and fails on activebelieve_me,really_believe_meoridris_crash. It is deliberately a lexical safety gate, not a proof checker or a statement that all assumptions have been discharged.Changes
scripts/check-idris-escape-hatches.sh: fail-closed source scan, nested Idris block comments, missing-source refusal.scripts/test-idris-escape-gate.sh: planted negatives for all three escapes, positives for comments, strings and inline comments, and missing-source negative control.trustfile.yml: execute control tests and actual scan before the SPDX/other policy steps; rerun on updates to either script. No threshold, no warning-only path.Verification
bash -non both scripts: PASS.Scope and precedence
The change deliberately does not alter
assert_totalrules, compiler-proof verification, the authoritative proof policy, or legacy A2ML governance semantics. Other Trustfile jobs and their pre-existing failures remain separately tracked. The mathematical-completion UltraPlan is in draft #241.