-
Notifications
You must be signed in to change notification settings - Fork 339
feat(gui): configure Codex auto-switch threshold #337
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
lidge-jun
merged 9 commits into
lidge-jun:dev
from
csa906:codex/gui-auto-switch-threshold
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
458b3a3
feat(gui): configure Codex auto-switch threshold
csa906 8feb098
fix(gui): harden Codex auto-switch threshold UX
csa906 b58c221
test(gui): cover Codex auto-switch interactions
lidge-jun b2660d3
fix(gui): address auto-switch review feedback
csa906 0c461c6
test: make Windows root fixtures deterministic
csa906 02dbd70
Merge upstream/dev into codex/gui-auto-switch-threshold
csa906 c5922bb
docs: record root suite candidate dispositions
csa906 ed7aeab
fix: address remaining PR review feedback
csa906 fa8ba7f
refactor(gui): extract auto-switch view/controller from CodexAccountPool
lidge-jun 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| export const DEFAULT_AUTO_SWITCH_THRESHOLD = 80; | ||
|
|
||
| const AUTO_SWITCH_PUT_TIMEOUT_MS = 10_000; | ||
|
|
||
| export type AutoSwitchFetch = (input: string, init: RequestInit) => Promise<Response>; | ||
|
|
||
| export function normalizeAutoSwitchThreshold(value: unknown): number { | ||
| return typeof value === "number" | ||
| && Number.isInteger(value) | ||
| && value >= 0 | ||
| && value <= 100 | ||
| ? value | ||
| : DEFAULT_AUTO_SWITCH_THRESHOLD; | ||
| } | ||
|
|
||
| export function parseEnabledAutoSwitchThreshold(value: string): number | null { | ||
| const trimmed = value.trim(); | ||
| if (!/^\d+$/.test(trimmed)) return null; | ||
| const threshold = Number(trimmed); | ||
| return threshold >= 1 && threshold <= 100 ? threshold : null; | ||
| } | ||
|
|
||
| export function nextAutoSwitchThreshold(current: number, lastEnabled: number): number { | ||
| if (current > 0) return 0; | ||
| return Number.isInteger(lastEnabled) && lastEnabled >= 1 && lastEnabled <= 100 | ||
| ? lastEnabled | ||
| : DEFAULT_AUTO_SWITCH_THRESHOLD; | ||
| } | ||
|
|
||
| export type AutoSwitchThresholdReadDisposition = "apply" | "defer" | "ignore"; | ||
|
|
||
| export function autoSwitchThresholdReadDisposition( | ||
| editing: boolean, | ||
| saving: boolean, | ||
| startedRevision: number, | ||
| currentRevision: number, | ||
| ): AutoSwitchThresholdReadDisposition { | ||
| if (startedRevision !== currentRevision) return "ignore"; | ||
| return editing || saving ? "defer" : "apply"; | ||
| } | ||
|
|
||
| export interface AutoSwitchTogglePlan { | ||
| threshold: number; | ||
| lastEnabled: number; | ||
| } | ||
|
|
||
| /** | ||
| * Disabling is one server write. A valid dirty draft becomes the page-lifetime | ||
| * restore value, so re-enabling can persist it without a partial two-write | ||
| * failure state. | ||
| */ | ||
| export function planAutoSwitchToggleWrite( | ||
| current: number, | ||
| draft: string, | ||
| lastEnabled: number, | ||
| ): AutoSwitchTogglePlan { | ||
| if (current <= 0) { | ||
| const threshold = nextAutoSwitchThreshold(current, lastEnabled); | ||
| return { threshold, lastEnabled: threshold }; | ||
| } | ||
| const restoreThreshold = parseEnabledAutoSwitchThreshold(draft) | ||
| ?? nextAutoSwitchThreshold(0, lastEnabled); | ||
| return { threshold: 0, lastEnabled: restoreThreshold }; | ||
| } | ||
|
|
||
| export async function putAutoSwitchThreshold( | ||
| apiBase: string, | ||
| threshold: number, | ||
| fetchImpl: AutoSwitchFetch = (input, init) => fetch(input, init), | ||
| timeoutMs = AUTO_SWITCH_PUT_TIMEOUT_MS, | ||
| ): Promise<boolean> { | ||
| if (!Number.isInteger(threshold) || threshold < 0 || threshold > 100) return false; | ||
| try { | ||
| const response = await fetchImpl(`${apiBase}/api/codex-auth/auto-switch`, { | ||
| method: "PUT", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ threshold }), | ||
| signal: AbortSignal.timeout(timeoutMs), | ||
| }); | ||
| return response.ok; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.