Skip to content

fix(gateway): track uptime for used provider - #1507

Merged
steebchen merged 1 commit into
mainfrom
fix/uptime-tracking-fallback
Jan 27, 2026
Merged

steebchen merged 1 commit into
mainfrom
fix/uptime-tracking-fallback

Conversation

@steebchen

@steebchen steebchen commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fixes uptime tracking to use the actual provider that handled a request, not the originally requested one
  • When low-uptime fallback routes to a different provider, stats are now correctly attributed to the fallback provider
  • Fixes test data inconsistency where usedModel had wrong provider prefix

Test plan

  • Existing stats-calculator tests pass (17 tests)
  • Provider-metrics tests pass (19 tests)
  • Build succeeds
  • Verify uptime stats are correctly attributed after low-uptime fallback in production

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved model identifier resolution to ensure the correct model is used for statistics and logging when routing or fallback occurs.
  • Tests

    • Aligned test data to ensure model and provider pairs are correctly matched in statistics calculations.

✏️ Tip: You can customize this high-level summary in your review settings.

When low-uptime fallback routes a request to a different provider,
ensure that the uptime stats are tracked for the actual provider
that handled the request, not the originally requested one.

The issue was that `baseModelName` was derived from `finalModelInfo`
which is computed after fallback using the updated `usedModel`. If
the search failed, it would fall back to using `usedModel` directly
(a provider-specific name) instead of the canonical model ID.

Now we use `modelInfo.id` (set before any routing/fallback) as the
primary source for the canonical model ID, ensuring correct stats
attribution.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Changes the baseModelName selection logic in the chat handler to prefer the canonical model ID from modelInfo when available, with a fallback order of modelInfo.id, finalModelInfo?.id, then usedModel. Updates corresponding test data to ensure model/provider pairs align properly.

Changes

Cohort / File(s) Summary
Model ID Resolution
apps/gateway/src/chat/chat.ts
Modified baseModelName calculation to prioritize canonical ID from modelInfo (when present as ModelDefinition) before falling back to finalModelInfo?.id and usedModel. Ensures correct model identifier is used for routing/fallback logic and downstream stats/logging.
Test Data Alignment
apps/worker/src/services/stats-calculator.spec.ts
Updated test entry to align usedModel (anthropic/gpt-4) with usedProvider for GPT-4 mapping, ensuring model/provider pairs match in statistics calculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #1230 — Directly related: modifies routing/fallback behavior that updates usedProvider/usedModel and routingMetadata in the same file.
  • PR #1291 — Related: changes model resolution behavior in apps/gateway/src/chat/chat.ts to refine model lookup logic.
  • PR #675 — Related: modifies how the base model identifier is determined and propagated through routing/fallback paths.

Suggested labels

auto-merge

Suggested reviewers

  • smakosh
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(gateway): track uptime for used provider' accurately summarizes the main change: correcting uptime tracking to attribute stats to the actual provider that handled requests rather than the originally requested provider.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steebchen
steebchen enabled auto-merge January 27, 2026 02:19
@steebchen
steebchen added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit e8c6ff8 Jan 27, 2026
13 checks passed
@steebchen
steebchen deleted the fix/uptime-tracking-fallback branch January 27, 2026 02:28
steebchen added a commit that referenced this pull request Jan 29, 2026
## Summary

- Fixes uptime tracking to use the actual provider that handled a
request, not the originally requested one
- When low-uptime fallback routes to a different provider, stats are now
correctly attributed to the fallback provider
- Fixes test data inconsistency where `usedModel` had wrong provider
prefix

## Test plan

- [x] Existing stats-calculator tests pass (17 tests)
- [x] Provider-metrics tests pass (19 tests)
- [x] Build succeeds
- [ ] Verify uptime stats are correctly attributed after low-uptime
fallback in production

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved model identifier resolution to ensure the correct model is
used for statistics and logging when routing or fallback occurs.

* **Tests**
* Aligned test data to ensure model and provider pairs are correctly
matched in statistics calculations.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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