perf(ai): clean up stream abort listeners#538
Closed
JustYannicc wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
|
Superseded by #556, which consolidates this AI/native media performance batch. |
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.
What changed
AI.ask()stream completion, stream error,electron.aiAskrejection, and caller abort through one cleanup helper.AbortSignallistener per active stream so terminal paths detach the listener before deleting_activeStreams.node:testharness for retained abort-listener counts across success, stream error,aiAskrejection, and explicit abort.Why
Extensions can reuse a long-lived
AbortSignalfor many successful AI asks. The stream map was cleared on terminal paths, but the inline abort listener remained attached to the caller signal, retaining the request closure until that signal was eventually aborted.I checked a bounded timeout/finalizer for never-finished renderer requests. This PR keeps behavior intact by not adding a new request timeout; it centralizes cleanup for every existing terminal path and leaves long-running streams unaffected.
Compatibility impact
AbortSignalcancellation still callselectron.aiCanceland rejects withRequest aborted.How tested
active=1, added=1, removed=0.active=0, added=1, removed=1for success, stream error,aiAskrejection, and explicit abort.node --test scripts/test-raycast-ai-abort-listeners.mjsnode --test scripts/test-use-ai-stream-batching.mjs scripts/test-raycast-ai-abort-listeners.mjson the integration stack before the clean cherry-pick../node_modules/.bin/vite build./node_modules/.bin/tsc -p tsconfig.renderer.json --noEmit --pretty falsestill fails on the cleanorigin/mainbaseline with unrelated existing renderer errors.Stack validation
origin/main; only this fix commit is included.