Repository navigation
gate(xtask): count-based gates now check bidirectionally — stale bounds and orphaned entries flagged (#2413, #2399) - #2466
Conversation
…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.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Sorry @EffortlessSteven, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Summary by CodeRabbit
WalkthroughThe count-based policy gates now flag stale positive ChangesCount Policy Gate Tightening
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
policy/network_allowlist.txtpolicy/process_allowlist.txtxtask/src/main.rsxtask/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
There was a problem hiding this comment.
💡 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".
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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 < allowedand 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 > 0while 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]
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):count < allowed→ violation naming the file, pattern, and the actual count to tighten to.check_local_context_impl:groupedso 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.use std::process::Commandentries:receipt.rs,git.rs,cli_smoke.rs,lsp_lifecycle.rs— these imports were removed by prior refactoring (into the sharedgit.rshelper).policy/network_allowlist.txt:httpentries:perl_gap_record_projection.rs(5) andtypescript_packet_projection.rs(3) — these tracked absence-assertions (comments verifyinghttpdoesn't appear), but the gate never searched forhttpas 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_boundsruns 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
Before the gate-logic fix,
check-process-policyflagged 2 stale + 4 orphaned entries;check-network-policyflagged 2 orphaned entries. After tightening the allowlist + the logic fix, all three gates pass clean.Scope
policy_checker_facadetest still passes.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::newor 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