Skip to content

fix(headers): strategy hint covers round_robin and least_busy - #3

Merged
routeplane-ops merged 1 commit into
mainfrom
fix/strategy-hint-round-robin-least-busy
Aug 3, 2026
Merged

fix(headers): strategy hint covers round_robin and least_busy#3
routeplane-ops merged 1 commit into
mainfrom
fix/strategy-hint-round-robin-least-busy

Conversation

@routeplane-ops

Copy link
Copy Markdown
Collaborator

The strategy Literal listed only priority, weighted, cost and latency. The gateway also accepts round_robin and least_busy.

Nothing was broken at runtime — a Literal is not enforced there, so strategy="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 priority for 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_strategy asserts against the annotation, not against a call. A test that just called headers(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 evaluates Literal[...] | None, and PEP 604 unions of typing objects are a TypeError at 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, pytest 77 passed (was 76). The 3.9–3.13 matrix runs in CI.

Not included

canary is a valid gateway strategy as well, but it is only meaningful alongside the canary-split header, which this SDK does not expose in HEADER_NAMES at 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.

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.
@routeplane-ops
routeplane-ops merged commit 7dd3d78 into main Aug 3, 2026
6 checks passed
@routeplane-ops
routeplane-ops deleted the fix/strategy-hint-round-robin-least-busy branch August 3, 2026 19:25
@routeplane-ops routeplane-ops mentioned this pull request Aug 3, 2026
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