Add a build gate for memory and unsafe rules, wired into CI #1466
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1466
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1466"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Krigsexe on GitHub · 2026-11-24 16:32 UTC · original
Krigsexe:add-build-gate→main· +798 −0 · 12 files · 5 commits · openWhat is in this PR
A small standalone crate,
crates/xcl-gate, with zero dependencies, plus one CI step that runs itbefore
Build and test. Nothing else in the emulator changes: no emulator source file is touched.The gate scans every
.rsfile andCargo.tomland flags patterns called out by the Rustdocumentation and tooling (
std,clippy, Cargo,rustup). For each failing rule, it prints thereason, the source of the rule, how to fix it, and the offending lines.
unsafe-implunsafe implwithout a// SAFETY:commentunsafe-fn-docunsafe fnwithout a# Safetysectionmissing_safety_docunsafe-blockunsafe { }without a// SAFETY:commentundocumented_unsafe_blockspanic-sourceunwrap()/expect()(a poisoned lock panics every subsequent caller)unwrap_used,expect_usedmem-leakmem::forget,Box::leak,.leak()mem_forgetmem-uninitmem::uninitializedstddocumentationunbounded-allocationvec![0; n]/with_capacity(n)with an unbounded sizeVec::try_reservehardcoded-memoryconfig.rs--config-file)cargo-lock,cargo-profile,toolchain-channelCargo.lock, overridden dev profile checks, nightly or beta pinThe gate hardcodes no paths from this repository:
--config-fileand--skipare passed asarguments, so it can be used on any Rust codebase.
Gradual adoption without blocking existing code
scripts/gate-limits.txtrecords the current baseline. The build only fails when a count goesabove its recorded limit, so existing code is not blocked while new violations are caught.
Limits are lowered as findings are fixed, and never raised. Current baseline on
b7aa9f3:Before scanning, the gate fetches the remote and fast-forwards a clean checkout, failing if it
cannot so it never evaluates a stale tree.
--no-syncis available for offline runs.Preventing changes from editing the gate
On pull requests, CI restores
crates/xcl-gatefrom the target branch before running it. The gateitself rejects any PR that modifies the gate, the workflow, or
CODEOWNERS, or that raises alimit, adds a limit line, or deletes the limits file.
.github/CODEOWNERSassigns those paths to asingle owner.
The final safeguard is a GitHub repository setting that a file cannot enable on its own: Require
review from Code Owners must be turned on in branch protection for the default branch. Until then,
the first two layers act as a check rather than a hard lock.
Background
This gate acts as a guardrail against drift from AI-generated contributions, which now make up a
large share of incoming code. Generated code often looks plausible while skipping the unglamorous
rules: bounded allocations, avoiding panicking
unwraps, and documenting everyunsafe. The gateenforces a fixed, human-defined set of rules drawn from official Rust documentation, applied
uniformly regardless of who or what wrote the code.
Why this is worth merging
The repository currently has 726 open pull requests and 155 open issues. Reviewers cannot manually
audit every unchecked allocation,
unwrap, or undocumentedunsafeacross all of them. Yet thoseare the exact details that determine whether shaders compile reliably, whether memory stays under
control, and whether
unsaferemains contained and justified. Left unchecked, they accumulate andmake the codebase harder to trust with each merge.
With this gate in place, every open and future pull request is checked automatically. A PR that
introduces a violation fails CI immediately with the rule, the reason, the reference, and the exact
line. Contributors get feedback when they push rather than weeks later in review, and review time
goes toward moving the project forward instead of catching recurring debt. Because limits start at
today's counts and can only move down, nothing currently in the tree is blocked.
This is offered in good faith as a shared baseline to lighten review for maintainers and raise the
bar for everyone.
Tested
cargo build --releaseon Linux and Windows 10.0.26100 (Rust stable, MSVC BuildTools).
b7aa9f3(the counts above).0with those counts as limits; adding a single unboundedvec![0u8; n]makes it exit1with the rule, reason, source, fix, and line number.
0for thePR that introduces the gate and for a harmless later PR, and exits
1withgate-tamperfor alater PR that edits the gate or raises a limit.
Not tested
not distinguish test code from production code. Type-aware checks remain clippy's job
AI use
Used only to polish this PR description and readme; all code was written by @krigsexe and verify with double check by Opus 5.5.
@futurepro62 on GitHub · 2026-11-24 16:57 UTC · original · edited 2026-11-24 17:17 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
9dd0d16(on its baseb7aa9f3).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 770 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.#[test]functions in the diff.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 770 passed, 0 failed, 41 ignored, no skips.The gate itself (
crates/xcl-gateis not a workspace member, so the suite above doesn't build or test it)cargo run --release --manifest-path crates/xcl-gate/Cargo.toml -- --root . --config-file crates/xcl/src/config.rs --skip crates/xcl-gate --no-sync --limits scripts/gate-limits.txt, which gave4238 finding(s),OK.mainis still at this PR's baseb7aa9f3, so that's also today's count.scripts/gate-limits.txtadds up to exactly 4238, so every rule sits at its limit with nothing to spare. The scan also counts#[cfg(test)]code. For example,config.rs:295, inside the test module, is listed underpanic-source.unwrap()in a test fails the build. I applied three other open PRs from today on top of this one (crates/diffs only) and ran the gate again. All three fail:panic-source: 2748 found, 2734 allowed,unsafe-block: 814 found, 812 allowedpanic-source: 2753 found, 2734 allowed,unsafe-block: 814 found, 812 allowedmem-leak: 37 found, 36 allowed(oneBox::leak),panic-source: 2756 found, 2734 allowedpanic-source(clippy'sunwrap_usedhasallow-unwrap-in-testsfor this), or adding some headroom, would stop most open PRs from failing CI once this merges.Not tested
AI use
@futurepro62 on GitHub · 2026-11-24 18:17 UTC · original
Retest at
57eb1af. Same command as CI (--no-sync --limits scripts/gate-limits.txt), Windows 11, Rust 1.100.0. Each PR was merged locally onto the #1466 head; nothing pushed.57eb1aff7b6286)84e7d21)8052b9c)mem-leak: 37 found, 36 allowedpanic-sourceand onunsafe-block(814 against 812). The first is the test-code exemption; the second is because the regeneratedunsafe-blocklimit is now 820.Box::leak, andmem-leakstays on in tests.AI use
@DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@Krigsexe on GitHub · 2026-11-25 16:21 UTC · original · edited 2026-11-25 16:23 UTC
@ivall @throny @DavidM1911 @futurepro62
Hi guys !
Quick note on the
off-goallabel. I get that world loading is the priority right now, and I'm totally fine with this waiting if all CI/tooling PRs are held until then.I just wanted to explain why I opened this now rather than later. I know this gate is imperfect. It was built quickly with simple pattern matching and could definitely be cleaner with a proper lexer. The goal isn't cleanup for cleanup's sake.
With so many LLM-assisted PRs coming in, an agent's only goal is to make the build pass on the contributor's own machine. Without a CI check, agents keep hardcoding memory limits, adding unbounded allocations, or applying local workarounds that introduce new issues on other hardware. That ends up causing OOMs, slowing down shader compilation, and creating more brute-force fixes down the road.
Putting a baseline gate in CI creates a shared feedback loop: it aligns everyone's contributors and agents around the same project-wide rules, telling them right away what needs to be fixed or routed through config/runtime limits, without blocking any existing code.
Happy to leave this on hold until after world loading if that's the call. Just wanted to make the intent clear.
Just my engineering POV on pooling everyone's efforts.
Krigs
@DavidM1911 on GitHub · 2026-11-26 05:27 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
@Krigsexe on GitHub · 2026-11-24 16:37 UTC · original · reviewed
Triple check done
@Krigsexe on GitHub · 2026-11-24 17:52 UTC · original · reviewed
@futurepro62
Thanks for testing the gate itself and running it against real open PRs, that's a very useful catch.
I agree on
panic-source:.unwrap()/.expect()in#[cfg(test)]/#[test]blocks andtests/files is idiomatic in Rust and shouldn't block test-only PRs. I've updatedrules.rsto skippanic-sourcein test code (similar to clippy'sallow-unwrap-in-tests) and regeneratedscripts/gate-limits.txtaccordingly.I intentionally kept
unsafe-blockandmem-leakactive everywhere, including tests, undocumentedunsafeorBox::leakshould still be justified or avoided.krigs
@Krigsexe on GitHub · 2026-11-24 18:11 UTC · original · reviewed
Final global check done with human review
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.