Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(backends): honor disk-level Codex API key + reject ok:false saves

cyh3db70db5d861
diff --git a/ui/src/components/settings/SettingsCodexProviderPage.tsx b/ui/src/components/settings/SettingsCodexProviderPage.tsx
index 9c5ae2082..090f9c379 100644
--- a/ui/src/components/settings/SettingsCodexProviderPage.tsx
+++ b/ui/src/components/settings/SettingsCodexProviderPage.tsx
@@ -113,6 +113,15 @@ export const SettingsCodexProviderPage: React.FC = () => {
base_url: baseUrl.trim() || null,
};
const result = await api.saveCodexAuth(payload);
+ if (result.ok === false) {
+ // The server returns ok:false for validation/persist failures
+ // (e.g. missing api_key when auth_mode is "api_key") with HTTP 200,
+ // so we must not advance into the success branch here — applying
+ // ``result`` into state would overwrite the user's in-progress
+ // edits with a malformed response that omits auth_mode / base_url.
+ showToast(result.message || t('settings.backends.codexSaveFailed'), 'error');
+ return;
+ }
setState(result);
setAuthMode(result.auth_mode);
setBaseUrl(result.base_url || '');
diff --git a/vibe/api.py b/vibe/api.py
index 678dc7ff3..72c2c516e 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -2082,7 +2082,22 @@ def get_codex_auth() -> dict:
configured_mode = getattr(cfg, "auth_mode", None)
except Exception:
configured_mode = None
- auth_mode = configured_mode if configured_mode in _VALID_AUTH_MODES else disk_state.get("auth_mode")
+
+ # Disk wins when it carries unambiguous evidence of API-key auth: an
+ # ``OPENAI_API_KEY`` in ``~/.codex/auth.json`` is a concrete artefact
+ # the user (or a prior ``codex login`` flow) placed there. ``V2Config``
+ # may still default ``auth_mode`` to ``"oauth"`` on the upgrade path
+ # (older configs lacked the field entirely), so trusting the config
+ # alone would make the UI render OAuth and a subsequent save would
+ # then wipe ``OPENAI_API_KEY``. Configured mode remains the source of
+ # truth only when disk has no key — i.e., the user's stated intent
+ # before they have signed in or pasted credentials.
+ if disk_state.get("has_api_key"):
+ auth_mode: str | None = "api_key"
+ elif configured_mode in _VALID_AUTH_MODES:
+ auth_mode = configured_mode
+ else:
+ auth_mode = disk_state.get("auth_mode")
return {
"ok": True,
"auth_mode": auth_mode or "oauth",