Skip to content

feat(inference): flip openai/codex + custom cloud slugs to crate-native OpenAiModel#4782

Merged
senamakel merged 1 commit into
tinyhumansai:mainfrom
senamakel:feat/inference-openai-codex-cutover
Jul 11, 2026
Merged

feat(inference): flip openai/codex + custom cloud slugs to crate-native OpenAiModel#4782
senamakel merged 1 commit into
tinyhumansai:mainfrom
senamakel:feat/inference-openai-codex-cutover

Conversation

@senamakel

@senamakel senamakel commented Jul 11, 2026

Copy link
Copy Markdown
Member

What & why

Extends the BYOK cloud cutover (#4780) to cover every configured cloud slug
except the managed OpenhumanJwt entry, so create_chat_model no longer builds
a host OpenAiCompatibleProvider for any managed / local / cloud role.

try_create_cloud_slug_chat_model now returns a crate-native OpenAiModel for:

  • Codex OAuth (Bearer + using_oauth) → OpenAI Responses API
    (with_responses_api_primary), carrying the codex account_id /
    originator headers, the codex user-agent, the client_version query param,
    and omitting max_output_tokens (parity with the legacy host codex path).
  • non-codex openai + custom proxy slugs → crate OpenAiModel on Chat
    Completions.

The legacy host's rare chat-404/v1/responses fallback is intentionally
not replicated: the crate models Responses as a primary mode, and Chat
Completions is these slugs' primary path.

Enabled by

Host CrateOpenAiConfig / build_crate_openai_model gain the matching knobs.

Testing

  • cargo check --lib clean (pre-existing warnings only).
  • factory_tests: try_create_cloud_slug_flips_openai_but_declines_non_cloud
    (openai flips → Some, provider == "openai", model_id == "gpt-4o-mini";
    managed / local / unconfigured still decline).

⚠️ Live per-provider wire validation (real openai /responses, codex OAuth,
each cloud endpoint) is deferred to a dedicated tinyagents run with live API
keys, per the migration plan.

Follow-up

The only remaining users of host compatible*.rs are the direct
create_chat_provider callers; migrating those and deleting compatible*.rs is
the next step.

Stacked on #4780.

https://claude.ai/code/session_01U8NDGbt9tKj443VquzycLB

Summary by CodeRabbit

  • New Features

    • Expanded BYOK cloud-provider routing for supported OpenAI-compatible, Anthropic, and DeepSeek configurations.
    • Added Codex-compatible Responses API support, including required headers and query parameters.
    • Added configurable user-agent and request parameter handling for compatible providers.
  • Bug Fixes

    • Preserved privacy and active-session safeguards across the updated provider paths.
  • Tests

    • Added coverage for supported, unsupported, managed, local, and unconfigured provider routing scenarios.
  • Documentation

    • Clarified which BYOK cloud-provider configurations are eligible for the updated routing.

@senamakel senamakel requested a review from a team July 11, 2026 03:23
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a54a1cab-e04c-44b3-b230-2dda0c100bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 76ee074 and 380107e.

📒 Files selected for processing (5)
  • docs/tinyagents-drift-ledger.md
  • src/openhuman/inference/provider/crate_openai.rs
  • src/openhuman/inference/provider/factory.rs
  • src/openhuman/inference/provider/factory_tests.rs
  • vendor/tinyagents
📝 Walkthrough

Walkthrough

Changes

The PR adds crate-native BYOK cloud-slug routing, shared slug resolution, Codex Responses API configuration, routing tests, ledger updates, and a tinyagents vendor pointer update.

BYOK cloud-slug crate-native cutover

Layer / File(s) Summary
Crate OpenAI routing configuration
src/openhuman/inference/provider/crate_openai.rs, vendor/tinyagents
Adds Responses API flags, query parameters, optional user-agent configuration, defaults, and updated test literals.
Cloud-slug resolution and factory routing
src/openhuman/inference/provider/factory.rs
Centralizes slug/model/key/Codex resolution and attempts crate-native construction before legacy provider fallback while preserving privacy and session gates.
Cutover validation and ledger
src/openhuman/inference/provider/factory_tests.rs, docs/tinyagents-drift-ledger.md
Tests DeepSeek, Anthropic, OpenAI, managed, local-runtime, and unconfigured slug behavior, and documents the expanded cutover coverage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Factory
  participant CloudSlugResolution
  participant CrateOpenAI
  Caller->>Factory: create_chat_model_with_model_id
  Factory->>CloudSlugResolution: resolve slug, model, key, and Codex route
  CloudSlugResolution-->>Factory: CloudSlugResolution
  Factory->>CrateOpenAI: build crate-native ChatModel
  CrateOpenAI-->>Caller: configured ChatModel
Loading

Possibly related issues

  • Issue 4727 — Covers the crate-native OpenAI client cutover for BYOK cloud-slug routing implemented here.

Possibly related PRs

Suggested labels: rust-core, feature

Suggested reviewers: CodeGhost21

Poem

I’m a rabbit with a crate-built cart,
Slugs now find their model part.
Codex hops through Responses bright,
DeepSeek and Anthropic route just right.
Tests thump softly—thump, thump, hooray!
The ledger marks the cutover day.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating OpenAI/Codex and custom cloud slugs to crate-native OpenAiModel.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot added feature Net-new user-facing capability or product behavior. rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. labels Jul 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76ee074ac5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

endpoint: endpoint.as_str(),
api_key: key.as_str(),
auth_style: auth,
model: effective_model.as_str(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remap Codex auto before crate Responses calls

When the openai slug resolves to Codex OAuth and the selected/default model is auto, this passes auto straight into the crate OpenAiModel. The legacy Responses path explicitly remaps that sentinel in compatible_helpers.rs (pinned by codex_oauth_responses_remaps_auto_model) because the ChatGPT Codex backend rejects auto; the crate Responses translator sends the model unchanged. As a result, OpenAI OAuth/Codex users configured as openai:auto now get a backend 400 instead of the previous successful concrete Codex-model request.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/openhuman/inference/provider/crate_openai.rs (1)

134-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add request-level coverage for the new transport options.

Current tests would still pass if query parameters, User-Agent, or Responses-mode flags stopped being applied. Add a mocked request test covering Codex Responses routing and non-Codex Chat Completions behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/inference/provider/crate_openai.rs` around lines 134 - 145, The
existing tests do not verify that transport options are applied to outgoing
requests. Add mocked request coverage for the provider configuration path around
extra query parameters, user-agent, responses_api_primary, and
responses_omit_max_output_tokens, asserting Codex requests use Responses routing
while non-Codex requests use Chat Completions and preserve the configured
query/header behavior.
src/openhuman/inference/provider/factory.rs (1)

2238-2380: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing unit coverage for the Codex OAuth branch.

This is the most complex new logic in the cutover (Responses API primary, account/originator headers, user-agent, client_version query param, max_output_tokens omission), yet none of the added tests in factory_tests.rs exercise codex.using_oauth == true. The existing OpenAI test (try_create_cloud_slug_flips_openai_but_declines_non_cloud) only covers the non-OAuth bearer key path.

Consider adding a test that stubs OAuth credentials (matching the bearer key) for the openai slug and asserts the built model's profile/headers reflect the Responses-primary configuration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/inference/provider/factory.rs` around lines 2238 - 2380, Add
unit coverage in factory_tests.rs for try_create_cloud_slug_chat_model when the
openai slug resolves to Codex OAuth credentials matching the bearer key. Stub
the OAuth configuration and assert the resulting model uses Responses API
primary behavior, includes the Codex account and originator headers, user-agent,
and client_version query parameter, and omits max_output_tokens; retain the
existing non-OAuth bearer test separately.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openhuman/inference/provider/crate_openai.rs`:
- Around line 134-145: The existing tests do not verify that transport options
are applied to outgoing requests. Add mocked request coverage for the provider
configuration path around extra query parameters, user-agent,
responses_api_primary, and responses_omit_max_output_tokens, asserting Codex
requests use Responses routing while non-Codex requests use Chat Completions and
preserve the configured query/header behavior.

In `@src/openhuman/inference/provider/factory.rs`:
- Around line 2238-2380: Add unit coverage in factory_tests.rs for
try_create_cloud_slug_chat_model when the openai slug resolves to Codex OAuth
credentials matching the bearer key. Stub the OAuth configuration and assert the
resulting model uses Responses API primary behavior, includes the Codex account
and originator headers, user-agent, and client_version query parameter, and
omits max_output_tokens; retain the existing non-OAuth bearer test separately.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05c63283-dbc7-4b38-85f4-bc85d3d70d23

📥 Commits

Reviewing files that changed from the base of the PR and between 8a6e780 and 76ee074.

📒 Files selected for processing (5)
  • docs/tinyagents-drift-ledger.md
  • src/openhuman/inference/provider/crate_openai.rs
  • src/openhuman/inference/provider/factory.rs
  • src/openhuman/inference/provider/factory_tests.rs
  • vendor/tinyagents

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 11, 2026
…ative

Extends the BYOK cloud cutover to cover EVERY configured cloud slug except the
managed OpenhumanJwt entry. try_create_cloud_slug_chat_model now:
- Codex OAuth (Bearer + using_oauth) -> crate OpenAiModel on the Responses API
  (with_responses_api_primary), with the codex account/originator headers,
  user-agent, client_version query param, and max_output_tokens omitted.
- non-codex openai + custom slugs -> crate OpenAiModel Chat Completions. The
  legacy host's rare chat-404 -> /v1/responses fallback is NOT replicated (the
  crate has responses-primary, not fallback); chat completions is these slugs'
  primary path.

Enabled by the crate /v1/responses port (tinyagents#51); host pinned at 8e57665
(= tinyhumansai#49 toggles + tinyhumansai#51 Responses, with tinyhumansai#50 error-source-chain reverted via tinyhumansai#52 so
an offline local provider stays retryable). CrateOpenAiConfig / build_crate_openai_model
gain responses_api_primary / responses_omit_max_output_tokens / extra_query_params /
user_agent knobs.

create_chat_model no longer constructs a host OpenAiCompatibleProvider for any
managed/local/cloud role; the remaining users of compatible*.rs are the direct
create_chat_provider callers (follow-up).

Lib compiles clean. LIVE per-provider validation (real openai /responses + codex
OAuth + each cloud wire) is deferred to a dedicated tinyagents run.

Claude-Session: https://claude.ai/code/session_01U8NDGbt9tKj443VquzycLB

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 380107ed4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

auth_style: auth,
model: effective_model.as_str(),
temperature_unsupported_models: unsupported.as_slice(),
temperature_override,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the factory temperature for crate cloud models

When this helper now returns a crate OpenAiModel for the newly flipped openai and custom cloud slugs, it only forwards the @<temp> suffix as temperature_override; the temperature argument passed to create_chat_model(..., temperature) never reaches this path. Callers such as meeting summaries (create_chat_model(SUMMARIZATION_ROLE, ..., 0.3)) and automation decisions (..., 0.0) invoke ModelRequest::new(...) without with_temperature, so those OpenAI/custom BYOK requests now go out with the crate default/omitted temperature instead of the deterministic value that ProviderModel previously pinned.

Useful? React with 👍 / 👎.

@senamakel senamakel merged commit e7a6b61 into tinyhumansai:main Jul 11, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Net-new user-facing capability or product behavior. rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant