Skip to content

feat(gui): configure Codex auto-switch threshold - #337

Merged
lidge-jun merged 9 commits into
lidge-jun:devfrom
csa906:codex/gui-auto-switch-threshold
Jul 24, 2026
Merged

feat(gui): configure Codex auto-switch threshold#337
lidge-jun merged 9 commits into
lidge-jun:devfrom
csa906:codex/gui-auto-switch-threshold

Conversation

@csa906

@csa906 csa906 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Expose the existing 1-100 Codex account-pool auto-switch threshold in the dashboard and render the persisted value.
  • Keep the control truthful through initial loading, Enter/blur saves, Escape cancellation, toggle restore, request failures, and background refreshes.
  • Provide contextual localized status/error feedback and stable responsive alignment across supported breakpoints.
  • Update all six GUI locales and the localized dashboard documentation without changing the API, configuration schema, or routing behavior.

Verification

  • bun run typecheck — passed.
  • bun run lint:gui — passed.
  • cd gui && bun run lint:i18n — passed.
  • bun test ./gui/tests — 26 passed, including all 16 threshold cases.
  • bun run privacy:scan — passed.
  • bun run build:gui — passed; existing large-chunk advisory only.
  • cd docs-site && bun run build — passed, 121 pages.
  • bun run doctor:gui:if-changed — advisory exit 0; the only feature-file finding is an existing barrel import.
  • Chrome 151 on Windows 11 — verified hydration, Enter/Escape focus, OFF/ON restore, 30-second refresh reconciliation, Korean/German copy, and 390/759/761/1280 CSS-pixel layouts.
  • Independent final review against upstream/dev — approved with no findings.

The isolated root suite completed with 3780 passed, 4 skipped, and 4 failures confined to the unchanged release-helper test. tests/release-helper.test.ts and scripts/release.ts have no diff from upstream/dev; the complete release-helper file passed 5/5 when rerun standalone.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults; no security-sensitive paths are changed.

Summary by CodeRabbit

  • New Features
    • Added Codex automatic account switching settings with an enable/disable toggle, configurable 1–100% threshold, and improved editing/save/cancel workflow with clear success/error feedback.
    • Added robust handling for load failures, invalid threshold input, and deferred sync to protect user edits.
  • Documentation
    • Updated web dashboard guides (multiple languages) to explicitly document quota refresh controls, auto-switch enable/disable, threshold range, and transient-failure failover.
    • Refined thread re-evaluation wording.
  • Localization
    • Updated Codex Auth UI copy to reflect threshold-based switching and new status/validation messages.
  • Tests
    • Expanded automated coverage for parsing/validation, sync behavior, toggle interactions, request error/timeout handling, plus adjusted test timeouts for stability.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The GUI adds configurable Codex auto-switch thresholds with validated persistence, revision-aware synchronization, editable controls, localized feedback, responsive styling, documentation updates, and expanded tests. Additional changes update test timeouts, request context fixtures, native execution commands, and a root-suite investigation record.

Changes

Codex auto-switch threshold

Layer / File(s) Summary
Threshold contracts and persistence
gui/src/codex-auto-switch.ts, gui/tests/codex-account-auto-switch.test.tsx
Adds threshold normalization, validation, toggle planning, revision dispositions, timed PUT persistence, and helper coverage.
Controller state and account-pool integration
gui/src/hooks/useCodexAutoSwitch.ts, gui/src/components/CodexAutoSwitchSetting.tsx, gui/src/components/CodexAccountPool.tsx, gui/tests/codex-auto-switch-controller.test.tsx
Adds draft editing, deferred reads, guarded saves, cancellation, retries, threshold controls, quota-bar wiring, and interaction tests.
Localized presentation and documentation
gui/src/i18n/*, gui/src/styles.css, docs-site/src/content/docs/**/guides/web-dashboard.md
Updates threshold copy, validation and feedback messages, responsive styles, and dashboard documentation across supported languages.

Root-suite investigation record

Layer / File(s) Summary
Failure investigation findings
devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md
Records rerun evidence, unavailable historical failure identities, and the unresolved suite-level disposition.

Test maintenance

