Skip to content

Fix BUG-138: Correct threshold checking by filtering qualified groundings#101

Merged
ColtonPayne merged 10 commits intomainfrom
fix-bug-138
Jan 30, 2026
Merged

Fix BUG-138: Correct threshold checking by filtering qualified groundings#101
ColtonPayne merged 10 commits intomainfrom
fix-bug-138

Conversation

@ColtonPayne
Copy link
Copy Markdown
Collaborator

@ColtonPayne ColtonPayne commented Jan 26, 2026

Summary

Fixed critical bug (Issue #98) in check_all_clause_satisfaction where threshold checks were broken due to passing unfiltered groundings twice instead of properly filtering by clause bounds.

Problem

BUG-138 (CRITICAL severity) affected threshold-based rule evaluation:

  • check_all_clause_satisfaction() was passing groundings[clause_var_1] twice:
    • Once as the total grounding (correct)
    • Again as the qualified grounding (incorrect - should be filtered by clause bound)

This caused threshold checks to always compare the same set against itself, breaking both quantifier types:

"available" quantifier

  • Expected: qualified_count / available_count
  • Actual (bug): total_count / available_count
  • Example: 5/4 = 125% instead of 2/4 = 50%

"total" quantifier

  • Expected: qualified_count / total_count
  • Actual (bug): total_count / total_count
  • Example: 5/5 = 100% instead of 2/5 = 40%

Solution

Added proper filtering by clause bounds before threshold checking:

# Extract clause bound
clause_bnd = clause[3]

# Filter groundings by clause bound
qualified_groundings = get_qualified_node_groundings(
    interpretations_node, groundings[clause_var_1], clause_label, clause_bnd)

# Pass filtered groundings to threshold check
satisfaction = check_node_grounding_threshold_satisfaction(
    interpretations_node, 
    groundings[clause_var_1],    # Total/available denominator
    qualified_groundings,         # Qualified numerator (now filtered!)
    clause_label, thresholds[i])

Changes

  • interpretation.py (lines 1237, 1242-1243, 1245-1247): Fixed threshold checking for both node and edge clauses
  • interpretation_fp.py (lines 1358, 1362-1363, 1365-1367): Applied same fix for consistency
  • test_ground_rule_helpers.py: Added comprehensive tests:
    • test_check_all_clause_satisfaction_available_threshold_bug138
    • test_check_all_clause_satisfaction_total_threshold_bug138

Testing

Added two tests test_check_all_clause_satisfaction_available_threshold_bug138 and test_check_all_clause_satisfaction_total_threshold_bug138 to verify the initial behavior and that the fix aligns this with the intended behavior.

Previous Interpretation - Failed tests
Screenshot from 2026-01-26 08-27-16

With Fixes - Tests pass
Uploading Screenshot from 2026-01-26 08-28-28.png…

🤖 Generated with Claude Code

ColtonPayne and others added 9 commits January 26, 2026 08:15
…ings

Fixed critical bug where check_all_clause_satisfaction was passing the
same grounding twice instead of filtering by clause bounds.

Problem:
- check_node/edge_grounding_threshold_satisfaction received unfiltered
  groundings for both total and qualified parameters
- This caused incorrect threshold calculations for both 'total' and
  'available' quantifier types
- Example: 5/5 = 100% instead of correct 2/4 = 50%

Solution:
- Extract clause_bnd from clause[3]
- Call get_qualified_node/edge_groundings to filter by clause bounds
- Pass filtered groundings as qualified_groundings parameter

Changes:
- interpretation.py: Added filtering in check_all_clause_satisfaction
- interpretation_fp.py: Added same fix for consistency
- test_ground_rule_helpers.py: Added comprehensive tests demonstrating
  the bug and validating the fix for both 'available' and 'total'
  quantifier types

Tests:
- test_check_all_clause_satisfaction_available_threshold_bug138
- test_check_all_clause_satisfaction_total_threshold_bug138

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated test cases to work with the corrected check_all_clause_satisfaction:

1. Made FakeWorld.is_satisfied backward compatible:
   - Uses bounds_by_label for interval containment checks (new BUG-138 tests)
   - Falls back to truth_by_label for legacy tests

2. Updated existing test clauses to use proper 5-element structure:
   - Added clause_bnd and operator to match real clause structure
   - Updated: test_check_all_clause_satisfaction_calls_both_helpers_and_ands_results
   - Updated: test_check_all_clause_satisfaction_all_true_returns_true
   - Updated: test_check_all_clause_satisfaction_multiple_clauses_no_short_circuit

3. Simplified mock assertions to check call counts instead of exact arguments
   since qualified_groundings is now passed as second parameter

All 142 tests now pass.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dyumanaditya dyumanaditya self-requested a review January 29, 2026 17:47
Copy link
Copy Markdown
Contributor

@dyumanaditya dyumanaditya left a comment

Choose a reason for hiding this comment

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

looks good @ColtonPayne

@ColtonPayne ColtonPayne merged commit fa3eccb into main Jan 30, 2026
3 checks passed
@ColtonPayne ColtonPayne deleted the fix-bug-138 branch January 30, 2026 11:28
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.

2 participants