Skip to content

Commit bf73afe

Browse files
authored
feat(gui): hide the Codex Spark quota by default behind a Codex Auth switch (#2649)
* feat(gui): hide the Codex Spark quota by default behind a Codex Auth switch Every Codex account card carried a second bar labelled "GPT-5.3-Codex-Spark Weekly", emitted unconditionally whenever the WHAM payload contains the codex_bengalfox feature. It applies to one model, reads 0% for most operators, and on a four-account pool it doubles the row count for information almost nobody acts on. It is now hidden unless the operator asks for it, and the switch that asks sits in the Codex Auth header beside Pause exhausted and Refresh quotas - the row that already holds the page-wide controls. A per-account toggle was rejected: the setting is about a window KIND, not an account, and four toggles that must agree is a state-sync bug waiting to happen. The filter lands in the API projection rather than in CSS, and at providerQuotaFromCodexQuota rather than only in the Codex Auth DTO. Spark reaches the GUI through three paths, not one: /api/codex-auth/accounts via quotaForPlan, /api/provider-quotas pooled via listCodexAuthAccountsSnapshot, and /api/provider-quotas direct via fetchMainAccountInfoSnapshot - which never touches the Codex Auth DTO at all. That third path was found by an existing test still passing after the first attempt, which is the useful kind of test failure. Matching on the exact label is load-bearing. customWindows is the generic carrier for Cursor's First-party models and API usage, Anthropic's Fable/Opus/Sonnet, Antigravity's Gem/Cla, Kimi's subscription credits and a dozen dynamic provider meters; a filter written as "drop custom windows" would blank all of them. A regression pins that. Nothing is filtered at parse or cache time. Custom windows participate in quota-presence checks, snapshot reconciliation and capacity aggregation, so removing Spark upstream of the projection would change routing state rather than display. Server: showCodexSparkQuota through GET/PUT /api/settings with the same validate-mutate-persist-rollback shape the neighbouring preferences use, and the same degrade-not-reject schema treatment - a malformed hand edit hides Spark rather than discarding the config. Tests: six visibility cases including the non-Spark preservation case and the absent-vs-empty wire distinction; the existing provider-quota Codex test now asserts the projection DROPS a window the fixture still carries. Falsified by disabling the filter: 4 tests fail. i18n across all nine locales. bun run typecheck exit 0. bun run test 0 fail. cd gui && bun test 994 pass. * fix(gui): tear the Spark settings read down with AbortController react-doctor's no-set-state-after-await-in-effect flagged the settings load: the effect awaited a fetch and then called setSparkVisible, guarded only by a `cancelled` closure flag the linter cannot see through. The guard was real but the teardown was not - a `cancelled` flag stops the state update while leaving the request itself in flight. An AbortController actually tears the request down on unmount, and the state update now lands in a .then() whose guard is visible to the rule. CI runs react-doctor with --scope changed, so this was a finding on this branch's own file rather than a pre-existing one.
1 parent 12f5876 commit bf73afe

19 files changed

Lines changed: 333 additions & 13 deletions

File tree

‎gui/src/components/CodexAccountPool.tsx‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
7272
const [actionFeedbackTone, setActionFeedbackTone] = useState<NoticeTone | null>(null);
7373
const feedbackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
7474
const [refreshingQuota, setRefreshingQuota] = useState(false);
75+
// undefined until /api/settings answers: the switch must not render a guessed position and
76+
// then visibly correct itself a moment later.
77+
const [sparkVisible, setSparkVisible] = useState<boolean | undefined>(undefined);
78+
const [sparkBusy, setSparkBusy] = useState(false);
7579
const [resetPopup, setResetPopup] = useState<CodexAccountEntry | null>(null);
7680
const [resetConfirm, setResetConfirm] = useState(false);
7781
const [redeeming, setRedeeming] = useState(false);
@@ -228,6 +232,49 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
228232
}
229233
};
230234

