Skip to content

fix(codex-sdk): pin gateway model calls to one deployment (0.1.1) - #387

Merged
al3xanndru merged 1 commit into
mainfrom
fix/codex-sdk-sticky-sessions
Nov 25, 2026
Merged

al3xanndru merged 1 commit into
mainfrom
fix/codex-sdk-sticky-sessions

Conversation

@al3xanndru

@al3xanndru al3xanndru commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

uipath-codex-sdk 0.1.1: Codex runs that make more than one model call (any tool use) failed on alpha with 400 invalid_encrypted_content, until the gateway started to retry such calls on 2026-11-24/25 (see the last section). This release makes every model call carry the LLM Gateway's sticky-session headers, so a run stays on one deployment. For jobs and conversations it uses the fix that uipath-llm-client 1.23 already has; for local runs the gateway proxy fills the gap.

Root cause

  • On 2026-11-09 (gitops 724ace2c6a55, LLM-4510), alpha's Standard-QoS traffic for most GPT models moved from native OpenAI to a pool of Azure OpenAI deployments. gpt-5.6-terra, gpt-6.1-sol and gpt-5-mini are among them, and gpt-5.4 followed on 11-18.
  • Codex calls the Responses API with store: false and replays its encrypted reasoning items on every follow-up. Only the deployment that produced them can decrypt them, so a follow-up served by another deployment fails.
  • Staging hit the same error and was rolled back on 11-20 (49c696b11a3f); alpha was not.
  • The gateway keeps the requests that carry the same sticky-session transaction id on one deployment. 0.1.0 never sent the headers: it pins uipath-llm-client<1.19, which has no sticky-session code.

Fix

  • Jobs and conversations: use the existing fix. uipath-llm-client 1.23.0 (feat: send LLM Gateway sticky-session headers from PlatformSettings uipath-llm-client-python#159, PC-5399) sends the sticky-session headers with the conversation id, otherwise the job key. This PR requires uipath-llm-client[openai]>=1.23.0,<1.24.0, and uipath>=2.15.1,<2.16.0, which 1.23 needs. No source change was needed for uipath 2.15.
  • Local runs: a small fallback in the gateway proxy. uipath-llm-client sends no headers when the run has neither id. When the upstream client carries no sticky-session header, the proxy adds both headers itself, with Codex's thread id (its session-id / thread-id request header) as the transaction id, cut to 128 characters. If a request has no thread id, it uses an id generated once per proxy.
  • Same minors as uipath-langchain and uipath-claude-sdk (chore(claude-sdk): require uipath-llm-client 1.23 and uipath 2.15 #386), so a project can use uipath-codex-sdk together with a current uipath-langchain. With 0.1.0 (uipath<2.15) that does not resolve.
  • README: a note in the Models section.

Testing

  • Unit: 589 passed on Python 3.11, 3.12 and 3.13, and on the lowest allowed versions (uipath 2.15.1, uipath-llm-client 1.23.0, uipath-platform 0.3.4). ruff, ruff format, mypy and uv lock --check are clean.
  • New tests:
    • Proxy: an unpinned run gets the headers with Codex's thread id (unary and streaming); headers that uipath-llm-client put on the client are left alone; thread-id header forms; the per-proxy id.
    • Contract, with the real codex 0.161 binary: every Responses request carries the thread id, also after a resume in a new app-server.
  • Headers reaching the gateway, checked with the real uipath-llm-client client behind the proxy and a stubbed transport: a job sends the job key, a conversation sends the conversation id, a local run sends Codex's thread id; one copy of each header per request.
  • Alpha, live, on this revision (2026-11-25), checked in the gateway's App Insights with each request joined to its Azure calls:
    • Local: 10 runs of a web_search agent (5 gpt-5.6-terra, 5 gpt-5-mini-2025-08-07), 42 model calls. Every call carried the sticky-session header with Codex's thread id, each run was served by one Azure deployment, and no call failed upstream.
    • Orchestrator (Personal Workspace, 0.1.1 wheel packed with the project): 6 jobs (3 per model), 24 model calls. Every call carried the header with the job key, sent by uipath-llm-client. Each job was served by one deployment, and no call failed upstream.
    • One local run and one job made a single model call (gpt-5-mini answered without calling the tool), so 9 runs and 5 jobs exercised follow-up calls.

What changed on alpha since the regression

Between 2026-11-24 15:26 UTC and 2026-11-25 09:47 UTC the gateway on alpha started to retry a call that Azure rejects with invalid_encrypted_content on the other deployment, also for callers that send no sticky-session headers. I see this in telemetry only; the routing flags in gitops did not change.

  • 11-24, calls without the headers (agenthub, these two models): 30 of 132 returned the 400 to the caller, none retried.
  • 11-25, 0.1.0 from PyPI: 5 of 5 runs pass again. 6 of their 16 calls failed on the first deployment and succeeded on the retry.
  • Calls with the headers: none failed upstream on either day.

So on alpha today this release no longer turns a failing run into a passing one. It keeps a run on one deployment, which avoids the failed call and the retry, does not depend on that retry staying, and is what low-code and uipath-langchain agents send.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:56

Copilot AI 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.

🟢 Approval recommended

No active review issues block the sticky-session and transaction-ID propagation changes.

No open issues 🎉

What changed in this PR

Releases uipath-codex-sdk 0.1.1 to prevent deployment switching from breaking multi-call Codex runs with invalid_encrypted_content errors.

Changes:

  • Adds sticky-session headers to unary and streaming Responses requests, with prioritized transaction IDs.
  • Passes conversation and runtime IDs through the runtime and gateway layers, with tests for selection and stability.
  • Updates dependencies, the lockfile, and model documentation.
File Description
packages/​uipath-codex-sdk/​uv.lock Locks the release version and updated dependencies.
packages/​uipath-codex-sdk/​tests/​test_gateway_proxy.py Tests sticky headers, ID precedence, stability, length limits, and shim wiring.
packages/​uipath-codex-sdk/​tests/​test_chat.py Tests conversation ID propagation from the factory.
packages/​uipath-codex-sdk/​src/​uipath_codex_sdk/​runtime/​runtime.py Passes conversation and runtime IDs to the gateway shim.
packages/​uipath-codex-sdk/​src/​uipath_codex_sdk/​runtime/​gateway/​proxy.py Selects transaction IDs and attaches sticky-session headers.
packages/​uipath-codex-sdk/​src/​uipath_codex_sdk/​runtime/​gateway/​__init__.py Supplies conversation, job, and fallback IDs to the proxy.
packages/​uipath-codex-sdk/​src/​uipath_codex_sdk/​runtime/​factory.py Forwards the context’s conversation ID to the runtime.
packages/​uipath-codex-sdk/​README.md Explains deployment pinning and transaction ID precedence.
packages/​uipath-codex-sdk/​pyproject.toml Bumps the SDK version and updates dependency constraints.

Review effort: Balanced

Since the LLM Gateway serves Standard-QoS GPT traffic from a pool of
Azure OpenAI deployments (alpha, from 2026-11-09), Codex runs that make
more than one model call fail with 400 invalid_encrypted_content. Codex
calls the Responses API with store: false and replays its encrypted
reasoning on every follow-up, and only the deployment that produced it
can decrypt it. The gateway keeps the requests that carry the same
sticky-session transaction id on one deployment.

- Require uipath-llm-client 1.23, which sends the sticky-session headers
  for a conversation (the conversation id) and for a job (the job key),
  and uipath 2.15, which it needs. These are the minors uipath-langchain
  and uipath-claude-sdk require, so the packages install together.
- A run with neither id (a local run) gets no headers from
  uipath-llm-client, so the gateway proxy sends them, with Codex's
  thread id as the transaction id.
- Contract test: codex sends its thread id on every Responses request,
  also after a resume in a new app-server.
- Version 0.1.1.

Co-Authored-By: Claude <[email protected]>
@al3xanndru
al3xanndru force-pushed the fix/codex-sdk-sticky-sessions branch from 1151d5e to fc06a58 Compare November 25, 2026 13:01
@sonarqubecloud

Copy link
Copy Markdown

@al3xanndru
al3xanndru merged commit 79d82a6 into main Nov 25, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants