Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Sources/QuotaCore/UsageMonitorPushMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,40 @@ public enum UsageMonitorPushMetadata {
if provider == "minimax", let model = window.modelId {
return "minimax:\(model)"
}
// Antigravity publishes four pooled windows (Gemini and Third-Party, 5h
// and weekly) that carry no model id. Bucketing them by the bare
// cadence made Gemini 5h and Third-Party 5h one bucket, and Gemini
// weekly and Third-Party weekly another, so the server kept one window
// of each pair and the phone drew a single bar per pool. The pool
// stays in the bucket, in the ids the server and
// AntigravityQuotaGroups.pool already read (`gemini-5h`, `3p-weekly`).
if provider == "google-antigravity", let cadence = window.window,
let pool = antigravityPoolPrefix(window) {
// Weekly arrives as "weekly" or "7d" depending on the producer path;
// the server bucket is always `weekly`.
let period = normalizeQuotaWindowToken(cadence)
return "\(pool)-\(period == "7d" ? "weekly" : period)"
}
Comment thread
swu-wise[bot] marked this conversation as resolved.
Resolved
if let modelId = window.modelId, !modelId.isEmpty {
let cadence = window.window ?? "window"
return "\(modelId)-\(cadence)"
}
return window.window ?? window.label.lowercased().replacingOccurrences(of: " ", with: "-")
}

private static func antigravityPoolPrefix(_ window: QuotaWindow) -> String? {
func pool(_ raw: String?) -> String? {
guard let family = raw?.lowercased(), !family.isEmpty else { return nil }
if family.hasPrefix("gemini") { return "gemini" }
if family.hasPrefix("3p") || family.hasPrefix("third") { return "3p" }
return nil
}
if let found = pool(window.modelType) { return found }
let parts = window.id.lowercased().split(separator: ":").map(String.init)
if parts.count >= 3, parts[0] == "antigravity" { return pool(parts[1]) }
return nil
}
Comment thread
swu-wise[bot] marked this conversation as resolved.
Resolved

private static func anthropicRateLimitKey(from window: QuotaWindow) -> String? {
if let suffix = localMacSuffix(window.id) { return suffix }
let model = window.modelId?.lowercased()
Expand Down
32 changes: 32 additions & 0 deletions Tests/QuotaCoreTests/UsageMonitorPushMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,36 @@ final class UsageMonitorPushMetadataTests: XCTestCase {
XCTAssertEqual(meta["source"] as? String, "codecaps")
XCTAssertEqual(meta["machine"] as? String, "Test-Mac")
}

func testAntigravityPoolWindowsKeepDistinctBuckets() {
func pooled(_ family: String, _ period: String) -> QuotaWindow {
QuotaWindow(
id: "antigravity:\(family):\(period)",
provider: "Antigravity",
providerKey: "google-antigravity",
modelType: family,
label: "\(family) \(period)",
remainingPercent: 50,
window: period,
occurredAt: "2026-11-24T19:00:00Z"
)
}
let buckets = [pooled("gemini", "5h"), pooled("gemini", "weekly"),
pooled("third-party", "5h"), pooled("third-party", "weekly")]
.map { UsageMonitorPushMetadata.bucketId(for: $0) }
XCTAssertEqual(buckets, ["gemini-5h", "gemini-weekly", "3p-5h", "3p-weekly"])
XCTAssertEqual(Set(buckets).count, 4)
}

func testAntigravityBucketsNormalizeCadenceAndServerStyleFamilies() {
func pooled(_ id: String, _ family: String?, _ token: String) -> QuotaWindow {
QuotaWindow(id: id, provider: "Antigravity", providerKey: "google-antigravity",
modelType: family, label: "x", remainingPercent: 50, window: token,
occurredAt: "2026-11-24T19:00:00Z")
}
XCTAssertEqual(UsageMonitorPushMetadata.bucketId(for: pooled("antigravity:gemini:weekly", "gemini", "7d")), "gemini-weekly")
XCTAssertEqual(UsageMonitorPushMetadata.bucketId(for: pooled("antigravity:gemini:weekly", "gemini", "weekly")), "gemini-weekly")
XCTAssertEqual(UsageMonitorPushMetadata.bucketId(for: pooled("x", "3p-5h", "5h")), "3p-5h")
XCTAssertEqual(UsageMonitorPushMetadata.bucketId(for: pooled("x", "3p-weekly", "weekly")), "3p-weekly")
}
}
25 changes: 25 additions & 0 deletions docs/rollouts/2026-11-24-antigravity-pool-buckets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Antigravity Pool Windows Reach The Phone

Jay reported that the iPhone showed one bar per Antigravity entry (Gemini 7d only, Third-Party 5h only) while the Mac showed both.

## Cause

The Mac publishes four pooled Antigravity windows: Gemini 5h, Gemini weekly, Third-Party 5h and Third-Party weekly. They carry no model id, so `UsageMonitorPushMetadata.fallbackBucketId` fell through to the bare cadence token. Gemini 5h and Third-Party 5h both became bucket `5h`, and the two weekly windows both became `weekly`. The server keeps one window per bucket, so one of each pair was overwritten and the phone drew a single bar per pool.

The live server payload showed exactly this: one fresh `5h` row (Third-Party) and one fresh `weekly` row (Gemini), with no fresh Gemini 5h.

## Change

Antigravity pool windows now bucket as `gemini-5h`, `gemini-weekly`, `3p-5h` and `3p-weekly`, the ids the server and `AntigravityQuotaGroups.pool` already read. A new test in `UsageMonitorPushMetadataTests` pins the four distinct buckets.

## Rollout note

The fix is on the publishing side. The phone shows both bars once the Mac app that pushes is rebuilt with this change and has pushed once.

## Verification

```sh
swift test -j 4 --filter UsageMonitorPushMetadataTests
```

The iOS `CompanionQuotaModel` was also run against the live server payload and against the payload the fixed publisher produces: before, Gemini showed only the 7-day bar; after, Gemini shows 5h and 7-day, and Third-Party shows 5h and 7-day.
Loading