235+
useEffect(() => {
236+
// AbortController rather than a `cancelled` flag: the in-flight request is actually torn
237+
// down on unmount, and the state update lands in a .then() the linter can see is guarded.
238+
const abort = new AbortController();
239+
fetch(`${apiBase}/api/settings`, { signal: abort.signal })
240+
.then(response => (response.ok ? response.json() : null))
241+
.then((payload: { showCodexSparkQuota?: unknown } | null) => {
242+
if (abort.signal.aborted || typeof payload?.showCodexSparkQuota !== "boolean") return;
243+
setSparkVisible(payload.showCodexSparkQuota);
244+
})
245+
// A settings read failure leaves the switch unrendered rather than guessing a position.
246+
.catch(() => {});
247+
return () => { abort.abort(); };
248+
}, [apiBase]);
249+
250+
const toggleSpark = async () => {
251+
if (sparkBusy || sparkVisible === undefined) return;
252+
const requested = !sparkVisible;
253+
setSparkBusy(true);
254+
// Optimistic, then reconciled against what the server confirms — the same shape the account
255+
// picker toggle uses, so a rejected write visibly snaps back instead of lying.
256+
setSparkVisible(requested);
257+
try {
258+
const response = await fetch(`${apiBase}/api/settings`, {
259+
method: "PUT",
260+
headers: { "content-type": "application/json" },
261+
body: JSON.stringify({ showCodexSparkQuota: requested }),
262+
});
263+
if (!response.ok) throw new Error("save");
264+
const payload = await response.json() as { showCodexSparkQuota?: unknown };
265+
const confirmed = typeof payload.showCodexSparkQuota === "boolean" ? payload.showCodexSparkQuota : requested;
266+
setSparkVisible(confirmed);
267+
showActionFeedback(t(confirmed ? "codexAuth.sparkQuotaShown" : "codexAuth.sparkQuotaHidden"), "ok");
268+
await load(true);
269+
} catch {
270+
setSparkVisible(!requested);
271+
showActionFeedback(t("codexAuth.sparkQuotaFailed"), "err");
272+
} finally {
273+
setSparkBusy(false);
274+
}
275+
};
276+
277+
231278
const pauseExhausted = async () => {
232279
const result = await controller.pauseExhaustedAccounts();
233280
if (!result.ok && result.reason === "busy") return;
@@ -294,6 +341,9 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
294341
pauseBusy={pauseBusy}
295342
onRefresh={() => { void refreshQuotas(); }}
296343
onPauseExhausted={() => { void pauseExhausted(); }}
344+
sparkVisible={sparkVisible}
345+
sparkBusy={sparkBusy}
346+
onToggleSpark={() => { void toggleSpark(); }}
297347
/>
298348

299349
{banner}

‎gui/src/components/codex-account-pool-main-card.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export function CodexAccountPoolPageHead({
183183
actionFeedbackTone,
184184
onRefresh,
185185
onPauseExhausted,
186+
sparkVisible,
187+
sparkBusy,
188+
onToggleSpark,
186189
}: {
187190
t: TFn;
188191
embedded: boolean;
@@ -193,6 +196,10 @@ export function CodexAccountPoolPageHead({
193196
actionFeedbackTone?: NoticeTone | null;
194197
onRefresh: () => void;
195198
onPauseExhausted: () => void;
199+
/** undefined until the preference has loaded, so the switch never renders a guessed state. */
200+
sparkVisible?: boolean;
201+
sparkBusy?: boolean;
202+
onToggleSpark?: () => void;
196203
}) {
197204
return (
198205
<div
@@ -208,6 +215,22 @@ export function CodexAccountPoolPageHead({
208215
>
209216
{actionFeedback ?? ""}
210217
</span>
218+
{sparkVisible !== undefined && onToggleSpark && (
219+
<span className="codex-auth-spark-toggle">
220+
<span className="codex-auth-spark-toggle__label">{t("codexAuth.sparkQuota")}</span>
221+
<button
222+
type="button"
223+
className={`toggle ${sparkVisible ? "on" : ""}`}
224+
onClick={onToggleSpark}
225+
disabled={!!sparkBusy}
226+
aria-pressed={sparkVisible}
227+
aria-label={t("codexAuth.sparkQuota")}
228+
title={t("codexAuth.sparkQuotaHint")}
229+
>
230+
<span className="toggle-knob" />
231+
</button>
232+
</span>
233+
)}
211234
<button
212235
type="button"
213236
className="btn btn-sm btn-ghost codex-auth-action-btn"

‎gui/src/i18n/de.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,11 @@ export const de: Record<TKey, string> = {
10031003
"codexAuth.openaiPresetUnavailable": "OpenAI-Anbieter-Preset ist nicht verfügbar.",
10041004
"codexAuth.openProviders": "Anbieter öffnen",
10051005
"codexAuth.add": "Hinzufügen",
1006+
"codexAuth.sparkQuota": "Codex-Spark-Kontingent",
1007+
"codexAuth.sparkQuotaHint": "Zeigt das GPT-5.3-Codex-Spark-Wochenfenster auf Kontokarten. Standardmäßig ausgeblendet, da es nur für ein Modell gilt.",
1008+
"codexAuth.sparkQuotaShown": "Codex-Spark-Kontingent wird angezeigt",
1009+
"codexAuth.sparkQuotaHidden": "Codex-Spark-Kontingent ausgeblendet",
1010+
"codexAuth.sparkQuotaFailed": "Codex-Spark-Kontingent konnte nicht geändert werden",
10061011
"codexAuth.refreshQuota": "Kontingente aktualisieren",
10071012
"codexAuth.refreshingQuota": "Aktualisiere…",
10081013
"codexAuth.quotaRefreshed": "Kontingente aktualisiert",

‎gui/src/i18n/en.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,11 @@ export const en = {
14951495
"codexAuth.openaiPresetUnavailable": "OpenAI provider preset is unavailable.",
14961496
"codexAuth.openProviders": "Open Providers",
14971497
"codexAuth.add": "Add",
1498+
"codexAuth.sparkQuota": "Codex Spark quota",
1499+
"codexAuth.sparkQuotaHint": "Show the GPT-5.3-Codex-Spark weekly window on account cards. Hidden by default because it applies to one model only.",
1500+
"codexAuth.sparkQuotaShown": "Codex Spark quota shown",
1501+
"codexAuth.sparkQuotaHidden": "Codex Spark quota hidden",
1502+
"codexAuth.sparkQuotaFailed": "Could not change the Codex Spark quota setting",
14981503
"codexAuth.refreshQuota": "Refresh quotas",
14991504
"codexAuth.refreshingQuota": "Refreshing...",
15001505
"codexAuth.quotaRefreshed": "Quotas refreshed",

‎gui/src/i18n/fr.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,11 @@ export const fr: Record<TKey, string> = {
14681468
"codexAuth.openaiPresetUnavailable": "Le préréglage du fournisseur OpenAI est indisponible.",
14691469
"codexAuth.openProviders": "Ouvrir Fournisseurs",
14701470
"codexAuth.add": "Ajouter",
1471+
"codexAuth.sparkQuota": "Quota Codex Spark",
1472+
"codexAuth.sparkQuotaHint": "Affiche la fenêtre hebdomadaire GPT-5.3-Codex-Spark sur les cartes de compte. Masquée par défaut car elle ne concerne qu'un seul modèle.",
1473+
"codexAuth.sparkQuotaShown": "Quota Codex Spark affiché",
1474+
"codexAuth.sparkQuotaHidden": "Quota Codex Spark masqué",
1475+
"codexAuth.sparkQuotaFailed": "Impossible de modifier le réglage du quota Codex Spark",
14711476
"codexAuth.refreshQuota": "Actualiser les quotas",
14721477
"codexAuth.refreshingQuota": "Actualisation…",
14731478
"codexAuth.quotaRefreshed": "Quotas actualisés",

‎gui/src/i18n/ja.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,11 @@ export const ja: Record<TKey, string> = {
14281428
"codexAuth.openaiPresetUnavailable": "OpenAI プロバイダーのプリセットを利用できません。",
14291429
"codexAuth.openProviders": "プロバイダーを開く",
14301430
"codexAuth.add": "追加",
1431+
"codexAuth.sparkQuota": "Codex Spark 使用量",
1432+
"codexAuth.sparkQuotaHint": "アカウントカードに GPT-5.3-Codex-Spark の週次枠を表示します。対象が 1 モデルのみのため既定は非表示です。",
1433+
"codexAuth.sparkQuotaShown": "Codex Spark 使用量を表示しました",
1434+
"codexAuth.sparkQuotaHidden": "Codex Spark 使用量を非表示にしました",
1435+
"codexAuth.sparkQuotaFailed": "Codex Spark 使用量の設定を変更できませんでした",
14311436
"codexAuth.refreshQuota": "クォータを更新",
14321437
"codexAuth.refreshingQuota": "更新中...",
14331438
"codexAuth.quotaRefreshed": "クォータを更新しました",

‎gui/src/i18n/ko.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ export const ko: Record<TKey, string> = {
10271027
"codexAuth.openaiPresetUnavailable": "OpenAI 공급자 프리셋을 사용할 수 없습니다.",
10281028
"codexAuth.openProviders": "프로바이더 열기",
10291029
"codexAuth.add": "추가",
1030+
"codexAuth.sparkQuota": "Codex Spark 할당량",
1031+
"codexAuth.sparkQuotaHint": "계정 카드에 GPT-5.3-Codex-Spark 주간 창을 표시합니다. 모델 하나에만 적용되므로 기본값은 숨김입니다.",
1032+
"codexAuth.sparkQuotaShown": "Codex Spark 할당량을 표시합니다",
1033+
"codexAuth.sparkQuotaHidden": "Codex Spark 할당량을 숨겼습니다",
1034+
"codexAuth.sparkQuotaFailed": "Codex Spark 할당량 설정을 바꾸지 못했습니다",
10301035
"codexAuth.refreshQuota": "할당량 새로고침",
10311036
"codexAuth.refreshingQuota": "새로고침 중...",
10321037
"codexAuth.quotaRefreshed": "할당량을 다시 조회했습니다",

‎gui/src/i18n/ru.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,11 @@ export const ru: Record<TKey, string> = {
14791479
"codexAuth.openaiPresetUnavailable": "Пресет провайдера OpenAI недоступен.",
14801480
"codexAuth.openProviders": "Открыть провайдеров",
14811481
"codexAuth.add": "Добавить",
1482+
"codexAuth.sparkQuota": "Квота Codex Spark",
1483+
"codexAuth.sparkQuotaHint": "Показывать недельное окно GPT-5.3-Codex-Spark на карточках аккаунтов. По умолчанию скрыто: оно относится лишь к одной модели.",
1484+
"codexAuth.sparkQuotaShown": "Квота Codex Spark показана",
1485+
"codexAuth.sparkQuotaHidden": "Квота Codex Spark скрыта",
1486+
"codexAuth.sparkQuotaFailed": "Не удалось изменить настройку квоты Codex Spark",
14821487
"codexAuth.refreshQuota": "Обновить квоты",
14831488
"codexAuth.refreshingQuota": "Обновление...",
14841489
"codexAuth.quotaRefreshed": "Квоты обновлены",

‎gui/src/i18n/tr.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,11 @@ export const tr: Record<TKey, string> = {
14971497
"codexAuth.openaiPresetUnavailable": "Ayar kullanılamıyor.",
14981498
"codexAuth.openProviders": "Sağlayıcıları Aç",
14991499
"codexAuth.add": "Ekle",
1500+
"codexAuth.sparkQuota": "Codex Spark kotası",
1501+
"codexAuth.sparkQuotaHint": "Hesap kartlarında GPT-5.3-Codex-Spark haftalık penceresini gösterir. Yalnızca tek bir modeli kapsadığı için varsayılan olarak gizlidir.",
1502+
"codexAuth.sparkQuotaShown": "Codex Spark kotası gösteriliyor",
1503+
"codexAuth.sparkQuotaHidden": "Codex Spark kotası gizlendi",
1504+
"codexAuth.sparkQuotaFailed": "Codex Spark kotası ayarı değiştirilemedi",
15001505
"codexAuth.refreshQuota": "Kotaları yenile",
15011506
"codexAuth.refreshingQuota": "Yenileniyor...",
15021507
"codexAuth.quotaRefreshed": "Kotalar yenilendi",

‎gui/src/i18n/zh-TW.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,11 @@ export const zhTW: Record<TKey, string> = {
11271127
"codexAuth.openaiPresetUnavailable": "OpenAI 供應商預設不可用。",
11281128
"codexAuth.openProviders": "開啟供應商",
11291129
"codexAuth.add": "新增",
1130+
"codexAuth.sparkQuota": "Codex Spark 配額",
1131+
"codexAuth.sparkQuotaHint": "在帳號卡片上顯示 GPT-5.3-Codex-Spark 週視窗。預設隱藏,因為只適用於單一模型。",
1132+
"codexAuth.sparkQuotaShown": "已顯示 Codex Spark 配額",
1133+
"codexAuth.sparkQuotaHidden": "已隱藏 Codex Spark 配額",
1134+
"codexAuth.sparkQuotaFailed": "無法變更 Codex Spark 配額設定",
11301135
"codexAuth.refreshQuota": "重新整理額度",
11311136
"codexAuth.refreshingQuota": "重新整理中...",
11321137
"codexAuth.quotaRefreshed": "額度已重新整理",

0 commit comments

Comments
 (0)