Skip to content

fix(downloads): delete downloads an administrator revoked - #673

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/531-delete-revoked-downloads
Oct 24, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/531-delete-revoked-downloads

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #531
Validation tasks: unblocks #329 C3

When an administrator revokes a download, the Android phone app keeps the copy. The server lists the entry as revoked and reports revoked_removes_local: true, but the app keeps the file in shared storage, shows the row as "Ready", plays it, and never confirms the delete. The user manual says the app deletes revoked downloads the next time it connects, and docs/downloads-api.md §9.3 in silo-server asks clients to do this.

This change makes the app delete a revoked download's local copy and confirm the delete with the server. It covers only the revoked-entry half of #531; the prepare_again half stays open there.

Approach

  • DownloadsRepository.refresh checks every registry read for revoked entries, including reads from the background status worker and item detail. When the capability reports revoked_removes_local (fetched if not yet known), it writes the existing durable delete tombstone, hides the row, deletes the local copy, and only then sends the DELETE. If the local delete fails, the server entry is kept and the next read retries; the tombstone replay skips these entries, so the server never records a removal that did not happen.
  • A new RevokedDownloadCleanupPort lets shared code ask the phone app to stop the transfer and delete the media file, offline assets and saved record under the slot lock. The TV app keeps no downloads and uses a no-op.
  • The Downloads tab re-reads saved downloads after a refresh or when another screen removes one, and hides any saved download with a pending delete, so a revoked copy is never shown as playable.
  • A queued transfer for a row that becomes revoked stops instead of continuing.
  • Without the flag (older servers), behaviour is unchanged.

The iOS app has the same gap; Silo-Server/silo-apple#716 tracks it and a separate pull request fixes it there.

Validation

  • ./scripts/test-check-build-supply-chain.sh, ./scripts/check-build-supply-chain.sh: pass.
  • ./gradlew testDebugUnitTest: 908 tests, 1 failure, ReflowStyleTest > line height flows from settings, which also fails on main (confirmed on main at 5e19a58). New repository tests cover the flag check, cleanup before DELETE, the tombstone, and a failed local delete.
  • Lint (:android-shared:lintDebug :androidApp:lintDebug :androidTvApp:lintDebug :androidApp:lintVitalRelease :androidTvApp:lintVitalRelease): pass. :androidApp:assembleDebug and :androidTvApp:assembleDebug: pass.
  • On a local Silo server (main) with a synthetic library, on a Pixel 7 and a Pixel Tablet emulator (Android 16):
    • Before: after an administrator revoked a completed download, opening Downloads read the registry (entry revoked) and kept the file and the "Ready" row (twice on the phone, once on the tablet).
    • After: opening Downloads deleted the file, sent the DELETE (204) and removed the row; the server entry was gone. Repeated with a fresh download on the phone, and on the tablet.
    • The rest of the Downloads validation (download, offline playback, network cut and Range resume, profile isolation, quota message) was re-run on a build with this change and still passes.
  • The gate above ran on a tree that also contains the two other open Android download fixes from this validation.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/pr-673/

Surface and build: Pixel 7, Pixel Tablet and Pixel Fold emulators, Android 16. Before: main at 5e19a58. After: this branch. Each pair shows the Downloads tab after an administrator revoked the listed download.

  • Foldable: Pixel Fold emulator (Android 16), open and folded, on the evidence page.
  • Android TV: not affected; the TV app has no downloads.

Risks

A server that reports revoked_removes_local: true now causes the app to delete local files. Servers without the flag see no change. Deletion only follows an administrator's revoke and touches only that download's slot.

