Skip to content

fix(metrics): guard boolean flags and non-finite values across fitness, prompts, traces, and coevolution - #625

Open
peterzhang987723 wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
peterzhang987723:fix/boolean-nonfinite-metric-integrity
Open

peterzhang987723 wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
peterzhang987723:fix/boolean-nonfinite-metric-integrity

Conversation

@peterzhang987723

Copy link
Copy Markdown

Summary

In Python, bool is a subclass of int (isinstance(True, int) is True). While openevolve already guarded some formatting and average paths, several remaining runtime paths still treated boolean status flags (timeout=True, valid=False, combined_score=True) or NaN/Inf/None values as numeric fitness scores or improvements, causing silent reward/metric spoofing and TypeError/ZeroDivisionError edge-case failures.

Root Causes Fixed

  1. openevolve/utils/metrics_utils.py:
    • Exclude bool and NaN in safe_numeric_sum, get_fitness_score (combined_score fast-path), and format_feature_coordinates.
  2. openevolve/evolution_trace.py:
    • Exclude bool and non-finite (NaN/Inf) deltas in both EvolutionTrace.calculate_improvement and extract_full_lineage_traces.
  3. openevolve/evaluator.py:
    • In evaluate_program (use_llm_feedback=True), skip blending combined_score when accuracy is a bool, NaN, or non-numeric.
    • In _passes_threshold, reject bool and NaN values on combined_score (allowing numeric fallback instead of passing True as 1.0) and ignore NaN in the fallback average.
  4. openevolve/coevolution.py:
    • Add _has_finite_score() checking not isinstance(score, bool) and isinstance(score, (int, float)) and math.isfinite(score) for both phase refresh re-evaluation and champion validation (so combined_score=True or None/str raises ValueError instead of passing or raising TypeError).
  5. openevolve/process_parallel.py:
    • Use format_metrics_safe when logging child metrics (avoiding timeout=1.0000).
    • Guard target_score and early_stopping checks against bool and NaN/Inf scores.
  6. openevolve/prompt/sampler.py:
    • Exclude bool from float formatting in _format_metrics, _format_evolution_history, and top_programs feature summaries.
    • Exclude bool and NaN from parent-child comparisons (preventing timeout: False -> True from emitting "Improvement in all metrics") and inspiration highlights (preventing timeout: True from emitting "Excellent timeout (1.000)").
  7. openevolve/api.py, openevolve/cli.py, openevolve/database.py:
    • Route api.run_evolution best_score calculation through get_fitness_score (so timed-out programs with {"error": 0.0, "timeout": True} yield 0.0 instead of 0.5).
    • Exclude bool in cli.py final metric printing.
    • Exclude NaN in database._safe_sum_metrics / _safe_avg_metrics, and guard ProgramDatabase.__init__ against empty feature_dimensions (ZeroDivisionError).

Verification

  • Added comprehensive regression tests in tests/test_metric_integrity_guards.py covering PromptSampler, Evaluator, run_coevolution, ProcessParallelController, ProgramDatabase, EvolutionTrace / extract_full_lineage_traces, and api.run_evolution.
  • Formatted all touched files with isort --profile black --line-length 100 and black --line-length 100.
  • Verified pytest tests -m "not slow and not integration" and tests/test_coevolution.py.

@CLAassistant

CLAassistant commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhangshoufa seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@peterzhang987723
peterzhang987723 force-pushed the fix/boolean-nonfinite-metric-integrity branch from e5daeb0 to 12e4d6b Compare November 27, 2026 14:25

This branch has not been deployed

No deployments
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