Repository navigation
Conversation
The 3.1.11 guard covered only the local account store. On the vault path a manual quota check runs outside the poller lock, so a late older reading replaced the poller's newer one in the state file and on the live row. Refuse a dated reading older than the stored one, as the local store does; the check still reports the account as checked.
|
Thanks @iceteaSA, this is a real bug and a clean fix. We reproduced it on 3.1.13: with your new tests and the unpatched code, the stored and live-row checks both read We've taken it into our next release branch as one commit, with you as co-author. We added two small things:
We'll close this pull request with a link once the release is out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Release 3.1.11 added a guard. When an older quota check stops after a newer quota check, the older check does not replace the newer quota value. This guard is in the local account store only (
StaleQuotaObservationErrorinpackages/core/src/account-repository-codecs.ts).On the OpenCode 2 vault path,
quotaUpdateandcheckVaultQuotainpackages/opencode/src/plugin/shared/vault-request-credentials.tswrite a quota value and do not do this check. The "Check quota now" menu item does not use the lock of the background quota check. If the manual check stops last, its older value replaces the newer value of the background check. This occurs in the shared state file and in the live pool row. The next background check corrects the value. Thus the effect is small, but the vault path and the local path do not agree.Change
isOlderQuotaReadinguses the same rule as the local store. It stops a new value only when the two values have a date and the date of the new value is earlier. It accepts a value with the same date or with no date.quotaUpdategives no update. Thus the commit result isunchangedwhile the commit holds the provider-state lock. The stored quota and the stored rate-limit data do not change.checkVaultQuotastops an older value, it counts the account as checked. The caller gets no error. The localrecordQuotadoes the same.Tests
packages/opencode/src/plugin/shared/vault-quota-newer-reading.test.ts, with a test clock, a temporary state file and no timed waits:keeps the newer stored reading when an older check commits lastlets a newer reading replace an older onekeeps a newer reading on the live row when the file has noneaccepts an undated reading over a dated one, as the local store doesvault-request-credentials.test.ts(keeps a newer local reading and limit when stored quota is older) changes fromoldertonewer. The previous assertion agreed with the defect: in the file, the older value replaced the newer value.Results on a branch from
v3.1.12, with Bun 1.4.4:168 pass, 0 fail.v3.1.12version ofvault-request-credentials.ts:3 fail(Expected: 2000,Received: 1000, andExpected: 1100,Received: 1000).tsc -p tsconfig.ga.json: no errors.The full
bun run testandbun run typecheckdid not run, becauseembed:checkand the TUI type build must have Bun 1.4.2. The branch merges into the currentmainwith no conflicts. The commits afterv3.1.12do not change these two files.Summary by cubic
Fixes vault quota so an older check finishing last can no longer replace a newer reading, matching the guard the local account store already has.
A manual "Check quota now" runs outside the background poller’s lock, so its older value could commit after a newer background check and overwrite it in the shared state file and on the live pool row. The next background check corrected it, but the vault path and the local path disagreed.
Bug Fixes
quotaUpdateandcheckVaultQuotainvault-request-credentials.tsnow refuse a dated reading older than the stored one; the account still counts as checked.Written for commit 7252331. Summary will update on new commits.