Item detail's offline playback reads the saved record directly; if local deletion keeps failing, it could still offer that copy while the Downloads tab hides it.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, Codex CLI (second reviewer)
  • Model(s): claude-opus-5-5 (implementation and review), gpt-6.1-sol (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: dual review of the final diff for correctness, standards and spec (Claude Opus 5.5 and GPT 6.1 Sol, medium effort), then a review of the fixes. Fixed: a revoked copy stayed playable from its saved record when local deletion failed; an open Downloads tab still showed a copy another screen had removed; the cleanup could cancel the status worker running it (and a second cancel path); transfer resolution did not check for revoked entries. Dismissed: two duplication suggestions where the existing helper behaves differently. Bot review follow-up (Kody): with an unknown capability, a tombstone could replay the DELETE while the local copy remained; fixed with a new test, dual-reviewed again with no findings.

When the server reports revoked_removes_local, every registry read now
handles entries that come back revoked: it queues a durable delete
tombstone, hides the row, removes the media file, offline assets and
metadata row, and only then sends DELETE /api/v2/downloads/{id}. If the
local copy cannot be removed, the server entry stays and the next read
retries. Without the flag, behaviour is unchanged.

The Downloads tab re-reads saved downloads when a refresh elsewhere
removes one, and hides any download with a pending delete, so a revoked
copy is never offered for playback. An older queued transfer stops when
its registry row is revoked.

Refs Silo-Server#531
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 23, 2026
@silo-kody

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08f1df7a-f850-4f52-b41f-7c6b32fb0454
📥 Commits

Reviewing files that changed from the base of the PR and between 5e19a58 and 848e60e.

📒 Files selected for processing: 10
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/DownloadStatusWorker.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/DownloadWorker.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/RevokedDownloadCleanup.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/di/AndroidModule.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/downloads/DownloadsViewModel.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/di/RepositoryModule.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/download/DownloadModels.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/repository/DownloadsRepository.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/repository/port/RevokedDownloadCleanupPort.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/repository/DownloadsRepositoryOfflineDeleteTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The repository now handles revoked downloads according to server capability. When local removal is required, it coordinates transfer cancellation, local cleanup, and durable server deletion. The downloads view reloads sidecar metadata after successful refreshes.

Changes: Revoked Download Handling

Layer / File(s) Summary
Repository reconciliation and deletion
shared/src/commonMain/kotlin/org/siloserver/silo/model/download/DownloadModels.kt, shared/src/commonMain/kotlin/org/siloserver/silo/repository/port/RevokedDownloadCleanupPort.kt, shared/src/commonMain/kotlin/org/siloserver/silo/repository/DownloadsRepository.kt, shared/src/commonTest/kotlin/org/siloserver/silo/repository/DownloadsRepositoryOfflineDeleteTest.kt
DownloadCapability now includes revokedRemovesLocal. When enabled, refresh queues a durable deletion, marks the record pending deletion, and attempts local cleanup before confirming server deletion. Tests cover cleanup failures, deletion replay, and the disabled capability.
Android local-copy cleanup
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/DownloadWorker.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/RevokedDownloadCleanup.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/downloads/DownloadStatusWorker.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/di/AndroidModule.kt, shared/src/commonMain/kotlin/org/siloserver/silo/di/RepositoryModule.kt
Android cleanup waits for transfer cancellation before deleting stored bytes and sidecar metadata. The Android module provides the cleanup port, and the status worker runs reconciliation refreshes in a non-cancellable context.
Download sections after refresh
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/downloads/DownloadsViewModel.kt
Successful initial and manual refreshes reload sidecar metadata and republish sections. The ViewModel detects records that disappear and excludes pending-deletion records from sidecar metadata.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DownloadsRepository
  participant RevokedDownloadCleanup
  participant DownloadWorker
  participant DownloadStorage
  participant DownloadsAPI
  DownloadsRepository->>RevokedDownloadCleanup: removeLocalCopy
  RevokedDownloadCleanup->>DownloadWorker: cancelTransferAndAwait
  RevokedDownloadCleanup->>DownloadStorage: delete media and sidecar
  DownloadsRepository->>DownloadsAPI: confirm deletion after successful cleanup
Loading

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 848e6

The available evidence does not establish a new reason to block merging. Confirm the status of the previously reported deletion-replay issue before release.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: deleting downloads revoked by an administrator. The wording is slightly awkward but remains specific and understandable.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description clearly explains the revoked-download cleanup changes, deletion flow, retry behavior, affected apps, validation results, and known scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@macroscopeapp

macroscopeapp Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The revoked-download row disappearing from Downloads (DownloadsViewModel.kt / DownloadsRepository.kt) reaches the Android phone, tablet, and foldable app. The Evidence URL is present, but the PR says foldable captures were not taken; “no layout” does not exclude this list-content change from folded or open foldables. The linked evidence page should show before/after views of the same Downloads screen and data on a phone, tablet, and a foldable both folded and open; include the missing foldable states or explain why this change cannot reach them.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added api-v2 API v2 / Huma program (epic silo-server#135) bug Something isn't working impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0 labels Oct 23, 2026
Comment on lines +162 to +163
// Revoked entries were settled above, and only once their local copy is gone.
if (pending.recordId in revoked) continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Premature server deletion occurs because revocation cleanup writes an ordinary deletion tombstone before removing local bytes, and scoped reconciliation skips it only while the current refresh includes pending.recordId in revoked; after local cleanup fails and the application restarts, a failed capability lookup causes removeRevokedEntries to return an empty set, allowing reconciliation to delete the server entry while the local file remains. Persist a local-cleanup-pending phase and block server-delete replay until local cleanup succeeds.

Prompt for LLM

File shared/src/commonMain/kotlin/org/siloserver/silo/repository/DownloadsRepository.kt:

Line 162 to 163:

Premature server deletion occurs because revocation cleanup writes an ordinary deletion tombstone before removing local bytes, and scoped reconciliation skips it only while the current refresh includes `pending.recordId` in `revoked`; after local cleanup fails and the application restarts, a failed capability lookup causes `removeRevokedEntries` to return an empty set, allowing reconciliation to delete the server entry while the local file remains. Persist a local-cleanup-pending phase and block server-delete replay until local cleanup succeeds.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e85fc8d: when the capability cannot be read, revoked rows stay hidden and their tombstones are not replayed, so the server entry stays until a later read can clean up locally first. A new repository test covers the restart case (failed local delete, then a capability fetch that fails) and fails without the fix. When the capability is known, behaviour is unchanged.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Based on your description, e85fc8d addresses the reported failure path: a failed capability lookup no longer permits tombstone replay before local cleanup succeeds, including after a restart.

The regression test covers the specific sequence raised in the suggestion. A persisted cleanup phase is not necessary for this scenario if the revised logic reliably blocks replay when the capability is unknown. I consider the original concern addressed as described; I haven’t independently inspected the commit.

@silo-kody

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Rhainland

Copy link
Copy Markdown
Contributor Author

Evidence is published at https://evidence.siloserver.org/r/silo-android/pr-673/: before and after on a Pixel 7, a Pixel Tablet and a Pixel Fold (open and folded). Android TV has no Downloads.

@Quick104
Quick104 merged commit 79eda0a into Silo-Server:main Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma program (epic silo-server#135) bug Something isn't working impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0 size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants