-
Notifications
You must be signed in to change notification settings - Fork 531
feat(codex-auth): add default_mode_request_user_input feature toggle #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Wibias
merged 6 commits into
lidge-jun:dev
from
Wibias:codex/default-mode-request-user-input
Aug 3, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03f4b55
feat(codex-auth): add default_mode_request_user_input feature toggle
Wibias 8d155e3
fix(gui): check fetch status before consuming toggle response
Wibias d9c34d0
refactor(codex-auth): dedupe feature-flag toggle fallback and guard G…
Wibias 43f65d1
fix(codex-auth): bound toggle PUT body, preserve CLI stderr, unify CL…
Wibias f0e2213
fix(gui): guard poll races, surface server errors, de-duplicate TOML …
Wibias 3a32423
Merge remote-tracking branch 'upstream/dev' into codex/default-mode-r…
Wibias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
gui/src/components/DefaultModeRequestUserInputSetting.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import { useCallback, useEffect, useRef, useState } from "react"; | ||
| import { useT } from "../i18n/shared"; | ||
| import { readJsonOrThrow } from "../fetch-json"; | ||
|
|
||
| const FEATURE_ENDPOINT = "/api/codex-auth/features/default-mode-request-user-input"; | ||
|
|
||
| type Feedback = { tone: "ok" | "err"; message: string } | null; | ||
|
|
||
| /** | ||
| * Codex Auth page toggle for Codex's own `default_mode_request_user_input` | ||
| * feature flag. Reads/writes $CODEX_HOME/config.toml through the management | ||
| * API, which flips the flag via the official `codex features` CLI. | ||
| */ | ||
| export default function DefaultModeRequestUserInputSetting({ apiBase }: { apiBase: string }) { | ||
| const t = useT(); | ||
| const [enabled, setEnabled] = useState(false); | ||
| const [hydrated, setHydrated] = useState(false); | ||
| const [saving, setSaving] = useState(false); | ||
| const [loadError, setLoadError] = useState(false); | ||
| const [feedback, setFeedback] = useState<Feedback>(null); | ||
| const savingRef = useRef(false); | ||
| const enabledRef = useRef(false); | ||
| const loadGenerationRef = useRef(0); | ||
|
|
||
| const load = useCallback(async () => { | ||
| // A poll landing between the optimistic flip and the PUT response must not | ||
| // revert the UI to the server's pre-save value. The generation also drops | ||
| // GETs that were already in flight when a save started. | ||
| if (savingRef.current) return; | ||
| const generation = ++loadGenerationRef.current; | ||
| try { | ||
| const res = await fetch(`${apiBase}${FEATURE_ENDPOINT}`); | ||
| if (!res.ok) throw new Error("load"); | ||
| const payload = await res.json() as { enabled?: unknown }; | ||
| if (savingRef.current || generation !== loadGenerationRef.current) return; | ||
| enabledRef.current = payload.enabled === true; | ||
| setEnabled(enabledRef.current); | ||
| setHydrated(true); | ||
| setLoadError(false); | ||
| } catch { | ||
| if (!savingRef.current && generation === loadGenerationRef.current) setLoadError(true); | ||
| } | ||
| }, [apiBase]); | ||
|
|
||
| useEffect(() => { | ||
| const timeout = window.setTimeout(() => { void load(); }, 0); | ||
| const interval = window.setInterval(() => { void load(); }, 30_000); | ||
| return () => { | ||
| window.clearTimeout(timeout); | ||
| window.clearInterval(interval); | ||
| }; | ||
| }, [load]); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const toggle = useCallback(async () => { | ||
| if (savingRef.current || !hydrated || loadError) return; | ||
| const next = !enabledRef.current; | ||
| const previous = enabledRef.current; | ||
| enabledRef.current = next; | ||
| setEnabled(next); | ||
| savingRef.current = true; | ||
| setSaving(true); | ||
| setFeedback(null); | ||
| loadGenerationRef.current++; | ||
| try { | ||
| const res = await fetch(`${apiBase}${FEATURE_ENDPOINT}`, { | ||
| method: "PUT", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify({ enabled: next }), | ||
| }); | ||
| const payload = (await readJsonOrThrow<{ ok?: boolean; enabled?: unknown; changed?: unknown }>(res)) ?? {}; | ||
| if (payload.ok !== true) throw new Error(String(res.status)); | ||
| enabledRef.current = payload.enabled === true; | ||
| setEnabled(enabledRef.current); | ||
| setHydrated(true); | ||
| setFeedback({ | ||
| tone: "ok", | ||
| message: t(payload.changed === true ? "codexAuth.requestUserInputUpdatedRestart" : "codexAuth.requestUserInputUpdated"), | ||
| }); | ||
| } catch (error) { | ||
| enabledRef.current = previous; | ||
| setEnabled(previous); | ||
| const reason = error instanceof Error && error.message && !/^HTTP \d{3}$/.test(error.message) | ||
| ? error.message | ||
| : t("codexAuth.requestUserInputUpdateFailed"); | ||
| setFeedback({ tone: "err", message: reason }); | ||
| } finally { | ||
| savingRef.current = false; | ||
| setSaving(false); | ||
| } | ||
| }, [apiBase, hydrated, loadError, t]); | ||
|
|
||
| const controlsDisabled = saving || !hydrated || loadError; | ||
|
|
||
| return ( | ||
| <div | ||
| className="card card-row codex-request-user-input-card" | ||
| style={{ marginTop: 16 }} | ||
| aria-busy={saving || (!hydrated && !loadError) || undefined} | ||
| > | ||
| <div className="codex-request-user-input-copy"> | ||
| <strong>{t("codexAuth.requestUserInput")}</strong> | ||
| <div className="card-sub" role={loadError ? "alert" : undefined}> | ||
| {loadError ? t("codexAuth.requestUserInputLoadFailed") : t("codexAuth.requestUserInputDesc")} | ||
| </div> | ||
| <code className="mono codex-request-user-input-config"> | ||
| {`[features]\ndefault_mode_request_user_input = true`} | ||
| </code> | ||
| </div> | ||
| <div className="codex-request-user-input-controls"> | ||
| {loadError && ( | ||
| <button type="button" className="btn btn-ghost btn-sm" onClick={() => { void load(); }}> | ||
| {t("common.retry")} | ||
| </button> | ||
| )} | ||
| <button | ||
| type="button" | ||
| className={`toggle ${enabled ? "on" : ""}`} | ||
| onClick={() => { void toggle(); }} | ||
| disabled={controlsDisabled} | ||
| aria-pressed={enabled} | ||
| aria-label={t("codexAuth.requestUserInput")} | ||
| title={t("codexAuth.requestUserInput")} | ||
| > | ||
| <span className="toggle-knob" /> | ||
| </button> | ||
| </div> | ||
| {feedback && ( | ||
| <div | ||
| className={`codex-request-user-input-feedback${feedback.tone === "err" ? " is-error" : ""}`} | ||
| role={feedback.tone === "err" ? "alert" : "status"} | ||
| aria-atomic="true" | ||
| > | ||
| {feedback.message} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the 30-second GET starts just before the user toggles and its stale response resolves during or after the PUT, these assignments overwrite
enabledRefand the rendered state with the pre-toggle value. The next click can then submit the opposite of the persisted state; track a request revision or defer/ignore reads that overlap a save, following the existing auto-switch controller's reconciliation pattern.AGENTS.md reference: gui/AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shipping-github] Fixed in
3a324231c:load()now tracks a generation ref; GETs that were in flight when a save started are ignored afterawait, so a stale poll can no longer revert the optimistic state. New GUI test covers the overlap window (poll resolves mid-PUT).