Skip to content

feat(routing): add reset-near-weighted account pool strategy - #8180

Merged
lidge-jun merged 13 commits into
lidge-jun:devfrom
vibewriter-hand:codex/reset-near-weighted
Nov 19, 2026
Merged

lidge-jun merged 13 commits into
lidge-jun:devfrom
vibewriter-hand:codex/reset-near-weighted

Conversation

@vibewriter-hand

@vibewriter-hand vibewriter-hand commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add an opt-in reset-near-weighted strategy for the Codex and Anthropic OAuth account pools.
  • For new/unbound sessions, the eligible account whose weekly reset is closest receives weight N-1 (about half of new assignments); the remaining eligible accounts share round-robin weight 1.
  • Falls back to ordinary round-robin when quota evidence is missing, stale, future-dated, or outside the 24-hour / 60% / 2% boundaries.
  • Preserves existing affinity, cooldown, pause, reauthentication, and model/priority rules.
  • Generic OAuth pools reject the strategy until their runtime implements it.
  • Related: [Feature]: reset-near weighted allocation for Codex and Anthropic account pools #8177.

Verification

  • bun run typecheck — 2,317 files, no type errors.
  • bun test tests/routing/machine-weighted-routing.test.ts tests/codex-integration/codex-pool-rotation.test.ts — 124 pass, 0 fail.
  • NOT RUN: full suite, GUI build, docs-site build, live provider calls, Anthropic integration test.

Screenshot

Codex pool rotation strategy set to Weighted by nearest reset, with its hint

Maintainer carry (2026-11-18)

Maintainers carried the review rework on this branch after a dev merge (29c2dd2): Anthropic keyed and keyless session holds and the plain round-robin cursor are kept (9043a26); the dashboard round-trips the strategy in every locale (bad2f24); the pasted local policy was removed, leaving only the 24 h / 60% / 2% rule (e16415d); test-layout registration (ec58983); docs and the ocx skill surface (98549e4); the generic-pool denial with HTTP 400 (1c64b10, 8361ffd); Codex weighting requires five-hour window provenance, and expired weights reset (c097bcb).

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.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Readiness boxes ticked by maintainer @lidge-jun at integration (2026-11-18) after the exact-head review and CI described in the PR comments.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/oauth/anthropic-routing.ts, src/oauth/pool-kernel.ts, src/oauth/pool-settings-capability.ts, src/server/management/oauth-account-routes.ts.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

Automatic draft conversion failed. Please convert this pull request to a draft manually until every box above is ticked.

Hygiene

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer review (contributor-backlog lane), head c1b424f4a6.

Opt-in, it falls back to round-robin, and it extends reset-first sensibly, so default users are safe. Before it can be reviewed for merge:

  1. The weights do not match [Feature]: reset-near weighted allocation for Codex and Anthropic account pools #8177. smoothWeightedIndex (src/routing/machine-weighted-routing.ts) clamps weights to max(3, ids.length - 1), so the "N-1 ≈ half" share only holds for small pools; with 4 accounts the target gets 3/6. Please make the formula match the issue and pin it with a 2-, 4- and 8-account test.
  2. The file says it is generated. Its header says it was "copied into OpenCodex src/routing by ocx_weighted_route_patch.py". Code in src/ has to be maintained here, not regenerated by an out-of-tree patcher. Please drop that header and make it ordinary source.
  3. Cut the scope to what [Feature]: reset-near weighted allocation for Codex and Anthropic account pools #8177 asks for (Anthropic and Codex pools). Drop the generic non-Anthropic branch and the Antigravity family handling. Move the hard-coded thresholds (24 h, 60%, 2%, 15 min) into named constants with a sentence of rationale each.
  4. Gates. The PR changes account selection (src/oauth/pool-kernel.ts, src/codex/routing/selection.ts), so hygiene needs maintainer security sponsorship. That review happens on the reduced head. Keep the new strategy name in sync across the CLI enum, the schema and VALID_STRATEGIES, and add docs-site text for it.

@lidge-jun

Copy link
Copy Markdown
Owner

Merge-manager review: the owner accepted the reset-near-weighted strategy, but this needs rework before it can merge:

  1. Session hold: src/oauth/anthropic-routing.ts ~1044 holds the current account only for round-robin/fill-first, so with the new strategy turns without a session key switch accounts every turn — [Feature]: reset-near weighted allocation for Codex and Anthropic account pools #8177 requires existing session bindings to stay put.
  2. Dashboard resets it: gui/src/account-pool-strategy.ts:1 doesn't know the strategy, so normalizeAccountPoolStrategy turns it into quota and AnthropicAccountPoolSettings.tsx ~319 / CodexPoolStrategySetting.tsx ~29 save that back on any edit. Add the strategy, its label and hint keys in every locale.
  3. Pasted local patch: src/routing/machine-weighted-routing.ts:4 ("Copied into OpenCodex … by ocx_weighted_route_patch.py"), the private note at :62, and the unreachable second policy at :90–117 must go; keep only the 24 h / 60% / 2% branch.
  4. tests/routing/machine-weighted-routing.test.ts needs entries in scripts/test-layout/layout*.json and tests/fixtures/test-layout-expected.json.
  5. The headroom filter now also changes plain round-robin (~1303) — limit it to the new strategy or justify with a test.
  6. Regenerate skills/ocx (bun run skill:surface) and update docs-site (providers.md, cli/providers-accounts.md, + es).
  7. Add a denied test: parseGenericPoolStrategy("reset-near-weighted") === null and a generic pool update with it returns 400.
    The branch is ~400 commits behind; merge dev (conflict in anthropic-routing.ts, a restricted file — I'll re-review that hunk before applying maintainer-sponsored).

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer security review (lane L3, gpt-6.2-sol, two rounds; the latter at exact head c097bcb): SECURITY APPROVE for the restricted src/oauth and Codex routing paths.

  • Account selection respects pause, reauthentication and model exclusions in both pools.
  • Healthy session bindings take precedence, and Anthropic keyless turns hold the active account.
  • Weighting needs fresh quota with five-hour window provenance, and expired weights reset to equal rotation.
  • Generic OAuth pools reject the strategy with HTTP 400.
  • Plain round-robin is unchanged.
  • An older build reading the saved value falls back to quota.
  • No token or account-id logging was added.

Focused routing, kernel and failover tests pass (522/0), as do typecheck, structure:check and privacy:scan. Applying maintainer-sponsored. The screenshot is in the description.

@lidge-jun lidge-jun added the maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface label Nov 18, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Nov 18, 2026
@lidge-jun
lidge-jun force-pushed the codex/reset-near-weighted branch 2 times, most recently from 8a64794 to 7530de2 Compare November 19, 2026 04:31
@lidge-jun
lidge-jun force-pushed the codex/reset-near-weighted branch from 7530de2 to a7e7b3d Compare November 19, 2026 07:52
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration record (lane L3, 2026-11-19).

Integrating exact head a7e7b3dc9fc6524ec0f8f36aa8afedc71c45b344 under the maintainer-integration path. The PR carries maintainer-sponsored and a dashboard screenshot. Closes #8177.

  • Review. The same gpt-6.2-sol reviewer covered every round. The final round at this head found no blockers, and the security verdict found no blocker.

  • Security scope. Weighted placement needs fresh five-hour and weekly evidence, and expired weights fall back to plain round-robin. Anthropic quota evidence is bound to a persisted credential revision, so reusing a credential (A→B→A) does not bring back superseded evidence. Delayed probe responses are rejected across rotation. Account and provider refreshes stamp readings the same way. Ownership metadata is kept out of the fields older readers project.

  • History. Rebased onto dev because of a conflict.

  • CI and threads. Exact-head PR CI is green, and there are 0 unresolved threads.

  • Second rebase (after feat(providers): add M365 Copilot with live account model discovery #7757). The same reviewer found no code or security blocker: authorship is preserved on all 13 commits, 75 of 76 paths are unchanged, and the change composes with the M365 credential generation. One xAI backup-cleanup test runs close to its 5 s timeout on loaded hosts (5.09 s locally on this head, 4.73 s on dev); exact-head CI is the deciding run.

  • Third rebase (after feat(providers): add AbliteratedLLM API-key preset #8747). The same reviewer found no code or security blocker: the patch is unchanged across all 76 paths, authorship is preserved, and there are 111 presets. The OAuth backup-cleanup test passed within its default timeout.

  • Union guards on the merge with current dev: file-size ratchet, test layout, Spanish localization, preset counts, typecheck, and structure:check all passed.

  • Files also changed on dev since the branch base: docs-site/src/content/docs/es/guides/providers.md docs-site/src/content/docs/es/reference/cli/providers-accounts.md docs-site/src/content/docs/es/reference/configuration/providers.md docs-site/src/content/docs/guides/providers.md docs-site/src/content/docs/reference/cli/providers-accounts.md docs-site/src/content/docs/reference/configuration/providers.md gui/src/i18n/de.ts gui/src/i18n/en.ts gui/src/i18n/fr.ts gui/src/i18n/ja.ts gui/src/i18n/ko.ts gui/src/i18n/pt.ts gui/src/i18n/ru.ts gui/src/i18n/tr.ts gui/src/i18n/vi.ts gui/src/i18n/zh-TW.ts gui/src/i18n/zh.ts src/cli/account.ts src/oauth/store.ts src/oauth/types.ts src/server/management/oauth-account-routes.ts structure/INDEX.md structure/manifest.json structure/providers-and-adapters.md structure/providers/anthropic-account-pool.md tests/fixtures/test-layout-expected.json tests/oauth/oauth-store-multi.test.ts

@lidge-jun
lidge-jun marked this pull request as ready for review November 19, 2026 08:42
@lidge-jun
lidge-jun merged commit 7d9de0d into lidge-jun:dev Nov 19, 2026
33 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T08:53:37.122472Z a7e7b3d Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: a7e7b3dc9f

ℹ️ 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 src/oauth/pool-kernel.ts
Comment on lines +193 to +195
if (state.hasWeightedScores && !weighted) {
state.currentWeights.clear();
state.hasWeightedScores = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve weighted scores across request-specific candidate sets

When Anthropic model routes alternate between [a,b,c] and [a,b], with b the qualifying reset target and stickyLimit: 1, the two-account route computes equal weights and clears the shared instance's entire score map. A reproduction using the actual kernel produced b,a for all 100 alternating pairs, leaving healthy c without assignments even on the full-pool route. This affects normal routing because anthropic-routing.ts shares one poolKey across model routes. Scope the reset to the candidate ring, or otherwise preserve accumulated scores when a request-specific subset happens to have equal weights.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants