Skip to content

fix(llm-gateway): classify provider request rejections - #10501

Merged
Git-on-my-level merged 4 commits into
mainfrom
codex/llm-gateway-provider-rejections
Jul 24, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
codex/llm-gateway-provider-rejections

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Stop classifying every upstream provider 4xx as capability_mismatch.
  • Preserve the attempted provider/model in terminal outcomes and add one bounded provider_rejection label derived only from allowlisted upstream error codes and parameter roots.
  • Keep true unsupported-parameter responses as non-fallback capability mismatches, while classifying invalid requests such as context_length_exceeded as the separate non-fallback provider_invalid_request class.
  • Update static and generated route contracts so both terminal classes are explicitly never-fallback.
  • Refresh the app-client and integration-public OpenAPI snapshots, plus their dependent generated Dart, TypeScript, and Swift clients, that the contract gate revealed were already stale for the baseline-memory schema and endpoint.
  • Keep label-aware desktop changelog enforcement in the canonical PR preflight; the macOS static lane now skips that metadata-only check instead of rejecting a valid no-changelog-needed label.
  • Keep owner-boundary Swift fixtures hermetic by installing their production effect handler without starting screen capture, audio capture, or system muting.

Root cause and scope

The production terminal events occurred after route resolution and before output. The gateway's OpenAI-compatible provider adapter mapped every non-auth, non-rate-limit provider 4xx to capability_mismatch; the executor then discarded the attempted provider/model when it built terminal telemetry. As a result, the historical records prove an upstream 4xx but cannot prove which request member the provider rejected.

This PR repairs that owning boundary. It parses only a bounded semantic enum from the already bounded provider error preview. Unknown codes and parameter names collapse to other_4xx / invalid_other; provider messages, raw bodies, prompts, IDs, credentials, and request values never become response, metric, or terminal-log fields.

The leading unproven explanation for the affected knowledge-graph and memories lanes is context size: the gateway override uses GPT-5.4 nano (400K context), while the legacy GPT-4.1 mini route has a 1M context and both callers can assemble large per-user history. Successful requests alongside intermittent rejections are consistent with that boundary. This PR intentionally does not change those routes until deployed telemetry reports provider_rejection=context_length_exceeded; an unsupported member will instead be reported as a bounded unsupported_* value.

The separate BYOK rate-limit events remain unchanged and retain their existing fail-closed behavior.

Two independent macOS CI defects were also exposed while verifying the generated Swift client. First, the static lane reran a changelog check without the PR label metadata owned by canonical preflight. Second, owner-boundary tests started the real automation capture path merely to install a voice-turn effect handler; on the runner, that path muted the output device and stalled during cleanup, while three other SwiftPM processes timed out waiting for the shared build lock. The workflow fix restores the metadata owner, and a DEBUG-only fixture seam now installs the production effect handler without touching OS capture or audio state.

Regression and privacy evidence

  • The provider adapter test distinguishes unsupported_parameter/reasoning_effort from context_length_exceeded and proves arbitrary parameter names and provider messages do not survive classification.
  • The HTTP route test sends both terminal classes through real gateway resolution/execution and asserts the exact public error code plus provider/model/rejection context.
  • The metrics test proves an arbitrary rejection value collapses to other_4xx and is absent from terminal logs.

Verification

  • backend/.venv/bin/pytest -q backend/tests/unit/test_llm_gateway_*.py backend/tests/unit/test_gateway_resilience.py backend/tests/unit/test_gateway_observability.py — 309 passed.
  • cd backend && .venv/bin/pytest tests/unit/test_llm_gateway_validator.py -q — 22 passed.
  • cd backend && .venv/bin/pytest tests/unit/test_llm_gateway_service.py tests/unit/test_gateway_resilience.py tests/unit/test_gateway_observability.py -q — 12 passed.
  • Local running gateway + local mock OpenAI HTTP endpoint: a synthetic context_length_exceeded 400 returned provider_request_rejected / provider_invalid_request; the terminal record contained provider=openai model=gpt-5.4-nano provider_rejection=context_length_exceeded and did not contain the synthetic private provider message.
  • OMI_PR_BODY_FILE=/tmp/omi-llm-gateway-provider-rejections-pr.md make preflight — 19 checks passed.
  • cd backend && scripts/openapi_runner.sh scripts/export_openapi.py --surface app-client --check ../docs/api-reference/app-client-openapi.json — passed.
  • cd backend && scripts/openapi_runner.sh scripts/export_openapi.py --surface integration-public --check ../docs/api-reference/integration-public-openapi.json — passed.
  • cd backend && .venv/bin/python scripts/generate_dart_models.py --group memories — generated output is clean and deterministic.
  • backend/.venv/bin/python backend/scripts/generate_ts_openapi_types.py --check — passed for all four generated TypeScript clients.
  • cd backend && .venv/bin/python scripts/generate_swift_openapi_types.py --check — passed.
  • cd desktop/macos && xcrun swift build -c debug --package-path Desktop — passed.
  • python3 .github/scripts/test_desktop_swift_ci_contract.py — 22 passed.
  • actionlint .github/workflows/desktop-swift-ci.yml — passed.
  • xcrun swift test --package-path Desktop --skip-build --filter 'PushToTalkStateMachineTests/' — 9 passed; repeated 50/50.
  • python3 desktop/macos/scripts/desktop-flow-lint.py — 58 flows and 135 registered actions passed.
  • make preflight — 30 checks passed.
  • The pre-push typecheck completed with 0 errors and its selected 22 backend test files passed.

Product invariants affected

  • INV-CHAT-1
  • INV-VOICE-1

Failure-Class: none

@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: 2c6b2c52be

ℹ️ 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".

Comment on lines +155 to +156
provider=error.provider,
model=error.model,

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 Carry the attempted route with provider labels

When an active route is eligible for LKG fallback and the LKG attempt is the one that fails, the caller still passes selected_serving_route_artifact_id(resolved_route) into observe_error, which is the originally selected active route. With these new labels, the terminal metric/log can now combine the active route id with the LKG provider/model, attributing 429/5xx incidents to a route that did not produce the terminal failure. Please carry the attempted route_artifact_id with the GatewayError as well, or otherwise pass the terminal attempt route into observe_error.

Useful? React with 👍 / 👎.

Preserve the attempted provider/model and expose only an allowlisted, bounded provider rejection label. Separate invalid provider requests such as context overflow from true unsupported-capability failures without changing fallback eligibility.

Failure-Class: none

Verification:
- 309 gateway tests passed
- 22 validator tests passed
- 12 service/resilience/observability tests passed
- local HTTP gateway + synthetic upstream 400 returned provider_invalid_request and logged context_length_exceeded without provider detail
- make preflight passed (pre-commit working-tree run)
Regenerate the app-client and integration-public contracts with the pinned OpenAPI runner, then refresh their dependent Dart, TypeScript, and Swift clients, so the baseline-memory schema and endpoint already present on main are reflected in committed artifacts.\n\nVerification:\n- scripts/openapi_runner.sh scripts/export_openapi.py --surface app-client --check ../docs/api-reference/app-client-openapi.json\n- scripts/openapi_runner.sh scripts/export_openapi.py --surface integration-public --check ../docs/api-reference/integration-public-openapi.json\n- .venv/bin/python scripts/generate_dart_models.py --all --check\n- .venv/bin/python scripts/generate_ts_openapi_types.py --check\n- .venv/bin/python scripts/generate_swift_openapi_types.py --check
@Git-on-my-level Git-on-my-level added the no-changelog-needed Skip desktop changelog enforcement for internal-only changes label Jul 24, 2026
@Git-on-my-level
Git-on-my-level force-pushed the codex/llm-gateway-provider-rejections branch from 2c6b2c5 to c9a5206 Compare July 24, 2026 19:40
@mintlify

mintlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jul 24, 2026, 7:41 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Keep the macOS static lane focused on deterministic checks while the canonical PR preflight owns label-aware changelog enforcement. Add a workflow contract for the failure observed in PR #10501 run 30121300487.

Failure-Class: none
Install the production voice-turn effect handler through a DEBUG-only fixture seam so owner-boundary tests do not start screen capture, audio capture, or system muting on CI runners.\n\nVerification: PushToTalkStateMachineTests passed 50/50; Swift test bundle built; make preflight passed 29 checks.\n\nFailure-Class: none
@Git-on-my-level
Git-on-my-level merged commit e1990a0 into main Jul 24, 2026
40 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/llm-gateway-provider-rejections branch July 24, 2026 21:09
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
Keep the macOS static lane focused on deterministic checks while the canonical PR preflight owns label-aware changelog enforcement. Add a workflow contract for the failure observed in PR BasedHardware#10501 run 30121300487.

Failure-Class: none
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…#10501)

## Summary

- Stop classifying every upstream provider 4xx as `capability_mismatch`.
- Preserve the attempted provider/model in terminal outcomes and add one
bounded `provider_rejection` label derived only from allowlisted
upstream error codes and parameter roots.
- Keep true unsupported-parameter responses as non-fallback capability
mismatches, while classifying invalid requests such as
`context_length_exceeded` as the separate non-fallback
`provider_invalid_request` class.
- Update static and generated route contracts so both terminal classes
are explicitly never-fallback.
- Refresh the app-client and integration-public OpenAPI snapshots, plus
their dependent generated Dart, TypeScript, and Swift clients, that the
contract gate revealed were already stale for the baseline-memory schema
and endpoint.
- Keep label-aware desktop changelog enforcement in the canonical PR
preflight; the macOS static lane now skips that metadata-only check
instead of rejecting a valid `no-changelog-needed` label.
- Keep owner-boundary Swift fixtures hermetic by installing their
production effect handler without starting screen capture, audio
capture, or system muting.

## Root cause and scope

The production terminal events occurred after route resolution and
before output. The gateway's OpenAI-compatible provider adapter mapped
every non-auth, non-rate-limit provider 4xx to `capability_mismatch`;
the executor then discarded the attempted provider/model when it built
terminal telemetry. As a result, the historical records prove an
upstream 4xx but cannot prove which request member the provider
rejected.

This PR repairs that owning boundary. It parses only a bounded semantic
enum from the already bounded provider error preview. Unknown codes and
parameter names collapse to `other_4xx` / `invalid_other`; provider
messages, raw bodies, prompts, IDs, credentials, and request values
never become response, metric, or terminal-log fields.

The leading unproven explanation for the affected `knowledge-graph` and
`memories` lanes is context size: the gateway override uses GPT-5.4 nano
(400K context), while the legacy GPT-4.1 mini route has a 1M context and
both callers can assemble large per-user history. Successful requests
alongside intermittent rejections are consistent with that boundary.
This PR intentionally does not change those routes until deployed
telemetry reports `provider_rejection=context_length_exceeded`; an
unsupported member will instead be reported as a bounded `unsupported_*`
value.

The separate BYOK rate-limit events remain unchanged and retain their
existing fail-closed behavior.

Two independent macOS CI defects were also exposed while verifying the
generated Swift client. First, the static lane reran a changelog check
without the PR label metadata owned by canonical preflight. Second,
owner-boundary tests started the real automation capture path merely to
install a voice-turn effect handler; on the runner, that path muted the
output device and stalled during cleanup, while three other SwiftPM
processes timed out waiting for the shared build lock. The workflow fix
restores the metadata owner, and a DEBUG-only fixture seam now installs
the production effect handler without touching OS capture or audio
state.

## Regression and privacy evidence

- The provider adapter test distinguishes
`unsupported_parameter/reasoning_effort` from `context_length_exceeded`
and proves arbitrary parameter names and provider messages do not
survive classification.
- The HTTP route test sends both terminal classes through real gateway
resolution/execution and asserts the exact public error code plus
provider/model/rejection context.
- The metrics test proves an arbitrary rejection value collapses to
`other_4xx` and is absent from terminal logs.

## Verification

- `backend/.venv/bin/pytest -q backend/tests/unit/test_llm_gateway_*.py
backend/tests/unit/test_gateway_resilience.py
backend/tests/unit/test_gateway_observability.py` — 309 passed.
- `cd backend && .venv/bin/pytest
tests/unit/test_llm_gateway_validator.py -q` — 22 passed.
- `cd backend && .venv/bin/pytest tests/unit/test_llm_gateway_service.py
tests/unit/test_gateway_resilience.py
tests/unit/test_gateway_observability.py -q` — 12 passed.
- Local running gateway + local mock OpenAI HTTP endpoint: a synthetic
`context_length_exceeded` 400 returned `provider_request_rejected` /
`provider_invalid_request`; the terminal record contained
`provider=openai model=gpt-5.4-nano
provider_rejection=context_length_exceeded` and did not contain the
synthetic private provider message.
- `OMI_PR_BODY_FILE=/tmp/omi-llm-gateway-provider-rejections-pr.md make
preflight` — 19 checks passed.
- `cd backend && scripts/openapi_runner.sh scripts/export_openapi.py
--surface app-client --check
../docs/api-reference/app-client-openapi.json` — passed.
- `cd backend && scripts/openapi_runner.sh scripts/export_openapi.py
--surface integration-public --check
../docs/api-reference/integration-public-openapi.json` — passed.
- `cd backend && .venv/bin/python scripts/generate_dart_models.py
--group memories` — generated output is clean and deterministic.
- `backend/.venv/bin/python backend/scripts/generate_ts_openapi_types.py
--check` — passed for all four generated TypeScript clients.
- `cd backend && .venv/bin/python
scripts/generate_swift_openapi_types.py --check` — passed.
- `cd desktop/macos && xcrun swift build -c debug --package-path
Desktop` — passed.
- `python3 .github/scripts/test_desktop_swift_ci_contract.py` — 22
passed.
- `actionlint .github/workflows/desktop-swift-ci.yml` — passed.
- `xcrun swift test --package-path Desktop --skip-build --filter
'PushToTalkStateMachineTests/'` — 9 passed; repeated 50/50.
- `python3 desktop/macos/scripts/desktop-flow-lint.py` — 58 flows and
135 registered actions passed.
- `make preflight` — 30 checks passed.
- The pre-push typecheck completed with 0 errors and its selected 22
backend test files passed.

## Product invariants affected

- INV-CHAT-1
- INV-VOICE-1

Failure-Class: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog-needed Skip desktop changelog enforcement for internal-only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant