Repository navigation
fix(usage): reject pre-cancelled quota waits - #734
Open
outlier27-cell wants to merge 1 commit into
Open
outlier27-cell wants to merge 1 commit into
outlier27-cell wants to merge 1 commit into
Conversation
Contributor
Author
Contributor
Author
This branch has not been deployed
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
Closes #733.
waitForUsage()can return an already-fulfilled credential or quota result after its caller'sAbortSignalhas already been cancelled. This lets a cancelled/usagecollection observe stale data at the shared waiting boundary.Value
Cancellation now wins before a provider result becomes observable, preserving the caller's lifecycle boundary without taking ownership of Pi's credential-refresh operation.
Approach
Check
signal.throwIfAborted()before registering the promise race. Keep the existing in-flight abort listener and cleanup behavior unchanged. Add a deterministic regression that uses a pre-cancelled signal and an already-fulfilled promise, and verifies that the original cancellation Error identity is preserved.Validation
node --test --experimental-strip-types tests/extensions/usage/providers.test.ts(13 passed){ "returnedResult": false, "keptReason": true }.bun run checkcompleted its config, docs, discipline, web, format, lint, and typecheck gates without reported errors.bun run testwas run after the isolated worktree dependency install; its child processes completed without a reported failure.git diff --checkImpact
/usagewait no longer emits a result that was already available.