Repository navigation
[codex] Add LLM gateway chat extraction pilot - #8427
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47dad57cb5
ℹ️ 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".
There was a problem hiding this comment.
10 issues found across 41 files
Confidence score: 2/5
backend/utils/llm/gateway_client.pyuses synchronoushttpx.post()inside an async path, which can block the event loop for up to the request timeout and stall health checks/autoscaling under load. This is the highest merge risk—move this call to the sharedhttpx.AsyncClientflow inutils/http_client.pybefore merging.- Validation gaps across
backend/llm_gateway/gateway/validator.py,backend/llm_gateway/gateway/credentials.py, andbackend/llm_gateway/gateway/resolver.pyallow malformed inputs through and then return misleading downstream/provider errors (including wrong 404 vs invalid-request semantics). Tighten request validation (json_schema.namerequired, trimmedkey_ref, blankmodelas invalid request) so clients get correct, actionable errors before merge. backend/utils/llm/gateway_client.pydoes not fully normalize strict JSON Schema output (missingadditionalProperties: falseon object schemas), so otherwise valid structured-output calls can be rejected by strict gateway/provider validation. Normalize generated schemas recursively before dispatch to reduce production request failures.backend/llm_gateway/gateway/executor.pyignores configuredretry.max_attempts, andbackend/llm_gateway/routers/openai_compatible.pymaps errortypeto the same value ascode, reducing retry resilience and OpenAI-format compatibility for clients. Respect per-route retry counts and correcttypeto category-level values before merging.
Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.
Re-trigger cubic
47dad57 to
e0cc0bd
Compare
Review Feedback AddressedAll 11 review threads from Codex and Cubic have been addressed in commit e0cc0bd. Summary:
Verification
Note: 8 pre-existing failures in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0cc0bdbc6
ℹ️ 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".
Fix: gate active-route execution on rollout stage/percentage (P2)Addresses Codex review comment on ProblemThe checked-in active route ( FixAdded rollout gating at the executor entry point:
Verification
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b36ddac9a
ℹ️ 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".
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
8b36dda to
4972d4f
Compare
Canary rollout percentage enforcementBoth review threads flagged the same root cause: Fix
The deterministic hash ensures the same request consistently lands on the same route across retries, while distributing traffic proportionally over many distinct requests. Verification
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4972d4f089
ℹ️ 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".
|
Fixed in What changed
Verification (local,
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec9543d6f3
ℹ️ 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".
|
Fixed in 5719856 — aligned the LKG route with the legacy model. The LKG route Change: set the LKG primary to Verification:
|
kodjima33
left a comment
There was a problem hiding this comment.
Separate FastAPI LLM gateway pilot (OpenAI-compatible) with auto-route config + telemetry. Large feature; approving only.
There was a problem hiding this comment.
8 issues found across 24 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/scripts/smoke-llm-gateway.py">
<violation number="1" location="backend/scripts/smoke-llm-gateway.py:18">
P1: Passing a service bearer token via `--token` command-line argument exposes the secret in process listings, shell history, and audit logs.</violation>
<violation number="2" location="backend/scripts/smoke-llm-gateway.py:55">
P2: `choices` indexing is unsafe: an empty `choices` array causes an unhandled `IndexError` before the script can emit a controlled failure message.</violation>
</file>
<file name="backend/charts/llm-gateway/templates/deployment.yaml">
<violation number="1" location="backend/charts/llm-gateway/templates/deployment.yaml:30">
P2: No configurable pod/container securityContext is included in the llm-gateway deployment template, reducing security hardening and preventing cluster operators from enforcing security policies through Helm values.</violation>
<violation number="2" location="backend/charts/llm-gateway/templates/deployment.yaml:36">
P1: Hardcoded uvicorn listen port (8080) conflicts with configurable containerPort (`.Values.service.port`), creating a port-drift risk. If operators change `service.port`, traffic and probes will target a different port than the container is actually listening on.</violation>
</file>
<file name="backend/scripts/validate-llm-gateway-env.py">
<violation number="1" location="backend/scripts/validate-llm-gateway-env.py:26">
P2: Validation script only checks presence of env variable names, not whether they have actual values or valid secret references. Empty or malformed secret configs can pass silently.</violation>
<violation number="2" location="backend/scripts/validate-llm-gateway-env.py:34">
P2: The `_load_yaml` function lacks error handling for file I/O and YAML parsing failures, causing unhandled exceptions and tracebacks instead of deterministic validation output. As a preflight/CI validation script, it should catch `OSError` and `yaml.YAMLError` and surface them as controlled validation `ERROR:` messages with a clean exit code.</violation>
</file>
<file name="backend/llm_gateway/routers/openai_compatible.py">
<violation number="1" location="backend/llm_gateway/routers/openai_compatible.py:38">
P2: Metrics emission is not fail-safe; unprotected `observe_success` and `observe_error` calls can raise and disrupt normal request handling</violation>
</file>
<file name="backend/charts/llm-gateway/prod_omi_llm_gateway_values.yaml">
<violation number="1" location="backend/charts/llm-gateway/prod_omi_llm_gateway_values.yaml:76">
P1: Readiness probe depends on `sh` and `curl` binaries being present in the container image, which is fragile and can break on minimal or distroless images. All other services in this repo use native `httpGet` or `tcpSocket` probes without shell dependencies.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".github/workflows/gcp_backend_pusher.yml">
<violation number="1" location=".github/workflows/gcp_backend_pusher.yml:126">
P2: Unredacted kubectl logs/describe output on deployment failure may leak sensitive runtime data into CI logs</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/scripts/smoke-llm-gateway.py">
<violation number="1" location="backend/scripts/smoke-llm-gateway.py:18">
P1: Passing a service bearer token via `--token` command-line argument exposes the secret in process listings, shell history, and audit logs.</violation>
<violation number="2" location="backend/scripts/smoke-llm-gateway.py:55">
P2: `choices` indexing is unsafe: an empty `choices` array causes an unhandled `IndexError` before the script can emit a controlled failure message.</violation>
</file>
<file name="backend/charts/llm-gateway/templates/deployment.yaml">
<violation number="1" location="backend/charts/llm-gateway/templates/deployment.yaml:30">
P2: No configurable pod/container securityContext is included in the llm-gateway deployment template, reducing security hardening and preventing cluster operators from enforcing security policies through Helm values.</violation>
<violation number="2" location="backend/charts/llm-gateway/templates/deployment.yaml:36">
P1: Hardcoded uvicorn listen port (8080) conflicts with configurable containerPort (`.Values.service.port`), creating a port-drift risk. If operators change `service.port`, traffic and probes will target a different port than the container is actually listening on.</violation>
</file>
<file name="backend/scripts/validate-llm-gateway-env.py">
<violation number="1" location="backend/scripts/validate-llm-gateway-env.py:26">
P2: Validation script only checks presence of env variable names, not whether they have actual values or valid secret references. Empty or malformed secret configs can pass silently.</violation>
<violation number="2" location="backend/scripts/validate-llm-gateway-env.py:34">
P2: The `_load_yaml` function lacks error handling for file I/O and YAML parsing failures, causing unhandled exceptions and tracebacks instead of deterministic validation output. As a preflight/CI validation script, it should catch `OSError` and `yaml.YAMLError` and surface them as controlled validation `ERROR:` messages with a clean exit code.</violation>
</file>
<file name="backend/llm_gateway/routers/openai_compatible.py">
<violation number="1" location="backend/llm_gateway/routers/openai_compatible.py:38">
P2: Metrics emission is not fail-safe; unprotected `observe_success` and `observe_error` calls can raise and disrupt normal request handling</violation>
</file>
<file name=".github/workflows/gcp_backend_pusher.yml">
<violation number="1" location=".github/workflows/gcp_backend_pusher.yml:69">
P1: Race condition in secret bootstrap: concurrent workflow runs can fail the deployment when both observe the secret missing and one create call loses the race with ALREADY_EXISTS.</violation>
<violation number="2" location=".github/workflows/gcp_backend_pusher.yml:126">
P2: Unredacted kubectl logs/describe output on deployment failure may leak sensitive runtime data into CI logs</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
The client (utils.llm.gateway_client) reads OMI_LLM_GATEWAY_SERVICE_TOKEN first and falls back to LLM_GATEWAY_SERVICE_TOKEN, but the gateway only read the bare name. When both vars were present with different values (e.g. local dev or token rotation), every gateway request was rejected and the pilot silently fell back. Make the gateway accept the same primary env var with identical precedence (OMI_ prefixed wins, bare name is legacy). Adds 4 tests covering primary-only, precedence, legacy fallback, and blank fails closed.
The LKG route (route.chat_structured.2026_06_20.001) served gpt-4o-mini
while the legacy get_llm('chat_extraction') path resolves to gpt-4.1-mini.
With the active route in shadow rollout (percent 0), enabling the gateway
silently changed classifier behavior for 100% of successful non-BYOK
pilot calls instead of being a no-user-visible shadow.
Align the LKG primary model to gpt-4.1-mini to match the legacy route, and
update the artifact_digest for the changed content. Update the executor and
openai-compatible tests that assert the served LKG model.
Addresses chatgpt-codex-connector review feedback (P2).
- smoke-llm-gateway.py: support token via OMI_LLM_GATEWAY_SERVICE_TOKEN env var instead of only --token CLI arg (avoids secret in process listings) - smoke-llm-gateway.py: guard against empty/missing choices array (IndexError) - validate-llm-gateway-env.py: add I/O and YAML parsing error handling in _load_yaml (controlled ERROR output + clean exit) - validate-llm-gateway-env.py: validate env vars have actual values or valid secret references, not just key presence - deployment.yaml: parameterize uvicorn listen port via .Values.service.port (fixes port-drift risk between containerPort and uvicorn) - deployment.yaml: add configurable podSecurityContext and container securityContext blocks (matches backend-listen chart pattern) - openai_compatible.py: wrap metrics observe calls in _safe_observe to prevent telemetry failures from disrupting request handling
Address cubic P2 (discussion_r3487225338): the llm-gateway is an OpenAI-compatible service that processes chat content and service tokens, so dumping raw `kubectl logs` on rollout failure could leak sensitive runtime data into CI output. Keep the safe status diagnostics (describe deploy/pods, get pods, ExternalSecret status, secret key presence) and drop only the raw log dump. The smoke-pod log line is intentionally retained since it only logs a controlled smoke test script.
Address two cubic review threads on gcp_backend_pusher.yml: - P1 (r3487241404): Tolerate ALREADY_EXISTS in the dev service-token bootstrap. Two concurrent workflow_dispatch dev deploys could both observe the secret missing and race on gcloud secrets create; the loser failed the whole deployment. Now a failed create re-checks existence and exits 0 if the secret is present (created by the other run), only failing if the secret is genuinely absent. - P2 (r3487301182): Append GITHUB_RUN_ATTEMPT to the smoke pod name so workflow reruns don't collide on the prior attempt's pod if its cleanup trap didn't fire.
…ing, sentinel - Gate provider error body preview behind LLM_GATEWAY_EXPOSE_PROVIDER_ERROR_DETAILS flag so pure-alpha error text is never surfaced to API clients by default (Cubic P1: information disclosure via sanitize() bypass) - Check HTTP status before reading full response body on error responses so a large/invalid-content-length body cannot reclassify a 401/403/429/4xx as PROVIDER_5XX_OMI_PAID, preserving correct retry/LKG-fallback behavior (Cubic P1: status-specific failure masking) - Replace magic-string sentinel 'provider request failed' with shared GENERIC_PROVIDER_FAILURE_MESSAGE constant to avoid drift (Cubic P2: fragile exact-string sentinel check)
57fc708 to
b95a74e
Compare
Review feedback addressed (Cubic P1/P1/P2)Fixed all three unresolved Cubic threads in Thread 1 — P1: Provider error body information disclosure
Thread 2 — P1: Body-size errors masking status-specific failures
Thread 3 — P2: Fragile exact-string sentinel check
Verification
|
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/scripts/smoke-llm-gateway.py">
<violation number="1" location="backend/scripts/smoke-llm-gateway.py:68">
P2: `--check-metrics` does not actually validate metric increment; it only validates metric is non-zero, allowing false positives from prior traffic.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| value = float(line.rsplit(' ', 1)[-1]) | ||
| except ValueError: | ||
| continue | ||
| if value > 0: |
There was a problem hiding this comment.
P2: --check-metrics does not actually validate metric increment; it only validates metric is non-zero, allowing false positives from prior traffic.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/scripts/smoke-llm-gateway.py, line 68:
<comment>`--check-metrics` does not actually validate metric increment; it only validates metric is non-zero, allowing false positives from prior traffic.</comment>
<file context>
@@ -40,6 +40,36 @@ def _get_ready(client: httpx.Client, url: str, headers: dict[str, str]) -> httpx
+ value = float(line.rsplit(' ', 1)[-1])
+ except ValueError:
+ continue
+ if value > 0:
+ return line
+ return None
</file context>
Summary
requires_contextthroughomi:auto:chat-structuredfirst, with existing provider fallback on gateway miss or failureValidation
rtk pytest backend/tests/unit/test_llm_gateway_service.py backend/tests/unit/test_llm_gateway_config.py backend/tests/unit/test_llm_gateway_auth.py backend/tests/unit/test_llm_gateway_credentials.py backend/tests/unit/test_llm_gateway_validator.py backend/tests/unit/test_llm_gateway_resolver.py backend/tests/unit/test_llm_gateway_executor.py backend/tests/unit/test_llm_gateway_openai_provider.py backend/tests/unit/test_llm_gateway_openai_compatible.py backend/tests/unit/test_llm_gateway_readiness.py backend/tests/unit/test_llm_gateway_client_config.py backend/tests/unit/test_llm_gateway_route_refs.py backend/tests/unit/test_llm_gateway_dependencies.py backend/tests/unit/test_llm_gateway_chat_extraction_pilot.py -v(113 passed)rtk bash backend/test-preflight.sh(passed with optional dependency warnings)rtk python backend/scripts/scan_async_blockers.py(completed; reports existing unrelated blockers)Notes
origin/mainwas already an ancestor of this branch after fetch, so no merge commit was needed.backend/test.shwas not used for final validation because it invokes barepytestin this shell; the equivalent gateway-focused tests were run throughrtk pytest.