Skip to content

fix(probe): fold env auth and binary fingerprint into codex model cache (#2787) - #2795

Closed
loulanyue wants to merge 1 commit into
garrytan:mainfrom
loulanyue:fix/2787-codex-probe-cache-auth-bin-invalidation
Closed

loulanyue wants to merge 1 commit into
garrytan:mainfrom
loulanyue:fix/2787-codex-probe-cache-auth-bin-invalidation

Conversation

@loulanyue

Copy link
Copy Markdown
Contributor

Summary of Changes

Fixes an issue where _gstack_codex_model_probe falsely returns cached MODEL_OK within the 1-hour window after the codex binary changes or environment authentication keys (CODEX_API_KEY / OPENAI_API_KEY) are rotated (#2787).

Root Cause

In bin/gstack-codex-probe, the cache signature was computed strictly from file modification timestamps:

_cfg_m=$(stat -c %Y "$_codex_home/config.toml" 2>/dev/null || stat -f %m "$_codex_home/config.toml" 2>/dev/null || echo 0)
_auth_m=$(stat -c %Y "$_codex_home/auth.json" 2>/dev/null || stat -f %m "$_codex_home/auth.json" 2>/dev/null || echo 0)
_sig="${_cfg_m}-${_auth_m}"

When authentication is supplied via environment variables (CODEX_API_KEY or OPENAI_API_KEY), or when the codex binary on PATH is updated or replaced, neither file's mtime moves. Consequently, _sig remained identical, and the probe served stale cached MODEL_OK for broken or revoked credentials.

Solution & Technical Decision

  1. Auth Fingerprint: Fold the hash of active environment keys (${CODEX_API_KEY}:${OPENAI_API_KEY}) into the cache signature when env auth is used, falling back to auth.json mtime for file auth.
  2. Binary Fingerprint: Fold the resolved codex binary path and mtime into the signature using stat (without invoking the binary, avoiding side-effects or process overhead).
  3. Automated Testing: Added unit tests in test/codex-model-probe.test.ts verifying that rotating env keys or updating the codex binary invalidates cached MODEL_OK immediately.

Fixes #2787

@trunk-io

trunk-io Bot commented Sep 4, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, @loulanyue. The fix is now on main: the Codex probe cache signature includes the env auth mode and the codex binary path and mtime (bin/gstack-codex-probe) (fixed in v1.91.16.0, #3014). Closing as superseded; if you still see the problem on the latest gstack, please open an issue with ./setup --status output.

@capy-ai capy-ai Bot closed this Oct 3, 2026
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.

gstack-codex-probe returns cached MODEL_OK after the codex binary or env-var auth changed

1 participant