Skip to content

Commit d2f3e06

Browse files
ntindleclaude
andcommitted
fix(providers): clear Muse usage when another account signs in
A status check that drops the kept report because another account signed in now publishes no usage. "Waiting for a report" uses probeFailed, which snapshot reconciliation treats as a failed probe and answers by keeping the last good windows, so the previous account's windows stayed on show under the new account until its first reply. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e5c5274 commit d2f3e06

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎apps/server/src/provider/Drivers/MuseDriver.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ export const MuseDriver: ProviderDriver<MuseSettings, MuseDriverEnv> = {
114114
const usagePermit = yield* Semaphore.make(1);
115115
const withUsageLimits = (provider: ServerProviderDraft) =>
116116
Effect.gen(function* () {
117-
const retained = yield* Ref.updateAndGet(latestUsage, (current) =>
118-
current && museUsageStillApplies(current.account, provider.auth) ? current : undefined,
119-
);
117+
const { retained, dropped } = yield* Ref.modify(latestUsage, (current) => {
118+
const drop =
119+
current !== undefined && !museUsageStillApplies(current.account, provider.auth);
120+
const kept = drop ? undefined : current;
121+
return [{ retained: kept, dropped: drop }, kept] as const;
122+
});
120123
const usageLimits = museStatusUsageLimits({
121124
auth: provider.auth,
122125
enabled: provider.enabled,
123126
observation: retained?.usage,
127+
dropped,
124128
nowMs: DateTime.toEpochMillis(yield* DateTime.now),
125129
});
126130
return usageLimits ? { ...provider, usageLimits } : provider;

‎apps/server/src/provider/museUsageLimits.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ describe("Muse usage limits", () => {
9595
expect(status(login, false, false)).toBeUndefined();
9696
// Signed out, the last report has no account to show under.
9797
expect(status({ status: "unauthenticated" }, true)).toBeUndefined();
98+
// Just after another account signs in, the old report is gone but its windows are still
99+
// published; no usage clears them, where "waiting for a report" would keep them.
100+
expect(
101+
museStatusUsageLimits({
102+
auth: { ...login, email: "[email protected]" },
103+
enabled: true,
104+
observation: undefined,
105+
dropped: true,
106+
nowMs: reported,
107+
}),
108+
).toBeUndefined();
98109
});
99110

100111
it("drops a kept report once its account logs out or another one signs in", () => {

‎apps/server/src/provider/museUsageLimits.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export function museStatusUsageLimits(input: {
123123
readonly auth: ServerProviderAuth;
124124
readonly enabled: boolean;
125125
readonly observation: MuseUsageObservation | undefined;
126+
/** This check dropped the kept report, for a logout or another account's login. */
127+
readonly dropped?: boolean;
126128
readonly nowMs: number;
127129
}): ServerProviderUsageLimits | undefined {
128130
const checkedAt = isoFromMillis(input.nowMs);
@@ -136,6 +138,9 @@ export function museStatusUsageLimits(input: {
136138
// Signed out, there is no account to report on.
137139
if (input.auth.status === "unauthenticated") return undefined;
138140
if (input.observation) return museUsageLimits(input.observation, input.nowMs);
141+
// The dropped report's windows are still published. "Waiting for a report" would
142+
// keep them, as a failed probe keeps the last good bars, so publish none to clear them.
143+
if (input.dropped) return undefined;
139144
if (!input.enabled || input.auth.type !== "accountLogin") return undefined;
140145
return makeUnavailableUsageLimits({
141146
checkedAt,

0 commit comments

Comments
 (0)