* fix: address pr-bug-scan validated finding from #3776 Remove unconditional generation bump in evictInactiveCodexCache; sibling in-flight fetches are no longer marked stale, while per-account guard still drops the evicted account's result. * test: cover inactive Codex sibling eviction --------- Co-authored-by: orca-bug-scan-bot <orca-bug-scan-bot@stably.ai> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
This commit is contained in:
co-authored by
orca-bug-scan-bot
Neil
parent
0fb10ea4c6
commit
a314cbfb9a
@@ -485,6 +485,42 @@ describe('RateLimitService', () => {
|
||||
await firstFetch
|
||||
})
|
||||
|
||||
it('keeps sibling inactive Codex preview fetches alive when one account is evicted', async () => {
|
||||
const service = new RateLimitService()
|
||||
const accountFetch = deferred<ProviderRateLimits>()
|
||||
let inactiveAccounts = [
|
||||
{ id: 'account-a', managedHomePath: '/tmp/account-a/home' },
|
||||
{ id: 'account-b', managedHomePath: '/tmp/account-b/home' }
|
||||
]
|
||||
service.setInactiveCodexAccountsResolver(() => inactiveAccounts)
|
||||
vi.mocked(fetchCodexRateLimits).mockReturnValueOnce(accountFetch.promise)
|
||||
|
||||
const fetchOnOpen = service.fetchInactiveCodexAccountsOnOpen()
|
||||
await Promise.resolve()
|
||||
expect(service.getState().inactiveCodexAccounts).toEqual([
|
||||
{ accountId: 'account-a', rateLimits: null, updatedAt: 0, isFetching: true },
|
||||
{ accountId: 'account-b', rateLimits: null, updatedAt: 0, isFetching: true }
|
||||
])
|
||||
|
||||
inactiveAccounts = [{ id: 'account-a', managedHomePath: '/tmp/account-a/home' }]
|
||||
service.evictInactiveCodexCache('account-b')
|
||||
accountFetch.resolve(okProvider('codex', 64, Date.now()))
|
||||
await fetchOnOpen
|
||||
|
||||
expect(fetchCodexRateLimits).toHaveBeenCalledTimes(1)
|
||||
expect(service.getState().inactiveCodexAccounts).toEqual([
|
||||
{
|
||||
accountId: 'account-a',
|
||||
rateLimits: expect.objectContaining({
|
||||
provider: 'codex',
|
||||
session: expect.objectContaining({ usedPercent: 64 })
|
||||
}),
|
||||
updatedAt: expect.any(Number),
|
||||
isFetching: false
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('does not recache an inactive Codex account that becomes active during fetch-on-open', async () => {
|
||||
const service = new RateLimitService()
|
||||
const accountFetch = deferred<ProviderRateLimits>()
|
||||
|
||||
@@ -487,7 +487,11 @@ export class RateLimitService {
|
||||
}
|
||||
|
||||
evictInactiveCodexCache(accountId: string): void {
|
||||
this.inactiveCodexAccountsGeneration += 1
|
||||
// Why: only the evicted account's state should be cleared. The per-account
|
||||
// isCurrentInactiveCodexAccount guard in fetchInactiveCodexAccountsOnOpen
|
||||
// already catches a removed account when its resolver entry disappears,
|
||||
// so bumping the generation here would also invalidate sibling fetches
|
||||
// still in flight and discard their fresh results.
|
||||
this.inactiveCodexCache.delete(accountId)
|
||||
this.inactiveCodexFetching.delete(accountId)
|
||||
this.pushToRenderer()
|
||||
|
||||
Reference in New Issue
Block a user