fix(headers): strategy hint covers round_robin and least_busy - #3
Merged
Merged
Conversation
The `strategy` Literal listed only priority/weighted/cost/latency, but the gateway has long accepted `round_robin` and `least_busy` too. The runtime was never wrong — a Literal is not enforced at runtime, so the header went out fine — but type-checked callers were told two valid strategies were invalid, and editors would not complete them. Also records the gateway's actual matching behaviour in the docstring: it matches case-insensitively and falls back to `priority` on an unknown or empty value rather than erroring, so a typo routes by priority instead of failing loudly. Worth knowing before debugging "why is my strategy ignored". The new test asserts on the annotation rather than on a call, since a call with a wrong hint still passes at runtime. It reads the raw annotation string instead of resolving it with get_type_hints: resolution would evaluate `Literal[...] | None`, which is a TypeError on the 3.9 leg of the support matrix.
Merged
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.
The
strategyLiteral listed onlypriority,weighted,costandlatency. The gateway also acceptsround_robinandleast_busy.Nothing was broken at runtime — a
Literalis not enforced there, sostrategy="least_busy"always went out on the wire correctly. The cost was to typed callers: mypy/pyright rejected two genuinely valid strategies, and editors would not complete them. This adds the two missing literals and mirrors them into the README options table.Also documented
The docstring now records how the gateway actually treats this header: it matches case-insensitively and falls back to
priorityfor an unknown or empty value rather than erroring. That is worth knowing before someone debugs "why is my strategy being ignored" — a typo does not fail loudly, it silently routes by priority.On the test
test_strategy_hint_covers_every_gateway_strategyasserts against the annotation, not against a call. A test that just calledheaders(strategy="round_robin")would have passed before this fix too, so it would have guarded nothing.It reads the raw annotation string rather than resolving it with
get_type_hints. Resolution evaluatesLiteral[...] | None, and PEP 604 unions of typing objects are aTypeErrorat runtime before 3.10 — that would have gone green locally and red on the 3.9 leg of the matrix. Verified both directions: the test fails against the old annotation and passes against the new one.Checks
Ran the repo's own gate locally on 3.12:
ruff check,ruff format --check,mypy src/all clean,pytest77 passed (was 76). The 3.9–3.13 matrix runs in CI.Not included
canaryis a valid gateway strategy as well, but it is only meaningful alongside the canary-split header, which this SDK does not expose inHEADER_NAMESat all. Adding the literal on its own would let a caller select a strategy they have no way to configure. Worth a follow-up that adds both together.