Skip to content

Commit 15867c9

Browse files
committed
fix stale footer account counts
1 parent ee7b855 commit 15867c9

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,10 +2869,13 @@ while (attempted.size < Math.max(1, accountCount)) {
28692869

28702870
accountManager.recordSuccess(account, modelFamily, model);
28712871
if (persistAccountFooter) {
2872+
const liveAccountCount = accountManager.getAccountCount();
28722873
const persistedAccountCount =
2873-
persistedAccountCountHint > 0
2874-
? persistedAccountCountHint
2875-
: accountManager.getAccountCount();
2874+
liveAccountCount > 0
2875+
? liveAccountCount
2876+
: persistedAccountCountHint > 0
2877+
? persistedAccountCountHint
2878+
: 1;
28762879
setPersistedAccountIndicator(
28772880
threadIdCandidate,
28782881
account,

test/index.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,40 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
22012201
expect(storageModule.loadAccounts).not.toHaveBeenCalled();
22022202
});
22032203

2204+
it("uses the live account count when the cached footer hint is stale", async () => {
2205+
await enablePersistedFooter("full-email");
2206+
mockStorage.accounts = [
2207+
{ accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
2208+
{ accountId: "acc-2", email: "user2@example.com", refreshToken: "refresh-2" },
2209+
];
2210+
const accountsModule = await import("../lib/accounts.js");
2211+
const manager = await accountsModule.AccountManager.loadFromDisk() as unknown as {
2212+
accounts: Array<{
2213+
index: number;
2214+
accountId: string;
2215+
email: string;
2216+
refreshToken: string;
2217+
}>;
2218+
};
2219+
manager.accounts = [
2220+
{ index: 0, accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
2221+
{ index: 1, accountId: "acc-2", email: "user2@example.com", refreshToken: "refresh-2" },
2222+
];
2223+
vi.spyOn(accountsModule.AccountManager, "loadFromDisk").mockResolvedValue(manager as never);
2224+
const { plugin, sdk } = await setupPlugin();
2225+
2226+
await sendPersistedAccountRequest(sdk, "session-live-count");
2227+
manager.accounts = [
2228+
{ index: 0, accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
2229+
];
2230+
2231+
await sendPersistedAccountRequest(sdk, "session-live-count");
2232+
2233+
expect((await readPersistedAccountIndicator(plugin, "session-live-count")).variant).toBe(
2234+
expectedFullIndicator,
2235+
);
2236+
});
2237+
22042238
it("decorates the last user message with a label-only indicator when configured", async () => {
22052239
await enablePersistedFooter("label-only");
22062240
const { plugin, sdk } = await setupPlugin();
@@ -2300,6 +2334,20 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
23002334
{ accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
23012335
{ accountId: "acc-2", email: "user2@example.com", refreshToken: "refresh-2" },
23022336
];
2337+
const accountsModule = await import("../lib/accounts.js");
2338+
const manager = await accountsModule.AccountManager.loadFromDisk() as unknown as {
2339+
accounts: Array<{
2340+
index: number;
2341+
accountId: string;
2342+
email: string;
2343+
refreshToken: string;
2344+
}>;
2345+
};
2346+
manager.accounts = [
2347+
{ index: 0, accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
2348+
{ index: 1, accountId: "acc-2", email: "user2@example.com", refreshToken: "refresh-2" },
2349+
];
2350+
vi.spyOn(accountsModule.AccountManager, "loadFromDisk").mockResolvedValue(manager as never);
23032351

23042352
const { plugin, sdk, mockClient } = await setupPlugin();
23052353
await sendPersistedAccountRequest(sdk, "session-switch");

0 commit comments

Comments
 (0)