Skip to content

feat: download stop logic on component unmount#16

Open
harryfrzz wants to merge 10 commits intocactus-compute:mainfrom
harryfrzz:main
Open

feat: download stop logic on component unmount#16
harryfrzz wants to merge 10 commits intocactus-compute:mainfrom
harryfrzz:main

Conversation

@harryfrzz
Copy link

No description provided.

Copilot AI review requested due to automatic review settings December 3, 2025 08:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds functionality to stop model downloads when components unmount, preventing resource leaks and unnecessary network activity. The implementation adds a stopDownload method across the TypeScript API, native iOS/Android implementations, and C++ bridge code.

Key Changes

  • Added stopDownload method to CactusFileSystem, CactusLM, and CactusSTT classes
  • Implemented cleanup logic in useCactusLM and useCactusSTT hooks to call stopDownload on unmount
  • Updated native iOS (Swift) and Android (Kotlin) implementations to cancel active downloads
  • Dependency updates in yarn.lock (various package version bumps)

Reviewed changes

Copilot reviewed 15 out of 42 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/specs/CactusFileSystem.nitro.ts Added stopDownload method to FileSystem spec
src/native/CactusFileSystem.ts Exposed stopDownload wrapper method
src/classes/CactusLM.ts Added stopDownload method to CactusLM class
src/classes/CactusSTT.ts Added stopDownload method to CactusSTT class
src/hooks/useCactusLM.ts Added cleanup call to stopDownload on unmount
src/hooks/useCactusSTT.ts Added cleanup call to stopDownload on unmount
ios/HybridCactusFileSystem.swift iOS implementation with URLSession task cancellation (contains syntax error)
android/.../HybridCactusFileSystem.kt Android implementation with connection cancellation (has race condition)
nitrogen/generated/**/* Auto-generated bridge code for new method
cpp/HybridCactusUtil.* Updated to use std::variant instead of std::optional for null handling
yarn.lock Dependency updates (various packages)
example/src/PerformanceScreen.tsx Example usage of stopDownload in cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +175 to +180
override fun stopDownload(model: String): Promise<Unit> {
return Promise.async {
if (activeConnection != null) {
isCancelled = true
activeConnection?.disconnect()
activeConnection = null
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition: The activeConnection and isCancelled variables are marked @Volatile but are not properly synchronized. The check-then-act pattern in stopDownload (lines 177-180) is not atomic. Between checking activeConnection != null and calling disconnect(), another thread could set it to null. Consider using synchronized blocks or a lock to ensure thread safety.

Copilot uses AI. Check for mistakes.
}
}

private var activeTask: URLSessionDownloadTask?
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition: The activeTask property is not thread-safe. Multiple concurrent calls to downloadModel could overwrite each other's tasks, and stopDownload could cancel the wrong download. Consider using a dictionary keyed by model name to track multiple downloads, or add synchronization to prevent concurrent downloads of the same model.

Copilot uses AI. Check for mistakes.
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