Skip to content

Fix composite feedback functions to handle score parameter properly#150

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-144
Draft

Fix composite feedback functions to handle score parameter properly#150
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-144

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 2, 2025

Problem

Composite feedback functions decorated with @CompositeFeedbackFunction (like prevent_advanced_iteration) were incorrectly passing composite-level parameters such as score to each constituent function. This caused score parameters to be multiplied by the number of triggered constituents instead of being applied once to the composite as a whole.

Example of the issue:

from pedal.assertions.static import prevent_advanced_iteration

# Student code that triggers multiple constituents
student_code = """
while True:
    pass
sum([1, 2, 3])
max([1, 2, 3])
"""

# Before fix: score=-5 applied to each triggered function
prevent_advanced_iteration(score=-5)
# Result: Total score impact = -15 (incorrect - multiplied by constituents)

# After fix: score=-5 applied once to the composite
prevent_advanced_iteration(score=-5) 
# Result: Total score impact = -5 (correct - single composite penalty)

Solution

  1. Enhanced the CompositeFeedbackFunction decorator to provide helper methods:

    • extract_composite_parameters() - separates composite-level parameters (score, correct, muted, unscored, priority, label) from constituent-level parameters
    • apply_composite_feedback() - creates a single composite feedback when any constituent is triggered
  2. Updated composite functions to use the new pattern:

    • prevent_advanced_iteration now properly handles composite parameters
    • ensure_prints_exactly updated for consistency
    • Functions track whether any constituent was triggered, then apply composite-level feedback once
  3. Maintained full backward compatibility:

    • Functions called without composite parameters behave identically to before
    • Individual detailed feedback messages are still provided to students
    • Only the scoring and metadata behavior changed

Key Changes

  • pedal/core/feedback.py: Enhanced CompositeFeedbackFunction decorator with parameter separation helpers
  • pedal/assertions/static.py: Updated prevent_advanced_iteration and ensure_prints_exactly to use new mechanism
  • tests/test_composite_feedback_score.py: Comprehensive test coverage for the new behavior

The solution provides a clean, reusable mechanism that other composite feedback functions can adopt, addressing the core architectural issue where composite functions should be treated as single logical units rather than collections of independent functions.

Fixes #144.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Copilot AI changed the title [WIP] Reconsider how prevent_advanced_iteration (and similar) handle score parameter Fix composite feedback functions to handle score parameter properly Sep 2, 2025
Copilot AI requested a review from acbart September 2, 2025 01:43
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.

Reconsider how prevent_advanced_iteration (and similar) handle score parameter

2 participants