fix stale account pool penalties after successful requests#324
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
📝 WalkthroughWalkthroughadded state-healing logic to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Issues to consider
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/accounts.ts`:
- Around line 559-561: The branch that sets healed currently leaves
cooldownReason dangling and relies on later stale-timestamp cleanup; modify the
branch where (!isCoolingDown && hadCooldownMetadata) { healed = true; } to also
call clearAccountCooldown(account) so both cooldownReason and coolingDownUntil
are normalized before save; update/extend tests (test/accounts.test.ts around
the existing expired-timestamp cases) to add a reason-only cooldown case
asserting cooldown fields are cleared, and ensure the change follows lib/**
guidelines (cite the updated test IDs) and that any queue or save path respects
EBUSY/429 retry behavior and Windows file-IO concurrency expectations.
In `@test/accounts.test.ts`:
- Around line 1906-1936: The test currently only asserts that
saveToDiskDebounced was called; instead call manager.recordSuccess(...) then
await manager.flushPendingSave() and assert the mocked saveAccounts payload
contains the normalized/healed account snapshot (consecutiveAuthFailures === 0
and no coolingDownUntil/cooldownReason) to verify the persisted state; do the
same for the active-cooldown scenario (call recordSuccess, await
flushPendingSave, and assert saveAccounts payload was left unchanged). Reference
AccountManager, recordSuccess, flushPendingSave, saveToDiskDebounced, and
saveAccounts when locating and updating the assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a2b1b79b-d87c-411f-82e0-500d8ea772f9
📒 Files selected for processing (2)
lib/accounts.tstest/accounts.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Greptile Review
🧰 Additional context used
📓 Path-based instructions (2)
lib/**
⚙️ CodeRabbit configuration file
focus on auth rotation, windows filesystem IO, and concurrency. verify every change cites affected tests (vitest) and that new queues handle EBUSY/429 scenarios. check for logging that leaks tokens or emails.
Files:
lib/accounts.ts
test/**
⚙️ CodeRabbit configuration file
tests must stay deterministic and use vitest. demand regression cases that reproduce concurrency bugs, token refresh races, and windows filesystem behavior. reject changes that mock real secrets or skip assertions.
Files:
test/accounts.test.ts
Summary
What Changed
AccountManager.recordSuccess(...)inlib/accounts.tsto clear stale auth-failure counters and expired cooldown metadata when an account succeeds againsaveToDiskDebounced()test/accounts.test.tsto prove success heals stale state without clearing an active newer cooldownValidation
npm run lintnpm run typechecknpm testnpm test -- test/documentation.test.tsnpm run buildDocs and Governance Checklist
docs/getting-started.mdupdated (if onboarding flow changed)docs/features.mdupdated (if capability surface changed)docs/reference/*pages updated (if commands/settings/paths changed)docs/upgrade.mdupdated (if migration behavior changed)SECURITY.mdandCONTRIBUTING.mdreviewed for alignmentRisk and Rollback
adbf49aAdditional Notes
origin/mainnote: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
this pr heals stale account-pool penalty state (expired cooldown metadata and
consecutiveAuthFailures) on the success path inAccountManager.recordSuccess, then persists the cleaned state viasaveToDiskDebounced. the previous orphaned-cooldownReasonconcern is resolved: the new code callsclearAccountCooldownexplicitly in thehadCooldownMetadatabranch rather than relying onisAccountCoolingDown's internal side effect, so a stored account with onlycooldownReasonset (andcoolingDownUntilabsent) will also be cleaned correctly.lib/accounts.ts: snapshotshadCooldownMetadataandhadAuthFailuresbefore callingisAccountCoolingDown; both healing branches are guarded by!isCoolingDownto preserve an active newer cooldowntest/accounts.test.ts: three new regression cases — full heal, orphaned-reason-only heal, and active-cooldown guard; all verify persist behavior viaflushPendingSave+mockSaveAccountsaccount.consecutiveAuthFailures = 2mutation in test cases 1 and 3 is redundant since the value is already present in thestoredfixture; no isolated test exists for theconsecutiveAuthFailures > 0/ no-cooldown-metadata-at-all path, though the risk is low given the branches are independentConfidence Score: 5/5
safe to merge — logic is correct, previous concern is addressed, no P0/P1 issues found
all remaining findings are P2 style/test-hygiene only. core healing logic is sound, guard against active cooldowns is correct, debounced persist coalesces concurrent heals safely, and the orphaned-cooldownReason gap from the prior review thread is explicitly closed by the direct clearAccountCooldown call.
test/accounts.test.ts — redundant post-construction mutation on lines 1929 and 2000, and missing isolated test for pure auth-failure healing path
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[recordSuccess called] --> B[snapshot hadCooldownMetadata\nhadAuthFailures] B --> C[isAccountCoolingDown] C -->|coolingDownUntil future| D[isCoolingDown = true] C -->|coolingDownUntil expired\nside-effect: clearAccountCooldown| E[isCoolingDown = false] C -->|coolingDownUntil undefined| E D --> F[skip all healing\nhealed = false] E --> G{hadCooldownMetadata?} G -->|yes| H[clearAccountCooldown\nhealed = true] G -->|no| I{hadAuthFailures?} H --> I I -->|yes| J[clearAuthFailures\nhealed = true] I -->|no| K{healed?} J --> K K -->|yes| L[saveToDiskDebounced] K -->|no| M[no persist] F --> MPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "fix: heal stale cooldown metadata on suc..." | Re-trigger Greptile