Skip to content

fix(request): restore media status correctly when deleting requests#3064

Merged
fallenbagel merged 1 commit into
developfrom
fix/request-delete-media-status-restore
May 25, 2026
Merged

fix(request): restore media status correctly when deleting requests#3064
fallenbagel merged 1 commit into
developfrom
fix/request-delete-media-status-restore

Conversation

@fallenbagel
Copy link
Copy Markdown
Collaborator

@fallenbagel fallenbagel commented May 23, 2026

Description

When a movie is deleted from the media server, its status is set to DELETED and existing completed requests remain in the database. If a new request is then created for that media and subsequently that request is deleted, the media status would stay as PENDING/REQUESTED instead of reverting to DELETED. This happened because previously it counted all remaining requests including stale completed ones when deciding whether to reset the status, and always reset to UNKNOWN regardless of prior history.

The PR fixes this by narrowing that check to active requests only and restores to DELETED when completed requests exist (indicating the media was previously downloaded), or UNKNOWN when there is no prior history.

How Has This Been Tested?

  • Manually verified the full lifecycle:
    • created a request, marked it available, deleted it from the media server, re-requested it, then deleted that request and observed status correctly restored to DELETED.
  • Manually confirmed deleting the stale completed request after resets status to UNKNOWN
  • Also covered by supertest integration tests in server/routes/request.test.ts

Screenshots / Logs (if applicable)

Checklist:

  • I have read and followed the contribution guidelines.
  • Disclosed any use of AI (see our policy)
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • Successful build pnpm build
  • Translation keys pnpm i18n:extract
  • Database migration (if required)

Summary by CodeRabbit

  • Bug Fixes

    • Corrected media availability updates when requests are deleted, including proper restoration to Deleted or Unknown based on remaining requests and preserving Partial/Pending states when appropriate.
    • Ensures 4K-specific status is handled consistently alongside standard media status.
  • Tests

    • Added comprehensive tests covering deletion scenarios to validate media status restoration and prevention of incorrect resets.

Review Change Stack

@fallenbagel fallenbagel requested a review from Copilot May 23, 2026 08:19
@fallenbagel fallenbagel requested a review from a team as a code owner May 23, 2026 08:19
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

📝 Walkthrough

Walkthrough

Refactors subscriber logic to restore DELETED media status when prior completed requests exist; adds integration tests verifying status restoration and preservation across non-4k and 4k deletion scenarios.

Changes

Media Status Restoration on Request Deletion

Layer / File(s) Summary
Status recalculation on request removal
server/subscriber/MediaRequestSubscriber.ts
handleRemoveParentUpdate now derives hasActive and hasActive4k from fullMedia.requests, uses them to decide needsStatusUpdate/needs4kStatusUpdate, and sets cleanMedia.status/status4k to DELETED if prior completed requests existed, otherwise UNKNOWN.
Deleted-media request deletion tests
server/routes/request.test.ts
Adds seedDeletedMediaScenario helper and seven tests covering: restoring DELETED for stale completed requests (non-4k and 4k), resetting to UNKNOWN when all requests removed (non-4k and 4k), and preserving PENDING/PARTIALLY_AVAILABLE when other active or partially-available conditions apply.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • gauthier-th
  • 0xSysR3ll

Poem

🐰 I hopped through requests both stale and new,
I checked each scope — 4K and the regular view,
If past completions lingered, I said "DELETED" true,
Otherwise UNKNOWN was what I knew,
Tests confirm the hop — hooray, review is due!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: restoring media status correctly when deleting requests, which directly aligns with the core bug fix described in the PR objectives.
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 Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@seerr-automation-bot seerr-automation-bot added this to the v3.3.0 milestone May 23, 2026
Copy link
Copy Markdown
Contributor

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 adjusts request-deletion behavior so that when a request is deleted, the parent Media status is restored based on active requests only, and (when relevant) returns to DELETED if historical completed requests still exist—addressing incorrect status lingering after re-request/delete flows for deleted media.

Changes:

  • Update MediaRequestSubscriber.handleRemoveParentUpdate to consider only non-completed/non-declined requests as “active” when deciding whether to reset Media.status / status4k.
  • When resetting status, restore to DELETED if any completed requests exist for that quality tier; otherwise restore to UNKNOWN.
  • Add integration tests covering restoration to DELETED vs UNKNOWN and ensuring status is not reset when other active requests remain.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
server/subscriber/MediaRequestSubscriber.ts Refines request-removal status reset logic to ignore stale completed/declined requests and restore DELETED vs UNKNOWN based on completion history (also for 4K).
server/routes/request.test.ts Adds integration tests covering the reported lifecycle regression and expected status restoration behavior on request deletion.

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

Comment thread server/subscriber/MediaRequestSubscriber.ts Outdated
Comment thread server/subscriber/MediaRequestSubscriber.ts
Comment thread server/routes/request.test.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/subscriber/MediaRequestSubscriber.ts`:
- Around line 955-960: Rename the misnamed boolean hasActiveNonFk to
hasActiveNon4k to correctly indicate it's checking for non-4k requests and to
match the existing hasActive4k naming; update the declaration that uses
fullMedia.requests.some(...) and replace all usages/references of hasActiveNonFk
(e.g., the later conditional around line where hasActive4k is used) to the new
hasActiveNon4k identifier so compilation and intent remain consistent in
MediaRequestSubscriber's request-status logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec1980b8-5c8d-4b46-9174-34ff701462d5

📥 Commits

Reviewing files that changed from the base of the PR and between 32169d9 and 83009b2.

📒 Files selected for processing (2)
  • server/routes/request.test.ts
  • server/subscriber/MediaRequestSubscriber.ts

Comment thread server/subscriber/MediaRequestSubscriber.ts Outdated
Reset media status to DELETED (or UNKNOWN) when the last active request is removed, based on whether
completed requests exist
@fallenbagel fallenbagel force-pushed the fix/request-delete-media-status-restore branch from 83009b2 to cb20918 Compare May 23, 2026 08:31
Copy link
Copy Markdown
Member

@gauthier-th gauthier-th left a comment

Choose a reason for hiding this comment

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

Tests not reviewed

@fallenbagel fallenbagel enabled auto-merge (squash) May 25, 2026 18:27
@fallenbagel fallenbagel merged commit ff88d52 into develop May 25, 2026
20 of 21 checks passed
@fallenbagel fallenbagel deleted the fix/request-delete-media-status-restore branch May 25, 2026 20:31
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.

5 participants