Skip to content

Commit 2550e7e

Browse files
committed
fix(usage): report failed hub account limit reads
1 parent 71c2d3a commit 2550e7e

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,54 @@ describe("pools", () => {
647647
]);
648648
});
649649

650+
it("reports unreadable hub accounts alongside usable limits", () => {
651+
const account = {
652+
id: "claude.json",
653+
driver: claude,
654+
655+
workspaceId: "org-a",
656+
usageLimits: { checkedAt, windows: [window] },
657+
};
658+
const input = new Map([
659+
[
660+
EnvironmentId.make("env-a"),
661+
{
662+
...laptop,
663+
serverConfig: {
664+
providers: [],
665+
usageLimitSources: [{ ...source, accounts: [account] }],
666+
},
667+
},
668+
],
669+
]);
670+
expect(collectLimitNotices(input)).toEqual([]);
671+
for (const unavailable of [
672+
{ reason: "probeFailed" as const, message: "The hub could not read this account's usage." },
673+
{ reason: "probeFailed" as const },
674+
]) {
675+
const failed = {
676+
...account,
677+
usageLimits: { checkedAt, windows: [], unavailable },
678+
};
679+
input.set(EnvironmentId.make("env-b"), {
680+
entry: { target: { label: "Desktop" } },
681+
serverConfig: {
682+
providers: [],
683+
usageLimitSources: [
684+
{
685+
...source,
686+
accounts: [failed, { ...failed, id: "other.json", workspaceId: "org-b" }],
687+
},
688+
],
689+
},
690+
});
691+
expect(collectLimitAccounts(input)).toHaveLength(1);
692+
expect(collectLimitNotices(input)).toEqual([
693+
`Desktop · hub · [email protected]: ${unavailable.message ?? "Could not read limits."}`,
694+
]);
695+
}
696+
});
697+
650698
it("keys a hub account without an email by hub, so two environments on one hub share it", () => {
651699
const seat = {
652700
id: "claude-team-seat.json",

‎packages/shared/src/usageLimits.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,17 @@ export function collectLimitNotices(presentations: LimitPresentations): readonly
407407
} else if (source.accounts.length === 0) {
408408
notices.push(`${label(environmentLabel, source.label)}: No accounts reported.`);
409409
}
410+
for (const account of source.accounts) {
411+
if (account.usageLimits.unavailable?.reason === "unsupported") continue;
412+
const notice = limitsNotice(account.usageLimits);
413+
if (notice) {
414+
const name = `${source.label} · ${account.email || hubAccountName(account)}`;
415+
notices.push(`${label(environmentLabel, name)}: ${notice}`);
416+
}
417+
}
410418
}
411419
}
412-
return notices;
420+
return [...new Set(notices)];
413421
}
414422

415423
export interface LimitPoolMember {

0 commit comments

Comments
 (0)