Skip to content

fix(usage): include Gemini quotas from the Antigravity CLI - #1678

Merged
devswha merged 3 commits into
devswha:mainfrom
Davesaggio:fix/antigravity-gemini-usage
Oct 25, 2026
Merged

devswha merged 3 commits into
devswha:mainfrom
Davesaggio:fix/antigravity-gemini-usage

Conversation

@Davesaggio

@Davesaggio Davesaggio commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Change

Antigravity usage could show only Claude/GPT quotas while omitting Gemini limits. Reproduced on Windows: both direct retrieveUserQuotaSummary hosts returned only third-party buckets, whereas the official agy --print /usage --output-format json command returned Gemini and third-party buckets for the CLI account. This affects WebUI quota collection, not the Pi Antigravity Bridge plugin.

  • Ask HTTP first and return immediately when it includes a readable Gemini bucket. Only invoke the official CLI when the successful HTTP answer omits Gemini quotas, with a bounded 35-second process timeout (--print-timeout 30s). No new environment variables.
  • Parse both CLI snake_case and HTTP camelCase buckets into the existing usage windows.
  • Keep the HTTP reading when the CLI is missing, fails, or returns malformed/empty output. Preserve HTTP authentication and rate-limit handling without starting the CLI on 401/403/429.
  • Add regression coverage and make the command output-limit test portable on Windows.
  • Include a changelog fragment. No UI or HTTP/WS schema changes, version bumps, or dependencies.

Validation

Rebased onto current main, then checked on Windows with Bun 1.4.3:

  • bun test ./server/usage.test.ts ./src/lib/usage.test.ts ./scripts/changelog-fold.test.ts: 92 passed, 0 failed.
  • bun run typecheck: both application and tooling TypeScript checks passed.
  • git diff --check: passed.
  • Manual local verification: after applying the fix, /api/usage returned both Gemini windows and both third-party windows without a provider problem.
  • Focused independent read-only review: no blocking findings.

Full CI, integration, and browser suites have not been run locally; fork CI may require maintainer approval. Existing expired-sign-in handling is unchanged. Only HTTP readings missing Gemini quotas incur the additional CLI latency.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8956961
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ad3ec9a-f20d-4fb0-97f4-8ad35cb75cb9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 0ba21b3
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 24559fb0-b005-4503-9d6c-81499ede350f
📥 Commits

Reviewing files that changed from the base of the PR and between 0ba21b3 and e91f133.

📒 Files selected for processing: 3
  • changelog.d/antigravity-gemini-usage.md
  • server/usage.test.ts
  • server/usage.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Antigravity usage can now display Gemini quota limits alongside Claude and GPT limits when the official CLI provides them.
  • Bug Fixes
    • When the CLI does not provide usable quota information, Antigravity usage falls back to the existing API lookup, preserving access to available usage data.

Antigravity usage now checks the official CLI first and falls back to the quota API when the CLI does not provide usable quota windows. The shared parser accepts alternate field names, and command execution supports configurable timeouts.

Changes: Antigravity usage retrieval

Layer / File(s) Summary
Configurable command timeout
server/usage.ts, server/usage.test.ts
UsageContext.run and runCommand accept an optional timeout. Tests cover timeout behavior, output-size limits, and null-byte output.
CLI quota parsing and fallback
server/usage.ts, server/usage.test.ts, changelog.d/antigravity-gemini-usage.md
Antigravity runs the configured CLI with a 35-second timeout. The shared parser handles alternate field names for recognized quota buckets. When the CLI result has no usable windows, usage falls back to the quota API. Tests cover successful CLI output and fallback cases.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nahwan-kim

Merge Risk: Minimal · up to e91f1