Layer / File(s) Summary
Native execution test commands
tests/cursor-native-exec.test.ts
Replaces printf fixtures with Node output commands.
Explicit test timeouts and request context
tests/cli-provider.test.ts, tests/codex-catalog.test.ts, tests/codex-v2-gate.test.ts, tests/combo-management-api.test.ts, tests/injection-model-api.test.ts, tests/management-provider-validation.test.ts, tests/server-auth.test.ts, tests/server-combo-failover-e2e.test.ts
Adds or increases test timeout values and supplies explicit provider discovery request context.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CodexAccountPool
  participant useCodexAutoSwitch
  participant CodexAutoSwitchSetting
  participant CodexAuthAPI
  CodexAccountPool->>useCodexAutoSwitch: beginServerRead
  CodexAccountPool->>CodexAuthAPI: GET accounts and active configuration
  CodexAuthAPI-->>useCodexAutoSwitch: active threshold
  useCodexAutoSwitch-->>CodexAutoSwitchSetting: threshold and draft state
  CodexAutoSwitchSetting->>useCodexAutoSwitch: commit or toggle
  useCodexAutoSwitch->>CodexAuthAPI: PUT auto-switch threshold
  CodexAuthAPI-->>useCodexAutoSwitch: success or failure
  useCodexAutoSwitch-->>CodexAutoSwitchSetting: feedback and updated threshold
Loading

Suggested reviewers: lidge-jun

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: exposing and configuring the Codex auto-switch threshold in the GUI.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the enhancement New feature or request label Jul 23, 2026
@csa906
csa906 marked this pull request as ready for review July 23, 2026 14:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f84301252

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gui/src/components/CodexAccountPool.tsx Outdated
@lidge-jun
lidge-jun force-pushed the codex/gui-auto-switch-threshold branch from 5f84301 to b58c221 Compare July 23, 2026 19:44
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer takeover update: I rebased the contributor commits onto c63589cc without semantic drift (git range-diff mapped both commits exactly), then preserved the threshold/API contract while extracting the view into CodexAutoSwitchSetting.tsx and the async controller into useCodexAutoSwitch.ts. CodexAccountPool.tsx is now 550 lines (840 before).

Mounted happy-dom coverage now exercises all four missing interactions through the real account-pool component: Enter followed by blur emits one PUT, an older 30-second refresh cannot overwrite a successful edit, a failed PUT restores the last confirmed value, and Escape cancels without writing. The Escape case exposed and fixed the stale-blur write while retaining the intended behavior.

Root-suite follow-up: the four reported release-helper failures are classified as non-reproduced / unconfirmed flake. On the rebased PR, three full suites passed 3861/3861 and three standalone helper runs passed 5/5; on exact base c63589cc, two full suites passed 3861/3861 and the standalone helper passed 5/5. The original aggregate report did not retain its four per-test names/assertions, so that provenance limitation is recorded rather than inventing assertion-level evidence. No root-suite source fix was justified.

Final verification at b58c221a: focused GUI 20/20; full GUI 30/30; bun run lint:gui, bun run build:gui, bun run typecheck, bun run privacy:scan, git diff --check, and two consecutive final bun run test runs (3861/3861 each) passed. Render checks at desktop 1280 and exact mobile 390×844 confirmed truthful threshold copy/input, visible % and toggle, responsive stacking, no horizontal overflow, one-write Enter behavior, and Escape restoration. Exact-head target enforcement, React Doctor, Linux, macOS, Windows, and npm-global CI are green: https://github.com/lidge-jun/opencodex/actions/runs/30039178858

Thank you for the original contribution. The contributor branch is updated and green. Because this PR changes gui/, it still requires explicit owner approval before merge; no merge was performed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md`:
- Around line 121-128: Revise the investigation table and the conclusion near
the cited lines so the four success-path tests are labeled only as inferred
candidates, not as the reported failures. State that the original failure names
and assertions remain unresolved at suite level unless CI/test-reporter metadata
is recovered, and remove the unsupported “no fix is justified” closure.

In `@gui/src/codex-auto-switch.ts`:
- Around line 64-80: The putAutoSwitchThreshold request can remain pending
indefinitely because its fetch has no timeout. Add a finite AbortSignal timeout
to the fetch options in putAutoSwitchThreshold, ensuring timeout-triggered
aborts flow through the existing catch and return false while preserving current
validation and response handling.
- Around line 45-62: Update planAutoSwitchToggleWrite so disabling always
returns a plan with threshold 0 when current > 0; use the parsed draft as
lastEnabled only when valid, otherwise fall back to the existing lastEnabled
value. Update the related test assertion to expect a disable write instead of
null for invalid drafts.

In `@gui/src/hooks/useCodexAutoSwitch.ts`:
- Around line 188-202: The toggle disable path must work even when the draft is
unparseable. In gui/src/hooks/useCodexAutoSwitch.ts:188-202, update toggle
around planAutoSwitchToggleWrite to fall back to lastEnabledRef.current when the
plan is null and current > 0, while preserving invalid-draft rejection for other
cases. In gui/tests/codex-auto-switch-controller.test.tsx:177-262, add coverage
that clears the input, clicks .toggle, and asserts a threshold: 0 write without
an invalid-feedback alert.

In `@gui/tests/codex-account-auto-switch.test.tsx`:
- Around line 141-147: Update the read-only attribute assertion in the “keeps
the focused input present but read-only while a write is pending” test to match
renderToStaticMarkup’s lowercase `readonly=""` output, while leaving the other
assertions unchanged.

In `@gui/tests/codex-auto-switch-controller.test.tsx`:
- Around line 177-262: Add regression coverage in the “Codex auto-switch
controller interactions” suite for clicking the toggle with an empty draft:
focus the input, clear it, click the harness toggle, and verify the PUT records
threshold 0 without rendering invalid-feedback alert. Use the existing harness
helpers and preserve the current assertions for other interactions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 761d19a1-597b-474d-8983-fca1f27b9cbb

📥 Commits

Reviewing files that changed from the base of the PR and between 5f84301 and b58c221.

📒 Files selected for processing (19)
  • devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md
  • docs-site/src/content/docs/guides/web-dashboard.md
  • docs-site/src/content/docs/ja/guides/web-dashboard.md
  • docs-site/src/content/docs/ko/guides/web-dashboard.md
  • docs-site/src/content/docs/ru/guides/web-dashboard.md
  • docs-site/src/content/docs/zh-cn/guides/web-dashboard.md
  • gui/src/codex-auto-switch.ts
  • gui/src/components/CodexAccountPool.tsx
  • gui/src/components/CodexAutoSwitchSetting.tsx
  • gui/src/hooks/useCodexAutoSwitch.ts
  • gui/src/i18n/de.ts
  • gui/src/i18n/en.ts
  • gui/src/i18n/ja.ts
  • gui/src/i18n/ko.ts
  • gui/src/i18n/ru.ts
  • gui/src/i18n/zh.ts
  • gui/src/styles.css
  • gui/tests/codex-account-auto-switch.test.tsx
  • gui/tests/codex-auto-switch-controller.test.tsx

Comment thread devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md Outdated
Comment thread gui/src/codex-auto-switch.ts
Comment thread gui/src/codex-auto-switch.ts
Comment thread gui/src/hooks/useCodexAutoSwitch.ts Outdated
Comment thread gui/tests/codex-account-auto-switch.test.tsx
Comment thread gui/tests/codex-auto-switch-controller.test.tsx
lidge-jun added a commit that referenced this pull request Jul 24, 2026

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The threshold control is useful, but the current GUI interaction contract is not complete. Clicking the toggle after editing can lose the click through blur/save ordering; disabling can silently no-op when the draft is temporarily invalid; the PUT can remain pending indefinitely; and the mounted suite does not cover the invalid-draft toggle path. Please make toggle intent atomic, add a finite abort/timeout, correct the unsupported root-suite evidence wording, add the missing mounted regressions, and re-request review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md`:
- Around line 127-132: Update the four-row candidate table to add explicit
classification and disposition columns required by the rubric. Populate every
candidate row with classification “Unresolved — original failure identity
unavailable” and disposition “No per-failure disposition; suite-level
unresolved,” while preserving the existing evidence and owner-path fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 80664e8d-cc42-40e0-9d36-8110f68a9b5e

📥 Commits

Reviewing files that changed from the base of the PR and between b58c221 and 0c461c6.

📒 Files selected for processing (8)
  • devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md
  • gui/src/codex-auto-switch.ts
  • gui/src/components/CodexAutoSwitchSetting.tsx
  • gui/src/hooks/useCodexAutoSwitch.ts
  • gui/tests/codex-account-auto-switch.test.tsx
  • gui/tests/codex-auto-switch-controller.test.tsx
  • tests/cursor-native-exec.test.ts
  • tests/settings-stream-mode.test.ts

Comment thread devlog/_plan/260724_bugfix_train/061_root_suite_investigation.md Outdated
Resolve the settings stream fixture with upstream and widen Windows integration-test timeouts observed under full-suite load.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
gui/src/i18n/ru.ts (1)

110-111: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep Codex clamp explanations current and localized.

These messages explain why reasoning options are currently hidden, but the Russian and Chinese wording can read as historical rather than describing the active binary.

  • gui/src/i18n/ru.ts#L110-L111: replace использовал with использует and translate reasoning effort as уровни рассуждений.
  • gui/src/i18n/zh.ts#L105-L106: replace 使用了 with 正在使用, matching the active-runtime wording at Line 107.
