Repository navigation
fix: count evaluator feedback and novelty judge calls in the token total - #604
Merged
codelion merged 1 commit intoNov 20, 2026
Conversation
The run's token total counted only each iteration's code-generation call. LLMEnsemble.generate_all_with_context (evaluator feedback) never recorded usage, and the novelty judge's calls inside database.add() were never added. LLMEnsemble now sums usage over every call (take_usage()), the worker adds the evaluator's usage to the iteration, and the run loop adds the novelty judge's usage and counts calls instead of iterations.
will-rice
added a commit
to will-rice/openevolve
that referenced
this pull request
Nov 21, 2026
Upstream's fixes: a NaN combined_score ranks worst (algorithmicsuperintelligence#603), the evaluator's and the novelty judge's LLM calls count in the token totals (algorithmicsuperintelligence#604), Mistral API support (algorithmicsuperintelligence#602), responses cut off at max_tokens are reported (algorithmicsuperintelligence#599), nested candidate definitions dedent (algorithmicsuperintelligence#601), llm.system_message is no longer dropped (algorithmicsuperintelligence#598), Gemini seeding without a trailing slash (algorithmicsuperintelligence#600) and an R example fix (algorithmicsuperintelligence#597). Two conflicts, both where the fork had moved upstream's code: - llm/ensemble.py: upstream's per-call usage sum (_record_usage, take_usage) beside the fork's last_message and last_backend, both kept. - process_parallel.py: the fork evaluates a child in _evaluate_child (generated and injected children alike); upstream's count of the evaluator's own LLM calls moves there, after the evaluation, into the result's and the metadata's usage. The fork's suite fails the same 23 tests before and after the merge (upstream's own, unrelated to it). Claude-Session: https://claude.ai/code/session_01RnaESRvvoubZsW6wWrQAPQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The run's token total (
Total LLM Token Usage (N calls), logged at the end ofrun_evolution) counts only the code-generation call of each iteration. Two features make their own LLM calls, and neither reaches the total:evaluator.use_llm_feedback,Evaluator._llm_evaluateasks every feedback model throughLLMEnsemble.generate_all_with_context, which never recorded usage.database.embedding_modelset, the novelty judge (ProgramDatabase._llm_judge_novelty) callsnovelty_llminsidedatabase.add(), in the main process.Both are off by default, so a default run is not affected. With LLM feedback on and 2 feedback models, an iteration makes 3 calls and the total counts 1 of them. The
N callsin the log also counted iterations, not calls.Changes:
LLMEnsemblesums the usage of every call it makes, including each model ingenerate_all_with_context.take_usage()returns that sum and starts a new one.last_usageis unchanged.token_usage, with acallscount.database.add()and counts calls instead of iterations. It readstoken_usageonly when it is a dict.Tests:
test_llm_ensemble.py(sums across feedback models and across single calls, and the two helpers),test_diff_format_validation_worker.py(evaluator usage is added to an iteration), andtest_process_parallel.py(a one-iteration run logs 4 calls and the right totals for 3 worker calls and 1 novelty call).Verified on macOS with Python 3.12.0, on
mainat01583a4:python -m unittest tests.test_llm_ensemble tests.test_diff_format_validation_worker tests.test_process_parallel: 47 tests OK.python -m unittest discover -s tests -p "test_*.py": 1,109 tests, 1 failure, 7 skipped. The failure istest_alphaevolve_reverse.test_unexpected_awaitable_result_is_closed_and_rejected('CORO_CREATED' != 'CORO_CLOSED'). It fails the same way onmainat01583a4without this change.black --checkpasses on the 5 changed files.Only the OpenAI-compatible backend reports usage today, so runs on the Claude Code, Codex app server and Copilot CLI backends still show no tokens. This PR does not change that.
This also gives a correct base for a run-level token budget, which I'd like to propose separately.
Claude Code helped prepare this change. I directed it and ran the checks above.