No confirmed issue remains that should block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: including Gemini quotas from the Antigravity CLI. It is concise and specific.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the required template. It has the Change section, which explains the Gemini-quota omission, the reproduction on Windows, the fix (HTTP first, CLI only when Gemini is missing, 3…
Full details: Description check

Explanation

The description follows the required template. It has the Change section, which explains the Gemini-quota omission, the reproduction on Windows, the fix (HTTP first, CLI only when Gemini is missing, 35-second timeout), the parsing changes, the fallback behavior, the tests, and the changelog fragment. The Validation section lists the test, typecheck, and diff-check results, manual verification, and the CI limits. It does not link an issue, though the template asks for one for features; this change is a bug fix, so the link is not required. The test count (92 passed) differs from the PR objectives (86 passed), so the author should confirm the figure.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha devswha left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, the parsing is right. I ran agy --print /usage --output-format json --print-timeout 30s with agy 1.4.4: status: SUCCESS, num_turns: 0, zero tokens, and buckets with id / remaining_fraction / reset_time, which matches antigravityWindows. Gemini buckets came through.

One change requested before merge: the CLI call took about 8.3 s here, and UsageService.report() waits on every provider (Promise.all). So every usage refresh for anyone with agy installed now waits 8 s (up to 35 s), even when the HTTP endpoint would answer in under a second. Please ask the HTTP endpoint first and run the CLI only when its answer has no Gemini bucket, or otherwise keep the CLI off the common path.

Minor: AGY_BIN is a new, undocumented knob. Drop it, or name it where the other usage env vars are documented.

@Davesaggio

Copy link
Copy Markdown
Contributor Author

Thanks for verifying this with agy 1.4.4 and for catching the refresh latency. Addressed both requests in 65aa556:

  • HTTP is now the first path. A readable Gemini session or weekly bucket returns immediately without invoking agy.
  • The CLI is only consulted after a successful HTTP response omits readable Gemini quotas. If it is unavailable or its output is unusable, the original HTTP reading is retained.
  • HTTP 401/403/429 handling remains unchanged and never starts the CLI.
  • Removed AGY_BIN; agy is resolved from PATH, with no new configuration knob.

Added regressions for both HTTP Gemini bucket types, HTTP error handling, HTTP-before-CLI ordering, and missing CLI output. All 92 targeted tests and both TypeScript checks pass on Windows. Full CI/integration/browser suites have not been run locally.

devswha added a commit that referenced this pull request Oct 23, 2026
…#1776)

## Change

On Linux, the Antigravity usage meter now also finds its sign-in when
the Antigravity CLI keeps it in the desktop keyring (GNOME Keyring /
Secret Service) and there is no `antigravity-oauth-token` file.

Fixes #1103

## Cause

`fromKeychain()` in `server/usage.ts` returns nothing unless the
platform is macOS. Antigravity's discovery went through it, so on Linux
only the token file was ever read. The CLI's go-keyring item on Linux is
a Secret Service item with `service=gemini` and `username=antigravity`,
the attributes the issue reports.

## What changed

- **`server/usage.ts`:** on Linux only, Antigravity reads that item with
`secret-tool lookup service gemini username antigravity`, through the
existing `runCommand`.
- A missing `secret-tool`, a non-zero exit or the 5 s timeout gives no
credential and no error.
- The value goes through the same `antigravitySignIn` parser as the
macOS keychain read, including its `go-keyring-base64:` form.
- The token-file fallback stays, and so does the rule that the
later-expiring credential wins.
  - macOS and the other providers are unchanged.
- **How often the lookup runs:** it is part of usage discovery, which is
cached: normally at most once every 5 minutes, and a forced refresh at
most once every 30 seconds. If the keyring is locked, `secret-tool` may
show the desktop's unlock prompt at that rate.

## Checks

- `HERDR_TEST_MODE=unit bun test server/usage.test.ts`: 62 pass, 0 fail.
The new Linux cases are:
  - the keyring item with no token file;
- `secret-tool` missing or failing, which gives no Antigravity and no
error;
- the later-expiring of the file and the keyring item winning, in both
orders.

With the old discovery restored, the keyring-only and keyring-preferred
cases fail.
- `bun run typecheck`: passes.
- `bun run check fast`: passes (unit 6258 pass, 0 fail, 13 skip in 443
files, 8 at a time, 57.7s).
- Not run against a real GNOME Keyring: the tests inject the
`secret-tool` output, as the existing macOS keychain tests inject
`security`.

## Outside PRs that touch the same files

The outside PR #1678 (Gemini quotas from the Antigravity CLI) also edits
`server/usage.ts` and `server/usage.test.ts` and will need a rebase
after this one.
@devswha
devswha force-pushed the fix/antigravity-gemini-usage branch from 65aa556 to 6a2d3a9 Compare October 25, 2026 02:56
@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Rechecked the contributor's HTTP-first revision against main a1e4f8b83.

  • Complete HTTP Gemini session or weekly buckets return without invoking agy. HTTP 401/403/429 also never invoke it; only a successful HTTP reading missing Gemini buckets incurs CLI startup, bounded to 35 seconds.

  • UsageService.report() still waits for every provider. The previous common-path CLI delay is removed; incomplete HTTP readings can still wait for the fallback, as requested in the earlier review. AGY_BIN is gone.

  • Fixed five Linux test failures: command counters now distinguish agy from the existing secret-tool keyring discovery instead of treating every command as quota CLI execution.

  • The missing-Gemini regression fails on exact main production code. Final targeted provider/UI-usage/changelog tests: 97 passed, 0 failed.

  • dori heavy ext-pr-review -- bun run check fast: 6,732 passed, 0 failed, 13 skipped; generated files, typecheck and build passed, and the report verifies unchanged final source.

Pushed the verification rebase and the separate Linux test correction together once. The contributor's requested HTTP-first behavior needs no further runtime change.

Review prepared with a code-review agent and checked against the code. The merge decision stays with the maintainer's merge pass.

@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Merge pass review-work report. Overall: PASSED. This is an outside-contributor PR, and the maintainer approved merging it in this pass. The ext-pr-review lane verified it; see its comment above.

Lane Verdict
Codex (gpt-6.1-sol, xhigh) APPROVE
Code review (omo-native-code-reviewer) PASS (no HIGH or MEDIUM blockers)

Gemini quotas come from the Antigravity CLI, with the HTTP reading tried first.

  • Malformed CLI output (non-JSON, a status other than SUCCESS, empty buckets) falls back to the HTTP reading, and each case is tested.
  • A 401, 403 or 429 from HTTP never starts the CLI.
  • The CLI runs with --print-timeout 30s and is killed after 35 s.
  • No token reaches the CLI or the logs, and Ovis never refreshes a token.
  • The requested changes are in: HTTP first, and AGY_BIN dropped.
  • 97 tests pass.

Follow-ups (MEDIUM/LOW):

  • One timeout test also passes on main.
  • The timeout kills only the CLI process itself, which was already the case before.
  • A CLI answer replaces the HTTP buckets rather than merging with them.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit f4437c5 into devswha:main Oct 25, 2026
19 checks passed
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.

2 participants