Skip to content

feat(inference): reuse Codex and Copilot subscriptions - #2432

Merged
hidb4ai merged 16 commits into
masterfrom
codex/subscription-inference
Nov 9, 2026
Merged

hidb4ai merged 16 commits into
masterfrom
codex/subscription-inference

Conversation

@PsiACE

@PsiACE PsiACE commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Which issue or RFC does this PR close?

No linked issue or RFC.

Rationale for this change

Reuse existing Codex and GitHub Copilot subscriptions for generation without adding a login flow. The Pydantic AI upgrade must preserve authentication, conversation boundaries, error classification and content-free observability.

What changes are included in this PR?

  • Upgrade pydantic-ai-slim to >=2.64.0,<3 and migrate provider clients, tracing and integration history to its HTTPX2/message contracts.
  • Keep Codex CLI as the sole renewal owner. Server and workers read its latest complete credentials for every request, never consume its single-use refresh token and never modify its login file. Rejected/expired credentials fail until the CLI renews them; subsequent requests adopt the update without restarting.
  • Preserve X-Api-Key authentication for Anthropic-compatible endpoints selected through either explicit configuration or ANTHROPIC_BASE_URL. Keep separate gateway and upstream credentials, and preserve default official-endpoint authentication.
  • Persist recalled context at the current-run boundary while retaining a leading model-facing system message on each tool step. Preserve caller history and body-based context-overflow classification for generic HTTP errors.
  • Integrate master c4c95e46, retaining its Source locators, provider observations and shared CI fixes. Adapt Atomic Memory retry fixtures to SDK-normalized feedback and assert exact Source sequence locators while preserving business assertions.

Are there any user-facing changes?

Use openai-codex:<model> with an existing file-backed Codex CLI login, or github-copilot:<model> with an existing OAuth token and a Chat Completions model. Memory, Experience and Profile generation are supported; Topic Memory, Dream and built-in inference protection are not supported for these subscription providers.

Codex credential renewal remains the CLI's responsibility; this integration does not provide unattended renewal. Server and worker processes must be able to read the same login file. SDK callers injecting clients for MiniMax embeddings or Jev reranking must use httpx2.AsyncClient. English and Chinese documentation describe these contracts.

How was this change tested?

  • Reproduced HTTP 401 for environment-selected Anthropic endpoints under both disabled and shadow protection; corrected regressions pass with the existing explicit-endpoint and dual-credential cases.
  • Reproduced the default Codex provider's refresh/lifecycle mismatch. Regression coverage verifies rejection without refresh-grant use, expired-JWT handling, two real spawned runtime processes observing CLI renewal, restart, per-request reload and content-free credential errors. Provider HTTP is simulated; no real subscription credential was read or exchanged.
  • Python 3.14.5: 516 passed across Pydantic AI adapters, built-in inference, endpoint authentication, provider observations, runtime composition, Topic Memory budgets, Atomic Memory retry/temporal behavior, RFC 2086 transports and Source/API contracts.
  • Python 3.11.15 with minimum pydantic==2.12.0: 97 passed across Source locator serialization, Source observations and API contracts in an isolated environment.
  • make check: passed, including all hooks, lock consistency and type checks.

Live subscription calls, the full Python/backend matrix and installed-release upgrade acceptance remain separate CI/operator checks. No claim of live-provider acceptance is made by the controlled transport tests.

AI usage statement

OpenAI Codex assisted implementation and review. Earlier repairs used local Bub with magpie:group/deepseek-flash at high reasoning effort. Codex directly reproduced and implemented the current authentication and integration fixes, reviewed the resulting diff and ran acceptance; Bub was not used for this update.

@PsiACE
PsiACE marked this pull request as ready for review November 3, 2026 03:24
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:24

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@AlexStocks AlexStocks added the 1.5.1 v1.5.1 release tracking label Nov 3, 2026
hidb4ai
hidb4ai previously requested changes Nov 3, 2026

@hidb4ai hidb4ai 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.

The dependency upgrade breaks authentication for existing Anthropic-compatible endpoints that require the configured API key in x-api-key.

Comment thread pyproject.toml Resolved
Copilot AI balanced review requested due to automatic review settings November 4, 2026 16:58

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 17:02

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:42

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hidb4ai hidb4ai 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.

Re-reviewed the Anthropic credential fix. Both API-key-only and gateway-plus-upstream authentication now pass the local runtime probes in disabled and shadow protection modes. CI is still running, and GitHub reports merge conflicts that need resolution.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Resolve merge conflicts with the target branch.

hidb4ai
hidb4ai previously requested changes Nov 6, 2026

