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(ui): gate OpenCode provider fan-out on successful runtime config load

cyh88663aa45d2a
diff --git a/ui/src/components/settings/SettingsOpencodeProviderPage.tsx b/ui/src/components/settings/SettingsOpencodeProviderPage.tsx
index 3145db157..0ef5025ff 100644
--- a/ui/src/components/settings/SettingsOpencodeProviderPage.tsx
+++ b/ui/src/components/settings/SettingsOpencodeProviderPage.tsx
@@ -179,6 +179,12 @@ export const SettingsOpencodeProviderPage: React.FC = () => {
// (matches the original "toggle then reload" UX exactly).
useEffect(() => {
if (!runtime.loaded) return;
+ // If the initial getConfig() failed, ``runtime.enabled`` is still
+ // the pre-load default rather than persisted state. Don't trigger
+ // provider fetches in that case — the toast in the runtime hook
+ // already informed the user; firing requests now would just emit
+ // misleading "server stopped" errors.
+ if (runtime.configError) return;
if (runtime.enabled) {
setServerStartAttempts(0);
void loadProviders();
@@ -190,7 +196,7 @@ export const SettingsOpencodeProviderPage: React.FC = () => {
if (retryTimerRef.current) clearTimeout(retryTimerRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [runtime.enabled, runtime.loaded]);
+ }, [runtime.enabled, runtime.loaded, runtime.configError]);
// Auto-retry server-start failures — common when the user has just
// enabled the backend. After SERVER_START_MAX_RETRIES the user can hit
diff --git a/ui/src/components/settings/shared/useBackendRuntime.ts b/ui/src/components/settings/shared/useBackendRuntime.ts
index 4da8af32a..f8ae9458f 100644
--- a/ui/src/components/settings/shared/useBackendRuntime.ts
+++ b/ui/src/components/settings/shared/useBackendRuntime.ts
@@ -28,8 +28,17 @@ export interface UseBackendRuntimeOptions {
}
export interface BackendRuntimeState {
- /** Initial V2Config + first detect() call have finished. */
+ /** Initial V2Config load attempt has finished (success or failure). */
loaded: boolean;
+ /**
+ * ``true`` when the initial ``getConfig()`` rejected. In that state,
+ * ``enabled`` / ``cliPath`` are still their pre-load defaults rather
+ * than reflecting persisted state, so consumers MUST treat
+ * ``loaded && !configError`` — not just ``loaded`` — as the gate for
+ * any side-effect that depends on actual backend state (e.g.
+ * OpenCode's providers fan-out).
+ */
+ configError: boolean;
enabled: boolean;
cliPath: string;
cliStatus: CliStatus;
@@ -77,6 +86,7 @@ export function useBackendRuntime({
const { t } = useTranslation();
const [loaded, setLoaded] = useState(false);
+ const [configError, setConfigError] = useState(false);
const [enabled, setEnabled] = useState(true);
const [cliPath, setCliPath] = useState(defaultCli);
const [savedCliPath, setSavedCliPath] = useState(defaultCli);
@@ -120,11 +130,21 @@ export function useBackendRuntime({
setEnabled(initialEnabled);
setCliPath(initialPath);
setSavedCliPath(initialPath);
+ setConfigError(false);
setLoaded(true);
void detect(initialPath);
})
- .catch(() => {
- if (!cancelled) setLoaded(true);
+ .catch((e: any) => {
+ if (cancelled) return;
+ // We still flip ``loaded`` so the page can drop its loading
+ // skeleton, but ``configError`` tells consumers the persisted
+ // state was never read — gate any side-effect that depends on
+ // ``enabled`` on ``!configError`` to avoid acting on a default
+ // we never confirmed (e.g. firing provider fetches when the
+ // backend may actually be disabled).
+ setConfigError(true);
+ setLoaded(true);
+ showToast(e?.message || t('common.saveFailed'), 'error');
});
return () => {
cancelled = true;
@@ -225,6 +245,7 @@ export function useBackendRuntime({
return {
loaded,
+ configError,
enabled,
cliPath,
cliStatus,