Skip to content

fix(engine): preserve single-pass engine iterables - #679

Open
linjiaye929 wants to merge 1 commit into
michaelfeil:mainfrom
linjiaye929:codex/engine-array-iterables
Open

linjiaye929 wants to merge 1 commit into
michaelfeil:mainfrom
linjiaye929:codex/engine-array-iterables

Conversation

@linjiaye929

Copy link
Copy Markdown

Summary

AsyncEngineArray.__init__ accepts an Iterable[AsyncEmbeddingEngine], but consumes it while counting engines and then iterates it again for name validation and storage. Valid iterators and generators therefore raise ValueError("Engines must have unique model names"). Empty iterators and generators bypass the initial truthiness check and create an empty array instead.

Materialize the iterable once before checking for empty input or duplicate names. Preserve engine order and identity, and document the constructor's iterable contract.

Validation

Linux, Python 3.12.14, NumPy 1.26.4, CPU-only PyTorch 2.8.0, sentence-transformers 3.3.1, and pytest 8.4.2.

From libs/infinity_emb:

DO_NOT_TRACK=1 HF_HUB_OFFLINE=1 python -m pytest tests/unit_test/test_engine_array.py -q
  • 16 passed after the change.
  • The same tests against unmodified 040269b give 6 failed, 10 passed. Failures cover valid single-pass iterables and empty single-pass iterables.
  • Each collection form (list, tuple, iterator, generator) is checked for preserved order/identity, empty-input rejection, duplicate-name rejection, startup, inference, and shutdown. Lifecycle tests use Infinity's actual debugengine and batching workers, with no inference mocks or model downloads. These are not pretrained-model or HTTP-server tests.

Adjacent checks:

DO_NOT_TRACK=1 HF_HUB_OFFLINE=1 python -m pytest \
  tests/unit_test/test_engine_array.py \
  tests/unit_test/test_engine.py::test_async_api_debug \
  tests/unit_test/test_engine.py::test_args_between_array_and_engine_same \
  tests/unit_test/test_sync_engine.py::test_sync_engine \
  tests/unit_test/test_sync_engine.py::test_sync_engine_double \
  tests/unit_test/inference/test_select_model.py \
  -k 'not torch and not optimum and not ctranslate2' -q
python -m pytest tests/unit_test/test_args.py -q
  • 25 passed, 3 deselected, then 3 passed.
  • ruff check . passes. Formatting, codespell, and git diff --check pass for changed files.
  • mypy infinity_emb reports the same 22 missing-optional-dependency errors on this branch and unmodified main, with identical output and no engine.py errors.
  • Full make precommit, pretrained-model, accelerator, and HTTP-server suites were not run in this minimal CPU environment.

Checklist

  • Read the contribution guidelines.
  • Added regression tests.
  • Updated the Python engine documentation.

AI assistance was used to prepare this contribution.

@linjiaye929
linjiaye929 marked this pull request as ready for review October 12, 2026 10:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T10:27:54.235212Z 5992433 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

AsyncEngineArray now saves the supplied engines before checking their count and names.

  • Engine arrays keep engines from iterators and generators.

No actionable issues were found. Tests were inspected but not run during this review.

Reviews (1) · Last reviewed commit: "fix(engine): preserve single-pass engine..." · Reviewed by Greptile

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.

1 participant