Skip to content

feat(daemon): read Antigravity quota with agy usage --json - #369

Merged
AnnatarHe merged 1 commit into
mainfrom
claude/ecstatic-gauss-n5kt5i
Dec 2, 2026
Merged

AnnatarHe merged 1 commit into
mainfrom
claude/ecstatic-gauss-n5kt5i

Conversation

@AnnatarHe

@AnnatarHe AnnatarHe commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The daemon now reads Google Antigravity's quota with agy usage --json and posts it to /api/v1/antigravity-usage (server: https://github.com/shelltime/server/pull/620).

  • model/antigravity_quota.go finds agy on PATH, then in ~/.local/bin (where the official installer puts it, and which a daemon's PATH usually lacks), /opt/homebrew/bin and /usr/local/bin. It runs agy usage --json with a 20 s limit and reads command.data.groups[].buckets[].
    • Each bucket becomes one window: used share (100 − remaining_fraction), reset time and window length (5h = 300 min, weekly = 10080 min).
    • agy's 1970-01-01 reset means the window hasn't started (it is full), so it is sent with no reset time.
    • Text printed before the JSON (such as an update notice) is skipped.
  • AntigravityUsageSyncService reads the quota on each 10-minute tick while Antigravity or agy is running. It is on wherever the service already runs, with no new setting.
    • A missing agy or a status other than SUCCESS is logged at debug level and skipped.
    • agy usage reports no tokens, so the conversation-DB token scan stays and still feeds tokens and cost.
  • Tests never run the machine's agy: the daemon TestMain stubs it. Docs are updated in CONFIG.md, the README and CLAUDE.md.

Test plan

  • TestParseAntigravityUsage*: the real agy usage --json output, text before the JSON, invalid buckets, failure statuses
  • TestRunAgyUsage: a fake agy script, checking the arguments, a failure that still printed its JSON, stderr in the error, the timeout
  • TestLookupAgyFindsTheInstallersFolder, TestFetchAntigravityQuota, TestAgyWindowMinutes
  • TestAntigravityUsageSyncService_SendsQuotaFromAgyUsage: the exact payload, no call while Antigravity isn't running, nothing sent when agy is missing
  • go test ./model/... ./daemon/... ./agenthook/... pass. TestDoctorCheckCursor in ./commands fails here on main too: it depends on the machine's PATH and is unrelated to this change.

Generated by Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The Antigravity usage sync now runs `agy usage --json` (the Antigravity
CLI, found on PATH or in ~/.local/bin where its installer puts it) and
posts each model group's 5-hour and weekly window to
/api/v1/antigravity-usage. It is on wherever the Antigravity sync runs,
with no extra setting. A missing agy or a non-SUCCESS status is skipped
quietly. agy reports no tokens, so the conversation DB scan stays for
token usage and cost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014EpZRfuvHAKPrJdv5Pd2Ym
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T10:17:03.162125Z 4a5f2ab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

for _, g := range env.Command.Data.Groups {
for _, b := range g.Buckets {
id := strings.TrimSpace(b.ID)
if id == "" || b.RemainingFraction == nil || seen[id] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): buckets are de-duplicated by id alone across all groups (seen[id]), so a second bucket with the same id in another group is dropped without a log line. This contradicts the CLAUDE.md claim that "every bucket of every model group" is posted as a window. If agy ever reuses an id (for example "5h") in two groups, one group's quota never reaches the server. Fix: key seen by group name plus id, or send the group in the key and log a drop.

// whose command.data.groups hold the model groups and their quota buckets. Text
// agy prints before the envelope (an update notice) is skipped.
func ParseAntigravityUsage(raw []byte) ([]AntigravityQuotaWindow, error) {
start := bytes.IndexByte(raw, '{')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): the parser starts decoding at the first { in the output. The doc comment says text before the envelope (an update notice) is skipped, but a notice that contains a brace (for example a {version} placeholder or a JSON-ish hint) makes the decode fail. That returns a non-skip error, so the daemon logs a Warn every 10 minutes and sends no quota. Fix: try each { that starts a line, or scan for the first offset where Decode succeeds with status or command set.

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.19497% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
model/antigravity_quota.go 90.65% 10 Missing ⚠️
daemon/antigravity_usage_sync.go 92.30% 4 Missing ⚠️
Flag Coverage Δ
unittests 86.29% <91.19%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/antigravity_usage_sync.go 78.52% <92.30%> (+13.21%) ⬆️
model/antigravity_quota.go 90.65% <90.65%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

// A child that agy leaves holding the pipes must not keep the daemon waiting.
cmd.WaitDelay = 2 * time.Second
err := cmd.Run()
if ctx.Err() != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): ctx.Err() here is the derived 20 s context, so a cancelled parent context (daemon shutdown) is reported as agy usage --json: context canceled. That is not a skip reason, so the daemon logs a Warn on every shutdown during a quota run. Related: on a non-zero exit with any stdout (line 134) the output is returned as success, so a crash that printed partial output surfaces as a JSON parse Warn rather than the real exit error. Also msg[:300] (line 139) can cut a multi-byte rune. Fix: return the context error quietly when the parent context is done, and truncate on a rune boundary.

parentCtx = context.Background()
}

if running {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): the quota pass runs inline in sync, before the token sync, and nothing in it watches stopChan. agy usage --json can take up to 20 s and the POST 5 s. Stop() (which calls wg.Wait()) can therefore block about 25 s if the daemon context is not cancelled first, and a hung agy delays the token backfill by the same time on every tick. A failed quota call also logs Warn on every cycle, and an older server answering 404 on /api/v1/antigravity-usage makes SendHTTPRequestJSON log Error plus Warn every 10 minutes (the Cursor sync behaves the same). Fix: run the quota pass after the token sync, or in its own goroutine tied to stopChan, and treat HTTPStatusError 404/405 as a quiet skip.

home, _ := os.UserHomeDir()
if runtime.GOOS == "windows" {
var paths []string
if local := os.Getenv("LOCALAPPDATA"); local != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): the Windows path %LOCALAPPDATA%\agy\bin\agy.exe has no stated source, unlike ~/.local/bin, which the comment ties to the installer. The daemon does not run on Windows, so this list is dead code and could point somewhere agy is never installed. Fix: drop the Windows branch, or cite the installer location.

}
var quotaHits atomic.Int32
var auth string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): auth and got are written by the httptest handler goroutine and read by the test goroutine without synchronization, while quotaHits is atomic. Nothing orders the plain writes before the reads, so go test -race can report a race. Fix: guard auth and got with a mutex, or pass them through a channel.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

⏱️ shelltime track performance

✅ No significant change in shelltime track latency

Comparing main @ f0ce50e → #369 @ 4a5f2ab. Each scenario execs the binary the way the shell hooks do; values are the median of 10 interleaved rounds. Lower is better.

Scenario base head Δ p
Startup/floor 514 µs ±1% 517 µs ±1% ~ 0.739 A/A
Startup/version 5.33 ms ±1% 5.40 ms ±1% +1.44% 0.004 ✅
Track/daemon/pre 5.64 ms ±1% 5.66 ms ±1% ~ 0.436 ✅
Track/daemon/post 5.63 ms ±1% 5.69 ms ±2% ~ 0.190 ✅
Track/direct/pre 5.59 ms ±2% 5.61 ms ±1% ~ 0.436 ✅
Track/direct/post 7.57 ms ±1% 7.61 ms ±1% ~ 0.853 ✅
Track/direct/post-sync 10.47 ms ±2% 10.39 ms ±1% ~ 0.052 ✅

Binary size: 23.6 MiB → 23.6 MiB (+0.0%).

CPU, tail latency and memory

Per exec, base → head (Δ when significant).

Scenario p95 wall user CPU sys CPU peak RSS
Startup/floor 571 µs → 572 µs 285 µs → 265 µs 178 µs → 200 µs 9.2 MiB → 9.2 MiB
Startup/version 5.78 ms → 5.82 ms 2.02 ms → 2.12 ms 4.03 ms → 3.97 ms 17.1 MiB → 16.8 MiB (-1.41%)
Track/daemon/pre 6.13 ms → 6.12 ms 2.28 ms → 2.22 ms 4.10 ms → 4.17 ms 18.0 MiB → 17.8 MiB (-1.14%)
Track/daemon/post 6.11 ms → 6.20 ms 2.23 ms → 2.22 ms 4.15 ms → 4.19 ms 17.7 MiB → 17.5 MiB (-1.25%)
Track/direct/pre 6.10 ms → 6.12 ms 2.17 ms → 2.20 ms 4.11 ms → 4.15 ms 18.0 MiB → 17.8 MiB (-1.13%)
Track/direct/post 8.18 ms → 8.27 ms 3.82 ms → 3.84 ms 4.65 ms → 4.70 ms 18.5 MiB → 18.2 MiB (-1.95%)
Track/direct/post-sync 11.15 ms → 11.06 ms 6.23 ms → 6.26 ms 7.20 ms → 7.03 ms 20.9 MiB → 20.7 MiB (-1.03%)
benchstat
goos: linux
goarch: amd64
pkg: github.com/malamtime/cli/perf
cpu: AMD EPYC 7763 64-Core Processor                
                         │    base     │                head                │
                         │   sec/op    │   sec/op     vs base               │
Startup/floor-4            514.3µ ± 1%   517.2µ ± 1%       ~ (p=0.739 n=10)
Startup/version-4          5.326m ± 1%   5.403m ± 1%  +1.44% (p=0.004 n=10)
Track/daemon/pre-4         5.638m ± 1%   5.663m ± 1%       ~ (p=0.436 n=10)
Track/daemon/post-4        5.627m ± 1%   5.692m ± 2%       ~ (p=0.190 n=10)
Track/direct/pre-4         5.590m ± 2%   5.608m ± 1%       ~ (p=0.436 n=10)
Track/direct/post-4        7.568m ± 1%   7.612m ± 1%       ~ (p=0.853 n=10)
Track/direct/post-sync-4   10.47m ± 2%   10.39m ± 1%       ~ (p=0.052 n=10)
geomean                    4.519m        4.544m       +0.55%

                         │    base     │                head                │
                         │ p50-sec/op  │ p50-sec/op   vs base               │
Startup/floor-4            505.9µ ± 2%   507.3µ ± 1%       ~ (p=0.853 n=10)
Startup/version-4          5.387m ± 4%   5.444m ± 2%       ~ (p=0.052 n=10)
Track/daemon/pre-4         5.611m ± 3%   5.605m ± 2%       ~ (p=0.579 n=10)
Track/daemon/post-4        5.586m ± 2%   5.716m ± 2%       ~ (p=0.143 n=10)
Track/direct/pre-4         5.535m ± 2%   5.531m ± 4%       ~ (p=0.684 n=10)
Track/direct/post-4        7.595m ± 1%   7.612m ± 2%       ~ (p=0.912 n=10)
Track/direct/post-sync-4   10.47m ± 1%   10.42m ± 2%       ~ (p=0.143 n=10)
geomean                    4.504m        4.525m       +0.47%

                         │    base     │                head                │
                         │ p95-sec/op  │ p95-sec/op   vs base               │
Startup/floor-4            571.1µ ± 2%   572.4µ ± 2%       ~ (p=0.796 n=10)
Startup/version-4          5.785m ± 1%   5.821m ± 2%       ~ (p=0.218 n=10)
Track/daemon/pre-4         6.133m ± 2%   6.116m ± 4%       ~ (p=0.853 n=10)
Track/daemon/post-4        6.115m ± 1%   6.195m ± 2%       ~ (p=0.165 n=10)
Track/direct/pre-4         6.099m ± 3%   6.119m ± 1%       ~ (p=1.000 n=10)
Track/direct/post-4        8.180m ± 6%   8.273m ± 5%       ~ (p=0.853 n=10)
Track/direct/post-sync-4   11.15m ± 4%   11.06m ± 3%       ~ (p=0.436 n=10)
geomean                    4.911m        4.929m       +0.36%

                         │     base     │                head                 │
                         │  peak-rss-B  │  peak-rss-B   vs base               │
Startup/floor-4            9.236Mi ± 1%   9.238Mi ± 2%       ~ (p=0.912 n=10)
Startup/version-4          17.07Mi ± 0%   16.83Mi ± 0%  -1.41% (p=0.000 n=10)
Track/daemon/pre-4         17.96Mi ± 0%   17.76Mi ± 0%  -1.14% (p=0.000 n=10)
Track/daemon/post-4        17.75Mi ± 0%   17.52Mi ± 0%  -1.25% (p=0.000 n=10)
Track/direct/pre-4         17.98Mi ± 0%   17.78Mi ± 0%  -1.13% (p=0.000 n=10)
Track/direct/post-4        18.53Mi ± 0%   18.17Mi ± 0%  -1.95% (p=0.000 n=10)
Track/direct/post-sync-4   20.87Mi ± 0%   20.66Mi ± 0%  -1.03% (p=0.000 n=10)
geomean                    16.62Mi        16.43Mi       -1.13%

                         │     base     │                head                 │
                         │  sys-sec/op  │  sys-sec/op   vs base               │
Startup/floor-4            178.2µ ± 19%   199.7µ ± 17%       ~ (p=0.436 n=10)
Startup/version-4          4.032m ±  3%   3.972m ±  4%       ~ (p=0.280 n=10)
Track/daemon/pre-4         4.099m ±  3%   4.166m ±  4%       ~ (p=0.280 n=10)
Track/daemon/post-4        4.150m ±  4%   4.188m ±  7%       ~ (p=0.123 n=10)
Track/direct/pre-4         4.114m ±  5%   4.147m ±  3%       ~ (p=0.481 n=10)
Track/direct/post-4        4.654m ±  3%   4.702m ±  5%       ~ (p=0.971 n=10)
Track/direct/post-sync-4   7.205m ±  3%   7.031m ±  4%       ~ (p=0.089 n=10)
geomean                    2.891m         2.940m        +1.70%

                         │     base     │                head                 │
                         │ user-sec/op  │ user-sec/op   vs base               │
Startup/floor-4            284.6µ ±  7%   265.1µ ± 11%       ~ (p=0.315 n=10)
Startup/version-4          2.019m ±  5%   2.119m ±  8%       ~ (p=0.123 n=10)
Track/daemon/pre-4         2.277m ±  8%   2.217m ±  8%       ~ (p=0.481 n=10)
Track/daemon/post-4        2.233m ± 10%   2.217m ± 13%       ~ (p=0.579 n=10)
Track/direct/pre-4         2.167m ±  9%   2.200m ±  8%       ~ (p=0.912 n=10)
Track/direct/post-4        3.820m ±  5%   3.842m ±  3%       ~ (p=0.529 n=10)
Track/direct/post-sync-4   6.226m ±  3%   6.264m ±  4%       ~ (p=0.529 n=10)
geomean                    2.047m         2.038m        -0.42%

Δ compares medians; ~ means no significant difference (Mann-Whitney U, p ≥ 0.05). A scenario is flagged when it is more than 10% and more than 250µs slower with p < 0.05. Startup/floor runs true, not shelltime: it is an A/A check of runner noise. Runner: linux/amd64, AMD EPYC 7763 64-Core Processor . go1.27.1, 10 rounds × 100 execs per scenario and binary.

@shelltime

shelltime Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

☁️ Claude Code cloud · Migrate Antigravity quota checks to agy usage --json

Replaced Antigravity’s file-based quota lookup with parsing of agy usage --json, then propagated and tested the resulting quota-window behavior across CLI, iOS, Android, and web clients.

💰 Cost 🔢 Tokens ⏱️ Duration 🧠 Models 💬 Prompts ✏️ Lines
$35.56 104.3M 1h 7m (22m active) claude-opus-5-5, claude-haiku-5-5 2 +1514 / −22

104.3M tokens: 17.2K input · 296.4K output · 102.5M cache read · 1.5M cache write

📝 AI summary

Updated the CLI Antigravity quota implementation in /home/user/cli/model/antigravity_quota.go to consume the new agy usage --json output rather than relying on the previous file-based check. The work handled Antigravity’s JSON envelope and tab-delimited usage response, including weekly and five-hour limits for Gemini and Claude/GPT model groups.

Aligned quota-window presentation and access logic across clients. Significant changes included iOS rate-limit/statistics models and GraphQL activity queries, Android limit-window and agent view-model handling, and the web Antigravity block-usage component. Added or updated focused tests in Go-adjacent client suites, Swift, Kotlin, and TypeScript/React—including AntigravityBlockUsageTests.swift, CodingAgentAccessTests.swift, AgentQuotaTest.kt, antigravity-block-usage.test.ts, and quota-card.test.tsx—to verify parsing, reset timing, access state, and quota-card behavior.

View this session on ShellTime →

Updated 2026-12-03 10:17 UTC by ShellTime · totals for the whole session so far · the session page is visible to its owner

@AnnatarHe
AnnatarHe merged commit 3b512d5 into main Dec 2, 2026
18 checks passed
@AnnatarHe
AnnatarHe deleted the claude/ecstatic-gauss-n5kt5i branch December 2, 2026 10:49
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