Skip to content

fix(desktop-gpui): retry Instant start cleanup so failed starts never leave empty caps - #3089

Merged
richiemcilroy merged 9 commits into
mainfrom
fix/gpui-instant-start-cleanup
Oct 24, 2026
Merged

richiemcilroy merged 9 commits into
mainfrom
fix/gpui-instant-start-cleanup

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Instant mode creates its share link on the server before capture starts. When a start fails or is cancelled after that point, the app deletes the server video. That delete can be skipped or lost, and the user is left with an empty cap stuck at "Uploading 0%" in their library. Today that happens when:

  • the delete request fails once (offline, server error, timeout); it is never retried;
  • a newer start stops waiting on the previous discard after 5 seconds (apps/desktop-gpui/src/session.rs:809), and dropping that task aborts the delete mid-flight;
  • the start task panics, so the session never learns the video id;
  • the app quits or crashes during startup.

This adds a small cleanup journal for Instant videos whose recording never started, so the server copy is removed eventually.

flowchart TD
    A[Server creates Instant video] --> B["begin: journal entry, stage starting"]
    B --> C{Recording starts?}
    C -- yes --> D["started: entry removed"]
    C -- "start failed / cancelled" --> E[Delete server video]
    E -- ok --> F["resolved: entry removed"]
    E -- "error or aborted" --> G["abandon: entry due for retry"]
    C -- "crash, panic, quit" --> H["entry left from an earlier session, due after 30 min grace"]
    G --> S[Sweep at launch, then every 5 min]
    H --> S
    S --> J{Signed in to the same account and server?}
    J -- no --> W[Wait for a later sweep]
    J -- yes --> K{Local recording needs the video?}
    K -- yes --> L[Forget entry, keep video]
    K -- no --> M[Delete server video]
    M -- ok --> F
    M -- error --> N[Retry with backoff]
Loading

How it works

  • begin records the video right after the server creates it (apps/desktop-gpui/src/recording.rs:2132). started removes it the moment recording activates (apps/desktop-gpui/src/session.rs:918); a successful delete removes it too.
  • A failed or cancelled start marks the entry abandoned (apps/desktop-gpui/src/recording.rs:2169, apps/desktop-gpui/src/session.rs:958). Entries left by an earlier app session count as interrupted, after a 30 minute grace period so another running copy of the app can finish its own start.
  • The sweep (apps/desktop-gpui/src/upload/instant_cleanup.rs:470) deletes due entries with backoff. Before deleting, it requires (locally_protected, apps/desktop-gpui/src/upload/instant_cleanup.rs:409):
    • the same signed-in account and server that created the video;
    • no local recording that points at the video and is finished, failed, unreadable, or (for interrupted starts) holds any recorded media;
    • for interrupted starts, the start's own folder exists, can be read and belongs to this video. Capture creates the folder after the server video and a later start can reuse its reserved name, so a missing, unreadable or reused folder keeps the video (it may have been moved with its media or sit on an unmounted drive);
    • the entry is still in the journal right before the delete.
  • Once the server verifies an upload, the upload queue clears that video's entry (apps/desktop-gpui/src/upload/queue.rs). If it cannot, the local copy is kept even when "delete after upload" is on, so a later sweep can never find an uploaded video without its folder.
  • When the local check is unsure, the video is kept and the entry dropped. Entries older than 14 days are dropped without a delete. A corrupt or oversized journal reads as empty; a journal that exists but cannot be read fails the operation instead, so nothing mistakes it for an empty one.
  • Linux is unchanged: its startup cleanup deliberately preserves files when cleanup is unconfirmed, so the journal is a no-op there.

Start, stop, discard, restart and delete behave as before. The journal only retries deletes the app was already making.

Visibility

The startup delete now sends a reason and, for failed starts, a coarse cause:

DELETE /api/desktop/video/delete?videoId=…&reason=start-failed&cause=microphone
  • reasons: start-failed, start-cancelled, interrupted
  • causes: microphone, camera, capture, permission, storage, account, network, other
  • No error text leaves the machine, and nothing is added when anonymous telemetry is turned off.
  • The app also adds gpui to X-Cap-Desktop-Features.

The web delete endpoint (apps/web/app/api/desktop/[...route]/video.ts:448) ignores unknown values, deletes exactly as before, and only after a successful delete records a desktop_instant_cleanup analytics event. Older servers ignore the extra query parameters, so the app works against any server version.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issue remains.

Summary

Adds a saved cleanup journal that retries deletes for Instant recordings that never started.

  • Unfinished Instant videos get another chance to be cleaned up.
  • Verified uploads stay on the computer if cleanup cannot be cleared.
  • The server records why the desktop removed an Instant video.

Reviews (7) · Last reviewed commit: "fix(desktop-gpui): keep a crashed start'..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cap-status Ready Ready Preview Oct 24, 2026 1:21pm UTC

@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

Comment thread apps/desktop-gpui/src/upload/instant_cleanup.rs Outdated
Comment thread apps/desktop-gpui/src/session.rs Outdated
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

Comment thread apps/desktop-gpui/src/upload.rs Outdated
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Capy found 1 potential issue (1 high).

Open in Capy

Comment thread apps/desktop-gpui/src/upload/instant_cleanup.rs
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Capy found 1 potential issue (1 medium).

View 1 other finding in Capy.

Open in Capy

Comment thread apps/desktop-gpui/src/upload/instant_cleanup.rs Outdated
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

Comment thread apps/desktop-gpui/src/upload/instant_cleanup.rs Outdated
Comment thread apps/desktop-gpui/src/upload/instant_cleanup.rs Outdated
… can be read, and never treat an unreadable journal as empty
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@richiemcilroy
richiemcilroy merged commit 916097f into main Oct 24, 2026
53 checks passed

This branch was successfully deployed

2 active deployments
Preview – cap-web — 714831eb Deployed Oct 24, 2026 by vercel[bot]
Preview – cap-status — 714831eb Deployed Oct 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant