Skip to content

fix(embeddings): clean up CodexOAuthEmbeddings token-refresh follow-up#1809

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/codex-oauth-followup
May 28, 2026
Merged

fix(embeddings): clean up CodexOAuthEmbeddings token-refresh follow-up#1809
nicoloboschi merged 1 commit into
mainfrom
fix/codex-oauth-followup

Conversation

@nicoloboschi
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1712 — small cleanups surfaced during review.

  • Drop dead import in CodexOAuthEmbeddings.encode() (CodexRefreshExpiredError was imported but never referenced — it propagates naturally from refresh_tokens).
  • Simplify _load_codex_refresh_token: make CodexAuthManager.load_refresh_token_from_file a @staticmethod taking the auth_file path. CodexLLM._load_codex_refresh_token now calls the same code path both pre- and post-__init__ instead of duplicating the file-read in a hasattr fallback.
  • Test robustness: the new CodexOAuthEmbeddings tests in test_codex_oauth_refresh.py set monkeypatch.setenv("HOME", tmp_path) and then manually overrode emb._auth_manager._auth_file post-construction. That works on CI but on a developer machine with a real ~/.codex/auth.json the construction step could still read the real file (depending on Path.home() resolution). Switched to monkeypatch.setattr(Path, "home", lambda: tmp_path) so CodexAuthManager.from_file() resolves to the tmp file directly, and dropped the manual _auth_file override.

Test plan

  • uv run pytest tests/test_codex_oauth_refresh.py — 25 passed
  • uv run pytest tests/test_codex_tool_choice.py tests/test_codex_base_url.py — 5 passed (verifies the _load_codex_* patch surface still works for callers that mock these methods)
  • uv run ruff check ., uv run ruff format --check ., uv run ty check hindsight_api/ — clean

- Drop unused CodexRefreshExpiredError import in CodexOAuthEmbeddings.encode
- Make CodexAuthManager.load_refresh_token_from_file a staticmethod taking
  the auth_file path, so CodexLLM._load_codex_refresh_token no longer needs
  a duplicate file-read branch for the pre-_auth_manager init path
- Patch Path.home() in the embeddings tests instead of monkeypatching HOME
  and manually overriding _auth_manager._auth_file post-construction; the
  prior shape worked on CI but could read the developer's real ~/.codex on
  local runs
@nicoloboschi nicoloboschi merged commit 4d9f4ab into main May 28, 2026
72 checks passed
@nicoloboschi nicoloboschi deleted the fix/codex-oauth-followup branch May 28, 2026 10:29
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.

1 participant