Skip to content

gate(xtask): parser-backed cfg-test region authority (#3631) - #3640

Merged
EffortlessSteven merged 2 commits into
mainfrom
feat/3631-parser-regions
Sep 5, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
feat/3631-parser-regions

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements #3631's parser-based rework: the check-rust-source-role-authority
gate's hand-written cfg-test region scanner (~654 lines, six review rounds of
lexer fixes) is replaced by a parser-backed region authority built on
ra_ap_syntax — already a direct xtask dependency, so zero new crates. The
product side was already parser-backed. This replaces the gate's region
scanner; the small exact-spelling recognizer remains, so this is not a claim
that every hand-written lexer in the repository has been removed.

Why

The scanner's long-tail was the finding generator: #3629's three rounds and
#3631's three documented edge cases (else-if initializer chains bailing to
end-of-file, multi-line attribute/doc-comment trim gaps, braced const-generic
args confusing item detection). The parser eliminates all three by
construction — item spans come from syntax nodes.

Differential evidence (fixture-first, run before the flip)

742 tracked .rs files scanned with both implementations side by side:

  • 0 gate-pattern differences — RULES and is_test_file( membership
    identical everywhere; gate output on this corpus is unchanged and goldens check stays exit 0 with zero re-bless.
  • 63 structural differences, with the parser exempting at least as much,
    attributed to two families of previously leaked test-only text. Broader
    exemption is not inherently safe; the relevant distinction is whether the
    removed text belongs to a test-gated item:
  • Edge cases 1 and 3 do not occur in this corpus; both are pinned by new
    unit tests.

Changes

  • xtask/src/rust_region_scan.rs (new): production_text_regions — clean
    parse → top-level item walk with the exact cfg(test) spelling predicate
    (re-hosted minimal spelling table, pinned by accepted/rejected tests);
    parse errors → verbatim scan with used_verbatim_fallback set, disclosed
    under a "Parse Fallbacks" section in source-role-authority.md (over-catch
    only relative to the retained matcher: test interiors remain scanned;
    no file in scope hits it today). The retired scanner was deliberately not
    kept as the fallback: an unreachable 600-line lexer with no live callers
    would be a false-confidence surface.
  • xtask/src/main.rs: gate consumes the authority; scanner + 12 helpers +
    raw_production_text_tests deleted; shared policy-report core refactored
    so the 27 existing finish_policy_report call sites stay byte-identical.
  • RIPR-SPEC-0153: dated rework note + implementation-mapping entry.

Named residuals

Reported local verification

  • cargo fmt --check; cargo test -p xtask (1794 passed);
    cargo test --workspace (6933 passed);
    cargo clippy --workspace --all-targets -- -D warnings;
    cargo xtask check-rust-source-role-authority (pass);
    cargo xtask goldens check (exit 0, zero re-bless);
    cargo xtask precommit; cargo xtask check-static-language;
    cargo xtask check-spec-format; cargo xtask check-traceability.

Closes #3631.


Devin Review

Replace the hand-written depth-tracking scanner behind
check-rust-source-role-authority with region detection from the real
grammar (ra_ap_syntax, already an xtask dependency; no new deps). The
new authority lives in xtask/src/rust_region_scan.rs: parse the file,
exempt each top-level item whose attribute run carries the exact
cfg(test) spelling (the same honored spelling table, re-hosted and
pinned, since facts::cfg_predicates is pub(crate)), and return the
complement with the same newline-seam guarantee. Producer exemptions,
allowed-site inventory, RULES matching, and the is_test_file inventory
are unchanged.

A differential scanner-vs-parser run over every tracked .rs file in the
repository (742 files, fixture corpora included) showed:

- 0 gate-pattern differences (RULES + is_test_file membership identical
  on every file), so gate output on this corpus is byte-compatible and
  goldens stay untouched;
- 289 whitespace-only region differences (seam bookkeeping);
- 63 structural differences, all in the safe direction (the parser
  exempts at least as much as the scanner, never less), each attributed
  to: (a) the scanner's char-literal ender overshooting escaped literals
  such as a backslash escaped in a char literal, which silently leaked
  whole cfg-test modules into production scans - the retired scanner
  failed to exempt even its own test module in xtask/src/main.rs - and
  (b) the documented multi-line attribute/doc-comment trim gap (#3631
  edge case 2). The three documented edge cases (else-if initializer
  chains, multi-line metadata trim, braced const-generic arguments) are
  eliminated by construction and pinned by new tests.

Files that do not parse cleanly are now scanned verbatim (over-catch
only) and the fallback is disclosed in a Parse Fallbacks section of
source-role-authority.md; no file in the scan scope (crates/ripr/src)
hits that path today. The retired scanner is not kept as the fallback:
an unreachable 600-line lexer would be a false-confidence surface.

Spec: RIPR-SPEC-0153 gains a rework note and the implementation mapping
for the new authority module.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: f9a4d257-cde3-45f7-a44d-f969849fb40d

📥 Commits

Reviewing files that changed from the base of the PR and between d5f7cf2 and 62a6bb8.

📒 Files selected for processing (3)
  • docs/specs/RIPR-SPEC-0153-rust-source-role.md
  • xtask/src/main.rs
  • xtask/src/rust_region_scan.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Summary by CodeRabbit

  • New Features

    • Policy reports now include a “Parse Fallbacks” disclosure when source analysis cannot be parsed and uses a conservative fallback.
    • Reports support additional advisory disclosure sections alongside violations.
  • Bug Fixes

    • Improved Rust source analysis accurately excludes top-level cfg(test) regions while handling complex syntax, comments, literals, and attributes.
  • Documentation

    • Updated the source-role authority specification to describe parser-backed detection and fallback behavior.

Walkthrough

The change replaces the hand-written Rust source scanner with parser-backed region detection. It adds exact cfg(test) handling, verbatim fallback reporting, disclosure-aware policy reports, tests, and specification updates.

Changes

Source-role authority gate

Layer / File(s) Summary
Parser-backed production regions
xtask/src/rust_region_scan.rs
The new scanner parses Rust syntax, removes top-level items with the exact #[cfg(test)] spelling, and falls back to verbatim text when parsing fails. Tests cover scanner edge cases and attribute spellings.
Authority scan and fallback disclosures
xtask/src/main.rs
The authority check uses production_text_regions, collects fallback files, and renders optional Parse Fallbacks disclosures. Report construction is split into reusable helpers with coverage for pass and fail output.
Specification alignment
docs/specs/RIPR-SPEC-0153-rust-source-role.md
The specification documents parser-backed detection, handled edge cases, and disclosed parse-failure fallback behavior.

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

Merge Risk: ⚪ Minimal · up to 62a6b

No concrete correctness or operational issue remains, so the change is ready to merge after normal checks.

Sequence Diagram(s)

sequenceDiagram
  participant AuthorityGate as check-rust-source-role-authority
  participant RegionScanner as production_text_regions
  participant PolicyReport as finish_policy_report_with_disclosures
  AuthorityGate->>RegionScanner: Parse Rust source and compute production text
  RegionScanner-->>AuthorityGate: Return production text and fallback flag
  AuthorityGate->>PolicyReport: Pass violations and fallback disclosure
  PolicyReport-->>AuthorityGate: Write policy report and status
Loading

Poem

I am a rabbit with syntax to scan
Parser leaves mark where test regions began
Fallbacks appear in a careful report
Edge cases hop through the newly built port
Green carrots await when the checks all succeed

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives strong technical context, scope, differential evidence, residuals, and verification results. However, it does not follow most required template sections, including Swarm / Source… Update the description to include every required template section. Complete the applicable checkboxes and fields, including source boundary, links, scope and acceptance criterion, support and policy impact, proof, claim boundary, rollback, …
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue [#3631] by replacing the hand-written scanner with parser-backed ra_ap_syntax region detection, preserving exact cfg(test) behavior, addressing the three documented edge case…
Out of Scope Changes check ✅ Passed The changed specification, xtask report plumbing, parser-backed scanner, fallback disclosure, and tests all support the linked issue and stated parser rework. No unrelated code changes are identified.
Docstring Coverage ✅ Passed Docstring coverage is 96.88% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 1 files. (2 skipped: 1 …
Title check ✅ Passed The title clearly and concisely identifies the main change: replacing the cfg(test) region authority with a parser-backed implementation in xtask.
Full details: Description check

Explanation

The description gives strong technical context, scope, differential evidence, residuals, and verification results. However, it does not follow most required template sections, including Swarm / Source Boundary, Source-of-truth Links, Scope Classification, Support-tier Impact, Policy Impact, Claim Boundary, Rollback, Spec-Test-Code Traceability, Static Language Check, CI Economics, Engineering Check, and Gates.

Resolution

Update the description to include every required template section. Complete the applicable checkboxes and fields, including source boundary, links, scope and acceptance criterion, support and policy impact, proof, claim boundary, rollback, traceability, static-language status, CI economics, engineering checks, and executed gates. Mark non-applicable sections as none or n/a and retain the existing technical evidence and verification results.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3631-parser-regions

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

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request replaces the hand-written depth-tracking scanner for the Rust source-role authority gate with a parser-backed scanner using ra_ap_syntax. This resolves several edge cases, such as escaped character literals leaking test modules, and introduces a safe verbatim fallback with disclosure reporting for files that fail to parse. The review feedback suggests optimizing the policy report generation in xtask/src/main.rs by avoiding format! allocations inside a loop.

Comment thread xtask/src/main.rs Resolved

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread xtask/src/rust_region_scan.rs Resolved
Comment thread xtask/src/rust_region_scan.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • Unreachable 600-line retired scanner was deliberately deleted (per PR body) instead of retained as a verbatim fallback; this is intentional but means a future parse failure mode has no second lexical authority to cross-check against.
  • xtask/src/main.rs:4524 — policy_report_body disclosure loop still uses format! per iteration inside the inner item loop; the outer heading/intro can use push_str but the inner - {item} line allocates a fresh String per disclosure item. Minor perf nit, same family as gemini-code-assist note on line 4532.

Verification questions

  • Confirm cargo-test scheduled-late: receipt lands before gate per profile. Tests cited by PR body (1794 xtask, 6933 workspace) are not yet witnessed in available receipts but are heavy-runnable and gated by the late phase; not blocking but trust-affecting until landed.

Parked follow-ups

  • Gemini's format!-in-loop nit is real but low-impact; disclosure rendering is bounded by fallbacks list (typically 0).

Evidence gaps

  • Cargo test receipt scheduled late; current lane has no live cargo witness — artifact-verifier failure is unrelated to region authority.
  • Model proof intent was rejected by deterministic validation.

@EffortlessSteven
EffortlessSteven merged commit 470b5ac into main Sep 5, 2026
39 checks passed
@EffortlessSteven
EffortlessSteven deleted the feat/3631-parser-regions branch September 5, 2026 04:06

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Source review and verification receipt

reviewed_head_sha: 39d68f216a386bf57af02dd5e1629d8ddb6884f4

integration_basis: d5f7cf2bf5a8e2110a7f312297a078c535e409c5

claim_boundary: replacement of the source-role gate's production-region scanner, not all repository lexers or a generalized cfg evaluator. This receipt records the review performed during the PR's final CI run; the PR has since merged as 470b5acb1856ea65dd534b7f515531962f146c25.

Changed surfaces and semantic owners inspected

  • xtask/src/rust_region_scan.rs: clean-parse top-level item ownership, exact cfg(test) spelling recognition, retained-region stitching, and whole-input fallback on parse errors.
  • xtask/src/main.rs: gate integration, unchanged pattern/authorized-consumer boundary, and shared report construction. Ordinary report callers supply no disclosure; fallback reporting is additive.
  • docs/specs/RIPR-SPEC-0153-rust-source-role.md: implementation mapping and rework boundary.
  • New region and report tests, including retained production before/after exempt items, nested items, comments/attributes, braced const generics, escaped literals, newline seams, malformed-input equality, and accepted/rejected cfg spellings.

Findings and counter-read

No remaining blocking source finding in the inspected scope. Three existing review threads were checked against the current source and resolved: disclosure allocation, malformed-parse fallback, and syntax-node macro/item boundaries.

The important counter-read is that removing more text is not inherently safer. Exclusion is justified by ownership of an exactly test-gated top-level item. Tests retaining production tails and nested production-owned text constrain accidental over-exclusion; malformed input must remain byte-for-byte available to the existing matcher. Always returning the input, dropping malformed input, broadening cfg recognition, and omitting the separator are distinct wrong implementations opposed by the reviewed oracles. These are source-level oracle challenges, not a claim of an executed mutation experiment.

I corrected the PR description's broad lexer-removal claim and its earlier safe-direction wording. The remaining tiny spelling recognizer, compound cfg non-goals, and separate orphaned-file cleanup are explicit.

Proof and CI observed

Routed Rust Small run 33942846269, exact head above: required Rust gates and PR evidence both completed successfully; Rust gate job 101243508029 completed successfully. Formatting preflight also passed. I inspected the workflow recipe and the job/step statuses.

Local Rust commands were not run in this session. Detailed job-log retrieval was unavailable; the builder-reported corpus comparison, test totals, and zero-rebless counts were not independently reproduced and remain attributed as such. No artifact-content inspection is claimed.

Currentness, residuals, and disposition

Head/source/tests/report integration were reviewed together. This does not certify a later head, release/source promotion, compound cfg semantics, or a new product capability. The malformed undeclared io_util.rs residual is isolated in #3641, not treated as part of this gate change.

disposition: REVIEW_READY for the bounded source change at the reviewed head, supported by the observed successful hosted gates. This is a COMMENT review, not a second-identity approval or a claim that this session performed the merge.

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.

gate(scanner): consolidate cfg-test region-scanner edge cases and move toward parser-based regions

1 participant