Skip to content

feat(account selection) Add relative availability routing strategy#507

Closed
egusev wants to merge 7 commits into
Soju06:mainfrom
egusev:rel_strategy
Closed

feat(account selection) Add relative availability routing strategy#507
egusev wants to merge 7 commits into
Soju06:mainfrom
egusev:rel_strategy

Conversation

@egusev

@egusev egusev commented Apr 27, 2026

Copy link
Copy Markdown

Description

  • add a new relative_availability routing strategy that prioritizes accounts by remaining weekly capacity relative to time left before reset
  • improve account usage when weekly windows differ, especially for mixed free, plus, and pro pools
  • prefer accounts whose remaining weekly limit would otherwise expire sooner, instead of looking only at current usage or absolute remaining capacity
  • add dashboard settings to tune strategy aggressiveness and candidate cutoff behavior
  • add selection diagnostics to make candidate scoring, shortlisted accounts, and final choice visible in logs
  • expose app logs through the root logger so routing diagnostics are visible in Docker logs

Compared with current strategies:

  • usage_weighted mainly follows lowest current usage percentage and does not account for how soon that weekly limit resets
  • capacity_weighted prefers larger remaining weekly capacity, but can under-prioritize accounts whose limit is about to expire
  • relative_availability balances both factors, helping reduce wasted weekly capacity near reset boundaries

@half144

half144 commented Apr 27, 2026

Copy link
Copy Markdown

amazing

@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: 31aeb0f578

ℹ️ 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 app/modules/proxy/load_balancer.py


def _relative_availability_label(state: AccountState) -> str:
return state.email or state.account_id

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 Stop emitting account emails in routing logs

Using state.email as the primary routing label causes INFO diagnostics to log raw email addresses for candidate scoring, top-k selection, and winner selection. In deployments that ship logs off-host, this introduces unnecessary PII exposure compared with using stable internal account IDs (or a redacted/hash form), and the change affects every relative-availability routing decision.

Useful? React with 👍 / 👎.

@egusev egusev changed the title Add relative availability routing strategy (feat) Add relative availability routing strategy Apr 27, 2026
@egusev egusev changed the title (feat) Add relative availability routing strategy feat(account selection) Add relative availability routing strategy Apr 27, 2026
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

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

ℹ️ 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".

"Selected account_id=%s strategy=%s sticky=%s model=%s",
selected_snapshot.id,
"Selected account=%s strategy=%s sticky=%s model=%s",
selected_snapshot.email or selected_snapshot.id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid logging raw account emails in selection logs

This changed the selection log payload from an internal identifier to selected_snapshot.email when present, so routine INFO logs now emit user email addresses on every account pick. In environments that forward app logs to centralized storage, this creates avoidable PII exposure and also breaks existing account_id-based log correlation. Keep the stable non-PII account ID in this hot-path log (or mask email and gate it behind debug diagnostics).

Useful? React with 👍 / 👎.

const relativeAvailabilityPowerChanged =
relativeAvailabilityPowerValid && parsedRelativeAvailabilityPower !== settings.relativeAvailabilityPower;

const parsedRelativeAvailabilityTopK = Number.parseInt(relativeAvailabilityTopK, 10);

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 Reject non-integer top-k values instead of truncating

Using Number.parseInt here silently truncates decimal input (for example, 1.5 becomes 1), and the subsequent Number.isInteger check then passes, so the UI saves a different value than the user entered. That can unintentionally reduce the candidate pool and change routing behavior without clear feedback. Validate that the raw input is an integer-form value (or use strict numeric parsing) before enabling save.

Useful? React with 👍 / 👎.

@Komzpa Komzpa added 🤖 codex: needs work [@codex review] raised an issue 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: needs work [@codex review] raised an issue 🤖 codex: ok [@codex review] says no issues found. labels May 16, 2026
# Conflicts:
#	app/core/balancer/logic.py
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 19, 2026
# Conflicts:
#	frontend/src/components/layout/status-bar.tsx
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06

Soju06 commented May 21, 2026

Copy link
Copy Markdown
Owner

Maintainer cleanup: closing this as stale / no longer merge-ready against the current main.

This PR has been open across substantial main-branch churn and is currently carrying at least one stale signal (conflicts/blocked or failing checks, outstanding codex: needs work, draft/old branch state, or overlap with newer/current implementation). Keeping it open is making the PR queue harder to reason about.

If the change is still needed, please open a fresh, focused PR rebased on current main with green CI and a clean Codex review.

@Soju06 Soju06 closed this May 21, 2026
@Komzpa Komzpa added needs rebase Needs rebase or conflict repair against current main stale No response from reporter; scheduled for close labels May 21, 2026
@Komzpa

Komzpa commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Revived on a maintainer-owned branch as #765 because this PR head has maintainerCanModify=false and cannot be updated here. Keeping credit to the original implementation in the replacement PR.

@Komzpa Komzpa removed 🤖 codex: needs work [@codex review] raised an issue needs rebase Needs rebase or conflict repair against current main labels May 21, 2026
@Komzpa Komzpa added the superseded Replaced by another PR, issue track, or merged implementation label May 21, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
Soju06 pushed a commit that referenced this pull request Jun 1, 2026
Add the relative availability account-routing strategy, which scores eligible accounts by remaining secondary-window credits over time to reset.

Also persists and exposes dashboard tuning for the strategy, wires the configured power/top-K through sticky fallback selection, keeps routing diagnostics on non-PII account IDs, and adds OpenSpec, migration, backend, and frontend coverage.

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

Labels

stale No response from reporter; scheduled for close superseded Replaced by another PR, issue track, or merged implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants