Skip to content

kraken: allow cancelling install/update operations#3857

Open
nicoschmdt wants to merge 2 commits intobluerobotics:masterfrom
nicoschmdt:stop-install
Open

kraken: allow cancelling install/update operations#3857
nicoschmdt wants to merge 2 commits intobluerobotics:masterfrom
nicoschmdt:stop-install

Conversation

@nicoschmdt
Copy link
Contributor

@nicoschmdt nicoschmdt commented Mar 26, 2026

fix: #3631

since we intend to move away from FastAPI and into zenoh I focused the operation cancellation handling mostly on the frontend code.

Summary by Sourcery

Add frontend and backend support for cancelling ongoing extension install and update operations, including proper rollback and UI feedback.

New Features:

  • Allow users to cancel ongoing extension installs, updates, and installs from file via the pull progress dialog.
  • Support abortable extension install, update, and finalize API calls in the frontend using AbortController and axios cancellation.
  • Expose an API to uninstall a specific extension version by identifier and tag.

Bug Fixes:

  • Prevent stale install/update state and network activity by aborting any in-flight operation when the ExtensionManager view is destroyed.

Enhancements:

  • Ensure extension update/install completion and error handling are centralized, with consistent alert and notification behavior.
  • Enable updating extensions without automatically enabling them on the backend via a configurable should_enable flag.
  • Add optional cancellation controls to the pull progress UI component.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 26, 2026

Reviewer's Guide

Implements cancellable install/update/finalize operations for Kraken extensions by wiring AbortController-based cancellation through the Vue frontend, Axios requests, and backend extension update/install semantics, while refining version handling and error reporting.

Sequence diagram for cancellable extension install operation

sequenceDiagram
    actor User
    participant ExtensionManagerView
    participant PullProgress
    participant KrakenManager
    participant Axios
    participant KrakenAPIv2
    participant ExtensionService

    User->>ExtensionManagerView: clickInstall(extension)
    ExtensionManagerView->>ExtensionManagerView: beginInstallOperation()
    note over ExtensionManagerView: Create AbortController and store as active_abort_controller
    ExtensionManagerView->>KrakenManager: installExtension(extension, progressHandler, signal)
    KrakenManager->>Axios: back_axios(POST /extension/install, signal)
    Axios->>KrakenAPIv2: HTTP POST /extension/install (stream)
    KrakenAPIv2->>ExtensionService: extension.install(clear_remaining_tags, atomic, should_enable=True)
    ExtensionService-->>KrakenAPIv2: progress chunks
    KrakenAPIv2-->>Axios: progress chunks
    Axios-->>ExtensionManagerView: onDownloadProgress events
    ExtensionManagerView->>ExtensionManagerView: handleDownloadProgress(event, tracker)

    User->>PullProgress: clickCancel()
    PullProgress-->>ExtensionManagerView: cancel
    ExtensionManagerView->>ExtensionManagerView: cancelInstallOperation()
    ExtensionManagerView->>ExtensionManagerView: active_abort_controller.abort()
    ExtensionManagerView->>Axios: abort via signal
    Axios-->>ExtensionManagerView: cancellationError (axios.isCancel)

    alt cancellation
        ExtensionManagerView->>KrakenManager: uninstallExtension(extension.identifier)
        KrakenManager->>Axios: back_axios(DELETE /extension/{identifier})
        Axios->>KrakenAPIv2: HTTP DELETE /extension/{identifier}
        KrakenAPIv2->>ExtensionService: extension.uninstall()
        ExtensionService-->>KrakenAPIv2: uninstall ok
        KrakenAPIv2-->>Axios: 202 Accepted
        Axios-->>ExtensionManagerView: uninstall ok
        ExtensionManagerView->>ExtensionManagerView: notifier.pushInfo(EXTENSION_INSTALL_CANCELLED)
    end

    ExtensionManagerView->>ExtensionManagerView: finishInstallOperation()
    note over ExtensionManagerView: active_abort_controller = null
    ExtensionManagerView->>ExtensionManagerView: clearInstallingState()
    ExtensionManagerView->>ExtensionManagerView: resetPullOutput()
    ExtensionManagerView->>ExtensionManagerView: fetchInstalledExtensions()
Loading

Sequence diagram for cancellable extension update with version swap

sequenceDiagram
    actor User
    participant ExtensionManagerView
    participant KrakenManager
    participant Axios
    participant KrakenAPIv2
    participant ExtensionService

    User->>ExtensionManagerView: clickUpdate(extension, newTag)
    ExtensionManagerView->>ExtensionManagerView: beginInstallOperation()
    ExtensionManagerView->>KrakenManager: updateExtensionToVersion(identifier, newTag, progressHandler, signal)
    KrakenManager->>Axios: back_axios(PUT /extension/{identifier}/{newTag}, params purge=false, should_enable=false, signal)
    Axios->>KrakenAPIv2: HTTP PUT /extension/{identifier}/{tag}?purge=false&should_enable=false
    KrakenAPIv2->>ExtensionService: extension.update(clear_remaining_tags=False, should_enable=False)
    ExtensionService->>ExtensionService: install(clear_remaining_tags=False, atomic=False, should_enable=False)
    ExtensionService->>ExtensionService: _create_extension_settings(should_enable=False)
    ExtensionService-->>KrakenAPIv2: progress chunks

    alt user cancels
        User->>ExtensionManagerView: cancel via PullProgress
        ExtensionManagerView->>ExtensionManagerView: cancelInstallOperation()
        ExtensionManagerView->>Axios: abort via signal
        Axios-->>ExtensionManagerView: cancellationError (axios.isCancel)
        ExtensionManagerView->>ExtensionManagerView: swapExtensionVersion(identifier, previousTag, newTag)
        ExtensionManagerView->>KrakenManager: enableExtension(identifier, previousTag)
        ExtensionManagerView->>KrakenManager: uninstallExtensionVersion(identifier, newTag)
    else success
        Axios-->>ExtensionManagerView: 200 OK
        ExtensionManagerView->>ExtensionManagerView: notifier.pushSuccess(EXTENSION_UPDATE_SUCCESS)
        ExtensionManagerView->>ExtensionManagerView: swapExtensionVersion(identifier, newTag, previousTag)
        ExtensionManagerView->>KrakenManager: enableExtension(identifier, newTag)
        ExtensionManagerView->>KrakenManager: uninstallExtensionVersion(identifier, previousTag)
    end

    ExtensionManagerView->>ExtensionManagerView: finishInstallOperation()
Loading

Class diagram for updated Kraken extension install/update behavior

classDiagram
    class ExtensionSettings {
        +str identifier
        +str name
        +str docker
        +str tag
        +Any permissions
        +bool enabled
        +Any user_permissions
    }

    class Extension {
        +str identifier
        +str tag
        +Any source
        +Any unique_entry
        +Any lock(key)
        +Any unlock(key)
        +async _disable_running_extension() Optional_Extension
        +_create_extension_settings(should_enable bool) ExtensionSettings
        +async install(clear_remaining_tags bool, atomic bool, should_enable bool) AsyncGenerator_bytes_None
        +async update(clear_remaining_tags bool, should_enable bool) AsyncGenerator_bytes_None
        +async uninstall() None
        +async _clear_remaining_tags() None
    }

    class ExtensionRouterV2 {
        +async update_to_tag(identifier str, tag str, purge bool, should_enable bool) Response
    }

    ExtensionSettings <.. Extension : creates
    Extension <.. ExtensionRouterV2 : used_by

    class KrakenManager {
        +installExtension(extension InstalledExtensionData, progressHandler Function, signal AbortSignal) Promise_void
        +updateExtensionToVersion(identifier str, version str, progressHandler Function, signal AbortSignal) Promise_void
        +finalizeExtension(extension InstalledExtensionData, tempTag str, progressHandler Function, signal AbortSignal) Promise_void
        +uninstallExtension(identifier str) Promise_void
        +uninstallExtensionVersion(identifier str, tag str) Promise_void
    }

    class ExtensionManagerView {
        +AbortController active_abort_controller
        +beginInstallOperation() AbortController
        +cancelInstallOperation() void
        +finishInstallOperation() void
        +showAlertError(error any) void
        +swapExtensionVersion(identifier str, enableTag str, removeTag str) Promise_void
        +getTracker(signal AbortSignal) PullTracker
    }

    ExtensionManagerView --> KrakenManager : calls
    ExtensionRouterV2 --> Extension : streams_to
    KrakenManager --> ExtensionRouterV2 : HTTP_calls
Loading

File-Level Changes

Change Details Files
Introduce frontend cancellation plumbing for extension install/update/finalize flows using AbortController and a cancelable progress dialog.
  • Add a cancel button to the PullProgress component and a cancelable prop to control its visibility
  • Track the active install/update operation with an AbortController, ensuring existing operations are aborted before starting new ones and on component destruction
  • Wire the cancel event from the progress dialog to abort in-flight Axios-backed operations
  • Refactor install/update/finalize calls to pass AbortSignal into PullTracker and Axios so progress and errors respect cancellation
core/frontend/src/views/ExtensionManagerView.vue
core/frontend/src/components/utils/PullProgress.vue
Extend KrakenManager HTTP helpers and backend API to support non-enabling updates and version-specific uninstall, enabling safe rollback on cancellation.
  • Update installExtension, updateExtensionToVersion, and finalizeExtension helpers to accept an optional AbortSignal and propagate it to Axios
  • Change updateExtensionToVersion to send purge=false and should_enable=false, decoupling image download from enabling
  • Add uninstallExtensionVersion helper and export for removing a specific extension tag
core/frontend/src/components/kraken/KrakenManager.ts
Adjust backend extension install/update behavior to parameterize enabling and propagate should_enable from the API layer.
  • Make _create_extension_settings accept a should_enable flag and use it when creating ExtensionSettings
  • Extend install and update methods to accept should_enable and pass it through to _create_extension_settings
  • Update the v2 update_to_tag API to accept a should_enable query parameter and forward it into Extension.update
core/services/kraken/extension/extension.py
core/services/kraken/api/v2/routers/extension.py
Improve UX on cancellation and failures with clearer error surfacing and rollback behavior.
  • Centralize error display into showAlertError and reuse it from trackers and install/update paths
  • On cancelled installs/updates/finalize-from-file, perform rollback by uninstalling the partially installed extension or swapping back to the previous version when appropriate
  • Gate cleanup/fetchInstalledExtensions calls on the active AbortController instance to avoid racing multiple overlapping operations
core/frontend/src/views/ExtensionManagerView.vue

Assessment against linked issues

Issue Objective Addressed Explanation
#3631 Provide a visible cancel control in the UI while an extension install/update is in progress.
#3631 Implement functional cancellation of extension install/update operations so that clicking cancel aborts the ongoing operation and cleans up frontend state.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new uninstallExtensionVersion helper calls DELETE /extension/${identifier}/${tag}, but there is no corresponding v2 route added in extension.py; if this endpoint doesn’t already exist elsewhere, this will consistently 404 and should either be implemented or the URL adjusted to an existing route.
  • In finalizeExtensionUpload, the axios.isCancel branch always resets install_from_file_phase to 'ready' and clears install_from_file_status_text before checking whether controller === this.active_abort_controller; this can cause a stale controller’s cancellation to reset the UI during a new operation, so consider moving the UI reset inside the controller === this.active_abort_controller check.
  • The PullProgress dialog is always rendered as cancelable from ExtensionManagerView even when there is no active abortable operation; tying cancelable to !!active_abort_controller would prevent showing a cancel button that can’t actually affect any in-flight request.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `uninstallExtensionVersion` helper calls `DELETE /extension/${identifier}/${tag}`, but there is no corresponding v2 route added in `extension.py`; if this endpoint doesn’t already exist elsewhere, this will consistently 404 and should either be implemented or the URL adjusted to an existing route.
- In `finalizeExtensionUpload`, the `axios.isCancel` branch always resets `install_from_file_phase` to `'ready'` and clears `install_from_file_status_text` before checking whether `controller === this.active_abort_controller`; this can cause a stale controller’s cancellation to reset the UI during a new operation, so consider moving the UI reset inside the `controller === this.active_abort_controller` check.
- The `PullProgress` dialog is always rendered as `cancelable` from `ExtensionManagerView` even when there is no active abortable operation; tying `cancelable` to `!!active_abort_controller` would prevent showing a cancel button that can’t actually affect any in-flight request.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Add cancel button when installing extensions

1 participant