Skip to content

fix(llm): avoid assuming custom clients store a model field - #568

Merged
codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
Elon-Jiang:fix/custom-client-sampling-log
Oct 31, 2026
Merged

codelion merged 1 commit into
algorithmicsuperintelligence:mainfrom
Elon-Jiang:fix/custom-client-sampling-log

Conversation

@Elon-Jiang

Copy link
Copy Markdown
Contributor

Problem

A custom client supplied through LLMModelConfig.init_client can implement every method required by LLMInterface and still fail before generation. _sample_model() evaluates vars(sampled_model)['model'] for a log message, although the interface does not require that instance field. Both generate() and generate_with_context() then raise KeyError: 'model'. A client exposing model as a property also fails.

Change

Log the selected entry's existing configuration name instead of inspecting the client's internal dictionary. Sampling weights, selected client, method arguments, output and usage propagation are unchanged. Extend the existing ensemble tests with interface-only and property-backed clients; these use real client implementations and no mocks or provider calls.

Reproduction

class CustomLLM(LLMInterface):
    async def generate(self, prompt, **kwargs):
        return "answer"

    async def generate_with_context(self, system_message, messages, **kwargs):
        return "context answer"

ensemble = LLMEnsemble([
    LLMModelConfig(name="custom-client", init_client=lambda cfg: CustomLLM())
])
await ensemble.generate("question")  # main raises KeyError('model')

Validation

Python 3.12.13, an isolated editable development install, and OpenAI 2.24.0, which satisfies the declared dependency. Unit tests use a placeholder key.

  • Before the fix, the ensemble module has 2 new errors and 3 passing controls.
  • After the fix, all 5 ensemble tests pass, including the existing weighted sampling and token-usage tests. These were rerun after formatting the touched test file.
  • OPENAI_API_KEY=test-for-offline-tests python -m unittest discover tests: 980 tests ran, OK (skipped=2), in 43.432 seconds.
  • Black checks pass on both changed files; git diff --check passes.

The first full-suite run was blocked by local IPC permissions and reported 2 setup errors. The successful run above allowed the unit tests' local process communication. A multi-file Black invocation hit the same restriction, so the final checks ran one file at a time. No paid model, optillm/model integration suite or browser was used. The test-file diff includes Black's formatting of a few existing lines.

Context

Source-discovered bug, no existing matching issue found. All 47 open PR file lists and the actual ensemble patches in #38, #369, #403, #480 and #495 were checked, as were source history and all-state searches.

AI assistance was used for investigation, implementation and executed local validation. No production incident or independent human review is claimed.

@CLAassistant

CLAassistant commented Oct 31, 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.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codelion
codelion merged commit 32a7e8d into algorithmicsuperintelligence:main Oct 31, 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.

3 participants