Skip to content

Commit d503115

Browse files
nullStack65Grok 4.7
andcommitted
fix(usage): name both Grok seats and keep held or signed-out state
Magpie's two SuperGrok rows share one product name and no alias, so the emergency direct login was the only named Grok seat and the other seat showed initials. Shared product names now get a person label. A chosen instance name still wins over a hub alias, in either row order. Held and signed-out seats stay on the bar and in the composer. Model: grok-4.7 Task: usage account labels Agent: grok Harness: t3/grok Co-Authored-By: Grok 4.7 <noreply@x.ai>
1 parent 1ce6e25 commit d503115

12 files changed

Lines changed: 757 additions & 51 deletions

File tree

‎apps/mobile/src/features/threads/ComposerUsageLimits.tsx‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ export function ComposerUsageLimits({
3737
account.resetCreditInput ??
3838
(account.instanceId ? { instanceId: account.instanceId } : undefined);
3939
const driverLabel = providerClients.get(account.driver)?.label ?? account.driver;
40+
const statusSuffix =
41+
account.status === "held"
42+
? " · Held"
43+
: account.status === "signed-out"
44+
? " · Sign in"
45+
: "";
46+
const instanceLabel = account.instanceId
47+
? account.displayName?.trim() ||
48+
(String(account.instanceId) !== String(account.driver)
49+
? account.instanceId
50+
: driverLabel)
51+
: account.label;
4052
return (
4153
<AccountLimits
4254
key={account.id}
@@ -45,14 +57,7 @@ export function ComposerUsageLimits({
4557
driver={account.driver}
4658
accentColor={account.accentColor}
4759
label={driverLabel}
48-
instanceLabel={
49-
account.instanceId
50-
? account.displayName?.trim() ||
51-
(String(account.instanceId) !== String(account.driver)
52-
? account.instanceId
53-
: driverLabel)
54-
: account.label
55-
}
60+
instanceLabel={`${instanceLabel}${statusSuffix}`}
5661
detail={account.plan}
5762
limits={account.limits}
5863
now={now}

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ import { ProviderIcon } from "../../components/ProviderIcon";
2929
import { SettingsScreen } from "../settings/components/SettingsScreen";
3030
import { environmentPresentations } from "../../state/presentation";
3131
import { ResetCredits } from "./UsageLimitsSection";
32+
import { pooledSegmentCaption } from "./pooledSegmentCaption";
3233
import { usageProviderKind, useProviderColors } from "./usageProviders";
3334

3435
const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace" } as const;
3536

3637
function accountName(account: LimitAccount) {
37-
if (account.displayName) return account.displayName;
38-
if (!account.email) return providerClients.get(account.driver)?.label ?? account.driver;
39-
return emailInitials(account.email) || "Account";
38+
const name = account.displayName
39+
? account.displayName
40+
: account.email
41+
? emailInitials(account.email) || "Account"
42+
: (providerClients.get(account.driver)?.label ?? account.driver);
43+
if (account.status === "held") return `${name} · Held`;
44+
if (account.status === "signed-out") return `${name} · Sign in`;
45+
return name;
4046
}
4147

4248
function emailInitials(email: string) {
@@ -235,6 +241,7 @@ function PoolWindowCard({
235241
/>
236242
);
237243
const { account, window } = member;
244+
const segmentCaption = pooledSegmentCaption(account, accountName(account), inlineName);
238245
const timeLeft = paceRemainingPercent(window, now);
239246
const credits = account.limits.resetCredits?.availableCount ?? 0;
240247
const resetsIn = formatResetsIn(window, now)?.replace("resets in ", "");
@@ -264,14 +271,14 @@ function PoolWindowCard({
264271
>
265272
<View className="min-w-0 shrink flex-row items-center gap-1.5">
266273
{account.email ? <AccountChip email={account.email} /> : null}
267-
{account.email && !(account.displayName && inlineName) ? null : (
274+
{segmentCaption ? (
268275
<Text
269276
numberOfLines={1}
270277
className="min-w-0 shrink text-xs font-t3-medium text-foreground"
271278
>
272-
{accountName(account)}
279+
{segmentCaption}
273280
</Text>
274-
)}
281+
) : null}
275282
<Text className="text-sm font-t3-bold tabular-nums text-foreground">
276283
{remainingPercent(window)}%
277284
</Text>
@@ -590,6 +597,9 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
590597
{account.plan}
591598
</Text>
592599
) : null}
600+
{account.statusDetail ? (
601+
<Text className="text-sm text-foreground-muted">{account.statusDetail}</Text>
602+
) : null}
593603
</View>
594604
<View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
595605
<Text className="text-sm font-t3-medium text-foreground">{window.label}</Text>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from "@effect/vitest";
2+
3+
import { pooledSegmentCaption } from "./pooledSegmentCaption";
4+
5+
describe("pooledSegmentCaption", () => {
6+
const held = {
7+
email: "a@example.com",
8+
displayName: null,
9+
status: "held" as const,
10+
};
11+
12+
it("keeps Held on a wide bar when the emailed name is hidden", () => {
13+
expect(pooledSegmentCaption(held, "AE · Held", false)).toBe("Held");
14+
expect(pooledSegmentCaption({ ...held, status: "signed-out" }, "AE · Sign in", false)).toBe(
15+
"Sign in",
16+
);
17+
});
18+
19+
it("leaves an unnamed emailed seat as the chip", () => {
20+
expect(pooledSegmentCaption({ ...held, status: null }, "AE", false)).toBeNull();
21+
});
22+
23+
it("shows the full name once the segment is wide enough", () => {
24+
expect(
25+
pooledSegmentCaption(
26+
{ ...held, displayName: "A Person · SuperGrok" },
27+
"A Person · SuperGrok · Held",
28+
true,
29+
),
30+
).toBe("A Person · SuperGrok · Held");
31+
});
32+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** What a wide pooled segment may print beside its chip. */
2+
export function pooledSegmentCaption(
3+
account: {
4+
readonly email: string | undefined;
5+
readonly displayName: string | null;
6+
readonly status: "held" | "signed-out" | null;
7+
},
8+
fullName: string,
9+
showFullName: boolean,
10+
): string | null {
11+
const showName = !account.email || (!!account.displayName && showFullName);
12+
if (showName) return fullName;
13+
if (account.status === "held") return "Held";
14+
if (account.status === "signed-out") return "Sign in";
15+
return null;
16+
}

‎apps/server/src/usage/magpieQuotas.test.ts‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ describe("magpieQuotasToAccounts", () => {
137137
"magpie-go:oc-billed",
138138
"magpie-go:oc-other",
139139
"claude:second@example.com",
140+
"grok:jeffrey.smith@closura.ai",
141+
"grok:kameron.smith@closura.ai",
140142
]);
141143
const team = accounts[2]!;
142144
const billed = accounts[3]!;
@@ -173,6 +175,129 @@ describe("magpieQuotasToAccounts", () => {
173175
"weekly",
174176
"monthly",
175177
]);
178+
// Both seats share the product name "Grok" and neither has an alias.
179+
expect(grok.map((account) => account.displayName)).toEqual(["Jeffrey Smith", "Kameron Smith"]);
180+
});
181+
182+
it("prefers an alias, splits a shared product name, and keeps held and lapsed seats", () => {
183+
const labeled = magpieQuotasToAccounts(
184+
[
185+
{
186+
provider: "claude",
187+
name: "Claude Code",
188+
plan: "max",
189+
user: "a@example.com",
190+
alias: "Kameron · Claude work",
191+
windows: [{ name: "5 hours", used: 0 }],
192+
},
193+
{
194+
provider: "claude",
195+
name: "Claude Code",
196+
plan: "max",
197+
user: "bee.person@example.com",
198+
alias: null,
199+
windows: [{ name: "5 hours", used: 10 }],
200+
},
201+
{
202+
provider: "grok",
203+
name: "Grok (SuperGrok)",
204+
user: "jeffrey.smith@example.com",
205+
alias: null,
206+
windows: [{ name: "7 days", used: 65 }],
207+
},
208+
{
209+
provider: "grok",
210+
name: "Grok (SuperGrok)",
211+
user: "kameron.smith@example.com",
212+
windows: [{ name: "7 days", used: 7 }],
213+
},
214+
{
215+
provider: "codex",
216+
name: "Codex",
217+
plan: "pro",
218+
user: "a@example.com",
219+
held: true,
220+
until: "2026-12-02T00:00:00Z",
221+
windows: [{ name: "7 days", used: 100 }],
222+
},
223+
{
224+
provider: "claude",
225+
user: "old@example.com",
226+
lapsed: "Claude Code is no longer signed in",
227+
windows: [{ name: "7 days", used: 100 }],
228+
},
229+
],
230+
checkedAt,
231+
);
232+
expect(labeled.find((account) => account.email === "a@example.com")?.displayName).toBe(
233+
"Kameron · Claude work",
234+
);
235+
// The second Claude seat shares the product name and has no alias.
236+
expect(labeled.find((account) => account.email === "bee.person@example.com")?.displayName).toBe(
237+
"Bee Person",
238+
);
239+
expect(
240+
labeled.filter((account) => account.driver === "grok").map((account) => account.displayName),
241+
).toEqual(["Jeffrey Smith · SuperGrok", "Kameron Smith · SuperGrok"]);
242+
const held = labeled.find((account) => account.driver === "codex");
243+
expect(held?.status).toBe("held");
244+
expect(held?.statusDetail).toBe("Held until 2026-12-02.");
245+
const lapsed = labeled.find((account) => account.email === "old@example.com");
246+
expect(lapsed?.status).toBe("signed-out");
247+
expect(lapsed?.statusDetail).toBe("Claude Code is no longer signed in.");
248+
expect(lapsed?.usageLimits.windows).toHaveLength(1);
249+
});
250+
251+
it("leaves one emailed seat unnamed, including a duplicate row, and keeps a colliding alias", () => {
252+
const lone = magpieQuotasToAccounts(
253+
[
254+
{
255+
provider: "grok",
256+
name: "Grok (SuperGrok)",
257+
user: "only@example.com",
258+
alias: null,
259+
held: null,
260+
lapsed: null,
261+
windows: [{ name: "7 days", used: 10 }],
262+
},
263+
{
264+
provider: "grok",
265+
name: "Grok (SuperGrok)",
266+
user: "only@example.com",
267+
windows: [{ name: "7 days", used: 12 }],
268+
},
269+
{
270+
provider: "claude",
271+
name: "Claude Code",
272+
user: "a@example.com",
273+
alias: "Bee Person",
274+
windows: [{ name: "5 hours", used: 1 }],
275+
},
276+
{
277+
provider: "claude",
278+
name: "Claude Code",
279+
user: "bee.person@example.com",
280+
alias: null,
281+
windows: [{ name: "5 hours", used: 2 }],
282+
},
283+
{
284+
provider: "claude",
285+
name: "Claude Code",
286+
user: "c@example.com",
287+
windows: [{ name: "5 hours", used: 3 }],
288+
},
289+
],
290+
checkedAt,
291+
);
292+
const grok = lone.filter((account) => account.driver === "grok");
293+
expect(grok.map((account) => account.email)).toEqual(["only@example.com"]);
294+
expect(grok[0]?.displayName).toBeUndefined();
295+
expect(lone.find((account) => account.email === "a@example.com")?.displayName).toBe(
296+
"Bee Person",
297+
);
298+
expect(lone.find((account) => account.email === "bee.person@example.com")?.displayName).toBe(
299+
"Bee Person · example",
300+
);
176301
});
177302
});
178303

@@ -327,6 +452,45 @@ describe("makeMagpieApi", () => {
327452
}),
328453
);
329454

455+
it.effect("accepts null alias, held, and lapsed on a quota row", () =>
456+
Effect.gen(function* () {
457+
const http = HttpClient.make((request) =>
458+
Effect.sync(() =>
459+
HttpClientResponse.fromWeb(
460+
request,
461+
Response.json({
462+
object: "list",
463+
data: [
464+
{
465+
provider: "grok",
466+
name: "Grok (SuperGrok)",
467+
user: "only@example.com",
468+
alias: null,
469+
held: null,
470+
until: null,
471+
lapsed: null,
472+
windows: [{ name: "7 days", used: 4, resetsAt: null }],
473+
},
474+
],
475+
}),
476+
),
477+
),
478+
);
479+
const result = yield* makeMagpieApi.pipe(
480+
Effect.flatMap((api) =>
481+
api.readAccounts({ url: "http://127.0.0.1:3425", managementKey: "" }),
482+
),
483+
Effect.result,
484+
Effect.provideService(HttpClient.HttpClient, http),
485+
);
486+
expect(result._tag).toBe("Success");
487+
if (result._tag !== "Success") return;
488+
expect(result.success.map((account) => account.id)).toEqual(["grok:only@example.com"]);
489+
expect(result.success[0]?.displayName).toBeUndefined();
490+
expect(result.success[0]?.status).toBeUndefined();
491+
}),
492+
);
493+
330494
it.effect("sends a configured gateway key and explains a refusal", () =>
331495
Effect.gen(function* () {
332496
const { result, seen } = yield* run("gateway-key", 401);

0 commit comments

Comments
 (0)