Skip to content

fix(checks): harden trusted policy scanners - #7159

Merged
cv merged 7 commits into
mainfrom
codex/7047-followup-policy-scanners
Jul 19, 2026
Merged

fix(checks): harden trusted policy scanners#7159
cv merged 7 commits into
mainfrom
codex/7047-followup-policy-scanners

Conversation

@apurvvkumaria

@apurvvkumaria apurvvkumaria commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

This follow-up hardens the trusted CI ratchet and OpenShell policy-read scanner after #7047 merged before the final maintainer fix could land. It removes a duplicate root-dependency execution path and prevents locally shadowed require or lookalike resolver calls from satisfying the policy-read check.

Related Issue

Follow-up to #7047.

Changes

  • Remove the duplicate root npx tsx invocation of the base-trusted createRequire ratchet.
  • Require CommonJS policy-builder imports to resolve to the ambient require, not a locally shadowed decoy.
  • Count resolveOpenshellBinary() policy reads only from the canonical policy command module and declaration.
  • Add workflow and scanner regressions covering the trust-boundary and AST-decoy cases.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: internal CI and static-analysis enforcement only; no user-facing behavior or configuration changes
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: exact diff reviewed for CI trust-boundary and policy-scanner false-negative behavior; focused negative regressions pass
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification: npx vitest run --project integration test/policy-mutation-read-discovery.test.ts test/pr-workflow-contract.test.ts (30 passed)
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result: npm run checks passed; diff-scoped prek and the normal pre-push TypeScript gates passed
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Apurv Kumaria akumaria@nvidia.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved policy-read discovery to reduce false positives from shadowed require usage and non-canonical OpenShell resolver calls.
    • Strengthened canonical resolver detection to improve classification of direct policy reads.
  • Tests
    • Added Vitest cases to ensure resolver decoys are not counted and canonical resolver reads are counted correctly (including --base and --full).
    • Expanded workflow contract assertions to prevent invoking the ratchet script via npx tsx.
  • Chores
    • Updated the static-checks workflow to run the ratchet validation script directly with Node.

Co-authored-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
@apurvvkumaria apurvvkumaria added area: ci CI workflows, checks, release automation, or GitHub Actions chore Build, CI, dependency, or tooling maintenance labels Jul 18, 2026
@apurvvkumaria apurvvkumaria self-assigned this Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ab4fd1af-2b65-496c-9086-bbae6832f282

📥 Commits

Reviewing files that changed from the base of the PR and between 0e1b1e2 and 3793c92.

📒 Files selected for processing (2)
  • scripts/checks/openshell-policy-mutation-read.mts
  • test/policy-mutation-read-discovery.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/policy-mutation-read-discovery.test.ts
  • scripts/checks/openshell-policy-mutation-read.mts

📝 Walkthrough

Walkthrough

The policy-read checker now validates require symbols and canonical OpenShell resolver sources. The static-checks action runs the create-require ratchet with Node’s experimental TypeScript support, with workflow contract coverage for the invocation change.

Changes

Policy mutation-read discovery

Layer / File(s) Summary
Checker-aware binding validation
scripts/checks/openshell-policy-mutation-read.mts
Required policy bindings now verify the require identifier through the TypeScript checker before extracting module specifiers.
Canonical resolver detection and coverage
scripts/checks/openshell-policy-mutation-read.mts, test/policy-mutation-read-discovery.test.ts
Direct reads require the canonical resolver from src/lib/policy/commands.ts; tests cover shadowed bindings and canonical resolver arrays.

CI ratchet execution

Layer / File(s) Summary
Node-based ratchet invocation
.github/actions/ci-static-checks/action.yaml, test/pr-workflow-contract.test.ts
The static-checks action invokes create-require-ratchet.mts with Node, and the workflow contract rejects the previous npx tsx command.

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

Possibly related PRs

  • NVIDIA/NemoClaw#6122: Directly relates to the policy mutation-read discovery logic and its detected policy-read targets.
  • NVIDIA/NemoClaw#7047: Directly overlaps with the AST-based policy-read discovery and counting changes.
  • NVIDIA/NemoClaw#7057: Directly relates to the create-require ratchet execution and workflow contract.

Suggested labels: area: policy, bug-fix

Suggested reviewers: laitingsheng

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: hardening the CI ratchet and OpenShell policy scanner checks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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/7047-followup-policy-scanners

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

@github-code-quality

github-code-quality Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage remains at 96%, unchanged from the main branch.