Proposed wording
-Некоторые уровни reasoning effort скрыты, потому что OpenCodex использовал Codex {version}.
+Некоторые уровни рассуждений скрыты, потому что OpenCodex использует Codex {version}.
-Некоторые уровни reasoning effort скрыты, потому что OpenCodex использовал Codex {version} (удалены: {efforts}).
+Некоторые уровни рассуждений скрыты, потому что OpenCodex использует Codex {version} (удалены: {efforts}).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gui/src/i18n/ru.ts` around lines 110 - 111, Update the clamp explanation
translations: in gui/src/i18n/ru.ts lines 110-111, use active wording with
“использует” and translate “reasoning effort” as “уровни рассуждений”; in
gui/src/i18n/zh.ts lines 105-106, replace “使用了” with “正在使用” to match the
active-runtime wording.
tests/codex-catalog.test.ts (1)

52-69: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add the missing OcxConfig fields to these test fixtures. src/types.ts requires both port and defaultProvider, and the inline objects in tests/codex-catalog.test.ts#L52-L69 and tests/management-provider-validation.test.ts#L123-L141 omit them. Add those fields or reuse a shared typed test config.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/codex-catalog.test.ts` around lines 52 - 69, Add the required OcxConfig
fields port and defaultProvider to the inline configuration fixture used by
providerDiscoveryDto in tests/codex-catalog.test.ts:52-69. Apply the same
fixture update to the inline OcxConfig object in
tests/management-provider-validation.test.ts:123-141, or reuse a shared typed
test configuration, ensuring both fields are present and valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@gui/src/i18n/ru.ts`:
- Around line 110-111: Update the clamp explanation translations: in
gui/src/i18n/ru.ts lines 110-111, use active wording with “использует” and
translate “reasoning effort” as “уровни рассуждений”; in gui/src/i18n/zh.ts
lines 105-106, replace “使用了” with “正在使用” to match the active-runtime wording.

In `@tests/codex-catalog.test.ts`:
- Around line 52-69: Add the required OcxConfig fields port and defaultProvider
to the inline configuration fixture used by providerDiscoveryDto in
tests/codex-catalog.test.ts:52-69. Apply the same fixture update to the inline
OcxConfig object in tests/management-provider-validation.test.ts:123-141, or
reuse a shared typed test configuration, ensuring both fields are present and
valid.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e2235b0f-be1e-4ed3-967b-fb907e766ed5

📥 Commits

Reviewing files that changed from the base of the PR and between 0c461c6 and 02dbd70.

📒 Files selected for processing (20)
  • docs-site/src/content/docs/guides/web-dashboard.md
  • docs-site/src/content/docs/ja/guides/web-dashboard.md
  • docs-site/src/content/docs/ko/guides/web-dashboard.md
  • docs-site/src/content/docs/ru/guides/web-dashboard.md
  • docs-site/src/content/docs/zh-cn/guides/web-dashboard.md
  • gui/src/i18n/de.ts
  • gui/src/i18n/en.ts
  • gui/src/i18n/ja.ts
  • gui/src/i18n/ko.ts
  • gui/src/i18n/ru.ts
  • gui/src/i18n/zh.ts
  • gui/src/styles.css
  • tests/cli-provider.test.ts
  • tests/codex-catalog.test.ts
  • tests/codex-v2-gate.test.ts
  • tests/combo-management-api.test.ts
  • tests/injection-model-api.test.ts
  • tests/management-provider-validation.test.ts
  • tests/server-auth.test.ts
  • tests/server-combo-failover-e2e.test.ts

@csa906

csa906 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@csa906
csa906 requested a review from Ingwannu July 24, 2026 13:11
- CodexAutoSwitchSetting.tsx: presentational component (threshold input,
  toggle, feedback, retry) with typed props interface
- useCodexAutoSwitch.ts: controller hook owning state, refs, revision-based
  read reconciliation, commit/cancel/toggle, feedback timer cleanup
- CodexAccountPool.tsx: imports hook + component, removes inline auto-switch
  state/refs/callbacks (553 lines, below 650 target)
- 4 mounted happy-dom interaction tests: Enter+blur single PUT, stale
  refresh ignore, failed-write rollback, Escape cancel

Existing 16 pure helper/SSR/transport tests unchanged and green.
Verification: bun run typecheck, 23 pass / 0 fail across 2 test files.
@lidge-jun
lidge-jun merged commit 782cdb7 into lidge-jun:dev Jul 24, 2026
2 checks passed
lidge-jun added a commit that referenced this pull request Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants