Repository navigation
Fix/optional usage metadata - #10
Merged
HenriqueAssumpcao merged 2 commits intoNov 10, 2026
Merged
HenriqueAssumpcao merged 2 commits into
HenriqueAssumpcao merged 2 commits into
Conversation
OpenAILM.generate read `ret.usage.prompt_tokens` inside its retry block. With OpenAI-compatible providers that omit the optional `usage` field, a successful (billed) completion raised AttributeError, was retried retries+1 times, and was finally discarded as a ConnectionError. OpenAIEmbedding.embed_batch had the same problem with `total_tokens`. - Only the request itself is retried; once it succeeds, missing or partial usage is reported as None token counts instead of an error. The ensemble logs a warning through the island logger. - Responses with no choices (or the wrong number of embedding vectors) raise a clear EmptyResponseError and are still retried. - Non-retryable client errors (400/401/403/404/422) fail immediately instead of going through the backoff loop; 429/5xx are still retried. - Update BaseLM/BaseEnsemble/BaseEmbedding hints to Optional[int] token counts, and fix the ensemble's mis-ordered return annotation. - Add offline tests using the real AsyncOpenAI client over httpx.MockTransport fixtures, counting HTTP attempts. Refs inter-science#9 Co-Authored-By: Claude Opus 5.5 <[email protected]>
mp.Queue.put() hands items to a background feeder thread, so calling get_nowait() immediately afterwards intermittently raised queue.Empty (failing ~80% of local runs). Wait for the item with a timeout instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
Fixes #9.
OpenAILM.generatereadret.usage.prompt_tokensinside its retry block. When an OpenAI-compatible provider leaves out the optionalusagefield, a completion that already succeeded raisedAttributeError. It was then resentretries + 1times (billed each time) and finally thrown away as aConnectionError.OpenAIEmbedding.embed_batchhad the same problem withtotal_tokens.Changes
usagegivesNonetoken counts, and the ensemble logs a warning.choices, or with the wrong number of embedding vectors, raises a clearEmptyResponseErrorand is still retried.Optional[int]token counts, which also fixes the ensemble's return annotation that had the wrong element order.test_queue_handler_truncated, whereget_nowait()ran before the queue's background thread had delivered the message. It failed in about 80% of local runs.Tests
tests/test_lm.pyrun the realAsyncOpenAIclient againsthttpx.MockTransportresponses and count HTTP attempts.