free-claude-code/api
Ali Khokhar 58aef0dc8a
Refactor provider runtime ownership (#925)
## Problem

Provider construction, model discovery, validation, and cleanup lived in
one registry module. API and admin routes depended on registry-shaped
app state and legacy process-level provider helpers.

## Changes

| Before | After |
| --- | --- |
| `providers.registry` mixed provider factories, config, cache,
discovery, validation, and cleanup. | `providers.runtime` splits
factories, config, cache, model cache, discovery, validation, and
runtime orchestration. |
| API and admin routes read `app.state.provider_registry` and sometimes
created registries ad hoc. | API and admin routes use app-scoped
`ProviderRuntime` through `app.state.provider_runtime`. |
| `api.dependencies` kept process-global provider cache helpers. |
`api.dependencies` resolves providers only through the app-scoped
runtime. |
| Registry-shaped tests preserved old internal boundaries. |
Runtime-shaped tests assert provider config, construction, cache,
discovery, validation, and import boundaries. |

<!-- greptile_comment -->

<details open><summary><h3>Greptile Summary</h3></summary>

This PR moves provider lifecycle ownership from the old registry module
into an app-scoped runtime package. The main changes are:

- Split provider config, factory wiring, instance cache, model cache,
discovery, validation, and cleanup into `providers.runtime` modules.
- Updated API and admin routes to resolve providers and model metadata
through `app.state.provider_runtime`.
- Removed legacy process-global provider helpers and the deleted
`providers.registry` module.
- Updated docs, smoke metadata, import-boundary checks, and tests for
the new runtime ownership model.
- Bumped the package version and lockfile metadata for the production
refactor.
</details>

<h3>Confidence Score: 5/5</h3>

The provider runtime refactor appears merge-safe with no identified
blocking issues.

The changes consistently move provider ownership to app-scoped runtime
modules and update API, admin, docs, smoke metadata, import-boundary
checks, and tests around that architecture.

<details><summary><h3><a href="https://www.greptile.com/trex"><img
alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="20" align="absmiddle"></a> T-Rex Logs</h3></summary>

**What T-Rex did**
- Ran a baseline and head comparison of provider registry and runtime
states, verifying the after-state shows head
state\_has\_provider\_registry=False and
state\_has\_provider\_runtime=True, that GET /v1/models and admin
endpoints respond with 200, and that provider\_resolver\_called via
runtime, with assertions passing.
- Verified that the four focused provider-runtime contract tests passed
in both the before and after refactor runs, including runtime split
checks, with exit code 0.
- Identified environmental blockers that prevented the smoke-runtime
workflow from running, including uv unavailability, missing pytest for
/usr/local/bin/python, and Python 3.11 being used despite pyproject.toml
requiring \>=3.14.

<a
href="https://app.greptile.com/trex/runs/12528505/artifacts"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifactsDark.svg?v=1"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=1"><img
alt="View all artifacts"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=1"
height="32"></picture></a>

<sub><a href="https://www.greptile.com/trex"><img alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="14" align="absmiddle"></a> Ran code and verified through
T-Rex</sub>
</details>

<sub>Reviews (1): Last reviewed commit: ["Refactor provider runtime
ownership"](01d5894881)
| [Re-trigger
Greptile](https://app.greptile.com/api/retrigger?id=40312173)</sub>

<!-- /greptile_comment -->
2026-06-27 15:04:34 -07:00
..
admin_static Add Codestral Provider 2026-05-23 19:09:22 -07:00
handlers Split API request handling by product surface (#923) 2026-06-27 13:13:32 -07:00
models Add Codex support (#691) 2026-06-16 16:32:43 -07:00
web_tools Refactor provider stream engine (#883) 2026-06-27 07:24:27 -07:00
__init__.py Major refactor: API, providers, messaging, and Anthropic protocol 2026-04-26 03:01:14 -07:00
admin_config.py Fix live provider smoke defaults 2026-05-31 13:02:15 -07:00
admin_routes.py Refactor provider runtime ownership (#925) 2026-06-27 15:04:34 -07:00
admin_urls.py log urls at startup 2026-05-10 01:45:04 -07:00
app.py Add Codex support (#691) 2026-06-16 16:32:43 -07:00
command_utils.py fix: only strip valid env assignments in command parsing (#229) 2026-04-27 18:34:48 -07:00
dependencies.py Refactor provider runtime ownership (#925) 2026-06-27 15:04:34 -07:00
detection.py Fix Claude auto-mode classifier thinking policy (#865) 2026-06-19 12:24:56 -07:00
gateway_model_ids.py Add no-thinking model picker variants 2026-04-30 21:27:23 -07:00
model_catalog.py Refactor provider runtime ownership (#925) 2026-06-27 15:04:34 -07:00
model_router.py Add no-thinking model picker variants 2026-04-30 21:27:23 -07:00
optimization_handlers.py refactor: remove OpenRouter rollback, shims, and redundant layers 2026-04-24 21:08:38 -07:00
provider_execution.py Split API request handling by product surface (#923) 2026-06-27 13:13:32 -07:00
request_errors.py Split API request handling by product surface (#923) 2026-06-27 13:13:32 -07:00
response_streams.py Split API request handling by product surface (#923) 2026-06-27 13:13:32 -07:00
routes.py Refactor provider runtime ownership (#925) 2026-06-27 15:04:34 -07:00
runtime.py Refactor provider runtime ownership (#925) 2026-06-27 15:04:34 -07:00
validation_log.py Major refactor: API, providers, messaging, and Anthropic protocol 2026-04-26 03:01:14 -07:00
web_server_tools.py Major refactor: API, providers, messaging, and Anthropic protocol 2026-04-26 03:01:14 -07:00