Skip to content

fix(openai): honor model_routing for Codex manifests and scheduling - #6688

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
suixincrazy:fix/codex-manifest-failover-alias
Sep 7, 2026
Merged

Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
suixincrazy:fix/codex-manifest-failover-alias

Conversation

@suixincrazy

Copy link
Copy Markdown
Contributor

Problem

An OpenAI group that keeps a failover account for a shared public alias serves a Codex model descriptor with no reasoning levels and text-only input. The client's reasoning-effort slider then has nothing to select and cannot be moved.

Reproduction: one OpenAI group, two accounts, both with an explicit model_mapping for the same public alias, pointing at different upstream models.

account A (primary):  {"my-alias": "my-alias"}
account B (failover): {"my-alias": "some-other-model"}

Account B exists because it cannot reach the aliased model natively, so it maps the alias onto the closest model it does have. That is the intended way to keep a standby for an alias, and the Anthropic side is already configured this way in practice.

Served descriptor:

{
  "slug": "my-alias",
  "supported_reasoning_levels": [],
  "input_modalities": ["text"]
}

default_reasoning_level is absent entirely.

Cause

Two accounts explicitly mapping one alias to different upstream models makes codexExplicitModelTargetsConflictForPlatform true. With no upstream_model_metadata snapshot to intersect, groupCodexModelMetadata short-circuits to {reasoningConflict: true, inputModalitiesConflict: true}.

That override empties the level list and forces input_modalities to ["text"]. Two details make it unrecoverable downstream:

  • DefaultReasoningLevel is *string with omitempty, so nil makes the key absent rather than null.
  • mergeMissingCodexModelFields fills only missing-or-null fields, and an empty array counts as present, so supported_reasoning_levels: [] is never repaired.

Failing closed is correct when the alias target is genuinely ambiguous. But a group that declares model_routing for the alias has already resolved that ambiguity: the operator has stated which accounts serve it, and account Priority states which one leads. Treating that as a conflict rejects a deliberate failover configuration.

Change

Manifest side. When a routing rule names the alias, capability declaration is restricted to the routed accounts and the conflict override is skipped. Capabilities then fall back to the same by-name derivation already used for a single account with no metadata snapshot. Behavior is unchanged for groups with no rule, a disabled rule, or a rule naming a different alias.

Scheduling side. model_routing is stored and looked up platform-agnostically (admin_group.go assigns it with no platform check; Group.GetRoutingAccountIDs is a plain table lookup), but four gates in gateway_scheduling.go only consulted it for Anthropic. An OpenAI group's rules were therefore accepted, persisted, and shown in the admin UI while never affecting selection.

Fixing only the manifest would leave a split brain: the manifest would honor a rule that scheduling ignores. Both sides now share one predicate, and the allowed platform set is defined in exactly one place so adding a platform later is a one-line change.

Selection within a routing list is deliberately untouched. The list is a membership set, and the winner is still decided by Priority (lower first), then load rate, then LastUsedAt.

Tests

  • TestCodexAliasFailoverMappingHonorsModelRouting — the routed alias regains low..max levels, medium default, and image input; three negative cases (no rule, rule disabled, rule for another alias) must still fail closed.
  • TestModelRoutingAppliesToPlatform — predicate table including composite groups and non-eligible target platforms.
  • TestGatewayService_SelectAccountForModelWithPlatform_RoutedOpenAIGroup — a routed OpenAI account must win over a higher-priority unrouted one, which fails before this change.

Verified with go build ./..., go vet -tags unit ./internal/service/, and go test -tags unit ./internal/service/ (411 tests matching Codex|ModelRouting|Routed pass). Five failures in the full package run (TestContentModerationRuntimeSnapshotRefreshFailureKeepsStaleConfig, four TestPluginPackageInstaller*) reproduce identically on unmodified main and are unrelated to this change.

An OpenAI group that keeps a failover account for a shared public alias
produced a Codex model descriptor with no reasoning levels and text-only
input, which leaves the client's reasoning-effort slider with nothing to
select.

Two accounts explicitly mapping one alias to different upstream models
makes codexExplicitModelTargetsConflictForPlatform true. With no
upstream_model_metadata snapshot to intersect, groupCodexModelMetadata
short-circuits to {reasoningConflict, inputModalitiesConflict}, so
DefaultReasoningLevel is nil (the key vanishes under omitempty) and
SupportedReasoningLevels is an empty array. mergeMissingCodexModelFields
fills only missing-or-null fields, so an empty array is never repaired.

Failing closed is right when the alias target is genuinely ambiguous, but
a group that declares model_routing for the alias has already resolved
that ambiguity: the operator stated which accounts serve it and which is
primary. Treating that as a conflict rejects a deliberate failover setup.

Manifest side: when a routing rule names the alias, restrict capability
declaration to the routed accounts and skip the conflict override.
Capabilities then fall back to the same by-name derivation used for a
single account without a metadata snapshot. Groups with no rule, a
disabled rule, or a rule for another alias keep failing closed.

Scheduling side: model_routing was stored and read platform-agnostically
(admin_group.go, Group.GetRoutingAccountIDs) but four gates in
gateway_scheduling.go only consulted it for Anthropic, so an OpenAI
group's rules were accepted and displayed yet never honored. Without
this, the manifest would honor a rule that scheduling ignores. Both
gates now share one predicate, with the allowed platform set defined in
a single place.

Selection inside a routing list is unchanged: the list is a membership
set, and the winner is still decided by Priority, then load, then
LastUsedAt.

Tests: alias-failover manifest recovery plus the three negative cases,
the platform predicate table, and an OpenAI routed selection that must
beat a higher-priority unrouted account.
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@suixincrazy

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Sep 6, 2026
@Wei-Shaw
Wei-Shaw merged commit 027e3f2 into Wei-Shaw:main Sep 7, 2026
9 of 10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants