Skip to content

feat: Multi-account OAuth with round-robin rotation - #269

Merged
steipete merged 3 commits into
openclaw:mainfrom
mukhtharcm:feat/multi-account-roundrobin
Jan 6, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
mukhtharcm:feat/multi-account-roundrobin

Conversation

@mukhtharcm

Copy link
Copy Markdown
Member

Summary

Adds support for multiple OAuth accounts per provider with automatic round-robin load balancing and failover.

Changes

1. Email-based profile IDs

  • Profiles now use email instead of :default (e.g., google-antigravity:[email protected])
  • Each OAuth login creates a separate profile automatically
  • No new CLI commands needed - uses existing clawdbot configure flow

2. Round-robin rotation

  • Tracks usageStats (lastUsed, cooldownUntil, errorCount) per profile
  • Profiles sorted by oldest lastUsed first (least-recently-used)
  • Automatic load distribution across multiple accounts

3. Exponential backoff cooldown

  • On auth/rate-limit errors: 1min ??? 5min ??? 25min ??? 60min max
  • Profiles in cooldown are deprioritized in rotation order

4. Timeout-based failover

  • Antigravity rate limits cause hangs rather than 429 errors
  • Timeouts now treated as potential rate limits
  • Triggers cooldown + rotation to next account
  • Logs: "Profile X timed out (possible rate limit). Trying next account..."

Files changed

  • src/commands/onboard-auth.ts - Email-based profile ID
  • src/commands/configure.ts - Email-based profile ID
  • src/wizard/onboarding.ts - Email-based profile ID
  • src/agents/auth-profiles.ts - Usage tracking, cooldown, round-robin logic
  • src/agents/pi-embedded-runner.ts - Timeout detection, cooldown/usage calls

Testing

  • Tested with 2 Antigravity accounts via clawdbot configure
  • Both profiles created with email-based IDs
  • Order list populated correctly for round-robin

Changes writeOAuthCredentials and applyAuthProfileConfig calls to use
the email from OAuth response as part of the profile ID instead of
hardcoded ":default".

This enables multiple accounts per provider - each login creates a
separate profile (e.g., google-antigravity:[email protected]) instead
of overwriting the same :default profile.

Affected files:
- src/commands/onboard-auth.ts (generic writeOAuthCredentials)
- src/commands/configure.ts (Antigravity flow)
- src/wizard/onboarding.ts (Antigravity flow)
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).
Antigravity rate limits cause requests to hang indefinitely rather than
returning 429 errors. This change detects timeouts and treats them as
potential rate limits:

- Added timedOut flag to track timeout-triggered aborts
- Timeout now triggers profile cooldown + rotation
- Logs: "Profile X timed out (possible rate limit). Trying next account..."

This ensures automatic failover when Antigravity hangs due to rate limiting.
@mukhtharcm
mukhtharcm force-pushed the feat/multi-account-roundrobin branch from 3b23b63 to 18c7795 Compare January 6, 2026 05:20
@steipete
steipete merged commit a7b5753 into openclaw:main Jan 6, 2026
mukhtharcm added a commit to mukhtharcm/clawdbot that referenced this pull request Jan 6, 2026
…ation

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 openclaw#269.
steipete pushed a commit that referenced this pull request Jan 6, 2026
…ation (#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
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
* feat: CRN proposal

* CRN: validate canonicalized resource-id (openclaw#271)

* Docs: tighten CRN parser resource-id rule (openclaw#269)

* CRN: add session and cron metadata (openclaw#267)
heatherstew44-maker pushed a commit to heatherstew44-maker/openclaw that referenced this pull request Mar 8, 2026
* fix: tooltip overflow

* Adds more responsive Css

* StartHidden has tooltip bottom

* in debug setting too

---------

Co-authored-by: CJ Pais <[email protected]>
Fato07 referenced this pull request in Fato07/elav Mar 26, 2026
fix(server): serve cached index.html in SPA catch-all to prevent 500
@gabrielbernal

Copy link
Copy Markdown

Addressing review feedback

P1: metabase_api.py consumers ✅

Restored in eea9b3c with deprecation notice. Active consumers confirmed:

  • analyst-performance/scripts/performance_compiler.py
  • pos-extra-quota-eval/scripts/eval.py
  • ato-lending-eval/SKILL.md
  • kb-diff-sync/SKILL.md

P2: bq_query.sh consumers ✅

Restored in eea9b3c with deprecation notice. Consumer: transaction-lookup/SKILL.md

P2: Memory materialization in bq-query/run.py

This is upstream nimbus-cortex code, imported as-is. The 20GB scan cap + practical row counts keep memory safe. Can patch downstream or contribute upstream if needed.

lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…undrobin

feat: Multi-account OAuth with round-robin rotation
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…ation (openclaw#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 openclaw#269.

* style: fix formatting
Primus-max referenced this pull request in Primus-max/god-mode-core May 7, 2026
…y helper

Фаза 3 sub-plan'а ['commitment_kernel_intent_contractor_freshness.plan.md'](../.cursor/plans/commitment_kernel_intent_contractor_freshness.plan.md) — pure scoring helper над типами Phase 2. NO contractor wiring, NO consumer changes; Phase 4 ландит провод в 'intent-contractor-impl.ts'.

Размещение: NEW 'src/platform/freshness/score-by-recency.ts'. Импорты — только sibling Phase 2 модуль ('./freshness-config.js') + stdlib (инвариант #8). Frozen-слой 'src/platform/commitment/**' и 5 frozen-контрактов — НЕ ТРОНУТЫ ('git diff --stat src/platform/decision/ src/platform/commitment/' пустой; инвариант #11).

Контракт хелпера ('ScoreByRecencyDeps<T>'):
- 'items: ReadonlyArray<T>' — каллер передаёт массив; helper его не мутирует.
- 'getTimestamp: (item: T) => number | null | undefined' — extractor задаётся каллером (Phase 4 будет передавать 'Date.parse(metadata.recordedAt)' для memory и 'Date.parse(updatedAt ?? createdAt)' для tasks).
- 'nowMs: number' — clock-injected (sub-plan §6: помощь purity load-bearing; внутри хелпера НЕТ 'Date.now()').
- 'config: ResolvedFreshnessConfig' — резолвед один раз на 'classify' call (lock-step консистенция, audit §c.3).

Decay-формула:
1. 'getTimestamp(item)' → 'rawTs'.
2. 'rawTs' null/undefined/NaN/Infinity → policy-driven branch ('penalize_to_floor' → 'ageMs=null, recencyDecay=DECAY_FLOOR'; 'treat_as_now' → 'ageMs=0, recencyDecay=1.0').
3. Иначе 'ageMs = max(0, nowMs - tsMs)' (negative ages clock-skew clamped to 0).
4. 'decay = Math.pow(0.5, ageMs / decayHalfLifeMs)'.
5. Cap at 1.0; floor at 'DECAY_FLOOR'.

Stable-sort discipline: каждый scored-envelope несёт internal '__idx' (original position); после сортировки ('b.recencyDecay - a.recencyDecay' с tiebreaker 'a.__idx - b.__idx') индекс снимается перед возвратом. Это исключает зависимость от engine 'Array.sort' стабильности (контракт sub-plan'а §6: equal decay → original order preserved).

Fail-soft posture (инварианты #9/#10/#15):
- Внутри ноль 'Date.now()' / 'console.*' / 'throw'.
- 'NaN' / 'Infinity' / 'null' / 'undefined' timestamp — фолбэк на policy.
- Future-stamped entry (negative raw age) — 'ageMs' clamped to 0, 'recencyDecay' capped at 1.0 (живой clock-skew vector audit §2.4).

Тесты ('__tests__/score-by-recency.test.ts', 15 кейсов, fail-first verified):
1. Empty array → empty result.
2. ageMs=0 → recencyDecay=1.0.
3. Exactly one half-life → recencyDecay=0.5 (strict equality, no FP fuzz at exponent=1).
4. 'penalize_to_floor' missing-ts → 'ageMs=null, recencyDecay=DECAY_FLOOR'.
5. 'treat_as_now' missing-ts → 'ageMs=0, recencyDecay=1.0'.
6. Two items different ages → fresher first (input order reversed → helper actually reorders).
7. Stable sort: three items с identical timestamps preserve declaration order.
8. Future-stamped (clock skew) → 'ageMs=0, recencyDecay=1.0' (cap holds).
9. 10× half-life → recencyDecay=DECAY_FLOOR (floor holds; pow(0.5,10)=0.000976 < floor).
10. Configurable half-life: 1h half-life + 1h-old item → recencyDecay=0.5.
11. Generic over T: 'Mem={id,ts}' shape works.
12. Generic over T: 'Task={name,recordedAt}' shape works.
13. Input array NOT mutated (length, snapshot equality, slot identity).
14. Item objects NOT mutated (Object.keys unchanged, envelope item === source).
15. NaN-tolerance: 'getTimestamp() => NaN' → falls into missing-ts branch (Phase 4 'Date.parse' regression guard, инвариант #15 fail-soft).

Fail-first evidence: с stubbed 'scoreByRecency' возвращающим '[]', vitest сообщил '14 failed | 1 passed' (только empty-array case прошёл — корректно). После реал-имплементации — 15/15 green. 'pnpm exec tsgo --noEmit' — exit 0, чисто.

Plan-Step: PR-#269 (freshness phase 3 — scoring helper)
Plan-Status: completed

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…undrobin

feat: Multi-account OAuth with round-robin rotation
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…ation (openclaw#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 openclaw#269.

* style: fix formatting
muneebhashone pushed a commit to muneebhashone/clawdbot that referenced this pull request Aug 25, 2026
…undrobin

feat: Multi-account OAuth with round-robin rotation
muneebhashone pushed a commit to muneebhashone/clawdbot that referenced this pull request Aug 25, 2026
…ation (openclaw#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 openclaw#269.

* style: fix formatting
zeekay pushed a commit to Dream-AI-4444/bot that referenced this pull request Sep 11, 2026
…undrobin

feat: Multi-account OAuth with round-robin rotation
zeekay pushed a commit to Dream-AI-4444/bot that referenced this pull request Sep 11, 2026
…ation (openclaw#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 openclaw#269.

* style: fix formatting
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…undrobin

feat: Multi-account OAuth with round-robin rotation
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…ation (openclaw#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 openclaw#269.

* style: fix formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants