This repository was archived by the owner on Sep 30, 2026. It is now read-only.
Repository navigation
Unify ScheduleWakeup #706 fix + pace-aware account balancing - #7
Merged
Merged
Conversation
jcode's multi-account policy was exhaustion-only: it switched off an Anthropic account only once both its 5h and 7d windows hit ~99%, then picked the peer with the most headroom. That ignores pace - how fast a window burns relative to how much window time remains - so one account's perishable weekly quota could expire unused while another was maxed. Add a native Rust pace module (crates/jcode-base/src/usage/pace.rs) mirroring the reference fork claude-swap's logic: 1. compute_window_pace: burn-rate pace per window (5h and weekly). A window is "ahead of pace" when usage exceeds the fraction of the cycle elapsed. Weekly pace is suppressed for 24h after a reset (matches claude-swap SUPPRESS_AFTER_RESET_S) since expected is near zero then. 2. select_balanced_target: a same-pace balancing decision. Instead of draining one account then moving on, it proactively consumes the soonest-resetting weekly window first (use-it-or-lose-it), keeping accounts at roughly equal pace. Hysteresis is a reset-time margin (two accounts resetting near the same instant never ping-pong) plus a cooldown between proactive switches. A 7d-heavy peer is deprioritized, not excluded, so 5h relief still wins when it is the only option. Failover on an exhausted active account keeps the old most-headroom behavior. 3. should_prime: whether to open an account's never-used 5-hour window (the 0%/0%-with-no-reset case) with a minimal request, so its clock is already counting down when the fleet needs it. Only fires when the active account is under real pressure (ahead of pace, or its 5h window near threshold) - otherwise priming just burns quota for no benefit. Wire it into MultiProvider::auto_select_multi_account_for_provider: when the active account is not yet exhausted and pace balancing is enabled, it evaluates the balancing decision (switching the active-account override exactly as the exhaustion failover does) and otherwise considers priming. Priming temporarily activates the peer, sends ONE minimal inference request via complete_simple, and always restores the original account. Design choice: build natively in Rust rather than vendor claude-swap's Python. jcode already exposes per-account 5h/7d ratios and reset times through AccountUsageProbe, so the pace math is small pure functions on existing data. A Python subprocess would need its own separate credential store and cross-runtime plumbing - fragile for no gain. We mirror claude-swap's algorithms (consume-first, per-window pace, hysteresis + cooldown, priming), not its process. Gated by [provider].pace_aware_account_balancing (default on, opt-out via config or JCODE_PACE_AWARE_ACCOUNT_BALANCING); off leaves the exhaustion-only behavior unchanged. No credential is ever reset, rotated, or refreshed by this path beyond the existing override/invalidate the manual /account switch already uses. Verified against real `jcode usage --json` output; pace_tests.rs includes a real-fleet scenario reproducing the captured live account data. 22 pace tests cover the pace math, the balancing decision (including flip-flop prevention), and the priming trigger. Co-authored-by: jeremy <[email protected]>
…ewakeup-plus-pace # Conflicts: # crates/jcode-tui/src/tui/ui_header.rs # scripts/code_size_budget.json
The merge of the ScheduleWakeup/opus-oauth branch (which added the client_terminal_env parameter, bringing the arg count to 8) trips clippy::too_many_arguments. Silence it with a scoped #[expect], matching the existing handle_client attribute in the same module.
This was referenced Aug 13, 2026
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Merges
origin/pace-base(#5 pace-aware multi-account balancing) intoorigin/master(1jehuang#706 ScheduleWakeup OAuth schema fix + #4 Opus-Pro-OAuth) so a single fork build carries BOTH features.Conflict resolutions (the 2 expected)
crates/jcode-tui/src/tui/ui_header.rs: both sides were formatting-only variants of the identical active-account-label logic. Kept master's rustfmt form; the active-account suffix display is preserved.scripts/code_size_budget.json: took the max of each divergent entry (config-types/src/lib.rs -> 1504, desktop2/src/editor.rs -> 1373) so neither feature trips the size budget.Extra fix
#[expect(clippy::too_many_arguments)]onstart_processing_message(master's side raised it to 8 args viaclient_terminal_env), matching the existinghandle_clientattribute in the same module.Verification (Linux, cargo build --release)
oauth_forwards_schedule_backend_schema_under_scheduled_wakeup_name(jcode-provider-anthropic): PASS.cargo test -p jcode-base pace): 43 passed, 0 failed.--all-targetsdead-code lints on Linux also exist onorigin/master(macOS-cfg helpers); not introduced by this merge.