Skip to content

gate(xtask): count-based gates now check bidirectionally — stale bounds and orphaned entries flagged (#2413, #2399) - #2466

Merged
EffortlessSteven merged 1 commit into
mainfrom
codex/count-gates-bidirectional-2413
Jul 26, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
codex/count-gates-bidirectional-2413

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

What

Makes the three count-based policy gates (check-process-policy, check-network-policy, check-local-context) bidirectional: they now flag stale bounds (actual < allowed) and orphaned entries (pattern not found in any tracked file), not just over-budget occurrences. This closes the false-confidence gap where allowlist bounds silently rot in the downward direction, providing slack for new occurrences to slip through.

Closes #2413 (the generalization). Closes #2399 (the specific instance: load.rs and run.rs stale bounds).

Change

Gate logic (xtask/src/main.rs)

check_count_policy (used by process + network gates):

  • Added stale-bound check: count < allowed → violation naming the file, pattern, and the actual count to tighten to.
  • Added orphaned-entry check: allowlisted path/pattern not in the counts map → violation naming the orphaned entry to remove.

check_local_context_impl:

  • Added the same two reverse-direction checks (stale bound + orphaned entry).
  • Refactored the loop to borrow grouped so the orphaned-entry check can reference it after the loop.

Allowlist cleanup

policy/process_allowlist.txt:

  • load.rs Command::new: tightened 16 → 7 (the actual count; was stale since prior refactoring removed git-probe sites).
  • run.rs Command::new: tightened 14 → 13.
  • Removed 4 orphaned use std::process::Command entries: receipt.rs, git.rs, cli_smoke.rs, lsp_lifecycle.rs — these imports were removed by prior refactoring (into the shared git.rs helper).

policy/network_allowlist.txt:

  • Removed 2 orphaned http entries: perl_gap_record_projection.rs (5) and typescript_packet_projection.rs (3) — these tracked absence-assertions (comments verifying http doesn't appear), but the gate never searched for http as a network pattern, so the entries were invisible to the detection and orphaned by the new bidirectional check.

Test (xtask/src/tests.rs)

New test count_policy_gates_have_no_stale_bounds runs all three count gates against the real allowlists and asserts they pass. Catches future drift introduced by refactoring that drops process/network occurrences without updating the allowlist.

Proof

cargo fmt --check                                     # exit 0
cargo clippy --workspace --all-targets -- -D warnings # exit 0
cargo xtask check-static-language                     # exit 0
cargo xtask check-file-policy                         # exit 0
cargo xtask check-process-policy                      # exit 0 (was failing before fix)
cargo xtask check-network-policy                      # exit 0 (was failing before fix)
cargo xtask check-local-context                       # exit 0
cargo test -p xtask count_policy_gates_have_no_stale_bounds  # pass
cargo test -p xtask policy_checker_facade             # pass (existing test, no regression)

Before the gate-logic fix, check-process-policy flagged 2 stale + 4 orphaned entries; check-network-policy flagged 2 orphaned entries. After tightening the allowlist + the logic fix, all three gates pass clean.

Scope

  • Production delta: 2 gate functions gain reverse-direction checks; 2 allowlist files tightened. No change to what the gates detect (only what they flag as stale).
  • Evidence delta: 1 new regression test; existing policy_checker_facade test still passes.
  • Cardinal-sin check: this fix removes false-confidence surface (bounds that claimed to constrain counts but didn't). No actionability flip touched.

Why this matters

This is a direct implementation of the #2463 contract-parity meta-issue for the count-gate family. The false-confidence pattern: the gate claims to bound process/network spawn sites, but stale bounds provide invisible slack. With the bidirectional check, any future refactoring that removes a Command::new or network call will immediately flag the stale entry, forcing an allowlist update (with owner + reason) — or at minimum, confirming the bound should stay loose.

Non-goals

Related

…ds and orphaned entries flagged (#2413, #2399)

The count-based policy gates (check-process-policy, check-network-policy,
check-local-context) previously checked one direction only: actual > allowed
(over-budget). They never flagged actual < allowed (stale bound) or entries
whose pattern no longer appears in any tracked file (orphaned). This is the
false-confidence-gate family: the allowlist bound rots silently in the
downward direction, providing slack that lets new occurrences slip through
without an allowlist update.

Fix:
- check_count_policy: add stale-bound check (actual < allowed) and orphaned-
  entry check (allowlisted path/pattern not found in any tracked file).
- check_local_context_impl: add the same two reverse-direction checks.
- Tighten 3 stale entries: load.rs Command::new 16→7, run.rs 14→13.
- Remove 6 orphaned entries: 4 use-std::process::Command imports removed by
  prior refactoring (receipt.rs, git.rs, cli_smoke.rs, lsp_lifecycle.rs) and
  2 http absence-assertion entries whose pattern the gate never searched for.
- Add a regression test that runs all three count gates and asserts they
  pass (catching future drift).

This closes #2413 (the generalization) and #2399 (the specific instance).
It is a direct implementation of the #2463 contract-parity meta-issue for
the count-gate family.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sourcery-ai sourcery-ai 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.

Sorry @EffortlessSteven, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes

    • Improved policy validation to detect outdated allowance limits and entries that no longer correspond to tracked content.
    • Tightened network and process policy allowances to better reflect current project behavior.
  • Tests

    • Added regression coverage ensuring policy checks catch both excessive allowances and orphaned entries across supported policy types.

Walkthrough

The count-based policy gates now flag stale positive max_count values and orphaned allowlist entries. Process and network policy entries are tightened, and a regression test runs all three gates against the repository.

Changes

Count Policy Gate Tightening

Layer / File(s) Summary
Bidirectional gate validation
xtask/src/main.rs
Local-context and shared count-policy checks now report positive stale bounds and allowlist entries whose patterns no longer occur.
Allowlist synchronization and regression coverage
policy/process_allowlist.txt, policy/network_allowlist.txt, xtask/src/tests.rs
Process and network counts and entries are updated, while a regression test checks process, network, and local-context gates for stale or orphaned entries.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: full-ci

Poem

I’m a rabbit with a tidy gate,
Counting calls before they propagate.
Stale bounds thump, orphans flee,
Policies match reality.
Carrots for tests—one, two, three!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Clear, specific title matches the main bidirectional policy-gate change and cites the relevant issues.
Description check ✅ Passed Covers the main change, scope, proof, non-goals, and related issues; only template metadata sections are omitted.
Linked Issues check ✅ Passed Implements bidirectional checks for process, network, and local-context counts, tightens stale bounds, and adds regression coverage for #2413/#2399.
Out of Scope Changes check ✅ Passed All code changes align with the gate fix and allowlist cleanup objectives; no unrelated surface stands out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 codex/count-gates-bidirectional-2413

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

@coderabbitai coderabbitai Bot added the full-ci Run required, advisory, and release-like CI lanes. label Jul 25, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@xtask/src/main.rs`:
- Around line 4798-4831: Centralize the stale-bound and orphan-entry validation
currently duplicated in check_local_context_impl and check_count_policy by
extracting a shared validator and result type. Reuse that validator from both
enforcement paths, while keeping each caller’s existing gate-specific violation
formatting and rendering behavior unchanged.

In `@xtask/src/tests.rs`:
- Around line 45638-45656: Extend count_policy_gates_have_no_stale_bounds beyond
validating the real allowlists by invoking the shared count-policy validator
with synthetic inputs where actual is below max_count and where the configured
pattern is absent. Assert that both cases produce violations, while retaining
the existing real-policy checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1208b087-8981-4551-b4e3-812bbee7f2c3

📥 Commits

Reviewing files that changed from the base of the PR and between 7f60622 and b722b35.

📒 Files selected for processing (4)
  • policy/network_allowlist.txt
  • policy/process_allowlist.txt
  • xtask/src/main.rs
  • xtask/src/tests.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/em-ci (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)
💤 Files with no reviewable changes (1)
  • policy/network_allowlist.txt

Comment thread xtask/src/main.rs Resolved
Comment thread xtask/src/tests.rs Resolved

@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: b722b35733

ℹ️ 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 thread xtask/src/tests.rs Resolved
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.78947% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
xtask/src/main.rs 15.78% 32 Missing ⚠️

📢 Thoughts on this report? Let us know!

@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

  • Extract a shared validator (e.g. validate_count_allowlist(allowlist, counts) -> Vec) and call it from both check_count_policy and check_local_context_impl. The two functions now carry identical stale-bound + orphan-entry logic; parallel maintenance invites semantic drift. Each caller keeps its own violation-rendering format.
  • Extend count_policy_gates_have_no_stale_bounds with synthetic fixtures: (1) counts map with actual<max_count to assert stale-bound violation text, (2) counts map missing an allowlist key with max_count>0 to assert orphan violation text. Without these, removing the new branches silently keeps the test green. Codex P2 at tests.rs:45653 and CodeRabbit minor at tests.rs:45656 converge on the same fix.
  • Extract a shared validator (e.g. evaluate_count_policy(counts, allowlist) -> Vec) used by both check_count_policy and check_local_context_impl; keep gate-specific rendering at each call site. Prevents semantic drift between the two bidirectional paths (CodeRabbit 'Major' major-4b0d0e0a).
  • count_policy_gates_have_no_stale_bounds is a weak oracle: if either new branch (stale-bound or orphan) is removed/inverted, the test still passes because every real allowlist currently matches. Add synthetic fixtures covering actual < allowed and missing-pattern cases against the shared validator to pin branch behavior. Codex P2 + CR minor already flagged this.

Confirmed findings

  • Two near-identical stale-bound/orphan blocks (main.rs:4798-4831 and 15578-15600) duplicate logic; tests-oracle depends on the shared validator existing to write cheap synthetic cases. Refactor unlocks oracle strength.
  • local_context orphan check uses && entry.max_count > 0 while count_policy orphan uses && *allowed > 0 — semantically identical but copy-paste signal supporting the shared-validator refactor; no behavior bug.
  • artifact-verifier sensor failed with exit code 2; for this diff (policy text + xtask gate logic, no built artifact) the failure is unlikely to indicate a security regression, but the receipt should be re-checked before merge to rule out a poisoned allowlist file or non-UTF8 content causing downstream issues.

Verification questions

  • Confirm new test count_policy_gates_have_no_stale_bounds only exercises the gates against the real allowlists and asserts Ok(()). If the bidirectional branches were removed/inverted, the test would still pass — it never supplies an actual<allowed or absent-pattern fixture. Both CodeRabbit (tests.rs:45656, minor) and ChatGPT Codex (tests.rs:45653, P2) flagged the same gap; this is a confirmed sibling-path concern (synthetic fixture coverage) not refuted by the current diff.
  • Confirm prior thread CodeRabbit + Codex comments already flagged the same synthetic-fixture oracle gap (CR xtask/src/tests.rs:45656, Codex xtask/src/tests.rs:45653). Current diff does not address those comments.
  • Confirm check_count_policy and check_local_context_impl contain duplicated stale-bound and orphan logic; only gate-specific rendering differs. Centralizing into a shared validator is the standard fix.
  • Confirm new test count_policy_gates_have_no_stale_bounds is tautological: passes iff allowlists + code match, never exercises stale-bound or orphan branches.

[review body truncated; see review artifacts]

[review body truncated; see review artifacts]

Comment thread xtask/src/main.rs Resolved
Comment thread xtask/src/tests.rs Resolved
Comment thread xtask/src/main.rs Resolved
Comment thread xtask/src/tests.rs Resolved
@EffortlessSteven
EffortlessSteven merged commit 259ca70 into main Jul 26, 2026
44 of 48 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/count-gates-bidirectional-2413 branch July 26, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run required, advisory, and release-like CI lanes.

Projects

None yet

1 participant