Skip to content

fix(hooks): propagate customPoliciesEnabled in readMergedHooksConfig … - #617

Open
AVPthegreat wants to merge 1 commit into
FailproofAI:mainfrom
AVPthegreat:fix/custom-policies-enabled-config
Open

fix(hooks): propagate customPoliciesEnabled in readMergedHooksConfig …#617
AVPthegreat wants to merge 1 commit into
FailproofAI:mainfrom
AVPthegreat:fix/custom-policies-enabled-config

Conversation

@AVPthegreat

Copy link
Copy Markdown

Summary

Fixes #590 by ensuring customPoliciesEnabled is read across project, local, and global configuration scopes and returned by readMergedHooksConfig.


❌ Root Cause Analysis

In src/hooks/hooks-config.ts, the readMergedHooksConfig(cwd) function merges policy configurations across 3 scopes:

  1. Project (.failproofai/policies-config.json)
  2. Local (.failproofai/policies-config.local.json)
  3. Global (~/.failproofai/policies-config.json)

Why it failed:

  1. The HooksConfig type defines customPoliciesEnabled?: boolean;.
  2. The configuration UI wizard writes customPoliciesEnabled: false to policies-config.json when unticking custom policies.
  3. Inside readMergedHooksConfig, the function merged enabledPolicies, policyParams, customPoliciesPath, and llm, but forgot to read or include customPoliciesEnabled!
  4. As a result, when src/hooks/handler.ts called:
    const config = readMergedHooksConfig(session.cwd);
    const loadResult = await loadAllCustomHooks(config.customPoliciesPath, {
      sessionCwd: session.cwd,
      customPoliciesEnabled: config.customPoliciesEnabled, // <--- ALWAYS UNDEFINED!
    });
    config.customPoliciesEnabled was always undefined, so setting "customPoliciesEnabled": false in config had no effect and custom convention policies continued to load.

✅ Fix Details

Updated readMergedHooksConfig in src/hooks/hooks-config.ts to merge customPoliciesEnabled using first-scope-wins priority (project > local > global):

// Merge customPoliciesEnabled (first scope that defines it wins):
const customPoliciesEnabled =
  project.customPoliciesEnabled ?? local.customPoliciesEnabled ?? global_.customPoliciesEnabled;

return {
  enabledPolicies: [...enabledSet],
  ...(Object.keys(mergedParams).length > 0 ? { policyParams: mergedParams } : {}),
  ...(customPoliciesPath !== undefined ? { customPoliciesPath } : {}),
  ...(customPoliciesEnabled !== undefined ? { customPoliciesEnabled } : {}), // <--- Included
  ...(llm !== undefined ? { llm } : {}),
};

🧪 Unit Tests & Verification

Added unit test coverage in __tests__/hooks/hooks-config.test.ts:

it("customPoliciesEnabled: first scope that defines it wins", async () => {
  mockFiles({
    [projectPath]: { enabledPolicies: [], customPoliciesEnabled: false },
    [globalPath]: { enabledPolicies: [], customPoliciesEnabled: true },
  });
  const { readMergedHooksConfig } = await import("../../src/hooks/hooks-config");
  const config = readMergedHooksConfig(CWD);
  expect(config.customPoliciesEnabled).toBe(false);
});

it("customPoliciesEnabled: local scope wins over global when project is undefined", async () => {
  mockFiles({
    [localPath]: { enabledPolicies: [], customPoliciesEnabled: false },
    [globalPath]: { enabledPolicies: [], customPoliciesEnabled: true },
  });
  const { readMergedHooksConfig } = await import("../../src/hooks/hooks-config");
  const config = readMergedHooksConfig(CWD);
  expect(config.customPoliciesEnabled).toBe(false);
});

Test Results:

  • Ran vitest run __tests__/hooks/hooks-config.test.ts
  • Result: ✓ 36 passed (36)

Copilot AI review requested due to automatic review settings July 28, 2026 09:23
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AVPthegreat, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f53913e-cc53-4060-b59f-967d8f92979a

📥 Commits

Reviewing files that changed from the base of the PR and between af74838 and 1017742.

📒 Files selected for processing (2)
  • __tests__/hooks/hooks-config.test.ts
  • src/hooks/hooks-config.ts

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.

@hermes-exosphere

Copy link
Copy Markdown
Contributor

Your PR is awaiting review by a reviewer. Till then you can join the Discord for conversation: https://discord.befailproof.ai

Copilot AI 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.

Pull request overview

This PR fixes a config-merging gap in the hooks subsystem by ensuring the customPoliciesEnabled flag is propagated through readMergedHooksConfig, so users can reliably disable convention-discovered custom policies via config.

Changes:

  • Merge customPoliciesEnabled across project/local/global scopes using “first defined scope wins”.
  • Include customPoliciesEnabled in the readMergedHooksConfig return value only when explicitly set.
  • Add unit tests covering scope precedence for customPoliciesEnabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/hooks/hooks-config.ts Adds merged customPoliciesEnabled handling to ensure enforcement respects the config toggle.
__tests__/hooks/hooks-config.test.ts Adds regression tests verifying the correct precedence rules for customPoliciesEnabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hooks/hooks-config.ts
Comment on lines 100 to 105
return {
enabledPolicies: [...enabledSet],
...(Object.keys(mergedParams).length > 0 ? { policyParams: mergedParams } : {}),
...(customPoliciesPath !== undefined ? { customPoliciesPath } : {}),
...(customPoliciesEnabled !== undefined ? { customPoliciesEnabled } : {}),
...(llm !== undefined ? { llm } : {}),
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.

customPoliciesEnabled: false is a silent no-op — never propagated by readMergedHooksConfig

3 participants