Skip to content

perf(ai): clean up stream abort listeners#538

Closed
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-ai-stream-abort-listeners-pr
Closed

perf(ai): clean up stream abort listeners#538
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-ai-stream-abort-listeners-pr

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Route Raycast AI.ask() stream completion, stream error, electron.aiAsk rejection, and caller abort through one cleanup helper.
  • Track the caller AbortSignal listener per active stream so terminal paths detach the listener before deleting _activeStreams.
  • Add a focused node:test harness for retained abort-listener counts across success, stream error, aiAsk rejection, and explicit abort.

Why

Extensions can reuse a long-lived AbortSignal for 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

  • No API behavior removed.
  • AbortSignal cancellation still calls electron.aiCancel and rejects with Request aborted.
  • Successful and failed streams resolve/reject as before, with listener cleanup added.

How tested

  • Before fix, the new harness reported retained listener counts on all terminal paths: active=1, added=1, removed=0.
  • After fix: active=0, added=1, removed=1 for success, stream error, aiAsk rejection, and explicit abort.
  • node --test scripts/test-raycast-ai-abort-listeners.mjs
  • node --test scripts/test-use-ai-stream-batching.mjs scripts/test-raycast-ai-abort-listeners.mjs on the integration stack before the clean cherry-pick.
  • ./node_modules/.bin/vite build
  • ./node_modules/.bin/tsc -p tsconfig.renderer.json --noEmit --pretty false still fails on the clean origin/main baseline with unrelated existing renderer errors.

Stack validation

@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by #556, which consolidates this AI/native media performance batch.

@JustYannicc JustYannicc closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant