Skip to content

Comments

feat: Antigravity multi-account round-robin with automatic failover#203

Closed
mukhtharcm wants to merge 3 commits intoopenclaw:mainfrom
mukhtharcm:feat/antigravity-multi-account
Closed

feat: Antigravity multi-account round-robin with automatic failover#203
mukhtharcm wants to merge 3 commits intoopenclaw:mainfrom
mukhtharcm:feat/antigravity-multi-account

Conversation

@mukhtharcm
Copy link
Member

@mukhtharcm mukhtharcm commented Jan 5, 2026

Summary

Adds support for multiple Antigravity accounts with automatic round-robin load balancing and failover.

Problem

  • Single Antigravity account can get rate limited, blocking all requests
  • Antigravity rate limits cause requests to hang indefinitely rather than returning errors
  • Upstream @mariozechner/pi-ai expects credentials under a single google-antigravity key

Solution

Multi-account storage

Accounts stored with namespaced keys in oauth.json:

{
  "google-antigravity": { ... },
  "google-antigravity:[email protected]": { ... }
}

Round-robin selection

Each request picks the account with the oldest lastUsed timestamp (least-recently-used).

Automatic failover

On retryable errors (401, 403, 429, quota, rate limit, timeout), marks the account as failed and automatically retries with the next available account.

Timeout-based failover (new)

Since Antigravity rate limits cause hangs rather than errors, we added timeout detection:

  • When a request times out (based on agent.timeoutSeconds), treat it as a rate limit
  • Mark the account as failed and try the next available account
  • Logs: Antigravity account X timed out (possible rate limit). Trying next account...

Exponential backoff

Failed accounts get cooldown: 1min → 5min → 25min → 1hr max. State tracked in antigravity-state.json.

The storage swap trick

We create a temp storage object with the selected account mapped to google-antigravity, so the upstream library's token refresh works transparently without modification.

CLI Commands

clawdbot antigravity add     # Add new account (opens browser auth)
clawdbot antigravity list    # List all accounts  
clawdbot antigravity remove  # Remove an account

Files changed

  • src/agents/model-auth.ts - Core multi-account logic
  • src/agents/pi-embedded-runner.ts - Failover retry loop with timeout detection
  • src/cli/antigravity-cli.ts - CLI command registration
  • src/cli/program.ts - Register antigravity subcommand
  • src/commands/antigravity.ts - Add/list/remove implementations

Configuration

The failover timeout is controlled by agent.timeoutSeconds (default: 600s / 10 min). For faster failover on rate limits, lower this value:

{
  "agent": {
    "timeoutSeconds": 180
  }
}

Trade-off: Lower timeout = faster failover but may cut off legitimately long-running tasks.

Testing

  • Tested with 4 accounts - round-robin alternation confirmed via antigravity-state.json timestamps
  • Timeout failover confirmed in production: account marked failed after timeout, switched to next account successfully
  • Verified failover logs appear correctly

@mukhtharcm
Copy link
Member Author

mukhtharcm commented Jan 5, 2026

@steipete yet to confirm rate limit since I haven't hit limits in this run

I'm currently running on 3 accounts btw :)

- Add namespaced storage for multiple Antigravity accounts (google-antigravity:[email protected])
- Implement round-robin selection based on least-recently-used
- Add automatic failover on retryable errors (401, 403, 429, quota, rate limit, timeout)
- Add exponential backoff for failed accounts (1min → 5min → 25min → 1hr max)
- Track account state in antigravity-state.json (lastUsed, errorCount, cooldownUntil)
- Add CLI commands: clawdbot antigravity add/list

The storage swap trick allows multiple accounts without modifying upstream pi-ai library -
we create a temp storage object with the selected account mapped to 'google-antigravity'
so the library's token refresh works transparently.
@mukhtharcm mukhtharcm force-pushed the feat/antigravity-multi-account branch from 3d2a48f to df4c14a Compare January 5, 2026 07:56
When an Antigravity request times out (hangs without error), treat it as
a rate limit hit and automatically fail over to the next available account.

Previously, timeouts would just abort the session without triggering
account rotation, causing the gateway to hang indefinitely on rate-limited
accounts.
@mukhtharcm mukhtharcm force-pushed the feat/antigravity-multi-account branch from df4c14a to 36d6909 Compare January 5, 2026 08:02
@mukhtharcm
Copy link
Member Author

Closing in favor of #263 which builds on Peter's new auth-profiles system instead of duplicating it. The round-robin logic is now integrated with the existing profile ordering mechanism.

@mukhtharcm mukhtharcm closed this Jan 6, 2026
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 7, 2026
* refactor(tools): create shared tool execution module

* refactor(pi): use shared tool execution in pi-tool-definition-adapter

* refactor(sdk): use shared tool execution in tool-bridge

* test(tools): add tests for shared tool execution module

* docs: add unified tool execution coverage gap analysis

* fix(auto-reply): use unified tool execution for inline skill commands

* docs(tools): document wrapper reliance on runtime adapters

* test(auto-reply): add inline skill command error handling tests

* docs: update gap analysis with completed fixes

* fix: missing stuff
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.

1 participant