Commit Graph

29 Commits

Author SHA1 Message Date
Peter Steinberger
402c35b91c refactor(agents): centralize failover normalization 2026-01-09 22:15:06 +01:00
Peter Steinberger
c27b1441f7 fix(auth): billing backoff + cooldown UX 2026-01-09 22:00:14 +01:00
Peter Steinberger
374aa856f2 refactor(agents): centralize failover handling 2026-01-09 21:31:18 +01:00
Peter Steinberger
1afa48fcdf style(models): biome format auth order 2026-01-09 14:36:46 +00:00
Peter Steinberger
3e400ff9f2 feat(models): add per-agent auth order overrides 2026-01-09 14:07:45 +00:00
Peter Steinberger
7b81d97ec2 feat: wire multi-agent config and routing
Co-authored-by: Mark Pors <1078320+pors@users.noreply.github.com>
2026-01-09 12:48:42 +00:00
Peter Steinberger
82b342e77b fix: respect auth cooldown with auth.order 2026-01-09 12:44:29 +00:00
Peter Steinberger
37cbcc97d3 feat: support token auth profiles 2026-01-09 08:13:04 +01:00
Peter Steinberger
b01d7e39d5 fix(onboarding): preflight claude cli keychain 2026-01-08 23:18:33 +01:00
Peter Steinberger
7a917602c5 feat(auth): sync OAuth from Claude/Codex CLIs
Add source profiles anthropic:claude-cli and openai-codex:codex-cli; surface them in onboarding/configure.

Co-authored-by: pepicrft <pepicrft@users.noreply.github.com>
2026-01-07 10:47:57 +01:00
Peter Steinberger
7176b114da fix(auth): harden legacy auth.json cleanup 2026-01-07 06:51:17 +00:00
Peter Steinberger
0707b1e487 Merge PR #368: delete legacy auth.json after migration 2026-01-07 06:47:46 +00:00
Peter Steinberger
2937c4861f fix(auth): doctor-migrate anthropic oauth profiles 2026-01-07 06:31:02 +00:00
Matthew Dicembrino
4f10279ac3 fix: delete legacy auth.json after migration to prevent stale token overwrites (#363) 2026-01-07 01:15:38 -05:00
Peter Steinberger
12d57da53a fix: normalize provider aliases in auth order 2026-01-07 05:43:32 +01:00
mneves75
3550dc294d fix: normalize z.ai provider ids in auth profiles 2026-01-07 05:31:01 +01:00
Peter Steinberger
19c95d0ff7 fix(auth): serialize profile stats updates 2026-01-07 01:06:51 +01:00
Peter Steinberger
96d72ff91e fix(auth): lock auth profile updates 2026-01-07 01:00:47 +01:00
Muhammed Mukhthar CM
eb5f758f6b fix(auth): improve multi-account round-robin rotation and 429 handling
This commit fixes several issues with multi-account OAuth rotation that
were causing slow responses and inefficient account cycling.

## Changes

### 1. Fix usageStats race condition (auth-profiles.ts)

The `markAuthProfileUsed`, `markAuthProfileCooldown`, `markAuthProfileGood`,
and `clearAuthProfileCooldown` functions were using a stale in-memory store
passed as a parameter. Long-running sessions would overwrite usageStats
updates from concurrent sessions when saving.

**Fix:** Re-read the store from disk before each update to get fresh
usageStats from other sessions, then merge the update.

### 2. Capture AbortError from waitForCompactionRetry (pi-embedded-runner.ts)

When a request timed out, `session.abort()` was called which throws an
`AbortError`. The code structure was:

```javascript
try {
  await session.prompt(params.prompt);
} catch (err) {
  promptError = err;  // Catches AbortError here
}
await waitForCompactionRetry();  // But THIS also throws AbortError!
```

The second `AbortError` from `waitForCompactionRetry()` escaped and
bypassed the rotation/fallback logic entirely.

**Fix:** Wrap `waitForCompactionRetry()` in its own try/catch to capture
the error as `promptError`, enabling proper timeout handling.

Root cause analysis and fix proposed by @erikpr1994 in #313.

Fixes #313

### 3. Fail fast on 429 rate limits (pi-ai patch)

The pi-ai library was retrying 429 errors up to 3 times with exponential
backoff before throwing. This meant a rate-limited account would waste
30+ seconds retrying before our rotation code could try the next account.

**Fix:** Patch google-gemini-cli.js to:
- Throw immediately on first 429 (no retries)
- Not catch and retry 429 errors in the network error handler

This allows the caller to rotate to the next account instantly on rate limit.

Note: We submitted this fix upstream (https://github.com/badlogic/pi-mono/pull/504)
but it was closed without merging. Keeping as a local patch for now.

## Testing

With 6 Antigravity accounts configured:
- Accounts rotate properly based on lastUsed (round-robin)
- 429s trigger immediate rotation to next account
- usageStats persist correctly across concurrent sessions
- Cooldown tracking works as expected

## Before/After

**Before:** Multiple 429 retries on same account, 30-90s delays
**After:** Instant rotation on 429, responses in seconds
2026-01-07 00:56:32 +01:00
Peter Steinberger
118c1e1042 fix: keep oauth profile stable 2026-01-06 19:43:28 +00:00
Peter Steinberger
dbfa316d19 feat: multi-agent routing + multi-account providers 2026-01-06 18:33:37 +00:00
Muhammed Mukhthar CM
9e49c762e0 fix(auth): prioritize round-robin over lastGood for multi-account rotation (#281)
* fix(auth): prioritize round-robin over lastGood for multi-account rotation

When multiple OAuth accounts are configured, the round-robin rotation was
not working because lastGood was always prioritized, defeating the sort by
lastUsed.

Changes:
- Remove lastGood prioritization in resolveAuthProfileOrder
- Always apply orderProfilesByMode (sorts by lastUsed, oldest first)
- Only respect configuredOrder when explicitly set in config
- preferredProfile still takes priority for explicit user choice

Tested with 2 Google Antigravity accounts - verified alternating usage.

Follow-up to PR #269.

* style: fix formatting
2026-01-06 08:16:35 +00:00
Peter Steinberger
aa16b679ad fix: improve auth profile failover 2026-01-06 07:18:06 +01:00
Muhammed Mukhthar CM
ce6c7737c1 feat: add round-robin rotation and cooldown for auth profiles
Adds usage tracking to auth profiles for automatic rotation:

- ProfileUsageStats type with lastUsed, cooldownUntil, errorCount
- markAuthProfileUsed(): tracks successful usage, resets errors
- markAuthProfileCooldown(): applies exponential backoff (1/5/25/60min)
- isProfileInCooldown(): checks if profile should be skipped
- orderProfilesByMode(): now sorts by lastUsed (oldest first)

On auth/rate-limit failures, profiles are marked for cooldown before
rotation. On success, usage is recorded for round-robin ordering.

This enables automatic load distribution across multiple accounts
(e.g., Antigravity 5-hour rate limit windows).
2026-01-06 05:17:59 +00:00
Peter Steinberger
77789cb9a8 fix: improve compaction queueing and oauth flows 2026-01-06 05:41:24 +01:00
Peter Steinberger
87f4efda8d fix: restore auth fallback ordering 2026-01-06 01:38:15 +00:00
Peter Steinberger
085c70a87b fix: prefer env keys unless profiles configured 2026-01-06 01:21:45 +00:00
Peter Steinberger
e73573eaea fix: clean model config typing 2026-01-06 01:08:36 +00:00
Peter Steinberger
b04c838c15 feat!: redesign model config + auth profiles 2026-01-06 00:56:58 +00:00