fix: respect cancellation for queued credential mutations - #4
Merged
bajrangCoder merged 2 commits intoSep 10, 2026
Merged
bajrangCoder merged 2 commits into
bajrangCoder merged 2 commits into
Conversation
bajrangCoder
requested changes
Sep 10, 2026
bajrangCoder
approved these changes
Sep 10, 2026
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.
Summary
Respect cancellation for queued credential mutations without releasing the provider's queue early.
Problem
PortableCredentialStore previously ignored the cancellation signal passed by Pi's Models.login. A cancelled login could overwrite stored credentials after an earlier mutation finished.
The initial fix prevented that delayed mutation. Review identified an additional gap: the store's own promise still waited for its predecessor before rejecting cancellation.
The revised implementation separates the caller-facing promise from the internal queue tail. Cancelling a queued operation rejects its caller promptly, while subsequent operations continue waiting for the actual preceding work.
Cancellation boundary
The abort listener is removed when queued work starts. An already-started host credential read is awaited, with cancellation checked before invoking the mutation callback.
Once the callback starts, the store awaits the callback and persistence before releasing the queue. It does not discard a returned credential because cancellation arrived after callback entry; an OAuth refresh may already have rotated tokens.
Tests
The credential test file now contains 15 cases covering:
Before the revision, the four new direct-store cancellation cases failed and the other 11 passed. All 15 pass with the revision.
Local validation
Windows, Node.js 24.15.0:
Tests use synthetic credentials and memory-only or simulated host storage. Android secret-storage integration has not been tested on a device.
Scope
Only the credential store and its regression tests change. Provider OAuth flows, transports, read/list behaviour, dependencies and lockfiles retain their existing behaviour.
[AI-assisted], reviewed by: Marko Marić