Skip to content

Commit 728e2a0

Browse files
committed
fix(muse): preserve complete reports and clear stale plan labels
1 parent 7889faf commit 728e2a0

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎packages/provider-muse/src/server/driver.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,14 @@ export const MuseDriver: ProviderDriver<
241241
// The probe may have advanced the generation before publishing its new account.
242242
if (!newer || auth.type === "apiKey" || museUsageAccount(auth) !== account.identity) return;
243243
const now = yield* DateTime.now;
244+
const authLabel = museUsageAuth(auth, usage.tier).label;
244245
yield* snapshot.applyUsageLimits({
245246
windows: museUsageWindows(usage, DateTime.toEpochMillis(now)),
246247
checkedAt: DateTime.formatIso(DateTime.makeUnsafe(usage.observedAtMs)),
247248
// A report is the account's whole state, so a window that has reset
248249
// since loses its old reset time instead of keeping it.
249-
replace: true,
250-
authLabel: museUsageAuth(auth, usage.tier).label,
250+
complete: true,
251+
...(authLabel !== undefined ? { authLabel } : {}),
251252
});
252253
}, usagePermit.withPermits(1)),
253254
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),

‎packages/provider-muse/src/server/usageLimits.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe("Muse usage limits", () => {
182182
});
183183
expect(museUsageAccount(apiKey)).toBeUndefined();
184184
expect(museUsageAuth(login, "tier-1")).toEqual({ ...login, label: "tier-1" });
185+
expect(museUsageAuth({ ...login, label: "tier-1" }, " ").label).toBeUndefined();
185186
const labelOnly = { status: "authenticated", type: "accountLogin", label: "Team A" } as const;
186187
expect(museUsageAuth(labelOnly, "tier-1")).toBe(labelOnly);
187188
const other = nextMuseUsageAccount(named, { ...login, email: "[email protected]" });

‎packages/provider-muse/src/server/usageLimits.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,5 @@ export function museUsageAuth(
177177
): ServerProviderAuth {
178178
if (auth.type === "accountLogin" && !auth.email) return auth;
179179
const label = tier?.trim();
180-
return label ? { ...auth, label } : auth;
180+
return { ...auth, label: label || undefined };
181181
}

‎packages/provider-muse/src/server/usageProbe.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const refreshMuseUsage = Effect.fn("MuseUsageProbe.refresh")(function* (i
164164
latestUsage,
165165
provider: {
166166
...provider,
167-
auth: museUsageAuth(provider.auth, latestUsage?.usage.tier),
167+
auth: latestUsage ? museUsageAuth(provider.auth, latestUsage.usage.tier) : provider.auth,
168168
usageLimits,
169169
...(message
170170
? {

0 commit comments

Comments
 (0)