Skip to content

Bug: Fix success_criteria to track when clause precedence#1653

Open
tteggelit wants to merge 10 commits into
GoogleCloudPlatform:developfrom
tteggelit:success_criteria_precedence_bug
Open

Bug: Fix success_criteria to track when clause precedence#1653
tteggelit wants to merge 10 commits into
GoogleCloudPlatform:developfrom
tteggelit:success_criteria_precedence_bug

Conversation

@tteggelit

Copy link
Copy Markdown

Currently, success_criteria allows for scoping via when clauses, but definitions of these criteria are not properly tracked in the success_criteria dict. In cases where multiple when clauses are satisfied and define the same criteria name, this leads to the last defined criteria winning. This fix properly tracks satisfying when conditions selecting the highest precedence criteria.

In the case where multiple when conditions are satisfied at the same precedence, ramble will now throw an error. Because of this, the WRF application was also fixed as it defined both an unscoped "Complete" criteria and one for specific WRF versions. The versioned definitions are mutually exclusive, but the unscoped criteria would always be satisfied resulting in a conflict between it and the satisfied versioned criteria.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors how success criteria are stored and resolved in Ramble. Success criteria are now grouped by their conditional 'when' sets (using frozenset) to handle conflicting conditions and prevent duplicate definitions. The WRF application's success criteria have been cleaned up, and the base class analysis logic has been updated to handle the new nested structure. The review feedback suggests simplifying the resolved_criteria dictionary to a set, as its values are never read and it is only used for membership testing.

Comment thread var/ramble/repos/builtin/base_classes/application-base/base_class.py Outdated
Comment thread var/ramble/repos/builtin/base_classes/application-base/base_class.py Outdated
@linsword13

Copy link
Copy Markdown
Member

/gcbrun

@ramble-pr-bot

ramble-pr-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

Ramble Performance Test Metrics

Results produced with commit: b34e11a

Test Name Outcome Duration (s) Most Recent Run (s) Last 5 Avg (s)
test_analyze_large_file passed 2.8904 2.9233 (0cae61a) 2.9249
test_large_template_expansion passed 2.1596 2.1519 (0cae61a) 2.1593
test_many_experiments passed 38.4660 37.2774 (0cae61a) 37.4424
test_many_objects_defaults passed 20.8432 19.9659 (0cae61a) 19.9664
test_matrix_filter_perf passed 1.5894 1.6012 (0cae61a) 1.5951

@linsword13 linsword13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be useful to add in some unit tests for the new/correct behavior?

Comment thread var/ramble/repos/builtin/applications/wrf/application.py
Comment thread var/ramble/repos/builtin/base_classes/application-base/base_class.py Outdated
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.32%. Comparing base (0cae61a) to head (b34e11a).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1653      +/-   ##
===========================================
+ Coverage    93.30%   93.32%   +0.02%     
===========================================
  Files          352      353       +1     
  Lines        34223    34311      +88     
===========================================
+ Hits         31931    32020      +89     
+ Misses        2292     2291       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tteggelit

Copy link
Copy Markdown
Author

Would it be useful to add in some unit tests for the new/correct behavior?

I added some unit tests to cover various precedence situations.

@tteggelit

Copy link
Copy Markdown
Author

@linsword13 I think with this latest push, it should be ready for a re-review.

@linsword13

Copy link
Copy Markdown
Member

/gcbrun

@linsword13

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates Ramble's success criteria handling to group criteria by their 'when' conditions, allowing the detection of conflicts when the same success criteria is defined multiple times under conflicting satisfied conditions. It also adds comprehensive tests and mock applications to verify precedence, inheritance, and conflict behavior. The review feedback suggests removing an unused loop variable 'prec' in 'base_class.py' and eliminating redundant loops in the test file that repeatedly open and assert against the same results file.

Comment thread var/ramble/repos/builtin/base_classes/application-base/base_class.py Outdated
Comment thread lib/ramble/ramble/test/success_criteria_functionality/success_precedence.py Outdated
Comment thread lib/ramble/ramble/test/success_criteria_functionality/success_precedence.py Outdated
Comment thread lib/ramble/ramble/test/success_criteria_functionality/success_precedence.py Outdated
@tteggelit

Copy link
Copy Markdown
Author

@linsword13 Implemented the Gemini code review suggestions, so I'll need one more re-review kicked off.

@linsword13

Copy link
Copy Markdown
Member

/gemini review

@linsword13

Copy link
Copy Markdown
Member

/gcbrun

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors how success criteria are stored and resolved in Ramble to handle conflicts, inheritance, and mutually exclusive conditions correctly. Specifically, success criteria are now grouped by their when conditions (as a frozenset), and the analysis resolution logic has been updated to detect and error out on conflicting satisfied conditions, while respecting inheritance precedence. Additionally, a new set of unit tests and mock applications have been introduced to verify these behaviors. I have no feedback to provide as there are no review comments to evaluate.

@linsword13

Copy link
Copy Markdown
Member

/gcbrun

@tteggelit

Copy link
Copy Markdown
Author

@linsword13 I think this is now ready for final review.

packages: {}
environments: {}
"""
with ramble.workspace.create(workspace_name) as ws:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: There's a pytest fixture make_workspace_from_config that may simplify some of these setup.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The unit test I cribbed off of did it this way, but I can update it to use make_worksapce_from_config if that is the preferred method now.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

OK. Just committed update to switch to make_workspace_from_config

existing_when_set = obj_satisfied_criteria[name][0]
logger.die(
f"Success criteria '{name}' in object '{obj_inst.name}' is defined multiple times "
f"under conflicting satisfied 'when' conditions:\n"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just curious: does that mean this will not tolerate duplicate when?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Without the specificity functionality we talked about, if there are multiple satisfying when conditions at the same precedence level, it will trigger an error. This seems to be the current way of handling this. Allowing 'when' specificity would change this and only trigger an error if there were multiple satisfies at the same specificity.

mode="application_function",
owning_object=self,
)
if "_application_function" not in resolved_criteria:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this guard needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There may be no current code path that defines an _application_function scoped success_criteria currently, but I added this in defense in case there is. I don't believe add_criteria() does any kind of deduplication so if one already existed for some reason, there would be duplicate criteria added then.

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