Skip to content

perf(media): cancel binary fetch downloads#614

Closed
JustYannicc wants to merge 121 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-media-fetch-binary-cancel
Closed

perf(media): cancel binary fetch downloads#614
JustYannicc wants to merge 121 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-media-fetch-binary-cancel

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Extended http-download-binary with an optional { requestId } payload while preserving httpDownloadBinary(url) callers.
  • Reused the existing HTTP cancel IPC path for binary downloads, including Node transport cancel, curl fallback cancel, redirect handoff, active request map cleanup, and bounded curl stderr in composed errors.
  • Wired extension fetch binary GETs and the axios binary shim to pass request IDs and cancel on abort/timeout.
  • Added focused lifecycle harnesses for binary cancellation, active request map cleanup, URL-only compatibility, and axios timeout cleanup.

Why

Binary GETs could outlive renderer aborts/timeouts and keep buffering in main after the renderer had already stopped waiting. The text fetch proxy already had request IDs and cancellation; the binary transport needed the same behavior-preserving lifecycle path.

Compatibility impact

  • Existing window.electron.httpDownloadBinary(url) and Raycast-style binary download callers continue to work.
  • Binary return shape remains a full Uint8Array; no public streaming API was introduced.
  • Redirects, headers, curl fallback, axios arraybuffer/stream behavior, and extension-observable response semantics are preserved.

How tested

  • node scripts/test-extension-fetch-proxy-abort.mjs
  • node scripts/test-http-download-binary-cancel.mjs
  • node scripts/test-camera-capture-single-encode.mjs
  • node scripts/test-cloud-media-buffering.mjs
  • node scripts/test-http-response-decode-async.mjs
  • node scripts/test-use-fetch-stale-runs.mjs && node scripts/test-raycast-ai-abort-listeners.mjs
  • node scripts/check-package-manager-parity.mjs
  • ./node_modules/.bin/tsc -p tsconfig.main.json --noEmit --pretty false && ./node_modules/.bin/tsc -p tsconfig.renderer.json --noEmit --pretty false
  • Codex LSP diagnostics: no errors for src/main/main.ts, src/main/preload.ts, src/renderer/src/extension-fetch-bridge.ts, src/renderer/src/ExtensionView.tsx, and src/renderer/types/electron.d.ts.

Performance evidence

  • Before: renderer-side timeout/abort could leave http-download-binary running in main, retaining chunk buffers until completion/error.
  • After: canceling by request ID destroys the active Node request or curl child, clears retained chunks, deletes the active request map entry in finally, and clears axios timeout/abort listeners.
  • Existing cloud media buffering harness remains green and still reports streaming upload/TTS paths avoiding full body/audio concatenation.

Stack validation

Started from codex/perf-wave4-integrated-stack-20260705 at exact SHA ac90ce403aeddab98d0a1b245afce268c48b8bfd; implementation branch is codex/perf-media-fetch-binary-cancel.

Replaces

Replaces the uncancelable binary download finding from the wave5 media fetch/binary transport audit. Left camera capture and cloud STT/TTS media buffering paths unchanged after validation because their existing focused harnesses stayed green.

(cherry picked from commit 83c2a89)
(cherry picked from commit 0a7560b)
# Conflicts:
#	src/renderer/src/raycast-api/hooks/use-cached-promise.ts
…launcher surfaces

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime-renderers.tsx
#	src/renderer/src/raycast-api/list-runtime.tsx
…IO stalls

# Conflicts:
#	src/renderer/src/CameraExtension.tsx
# Conflicts:
#	src/renderer/src/raycast-api/list-runtime.tsx
…resh overhead

# Conflicts:
#	scripts/bench-script-command-discovery.mjs
#	scripts/benchmark-file-search-delete-batch.mjs
#	scripts/lib/script-command-runner-harness.mjs
#	scripts/lib/ts-import.mjs
#	scripts/test-file-search-delete-batch.mjs
#	scripts/test-script-command-runner.mjs
#	src/main/file-search-index.ts
#	src/main/main.ts
…hurn

# Conflicts:
#	scripts/lib/script-command-runner-harness.mjs
#	scripts/lib/ts-import.mjs
#	scripts/test-extension-lifecycle-sandbox.mjs
#	scripts/test-script-command-runner.mjs
#	src/main/main.ts
#	src/renderer/src/ExtensionView.tsx
… hot paths

# Conflicts:
#	scripts/test-use-frecency-sorting.mjs
#	src/renderer/src/raycast-api/form-runtime.tsx
#	src/renderer/src/raycast-api/grid-runtime-hooks.ts
#	src/renderer/src/raycast-api/grid-runtime-items.tsx
#	src/renderer/src/raycast-api/hooks/use-frecency-sorting.ts
# Conflicts:
#	.github/workflows/project-checks.yml
#	package.json
#	scripts/file-search-perf-harness.mjs
#	scripts/test-browser-search-performance.mjs
#	scripts/test-file-search-perf-harness.mjs
#	scripts/test-root-search-perf.mjs
#	src/renderer/src/CameraExtension.tsx
#	src/renderer/src/hooks/useBrowserSearch.ts
#	src/renderer/src/raycast-api/list-runtime.tsx
…cle and media fixes

# Conflicts:
#	scripts/lib/ts-import.mjs
#	scripts/measure-extension-bundle-cache.mjs
#	src/main/commands.ts
#	src/main/extension-runner.ts
#	src/main/main.ts
#	src/renderer/src/ExtensionView.tsx
#	src/renderer/src/raycast-api/grid-runtime-hooks.ts
#	src/renderer/src/raycast-api/list-runtime-hooks.ts
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by the consolidated runtime/lifecycle/media PR: #622

@JustYannicc JustYannicc closed this Jul 5, 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