TypeScript / code-coverage/cli

The overall coverage in the codex/7047-followup-... branch remains at 80%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main 6fbbcb3 codex/7047-followup-... ef31883 +/-
src/lib/inferen...lama/process.ts 100% 50% -50%
src/lib/inferen...er-lifecycle.ts 71% 65% -6%
src/lib/sandbox...rce-identity.ts 91% 91% 0%
src/lib/state/m...ock-identity.ts 95% 95% 0%
src/lib/state/m...lock-storage.ts 97% 97% 0%
src/lib/tunnel/services.ts 73% 73% 0%
src/lib/onboard...carryforward.ts 92% 96% +4%
src/lib/state/m...-acquisition.ts 84% 89% +5%

Updated July 19, 2026 15:03 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / high confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

Since last review: 0 prior items resolved · 0 still apply · 0 new items found

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: None

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

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

Actionable comments posted: 1

🤖 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 `@test/policy-mutation-read-discovery.test.ts`:
- Around line 55-64: Add a focused false-positive test for countPolicyReadCalls
using the canonical /repo/src/lib/policy/commands.ts path, with a nested
function parameter or local named resolveOpenshellBinary shadowing the resolver
symbol; assert the result is 0. Keep the existing decoy test, and ensure the new
case exercises declaration-origin validation rather than being rejected by the
filename guard.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 31419bc9-596d-4a36-ad26-0520eb9eb066

📥 Commits

Reviewing files that changed from the base of the PR and between 07432e6 and 683bdb1.

📒 Files selected for processing (4)
  • .github/actions/ci-static-checks/action.yaml
  • scripts/checks/openshell-policy-mutation-read.mts
  • test/policy-mutation-read-discovery.test.ts
  • test/pr-workflow-contract.test.ts
💤 Files with no reviewable changes (1)
  • .github/actions/ci-static-checks/action.yaml

Comment thread test/policy-mutation-read-discovery.test.ts
Co-authored-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
@cv cv added the v0.0.89 label Jul 19, 2026
@apurvvkumaria

Copy link
Copy Markdown
Collaborator Author

Exact-head maintainer security audit completed at 5adc302956d6627be831db4f893494c581dac4d0.

  • The PR job checks out the trusted composite action from the exact base SHA under .trusted-ci-actions, retains contents: read, and disables persisted checkout credentials.
  • Relevant external actions are pinned to immutable, GitHub-verified commits.
  • The createRequire ratchet executes once from the base-trusted action path before root dependencies are installed; the duplicate root npx tsx execution path is gone.
  • Policy-read discovery now resolves symbols, rejecting locally shadowed require and resolver decoys while preserving the canonical src/lib/policy/commands.ts reads.
  • Local validation: focused integration tests 31/31 passed, direct policy-mutation audit passed, and git diff --check passed.
  • All three commits are GitHub Verified, DCO is green, all current CI/advisor/protected-E2E checks are green, and there are no unresolved review threads.

No blocker found. Independent review requested from @laitingsheng; I am not self-approving an author-owned PR.

Co-authored-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Apurv Kumaria <akumaria@nvidia.com>
@apurvvkumaria

Copy link
Copy Markdown
Collaborator Author

Follow-up exact-head security audit found one remaining declaration-origin gap in the policy-read scanner: a nested function declaration named resolveOpenshellBinary inside the canonical command file still satisfied the same-file/function predicate and could be counted as the canonical resolver.\n\nFixed in 3793c92 by requiring the resolver declaration to be top-level (SourceFile-owned), with a focused nested-function regression.\n\nValidation on the pushed revision:\n- targeted integration tests: 32/32 passed\n- direct OpenShell policy-mutation audit passed\n- Biome, changed-file prek hooks, test-title check, and git diff --check passed\n- pre-push CLI typecheck and version-sync hooks passed\n- commit is signed, DCO-compliant, GitHub Verified, and retains Carlos co-author credit\n\nCurrent CI/advisor/E2E checks are running. Existing labels were preserved unchanged.

@cv cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved after current-base review: trusted scanner hardening is fail-closed, security review found no blocker, the canonical advisor reports no findings, risky paths have regression coverage, contributor compliance is complete, and all 51 current checks are green.

@cv
cv merged commit bb5ec40 into main Jul 19, 2026
52 checks passed
@cv
cv deleted the codex/7047-followup-policy-scanners branch July 19, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci CI workflows, checks, release automation, or GitHub Actions chore Build, CI, dependency, or tooling maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants