diff --git a/Sources/QuotaCore/UsageMonitorPushMetadata.swift b/Sources/QuotaCore/UsageMonitorPushMetadata.swift index cb8d7464..478c9df0 100644 --- a/Sources/QuotaCore/UsageMonitorPushMetadata.swift +++ b/Sources/QuotaCore/UsageMonitorPushMetadata.swift @@ -89,6 +89,20 @@ 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)" + } if let modelId = window.modelId, !modelId.isEmpty { let cadence = window.window ?? "window" return "\(modelId)-\(cadence)" @@ -96,6 +110,19 @@ public enum UsageMonitorPushMetadata { 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 + } + private static func anthropicRateLimitKey(from window: QuotaWindow) -> String? { if let suffix = localMacSuffix(window.id) { return suffix } let model = window.modelId?.lowercased() diff --git a/Tests/QuotaCoreTests/UsageMonitorPushMetadataTests.swift b/Tests/QuotaCoreTests/UsageMonitorPushMetadataTests.swift index e989dcae..d7eec910 100644 --- a/Tests/QuotaCoreTests/UsageMonitorPushMetadataTests.swift +++ b/Tests/QuotaCoreTests/UsageMonitorPushMetadataTests.swift @@ -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") + } } diff --git a/docs/rollouts/2026-11-24-antigravity-pool-buckets.md b/docs/rollouts/2026-11-24-antigravity-pool-buckets.md new file mode 100644 index 00000000..89d888b6 --- /dev/null +++ b/docs/rollouts/2026-11-24-antigravity-pool-buckets.md @@ -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.