Skip to content

fix(codex): preserve OAuth model context window metadata - #774

Merged
pancacake merged 1 commit into
HKUDS:devfrom
NoxsMedia:fix/codex-context-window-metadata
Aug 6, 2026
Merged

pancacake merged 1 commit into
HKUDS:devfrom
NoxsMedia:fix/codex-context-window-metadata

Conversation

@NoxsMedia

Copy link
Copy Markdown
Contributor

Description

Codex OAuth model discovery currently drops context_window and max_context_window from the /codex/models response before publishing the read-only managed model profile. As a result, downstream runtime configuration cannot use the provider metadata and may fall back to a conservative default, encouraging users to create a second manual profile.

This PR:

  • parses optional positive context_window and max_context_window values from Codex model metadata;
  • preserves both fields in the cached CodexModel contract while remaining compatible with caches written before these fields existed;
  • publishes context_window to managed catalog models with context_window_source: metadata;
  • falls back to max_context_window when the current context field is absent;
  • adds parser, serialization, backward-compatibility, and managed-profile regression tests.

No context-window value is hardcoded in production code.

Related Issues

  • None found.

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (not necessary: no user-facing workflow or configuration syntax changes).
  • My changes do not introduce any new security vulnerabilities.

Verification

  • pre-commit run --files <changed files>: passed (including Ruff, format, JSON, detect-secrets, Bandit, and MyPy)
  • pytest -q tests/services/codex_auth tests/services/test_model_catalog.py tests/services/config/test_provider_runtime.py tests/services/config/test_context_window_detection.py: 139 passed
  • A read-only live metadata probe confirmed the endpoint returns integer context-window fields and that the updated parser publishes them into a temporary managed catalog. No credentials or account data are included in this PR.

The all-files pre-commit run was attempted. It rewrites tracked web/.next-deeptutor build artifacts and unrelated pre-existing frontend formatting; those unrelated changes were reverted rather than included here.

Additional Notes

This intentionally does not add editable reasoning-effort overrides to the read-only OAuth-managed profile. That is a separate UI/configuration design change and should be reviewed independently.

Design sync: not applicable — this preserves the existing OAuth-managed catalog architecture and restores provider metadata that was already present upstream.

@pancacake
pancacake merged commit 1f37e85 into HKUDS:dev Aug 6, 2026
11 checks passed
pancacake added a commit that referenced this pull request Aug 6, 2026
…ack everywhere

#784 fixed the launcher, but the same address is rendered on two other paths
that kept "localhost": the Docker entrypoint (render_environment) and the
last-resort default in web/proxy.ts. On a dual-stack host that name resolves
to ::1 first while uvicorn binds 0.0.0.0 (IPv4 only), so every rewritten
/api/* request fails to connect — the launcher and container paths are meant
to stay in sync, and after #784 they no longer did.

Also disambiguates the two same-named _optional_positive_int helpers added by
#774: catalog's drops junk from a live API response, contracts' rejects it as
cache corruption. Same name, opposite behaviour — the strict one is now
_require_optional_positive_int and says why it differs.
pancacake added a commit that referenced this pull request Aug 12, 2026
An adversarial pass over #818 / #789 / #780 after merging.

**Codex sign-ins from before this week stopped working (#789).**
``validate_runtime_profile`` compared the profile's ``codex_account_binding``
for equality, but that key is written only by ``sync_codex_catalog`` — every
managed profile published by #690/#774 has none, so ``None != <hash>`` made
each of them look like another account's and locked its owner out of Codex
until they re-ran "Refresh models". Absent now reads as legacy; a binding
that is present and different is still an account switch and still refused.

**Overriding reasoning effort for one turn returned 409 (#789).** The same
function also required the request's effort to be byte-equal to the value
stored in the catalog. Effort is a per-request knob, not part of the identity
that ties a config to a token — the check now stops at model membership.
Its test asserted the old behaviour and has been rewritten around what the
function is actually for.

**The reasoning-effort endpoint left the runtime caches stale (#789).** It
writes the catalog the runtime resolves against, like every other catalog
write in this router, but skipped ``_invalidate_runtime_caches()``.

**OrcaRouter claimed Anthropic prompt caching (#818).** ``supports_prompt_caching``
makes ``_build_kwargs`` inject ``cache_control`` blocks into any ``anthropic/*``
or ``claude*`` request — an OpenRouter extension. No other gateway sets it and
nothing established the second one accepts it; a strict gateway would 400 every
Claude turn. Also fixed ``anthropic/claude-sonnet-4.6`` in the fallback list,
which the rest of the repo spells with dashes, so a user picking it from our
own menu would have got "model not found".

**OrcaRouter inserted itself into the curated menus (#818).** The featured
lists are hand-picked and rendered as a positional numbered menu, so adding an
entry shifted Ollama from [10] to [11]. The registry entry alone already makes
a provider reachable via "Show all" and the Settings dropdown; which providers
are featured is a maintainer decision. The README paragraph goes with it — no
other provider has per-provider prose there, and it would have been translated
into ten languages.
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.

2 participants