Skip to content

fix(api): dedent nested candidate definitions - #601

Merged
codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
original4422:fix/nested-definition-source
Nov 17, 2026
Merged

codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
original4422:fix/nested-definition-source

Conversation

@original4422

Copy link
Copy Markdown
Contributor

Summary

Self-contained functions and classes defined inside another function currently reach their generated standalone file with the enclosing indentation from inspect.getsource. Their first evaluation returns unexpected indent and a zero score before any evolution.

Normalize both convenience helpers before their existing marker handling:

- source = inspect.getsource(candidate)
+ source = textwrap.dedent(inspect.getsource(candidate))

Add six tests that pass the actual emitted candidate and evaluator through _prepare_program/_prepare_evaluator and a real Python subprocess. They cover nested functions/classes, already-marked nested definitions and top-level controls, including relative body indentation. The existing evaluator serialization contract from #423 is unchanged. This does not add closure/free-global capture or decorator/async support.

Evidence

  • Before: all four nested cases fail with unexpected indent/score0; the two top-level controls pass.
  • After: all six new cases and all17 original API tests pass.
  • OPENAI_API_KEY=test-key-for-unit-tests python -m unittest discover tests: 1093 tests run,1086 passed,7 original skips on current main 88efea9. Validation allowed only the original loopback ProposalServer fixtures; no external or LLM provider calls.
  • git diff --check passes. With configured Black25.12.0/isort7.0.0, the new test file passes both checks. The existing api.py and unchanged test_api.py fail the same formatting/import checks before and after (13 Black diff hunks/4 isort hunks; identical residual edit lines). These full-file checks are not reported as passing; unrelated cleanup is excluded.

Implementation and validation assisted by OpenAI Codex; no external implementation copied.

@codelion, when convenient, could you review this focused source-generation fix? Thank you.

Merge Danger

Door: two-way.

Blast Radius: API.

Only the source emitted by evolve_function and evolve_algorithm is normalized. Existing relative indentation and marker handling remain in use.

Signed-off-by: Daniel Peng <zgpeng2002@163.com>
@codelion
codelion merged commit a7950ff into algorithmicsuperintelligence:main Nov 17, 2026
5 checks passed
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
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