@hidb4ai hidb4ai 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.

I reproduced the conversation-history regression reported in this existing thread: after a second run with the first run's history, new_messages() includes both the first and second user prompts. I am changing my earlier approval to request changes until that boundary is preserved.

Reconcile the PR's httpx2 SDK migration with master's provider observation
wrapping: observability and composition inspect httpx2 clients and transports,
and MiniMax keeps its observation operation around the httpx2 request path.
Merge the bilingual observability docs onto master's full text, which already
covers the tracing, worker coverage, and provider-observation contracts.

Keep the uncategorized-HTTP-400 context-overflow fallback and its single helper
definition.
… every step

The new-message boundary fix moved recalled context to the current-run boundary
in persisted history, which also demoted it from a leading SystemPromptPart to a
mid-conversation <system>-tagged user turn for providers without inline system
prompts.

Pydantic AI keeps the outgoing request list and the persisted history separate
after the before-hook chain detaches, so persist the context at the boundary for
new_messages() and lead the model-facing request with it. Later tool steps rebuild
their request from persisted history, so reorder there too, restoring the
system-role contract on every step.

The regression now covers a new prompt, the multi-step tool turn, and a
history-only resume whose input ends in a ModelRequest, and snapshots the
caller's history instead of asserting message counts.

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

…ult ACLs

The case directory is a temporary directory, and on a runner whose temp root
carries a default POSIX ACL that entry is inherited by every hook-created
subdirectory and file. A default ACL overrides the umask, so the hooks' own
`$HOME/.local`, `$HOME/.local/state/powercontext`, and diagnostics file were
recorded as 775/664 instead of the characterized 755/644 even though each hook
process already starts with umask 0o022.

Remove the inherited default entry at the case root before any hook runs; it is
created before the first step, so modes below it then follow the umask alone.
Only the root needs handling, and private 0600/0700 expectations are unchanged.
The attribute is Linux-specific, so other hosts are left alone, and an
unexpected removal error still fails the case. Every other fixture field was
identical in the failing CI run.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:09

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Comment thread website/next.config.mjs Resolved

@knqiufan knqiufan left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The existing website-build issue remains open on this head. I also found the two authentication issues below; please address them before merging.

hidb4ai
hidb4ai previously requested changes Nov 7, 2026

@hidb4ai hidb4ai 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.

The earlier new_messages() counterexample now passes, but I independently confirmed the existing environment-selected Anthropic gateway issue in both disabled and shadow modes. I also reproduced the Codex refresh lifecycle issue with synthetic credentials and a single-use refresh stub; this was not a live subscription test. These issues still need resolution before approval.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 18:24

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hidb4ai

hidb4ai commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

please resolve conflicts

Copilot AI balanced review requested due to automatic review settings November 8, 2026 14:46

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 04:09

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@PsiACE
PsiACE dismissed stale reviews from hidb4ai, hidb4ai, knqiufan, and hidb4ai November 9, 2026 04:09

Superseded by the Anthropic authentication fixes in 8c83d2c: custom endpoints retain X-Api-Key and gateway Authorization alongside the upstream API key. The associated thread is resolved; requesting a fresh review.

@PsiACE
PsiACE requested review from hidb4ai and knqiufan November 9, 2026 04:09

@hidb4ai hidb4ai 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.

LGTM

@hidb4ai
hidb4ai merged commit 6d781dc into master Nov 9, 2026
35 of 45 checks passed
jasondeng1997 added a commit to jasondeng1997/powercontext that referenced this pull request Nov 9, 2026
`test_codex_workers_and_restart_observe_cli_renewal` joins each spawned
worker for ten seconds and then asserts `exitcode == 0`. Every worker has
already answered on the pipe at that point, so the assertion is about
interpreter shutdown, not about the credential behaviour under test, and the
shared matrix runner gives two cores to eight pytest workers:

- run 42687710011, `tests (3.12, unit)`:
  `AssertionError: assert None == 0 ... <SpawnProcess name='SpawnProcess-2' pid=... started>`
- run 42714396200, `tests (3.11, unit)`: the same assertion, same worker
  state, after the expected `[(".../codex/responses", "***", "renewed-account")]`
  reply had already been asserted.

The test arrived on master today in oceanbase#2432 (`6d781dcfe`). Wait up to a minute
and report the worker that did not exit, so a scheduling delay no longer
reads as a product failure while a worker that never exits still fails here.

No production code changes.
@PsiACE
PsiACE deleted the codex/subscription-inference branch November 16, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.5.1 v1.5.1 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants