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