Skip to content

fix: PR #4 post-merge review follow-ups - #5

Draft
radudobrinescu wants to merge 3 commits into
mainfrom
fix/pr4-review-followups
Draft

radudobrinescu wants to merge 3 commits into
mainfrom
fix/pr4-review-followups

Conversation

@radudobrinescu

@radudobrinescu radudobrinescu commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Follow-up fixes from the post-merge review of #4. Draft while the batch accumulates; validated together, merged once.

  • litellm-sync readiness probe: fail on non-404 API errors. PR #3 review fixes (batch) #4 broadened the probe to swallow all ApiException statuses (200), so a 403 (broken/rolled-back RBAC — which PR #3 review fixes (batch) #4's new bedrockmodels rule can trigger) reported healthy while the single-replica controller registered nothing. Now only 404 (CRD absent: kro=false / Bedrock-only) is healthy; 403/401/other + transport failures return 503.

  • litellm-sync: re-register a model when its CR params drift. Editing a live BedrockModel's price/endpoint (or a serving model's params) was accepted by k8s but silently ignored by LiteLLM (monotonic registration). Now register_model diffs the CR's litellm_params against the live registration and re-registers (delete+add under the lock) on a genuine change. Conservative so it cannot churn: compares only keys LiteLLM echoes in /model/info (missing key ⇒ not drift), excludes redacted api_key, tolerances float costs.

  • new-model: derive Bedrock per-token price scale from the unit, not a guess. token_prices() inferred per-1K vs per-1M from free text and defaulted to per-1K, so a per-1,000,000 dimension with a bare tokens unit was recorded 1000x too high into the committed CR (wrong spend tracking + budgets). Now reads the scale structurally (_tokens_per_unit: numeric magnitude, 1M before 1K), returns None when ambiguous (skip → fall back to --input-cost/--output-cost or LiteLLM's map), and adds a sanity clamp rejecting implausibly high per-token values. Adds tests/test_bedrock_pricing.py.

Pre-merge note: fix #2 (drift-reconcile) should get a live smoke-test — edit an enrolled Bedrock model's price and confirm LiteLLM picks it up — since LiteLLM's /model/info param echo can't be verified statically. It fails safe (no churn) if a field isn't echoed.

86 unit tests pass.

… RBAC)

The readiness probe (added in #4) swallowed ALL ApiException statuses and returned
200, so a 403 — the ServiceAccount can't list the CRs it exists to reconcile, e.g.
a partial/rolled-back RBAC apply (exactly what #4's new bedrockmodels rule can
trigger) — reported healthy while the single-replica controller registered nothing.
Now only 404 (CRD absent: kro=false / Bedrock-only install) is treated as healthy;
403/401/other API errors and transport failures return 503, so a controller that
can reconcile nothing surfaces a failing signal instead of a green probe.
@radudobrinescu
radudobrinescu marked this pull request as draft September 18, 2026 09:17
register_model was monotonic (add only when no DB row), so editing a live
BedrockModel's spec.inputCostPerToken/outputCostPerToken/bedrockEndpoint (or a
serving model's params) was accepted by k8s but silently ignored by LiteLLM —
cost tracking stayed wrong with no signal. Now, when a row already exists,
compare the CR's litellm_params against the live ones and re-register
(delete+add under the lock) on a genuine change.

Drift detection is conservative so it cannot churn: it only compares keys
LiteLLM echoes back in /model/info (a key absent from the live params is treated
as 'can't compare -> not drift', degrading to the old no-hot-apply behavior for
that field rather than re-registering every reconcile), excludes the redacted
api_key, and uses a tolerance for float costs. Steady state never triggers it;
only a real edit does.
…ot a guess

token_prices() inferred per-1K vs per-1M from free-text substrings and DEFAULTED
to per-1K, so a per-1,000,000 Price List dimension with a bare 'tokens' unit was
divided by 1,000 -> a per-token cost 1000x too high, baked into the committed CR
and driving LiteLLM/Langfuse cost tracking + budgets.

Read the scale structurally (_tokens_per_unit): match the numeric magnitude
(1,000,000 before 1,000) in the unit/description, and return None when ambiguous
so the dimension is skipped (fall back to --input-cost/--output-cost or LiteLLM's
map) rather than guessed. Add a sanity clamp that rejects implausibly high
per-token values (> $1000/1M) as a unit-scale backstop. Adds
tests/test_bedrock_pricing.py.
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